Commit fa869e00 authored by Naomi Musgrave's avatar Naomi Musgrave Committed by Commit Bot

Implement the send surface in NearbySharingService.

Track share targets as they are (un)registered, and start scanning.
Only handles surfaces registered to the foreground for now.

Bug: 1084644
Change-Id: I852388f8dd1d355263979d94f2959cc79f905929
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2292214
Commit-Queue: Naomi Musgrave <nmusgrave@chromium.org>
Reviewed-by: default avatarRichard Knoll <knollr@chromium.org>
Reviewed-by: default avatarAlex Chau <alexchau@chromium.org>
Cr-Commit-Position: refs/heads/master@{#796384}
parent b4283204
...@@ -110,6 +110,23 @@ void FakeNearbyConnectionsManager::UpgradeBandwidth( ...@@ -110,6 +110,23 @@ void FakeNearbyConnectionsManager::UpgradeBandwidth(
upgrade_bandwidth_endpoint_ids_.insert(endpoint_id); upgrade_bandwidth_endpoint_ids_.insert(endpoint_id);
} }
void FakeNearbyConnectionsManager::OnEndpointFound(
const std::string& endpoint_id,
location::nearby::connections::mojom::DiscoveredEndpointInfoPtr info) {
if (!discovery_listener_)
return;
discovery_listener_->OnEndpointDiscovered(endpoint_id, info->endpoint_info);
}
void FakeNearbyConnectionsManager::OnEndpointLost(
const std::string& endpoint_id) {
if (!discovery_listener_)
return;
discovery_listener_->OnEndpointLost(endpoint_id);
}
bool FakeNearbyConnectionsManager::IsAdvertising() { bool FakeNearbyConnectionsManager::IsAdvertising() {
return advertising_listener_ != nullptr; return advertising_listener_ != nullptr;
} }
......
...@@ -12,11 +12,13 @@ ...@@ -12,11 +12,13 @@
#include <vector> #include <vector>
#include "chrome/browser/nearby_sharing/nearby_connections_manager.h" #include "chrome/browser/nearby_sharing/nearby_connections_manager.h"
#include "chrome/services/sharing/public/mojom/nearby_connections.mojom.h"
// Fake NearbyConnectionsManager for testing. // Fake NearbyConnectionsManager for testing.
class FakeNearbyConnectionsManager : public NearbyConnectionsManager { class FakeNearbyConnectionsManager
: public NearbyConnectionsManager,
public location::nearby::connections::mojom::EndpointDiscoveryListener {
public: public:
FakeNearbyConnectionsManager(); FakeNearbyConnectionsManager();
~FakeNearbyConnectionsManager() override; ~FakeNearbyConnectionsManager() override;
...@@ -50,6 +52,13 @@ class FakeNearbyConnectionsManager : public NearbyConnectionsManager { ...@@ -50,6 +52,13 @@ class FakeNearbyConnectionsManager : public NearbyConnectionsManager {
const std::string& endpoint_id) override; const std::string& endpoint_id) override;
void UpgradeBandwidth(const std::string& endpoint_id) override; void UpgradeBandwidth(const std::string& endpoint_id) override;
// mojom::EndpointDiscoveryListener:
void OnEndpointFound(
const std::string& endpoint_id,
location::nearby::connections::mojom::DiscoveredEndpointInfoPtr info)
override;
void OnEndpointLost(const std::string& endpoint_id) override;
// Testing methods // Testing methods
bool IsAdvertising(); bool IsAdvertising();
bool IsDiscovering(); bool IsDiscovering();
......
...@@ -33,6 +33,14 @@ class NearbySharingService : public KeyedService { ...@@ -33,6 +33,14 @@ class NearbySharingService : public KeyedService {
kOk, kOk,
// The operation failed since it was called in an invalid order. // The operation failed since it was called in an invalid order.
kOutOfOrderApiCall, kOutOfOrderApiCall,
// Tried to stop something that was already stopped.
kStatusAlreadyStopped,
// Tried to register an opposite foreground surface in the midst of a
// transfer or connection.
// (Tried to register Send Surface when receiving a file or tried to
// register Receive Surface when
// sending a file.)
kTransferAlreadyInProgress,
}; };
enum class ReceiveSurfaceState { enum class ReceiveSurfaceState {
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/scoped_observer.h" #include "base/scoped_observer.h"
#include "base/sequence_checker.h" #include "base/sequence_checker.h"
#include "base/time/time.h"
#include "base/unguessable_token.h" #include "base/unguessable_token.h"
#include "chrome/browser/nearby_sharing/attachment.h" #include "chrome/browser/nearby_sharing/attachment.h"
#include "chrome/browser/nearby_sharing/attachment_info.h" #include "chrome/browser/nearby_sharing/attachment_info.h"
...@@ -23,6 +24,7 @@ ...@@ -23,6 +24,7 @@
#include "chrome/browser/nearby_sharing/common/nearby_share_enums.h" #include "chrome/browser/nearby_sharing/common/nearby_share_enums.h"
#include "chrome/browser/nearby_sharing/incoming_frames_reader.h" #include "chrome/browser/nearby_sharing/incoming_frames_reader.h"
#include "chrome/browser/nearby_sharing/incoming_share_target_info.h" #include "chrome/browser/nearby_sharing/incoming_share_target_info.h"
#include "chrome/browser/nearby_sharing/local_device_data/nearby_share_local_device_data_manager.h"
#include "chrome/browser/nearby_sharing/nearby_connections_manager.h" #include "chrome/browser/nearby_sharing/nearby_connections_manager.h"
#include "chrome/browser/nearby_sharing/nearby_notification_manager.h" #include "chrome/browser/nearby_sharing/nearby_notification_manager.h"
#include "chrome/browser/nearby_sharing/nearby_process_manager.h" #include "chrome/browser/nearby_sharing/nearby_process_manager.h"
...@@ -52,7 +54,8 @@ class NearbySharingServiceImpl ...@@ -52,7 +54,8 @@ class NearbySharingServiceImpl
public nearby_share::mojom::NearbyShareSettingsObserver, public nearby_share::mojom::NearbyShareSettingsObserver,
public NearbyProcessManager::Observer, public NearbyProcessManager::Observer,
public device::BluetoothAdapter::Observer, public device::BluetoothAdapter::Observer,
public NearbyConnectionsManager::IncomingConnectionListener { public NearbyConnectionsManager::IncomingConnectionListener,
public NearbyConnectionsManager::DiscoveryListener {
public: public:
explicit NearbySharingServiceImpl( explicit NearbySharingServiceImpl(
PrefService* prefs, PrefService* prefs,
...@@ -117,8 +120,15 @@ class NearbySharingServiceImpl ...@@ -117,8 +120,15 @@ class NearbySharingServiceImpl
NearbyShareContactManager* GetContactManager() override; NearbyShareContactManager* GetContactManager() override;
NearbyShareCertificateManager* GetCertificateManager() override; NearbyShareCertificateManager* GetCertificateManager() override;
// NearbyConnectionsManager::DiscoveryListener:
void OnEndpointDiscovered(const std::string& endpoint_id,
const std::vector<uint8_t>& endpoint_info) override;
void OnEndpointLost(const std::string& endpoint_id) override;
private: private:
bool IsVisibleInBackground(Visibility visibility); bool IsVisibleInBackground(Visibility visibility);
const base::Optional<std::vector<uint8_t>> CreateEndpointInfo(
const base::Optional<std::string>& device_name);
void StartFastInitiationAdvertising(); void StartFastInitiationAdvertising();
void StopFastInitiationAdvertising(); void StopFastInitiationAdvertising();
void GetBluetoothAdapter(); void GetBluetoothAdapter();
...@@ -126,12 +136,19 @@ class NearbySharingServiceImpl ...@@ -126,12 +136,19 @@ class NearbySharingServiceImpl
void OnStartFastInitiationAdvertising(); void OnStartFastInitiationAdvertising();
void OnStartFastInitiationAdvertisingError(); void OnStartFastInitiationAdvertisingError();
void OnStopFastInitiationAdvertising(); void OnStopFastInitiationAdvertising();
void OnOutgoingAdvertisementDecoded(
const std::string& endpoint_id,
sharing::mojom::AdvertisementPtr advertisement);
bool IsBluetoothPresent() const; bool IsBluetoothPresent() const;
bool IsBluetoothPowered() const; bool IsBluetoothPowered() const;
bool HasAvailableConnectionMediums();
void AdapterPresentChanged(device::BluetoothAdapter* adapter, void AdapterPresentChanged(device::BluetoothAdapter* adapter,
bool present) override; bool present) override;
void AdapterPoweredChanged(device::BluetoothAdapter* adapter, void AdapterPoweredChanged(device::BluetoothAdapter* adapter,
bool powered) override; bool powered) override;
void InvalidateSurfaceState();
void InvalidateSendSurfaceState();
void InvalidateScanningState();
void InvalidateReceiveSurfaceState(); void InvalidateReceiveSurfaceState();
void InvalidateAdvertisingState(); void InvalidateAdvertisingState();
void StopAdvertising(); void StopAdvertising();
...@@ -143,6 +160,10 @@ class NearbySharingServiceImpl ...@@ -143,6 +160,10 @@ class NearbySharingServiceImpl
NearbyConnection& connection, NearbyConnection& connection,
sharing::nearby::ConnectionResponseFrame::Status reponse_status); sharing::nearby::ConnectionResponseFrame::Status reponse_status);
void Fail(const ShareTarget& share_target, TransferMetadata::Status status); void Fail(const ShareTarget& share_target, TransferMetadata::Status status);
void StartScanning(
base::Optional<ShareTargetDiscoveredCallback*> discovery_callback);
void StartScanning();
StatusCodes StopScanning();
void OnIncomingTransferUpdate(const ShareTarget& share_target, void OnIncomingTransferUpdate(const ShareTarget& share_target,
TransferMetadata metadata); TransferMetadata metadata);
void CloseConnection(const ShareTarget& share_target); void CloseConnection(const ShareTarget& share_target);
...@@ -158,7 +179,6 @@ class NearbySharingServiceImpl ...@@ -158,7 +179,6 @@ class NearbySharingServiceImpl
const sharing::mojom::CertificateInfoFramePtr& certificate_frame); const sharing::mojom::CertificateInfoFramePtr& certificate_frame);
void OnIncomingConnectionDisconnected(const ShareTarget& share_target); void OnIncomingConnectionDisconnected(const ShareTarget& share_target);
void UnregisterShareTarget(const ShareTarget& share_target);
bool IsOutOfStorage(const ShareTarget& share_target); bool IsOutOfStorage(const ShareTarget& share_target);
void OnIncomingMutualAcceptanceTimeout(const ShareTarget& share_target); void OnIncomingMutualAcceptanceTimeout(const ShareTarget& share_target);
...@@ -166,14 +186,19 @@ class NearbySharingServiceImpl ...@@ -166,14 +186,19 @@ class NearbySharingServiceImpl
IncomingShareTargetInfo& GetIncomingShareTargetInfo( IncomingShareTargetInfo& GetIncomingShareTargetInfo(
const ShareTarget& share_target); const ShareTarget& share_target);
NearbyConnection* GetIncomingConnection(const ShareTarget& share_target); NearbyConnection* GetIncomingConnection(const ShareTarget& share_target);
OutgoingShareTargetInfo& GetOutgoingShareTargetInfo( OutgoingShareTargetInfo& GetOrCreateOutgoingShareTargetInfo(
const ShareTarget& share_target); const ShareTarget& share_target,
const std::string& endpoint_id);
void ClearOutgoingShareTargetInfoMap(); void ClearOutgoingShareTargetInfoMap();
void SetAttachmentPayloadId(const Attachment& attachment, int64_t payload_id); void SetAttachmentPayloadId(const Attachment& attachment, int64_t payload_id);
base::Optional<int64_t> GetAttachmentPayloadId( base::Optional<int64_t> GetAttachmentPayloadId(
const base::UnguessableToken& attachment_id); const base::UnguessableToken& attachment_id);
base::Optional<ShareTarget> CreateShareTarget(
const std::string& endpoint_id,
sharing::mojom::AdvertisementPtr advertisement,
bool is_incoming);
void UnregisterShareTarget(const ShareTarget& share_target);
PrefService* prefs_;
Profile* profile_; Profile* profile_;
NearbyShareSettings settings_; NearbyShareSettings settings_;
std::unique_ptr<NearbyConnectionsManager> nearby_connections_manager_; std::unique_ptr<NearbyConnectionsManager> nearby_connections_manager_;
...@@ -193,6 +218,20 @@ class NearbySharingServiceImpl ...@@ -193,6 +218,20 @@ class NearbySharingServiceImpl
base::ObserverList<TransferUpdateCallback> foreground_receive_callbacks_; base::ObserverList<TransferUpdateCallback> foreground_receive_callbacks_;
// A list of foreground receivers. // A list of foreground receivers.
base::ObserverList<TransferUpdateCallback> background_receive_callbacks_; base::ObserverList<TransferUpdateCallback> background_receive_callbacks_;
// A list of foreground receivers for transfer updates on the send surface.
base::ObserverList<TransferUpdateCallback>
foreground_send_transfer_callbacks_;
// A list of foreground receivers for discovered device updates on the send
// surface.
base::ObserverList<ShareTargetDiscoveredCallback>
foreground_send_discovery_callbacks_;
// A list of background receivers for transfer updates on the send surface.
base::ObserverList<TransferUpdateCallback>
background_send_transfer_callbacks_;
// A list of background receivers for discovered device updates on the send
// surface.
base::ObserverList<ShareTargetDiscoveredCallback>
background_send_discovery_callbacks_;
// Registers the most recent TransferMetadata and ShareTarget used for // Registers the most recent TransferMetadata and ShareTarget used for
// transitioning notifications between foreground surfaces and background // transitioning notifications between foreground surfaces and background
...@@ -207,6 +246,10 @@ class NearbySharingServiceImpl ...@@ -207,6 +246,10 @@ class NearbySharingServiceImpl
// incoming share target. // incoming share target.
base::flat_map<base::UnguessableToken, IncomingShareTargetInfo> base::flat_map<base::UnguessableToken, IncomingShareTargetInfo>
incoming_share_target_info_map_; incoming_share_target_info_map_;
// A map of endpoint id to ShareTarget, where each ShareTarget entry
// directly corresponds to a OutgoingShareTargetInfo entry in
// outgoing_share_target_info_map_;
base::flat_map<std::string, ShareTarget> outgoing_share_target_map_;
// A map of ShareTarget id to OutgoingShareTargetInfo. This lets us know which // A map of ShareTarget id to OutgoingShareTargetInfo. This lets us know which
// endpoint and public certificate are related to the outgoing share target. // endpoint and public certificate are related to the outgoing share target.
// TODO(crbug/1085068) update this map when handling payloads // TODO(crbug/1085068) update this map when handling payloads
...@@ -227,7 +270,13 @@ class NearbySharingServiceImpl ...@@ -227,7 +270,13 @@ class NearbySharingServiceImpl
// True if we are currently scanning for remote devices. // True if we are currently scanning for remote devices.
bool is_scanning_ = false; bool is_scanning_ = false;
// True if we're currently sending or receiving a file. // True if we're currently sending or receiving a file.
bool is_transferring_files_ = false; bool is_transferring_ = false;
// True if we're currently receiving a file.
bool is_receiving_files_ = false;
// True if we're currently attempting to connect to a remote device.
bool is_connecting_ = false;
// The time scanning began.
base::Time scanning_start_timestamp_;
mojo::Receiver<nearby_share::mojom::NearbyShareSettingsObserver> mojo::Receiver<nearby_share::mojom::NearbyShareSettingsObserver>
settings_receiver_{this}; settings_receiver_{this};
......
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