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(
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() {
return advertising_listener_ != nullptr;
}
......
......@@ -12,11 +12,13 @@
#include <vector>
#include "chrome/browser/nearby_sharing/nearby_connections_manager.h"
#include "chrome/services/sharing/public/mojom/nearby_connections.mojom.h"
// Fake NearbyConnectionsManager for testing.
class FakeNearbyConnectionsManager : public NearbyConnectionsManager {
class FakeNearbyConnectionsManager
: public NearbyConnectionsManager,
public location::nearby::connections::mojom::EndpointDiscoveryListener {
public:
FakeNearbyConnectionsManager();
~FakeNearbyConnectionsManager() override;
......@@ -50,6 +52,13 @@ class FakeNearbyConnectionsManager : public NearbyConnectionsManager {
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
bool IsAdvertising();
bool IsDiscovering();
......
......@@ -33,6 +33,14 @@ class NearbySharingService : public KeyedService {
kOk,
// The operation failed since it was called in an invalid order.
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 {
......
......@@ -16,6 +16,7 @@
#include "base/memory/weak_ptr.h"
#include "base/scoped_observer.h"
#include "base/sequence_checker.h"
#include "base/time/time.h"
#include "base/unguessable_token.h"
#include "chrome/browser/nearby_sharing/attachment.h"
#include "chrome/browser/nearby_sharing/attachment_info.h"
......@@ -23,6 +24,7 @@
#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_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_notification_manager.h"
#include "chrome/browser/nearby_sharing/nearby_process_manager.h"
......@@ -52,7 +54,8 @@ class NearbySharingServiceImpl
public nearby_share::mojom::NearbyShareSettingsObserver,
public NearbyProcessManager::Observer,
public device::BluetoothAdapter::Observer,
public NearbyConnectionsManager::IncomingConnectionListener {
public NearbyConnectionsManager::IncomingConnectionListener,
public NearbyConnectionsManager::DiscoveryListener {
public:
explicit NearbySharingServiceImpl(
PrefService* prefs,
......@@ -117,8 +120,15 @@ class NearbySharingServiceImpl
NearbyShareContactManager* GetContactManager() 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:
bool IsVisibleInBackground(Visibility visibility);
const base::Optional<std::vector<uint8_t>> CreateEndpointInfo(
const base::Optional<std::string>& device_name);
void StartFastInitiationAdvertising();
void StopFastInitiationAdvertising();
void GetBluetoothAdapter();
......@@ -126,12 +136,19 @@ class NearbySharingServiceImpl
void OnStartFastInitiationAdvertising();
void OnStartFastInitiationAdvertisingError();
void OnStopFastInitiationAdvertising();
void OnOutgoingAdvertisementDecoded(
const std::string& endpoint_id,
sharing::mojom::AdvertisementPtr advertisement);
bool IsBluetoothPresent() const;
bool IsBluetoothPowered() const;
bool HasAvailableConnectionMediums();
void AdapterPresentChanged(device::BluetoothAdapter* adapter,
bool present) override;
void AdapterPoweredChanged(device::BluetoothAdapter* adapter,
bool powered) override;
void InvalidateSurfaceState();
void InvalidateSendSurfaceState();
void InvalidateScanningState();
void InvalidateReceiveSurfaceState();
void InvalidateAdvertisingState();
void StopAdvertising();
......@@ -143,6 +160,10 @@ class NearbySharingServiceImpl
NearbyConnection& connection,
sharing::nearby::ConnectionResponseFrame::Status reponse_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,
TransferMetadata metadata);
void CloseConnection(const ShareTarget& share_target);
......@@ -158,7 +179,6 @@ class NearbySharingServiceImpl
const sharing::mojom::CertificateInfoFramePtr& certificate_frame);
void OnIncomingConnectionDisconnected(const ShareTarget& share_target);
void UnregisterShareTarget(const ShareTarget& share_target);
bool IsOutOfStorage(const ShareTarget& share_target);
void OnIncomingMutualAcceptanceTimeout(const ShareTarget& share_target);
......@@ -166,14 +186,19 @@ class NearbySharingServiceImpl
IncomingShareTargetInfo& GetIncomingShareTargetInfo(
const ShareTarget& share_target);
NearbyConnection* GetIncomingConnection(const ShareTarget& share_target);
OutgoingShareTargetInfo& GetOutgoingShareTargetInfo(
const ShareTarget& share_target);
OutgoingShareTargetInfo& GetOrCreateOutgoingShareTargetInfo(
const ShareTarget& share_target,
const std::string& endpoint_id);
void ClearOutgoingShareTargetInfoMap();
void SetAttachmentPayloadId(const Attachment& attachment, int64_t payload_id);
base::Optional<int64_t> GetAttachmentPayloadId(
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_;
NearbyShareSettings settings_;
std::unique_ptr<NearbyConnectionsManager> nearby_connections_manager_;
......@@ -193,6 +218,20 @@ class NearbySharingServiceImpl
base::ObserverList<TransferUpdateCallback> foreground_receive_callbacks_;
// A list of foreground receivers.
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
// transitioning notifications between foreground surfaces and background
......@@ -207,6 +246,10 @@ class NearbySharingServiceImpl
// incoming share target.
base::flat_map<base::UnguessableToken, IncomingShareTargetInfo>
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
// endpoint and public certificate are related to the outgoing share target.
// TODO(crbug/1085068) update this map when handling payloads
......@@ -227,7 +270,13 @@ class NearbySharingServiceImpl
// True if we are currently scanning for remote devices.
bool is_scanning_ = false;
// 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>
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