Commit 5528fce5 authored by Himanshu Jaju's avatar Himanshu Jaju Committed by Commit Bot

Read attachments from introduction

Reads text and file attachments from introduction frame and appends
them to the share target.

Bug: 1085068
Change-Id: I0198a9edcfa5d8c7691514072c50577ff3d72428
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2320599
Commit-Queue: Himanshu Jaju <himanshujaju@chromium.org>
Reviewed-by: default avatarAlex Chau <alexchau@chromium.org>
Cr-Commit-Position: refs/heads/master@{#793136}
parent 616669a4
......@@ -3357,6 +3357,8 @@ static_library("browser") {
"nearby_sharing/text_attachment.h",
"nearby_sharing/transfer_metadata.cc",
"nearby_sharing/transfer_metadata.h",
"nearby_sharing/transfer_metadata_builder.cc",
"nearby_sharing/transfer_metadata_builder.h",
"nearby_sharing/transfer_update_callback.h",
"nearby_sharing/webrtc_signaling_messenger.cc",
"nearby_sharing/webrtc_signaling_messenger.h",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/nearby_sharing/fake_nearby_connection.h"
FakeNearbyConnection::FakeNearbyConnection() = default;
FakeNearbyConnection::~FakeNearbyConnection() = default;
void FakeNearbyConnection::Read(ReadCallback callback) {
callback_ = std::move(callback);
MaybeRunCallback();
}
void FakeNearbyConnection::Write(std::vector<uint8_t> bytes,
WriteCallback callback) {
NOTIMPLEMENTED();
}
void FakeNearbyConnection::Close() {
closed_ = true;
if (callback_)
std::move(callback_).Run(base::nullopt);
}
bool FakeNearbyConnection::IsClosed() const {
return closed_;
}
void FakeNearbyConnection::RegisterForDisconnection(
base::OnceClosure callback) {
NOTIMPLEMENTED();
}
void FakeNearbyConnection::AppendReadableData(std::vector<uint8_t> bytes) {
data_.push(std::move(bytes));
MaybeRunCallback();
}
void FakeNearbyConnection::MaybeRunCallback() {
if (!callback_ || data_.empty())
return;
auto item = std::move(data_.front());
data_.pop();
std::move(callback_).Run(std::move(item));
}
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_NEARBY_SHARING_FAKE_NEARBY_CONNECTION_H_
#define CHROME_BROWSER_NEARBY_SHARING_FAKE_NEARBY_CONNECTION_H_
#include <queue>
#include <vector>
#include "chrome/browser/nearby_sharing/nearby_connection.h"
class FakeNearbyConnection : public NearbyConnection {
public:
FakeNearbyConnection();
~FakeNearbyConnection() override;
void Read(ReadCallback callback) override;
void Write(std::vector<uint8_t> bytes, WriteCallback callback) override;
void Close() override;
bool IsClosed() const override;
void RegisterForDisconnection(base::OnceClosure callback) override;
void AppendReadableData(std::vector<uint8_t> bytes);
private:
void MaybeRunCallback();
bool closed_ = false;
ReadCallback callback_;
std::queue<std::vector<uint8_t>> data_;
};
#endif // CHROME_BROWSER_NEARBY_SHARING_FAKE_NEARBY_CONNECTION_H_
......@@ -10,23 +10,13 @@
#include "base/files/file_path.h"
#include "base/optional.h"
#include "chrome/browser/nearby_sharing/attachment.h"
#include "chrome/services/sharing/public/mojom/nearby_decoder_types.mojom.h"
// A single attachment to be sent by / received from a |ShareTarget|, can be
// either a file or text.
class FileAttachment : public Attachment {
public:
// Different types are used to offer richer experiences on Receiver side,
// mainly for: 1. displaying notification of attachment types, 2. opening
// different types with different apps. Remember to update Notifications,
// ShareTarget, etc once more types are introduced here.
enum class Type {
kUnknown,
kImage,
kVideo,
kApp,
kAudio,
kMaxValue = kAudio
};
using Type = sharing::mojom::FileMetadata::Type;
FileAttachment(std::string file_name,
Type type,
......
......@@ -4,15 +4,14 @@
#include "chrome/browser/nearby_sharing/incoming_frames_reader.h"
#include <queue>
#include <vector>
#include "base/run_loop.h"
#include "base/test/bind_test_util.h"
#include "base/time/time.h"
#include "chrome/browser/nearby_sharing/fake_nearby_connection.h"
#include "chrome/browser/nearby_sharing/mock_nearby_process_manager.h"
#include "chrome/browser/nearby_sharing/mock_nearby_sharing_decoder.h"
#include "chrome/browser/nearby_sharing/nearby_connection.h"
#include "chrome/services/sharing/public/proto/wire_format.pb.h"
#include "chrome/test/base/testing_profile.h"
#include "content/public/test/browser_task_environment.h"
......@@ -56,51 +55,6 @@ void ExpectIntroductionFrame(
} // namespace
class FakeNearbyConnection : public NearbyConnection {
public:
FakeNearbyConnection() = default;
~FakeNearbyConnection() override = default;
void Read(ReadCallback callback) override {
callback_ = std::move(callback);
MaybeRunCallback();
}
void Write(std::vector<uint8_t> bytes, WriteCallback callback) override {
NOTIMPLEMENTED();
}
void Close() override {
closed_ = true;
if (callback_)
std::move(callback_).Run(base::nullopt);
}
bool IsClosed() const override { return closed_; }
void RegisterForDisconnection(base::OnceClosure callback) override {
NOTIMPLEMENTED();
}
void AppendReadableData(std::vector<uint8_t> bytes) {
data_.push(std::move(bytes));
MaybeRunCallback();
}
private:
void MaybeRunCallback() {
if (!callback_ || data_.empty())
return;
auto item = std::move(data_.front());
data_.pop();
std::move(callback_).Run(std::move(item));
}
bool closed_ = false;
ReadCallback callback_;
std::queue<std::vector<uint8_t>> data_;
};
class IncomingFramesReaderTest : public testing::Test {
public:
IncomingFramesReaderTest()
......
......@@ -59,15 +59,16 @@ KeyedService* NearbySharingServiceFactory::BuildServiceInstanceFor(
return nullptr;
}
NearbyProcessManager& process_manager = NearbyProcessManager::GetInstance();
Profile* profile = Profile::FromBrowserContext(context);
PrefService* pref_service = profile->GetPrefs();
auto nearby_connections_manager =
std::make_unique<NearbyConnectionsManagerImpl>(
&NearbyProcessManager::GetInstance(), profile);
std::make_unique<NearbyConnectionsManagerImpl>(&process_manager, profile);
NS_LOG(VERBOSE) << __func__ << ": creating NearbySharingService.";
return new NearbySharingServiceImpl(pref_service, profile,
std::move(nearby_connections_manager));
std::move(nearby_connections_manager),
&process_manager);
}
content::BrowserContext* NearbySharingServiceFactory::GetBrowserContextToUse(
......
......@@ -27,8 +27,10 @@
#include "chrome/browser/nearby_sharing/nearby_sharing_service.h"
#include "chrome/browser/nearby_sharing/outgoing_share_target_info.h"
#include "chrome/browser/nearby_sharing/share_target.h"
#include "chrome/browser/nearby_sharing/transfer_metadata.h"
#include "chrome/browser/ui/webui/nearby_share/public/mojom/nearby_share_settings.mojom.h"
#include "chrome/services/sharing/public/mojom/nearby_decoder_types.mojom.h"
#include "chrome/services/sharing/public/proto/wire_format.pb.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/prefs/pref_change_registrar.h"
......@@ -53,7 +55,8 @@ class NearbySharingServiceImpl
explicit NearbySharingServiceImpl(
PrefService* prefs,
Profile* profile,
std::unique_ptr<NearbyConnectionsManager> nearby_connections_manager);
std::unique_ptr<NearbyConnectionsManager> nearby_connections_manager,
NearbyProcessManager* process_manager);
~NearbySharingServiceImpl() override;
// NearbySharingService:
......@@ -127,25 +130,33 @@ class NearbySharingServiceImpl
void InvalidateReceiveSurfaceState();
void InvalidateAdvertisingState();
void StopAdvertising();
void WriteResponse(
NearbyConnection& connection,
sharing::nearby::ConnectionResponseFrame::Status reponse_status);
void Fail(const ShareTarget& share_target, TransferMetadata::Status status);
void OnIncomingTransferUpdate(const ShareTarget& share_target,
TransferMetadata metadata);
void ReceiveIntroduction(const ShareTarget& share_target,
const std::string& token);
void ReceiveIntroduction(ShareTarget share_target,
base::Optional<std::string> token);
void OnReceivedIntroduction(
NearbyConnection* connection,
ShareTarget share_target,
base::Optional<std::string> token,
std::unique_ptr<IncomingFramesReader> frames_reader,
base::Optional<sharing::mojom::V1FramePtr> frame);
void UnregisterShareTarget(const ShareTarget& share_target);
IncomingShareTargetInfo& GetIncomingShareTargetInfo(
const ShareTarget& share_target);
NearbyConnection* GetIncomingConnection(const ShareTarget& share_target);
OutgoingShareTargetInfo& GetOutgoingShareTargetInfo(ShareTarget share_target);
OutgoingShareTargetInfo& GetOutgoingShareTargetInfo(
const ShareTarget& share_target);
void ClearOutgoingShareTargetInfoMap();
PrefService* prefs_;
Profile* profile_;
NearbyShareSettings settings_;
std::unique_ptr<NearbyConnectionsManager> nearby_connections_manager_;
NearbyProcessManager* process_manager_;
ScopedObserver<NearbyProcessManager, NearbyProcessManager::Observer>
nearby_process_observer_{this};
scoped_refptr<device::BluetoothAdapter> bluetooth_adapter_;
......
......@@ -33,6 +33,10 @@ struct ShareTarget {
ShareTarget& operator=(ShareTarget&&);
~ShareTarget();
bool has_attachments() const {
return !text_attachments.empty() || !file_attachments.empty();
}
base::UnguessableToken id = base::UnguessableToken::Create();
std::string device_name;
// Uri that points to an image of the ShareTarget, if one exists.
......
......@@ -9,21 +9,12 @@
#include "base/optional.h"
#include "chrome/browser/nearby_sharing/attachment.h"
#include "chrome/services/sharing/public/mojom/nearby_decoder_types.mojom.h"
// Represents a text attachment.
class TextAttachment : public Attachment {
public:
// Different types are used to offer richer experiences on Receiver side,
// mainly for: 1. displaying notification of attachment types, 2. opening
// different types with different apps. Remember to update Notifications,
// ShareTarget, etc once more types are introduced here.
enum class Type {
kText,
kUrl,
kAddress,
kPhoneNumber,
kMaxValue = kPhoneNumber
};
using Type = sharing::mojom::TextMetadata::Type;
TextAttachment(std::string text_body, Type type, int64_t size);
~TextAttachment() override;
......
......@@ -3665,6 +3665,8 @@ test("unit_tests") {
"../browser/media/feeds/media_feeds_fetcher_unittest.cc",
"../browser/media/feeds/media_feeds_service_unittest.cc",
"../browser/media/kaleidoscope/kaleidoscope_switches_unittest.cc",
"../browser/nearby_sharing/fake_nearby_connection.cc",
"../browser/nearby_sharing/fake_nearby_connection.h",
"../browser/nearby_sharing/fake_nearby_connections_manager.cc",
"../browser/nearby_sharing/fake_nearby_connections_manager.h",
"../browser/nearby_sharing/fast_initiation_manager_unittest.cc",
......@@ -3689,8 +3691,6 @@ test("unit_tests") {
"../browser/nearby_sharing/nearby_process_manager_unittest.cc",
"../browser/nearby_sharing/nearby_share_settings_unittest.cc",
"../browser/nearby_sharing/nearby_sharing_service_impl_unittest.cc",
"../browser/nearby_sharing/transfer_metadata_builder.cc",
"../browser/nearby_sharing/transfer_metadata_builder.h",
"../browser/nearby_sharing/webrtc_signaling_messenger_unittest.cc",
"../browser/password_manager/generated_password_leak_detection_pref_unittest.cc",
"../browser/performance_manager/test_support/page_discarding_utils.cc",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment