Commit 05a1565a authored by Kyle Horimoto's avatar Kyle Horimoto Committed by Commit Bot

[CrOS PhoneHub] Handle pending Nearby connection requests

This CL implements a TODO in PendingConnectionManagerImpl to handle
incoming requests for connections via the Nearby Connections library.
When a request is received, we create a NearbyInitiatorConnectionAttempt
(if one does not already exist), then add a new
PendingNearbyInitiatorConnectionRequest to it.

Additionally, this CL updates the initialization flow for the
SecureChannel service so that it now creates an instance of
NearbyConnectionManager.

Bug: 1106937
Change-Id: Ibe56476babfb201b748beed1fefc80efda7e304e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2419374
Commit-Queue: Kyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarJames Vecore <vecore@google.com>
Cr-Commit-Position: refs/heads/master@{#809534}
parent da6b36bc
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "chromeos/services/secure_channel/connection_attempt_delegate.h" #include "chromeos/services/secure_channel/connection_attempt_delegate.h"
#include "chromeos/services/secure_channel/connection_role.h" #include "chromeos/services/secure_channel/connection_role.h"
#include "chromeos/services/secure_channel/device_id_pair.h" #include "chromeos/services/secure_channel/device_id_pair.h"
#include "chromeos/services/secure_channel/nearby_initiator_failure_type.h"
#include "chromeos/services/secure_channel/pending_connection_manager.h" #include "chromeos/services/secure_channel/pending_connection_manager.h"
#include "chromeos/services/secure_channel/public/cpp/shared/connection_medium.h" #include "chromeos/services/secure_channel/public/cpp/shared/connection_medium.h"
#include "chromeos/services/secure_channel/public/cpp/shared/connection_priority.h" #include "chromeos/services/secure_channel/public/cpp/shared/connection_priority.h"
...@@ -28,6 +29,7 @@ namespace chromeos { ...@@ -28,6 +29,7 @@ namespace chromeos {
namespace secure_channel { namespace secure_channel {
class BleConnectionManager; class BleConnectionManager;
class NearbyConnectionManager;
// Concrete PendingConnectionManager implementation. This class creates one // Concrete PendingConnectionManager implementation. This class creates one
// ConnectionAttempt per ConnectionAttemptDetails requested; if more than one // ConnectionAttempt per ConnectionAttemptDetails requested; if more than one
...@@ -45,6 +47,7 @@ class PendingConnectionManagerImpl : public PendingConnectionManager, ...@@ -45,6 +47,7 @@ class PendingConnectionManagerImpl : public PendingConnectionManager,
static std::unique_ptr<PendingConnectionManager> Create( static std::unique_ptr<PendingConnectionManager> Create(
Delegate* delegate, Delegate* delegate,
BleConnectionManager* ble_connection_manager, BleConnectionManager* ble_connection_manager,
NearbyConnectionManager* nearby_connection_manager,
scoped_refptr<device::BluetoothAdapter> bluetooth_adapter); scoped_refptr<device::BluetoothAdapter> bluetooth_adapter);
static void SetFactoryForTesting(Factory* test_factory); static void SetFactoryForTesting(Factory* test_factory);
...@@ -53,6 +56,7 @@ class PendingConnectionManagerImpl : public PendingConnectionManager, ...@@ -53,6 +56,7 @@ class PendingConnectionManagerImpl : public PendingConnectionManager,
virtual std::unique_ptr<PendingConnectionManager> CreateInstance( virtual std::unique_ptr<PendingConnectionManager> CreateInstance(
Delegate* delegate, Delegate* delegate,
BleConnectionManager* ble_connection_manager, BleConnectionManager* ble_connection_manager,
NearbyConnectionManager* nearby_connection_manager,
scoped_refptr<device::BluetoothAdapter> bluetooth_adapter) = 0; scoped_refptr<device::BluetoothAdapter> bluetooth_adapter) = 0;
private: private:
...@@ -65,6 +69,7 @@ class PendingConnectionManagerImpl : public PendingConnectionManager, ...@@ -65,6 +69,7 @@ class PendingConnectionManagerImpl : public PendingConnectionManager,
PendingConnectionManagerImpl( PendingConnectionManagerImpl(
Delegate* delegate, Delegate* delegate,
BleConnectionManager* ble_connection_manager, BleConnectionManager* ble_connection_manager,
NearbyConnectionManager* nearby_connection_manager,
scoped_refptr<device::BluetoothAdapter> bluetooth_adapter); scoped_refptr<device::BluetoothAdapter> bluetooth_adapter);
// PendingConnectionManager: // PendingConnectionManager:
...@@ -97,9 +102,29 @@ class PendingConnectionManagerImpl : public PendingConnectionManager, ...@@ -97,9 +102,29 @@ class PendingConnectionManagerImpl : public PendingConnectionManager,
const ConnectionAttemptDetails& connection_attempt_details, const ConnectionAttemptDetails& connection_attempt_details,
std::unique_ptr<ClientConnectionParameters> client_connection_parameters, std::unique_ptr<ClientConnectionParameters> client_connection_parameters,
ConnectionPriority connection_priority); ConnectionPriority connection_priority);
void HandleNearbyInitiatorRequest(
const ConnectionAttemptDetails& connection_attempt_details,
std::unique_ptr<ClientConnectionParameters> client_connection_parameters,
ConnectionPriority connection_priority);
// Retrieves ClientConnectionParameters for a given connection attempt.
// Because a single connection attempt may have multiple client requests
// (e.g., when multiple clients requets a connection at the same time), this
// function returns a vector.
//
// Note that this function std::move()s results from the |id_pair_to_*_| maps
// below, so these maps will end up having "empty" values after the function
// is called. This function is expected to be used in conjunction with
// RemoveMapEntriesForFinishedConnectionAttempt(), which cleans up those empty
// values.
std::vector<std::unique_ptr<ClientConnectionParameters>>
ExtractClientConnectionParameters(
const ConnectionAttemptDetails& connection_attempt_details);
void RemoveMapEntriesForFinishedConnectionAttempt( void RemoveMapEntriesForFinishedConnectionAttempt(
const ConnectionAttemptDetails& connection_attempt_details); const ConnectionAttemptDetails& connection_attempt_details);
void RemoveIdPairToConnectionAttemptMapEntriesForFinishedConnectionAttempt(
const ConnectionAttemptDetails& connection_attempt_details);
base::flat_map<DeviceIdPair, base::flat_map<DeviceIdPair,
std::unique_ptr<ConnectionAttempt<BleInitiatorFailureType>>> std::unique_ptr<ConnectionAttempt<BleInitiatorFailureType>>>
...@@ -109,10 +134,15 @@ class PendingConnectionManagerImpl : public PendingConnectionManager, ...@@ -109,10 +134,15 @@ class PendingConnectionManagerImpl : public PendingConnectionManager,
std::unique_ptr<ConnectionAttempt<BleListenerFailureType>>> std::unique_ptr<ConnectionAttempt<BleListenerFailureType>>>
id_pair_to_ble_listener_connection_attempts_; id_pair_to_ble_listener_connection_attempts_;
base::flat_map<DeviceIdPair,
std::unique_ptr<ConnectionAttempt<NearbyInitiatorFailureType>>>
id_pair_to_nearby_initiator_connection_attempts_;
base::flat_map<ConnectionDetails, base::flat_set<ConnectionAttemptDetails>> base::flat_map<ConnectionDetails, base::flat_set<ConnectionAttemptDetails>>
details_to_attempt_details_map_; details_to_attempt_details_map_;
BleConnectionManager* ble_connection_manager_; BleConnectionManager* ble_connection_manager_;
NearbyConnectionManager* nearby_connection_manager_;
scoped_refptr<device::BluetoothAdapter> bluetooth_adapter_; scoped_refptr<device::BluetoothAdapter> bluetooth_adapter_;
DISALLOW_COPY_AND_ASSIGN(PendingConnectionManagerImpl); DISALLOW_COPY_AND_ASSIGN(PendingConnectionManagerImpl);
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "chromeos/services/secure_channel/bluetooth_helper_impl.h" #include "chromeos/services/secure_channel/bluetooth_helper_impl.h"
#include "chromeos/services/secure_channel/client_connection_parameters_impl.h" #include "chromeos/services/secure_channel/client_connection_parameters_impl.h"
#include "chromeos/services/secure_channel/device_id_pair.h" #include "chromeos/services/secure_channel/device_id_pair.h"
#include "chromeos/services/secure_channel/nearby_connection_manager_impl.h"
#include "chromeos/services/secure_channel/pending_connection_manager_impl.h" #include "chromeos/services/secure_channel/pending_connection_manager_impl.h"
#include "chromeos/services/secure_channel/timer_factory_impl.h" #include "chromeos/services/secure_channel/timer_factory_impl.h"
#include "device/bluetooth/bluetooth_adapter.h" #include "device/bluetooth/bluetooth_adapter.h"
...@@ -80,9 +81,12 @@ SecureChannelImpl::SecureChannelImpl( ...@@ -80,9 +81,12 @@ SecureChannelImpl::SecureChannelImpl(
ble_synchronizer_.get(), ble_synchronizer_.get(),
ble_scanner_.get(), ble_scanner_.get(),
timer_factory_.get())), timer_factory_.get())),
nearby_connection_manager_(
NearbyConnectionManagerImpl::Factory::Create()),
pending_connection_manager_(PendingConnectionManagerImpl::Factory::Create( pending_connection_manager_(PendingConnectionManagerImpl::Factory::Create(
this /* delegate */, this /* delegate */,
ble_connection_manager_.get(), ble_connection_manager_.get(),
nearby_connection_manager_.get(),
bluetooth_adapter_)), bluetooth_adapter_)),
active_connection_manager_( active_connection_manager_(
ActiveConnectionManagerImpl::Factory::Create(this /* delegate */)) {} ActiveConnectionManagerImpl::Factory::Create(this /* delegate */)) {}
......
...@@ -32,6 +32,7 @@ class BleConnectionManager; ...@@ -32,6 +32,7 @@ class BleConnectionManager;
class BleScanner; class BleScanner;
class BluetoothHelper; class BluetoothHelper;
class BleSynchronizerBase; class BleSynchronizerBase;
class NearbyConnectionManager;
class TimerFactory; class TimerFactory;
// Concrete SecureChannelImpl implementation, which contains three pieces: // Concrete SecureChannelImpl implementation, which contains three pieces:
...@@ -178,6 +179,7 @@ class SecureChannelImpl : public mojom::SecureChannel, ...@@ -178,6 +179,7 @@ class SecureChannelImpl : public mojom::SecureChannel,
std::unique_ptr<BleSynchronizerBase> ble_synchronizer_; std::unique_ptr<BleSynchronizerBase> ble_synchronizer_;
std::unique_ptr<BleScanner> ble_scanner_; std::unique_ptr<BleScanner> ble_scanner_;
std::unique_ptr<BleConnectionManager> ble_connection_manager_; std::unique_ptr<BleConnectionManager> ble_connection_manager_;
std::unique_ptr<NearbyConnectionManager> nearby_connection_manager_;
std::unique_ptr<PendingConnectionManager> pending_connection_manager_; std::unique_ptr<PendingConnectionManager> pending_connection_manager_;
std::unique_ptr<ActiveConnectionManager> active_connection_manager_; std::unique_ptr<ActiveConnectionManager> active_connection_manager_;
......
...@@ -28,8 +28,10 @@ ...@@ -28,8 +28,10 @@
#include "chromeos/services/secure_channel/fake_bluetooth_helper.h" #include "chromeos/services/secure_channel/fake_bluetooth_helper.h"
#include "chromeos/services/secure_channel/fake_client_connection_parameters.h" #include "chromeos/services/secure_channel/fake_client_connection_parameters.h"
#include "chromeos/services/secure_channel/fake_connection_delegate.h" #include "chromeos/services/secure_channel/fake_connection_delegate.h"
#include "chromeos/services/secure_channel/fake_nearby_connection_manager.h"
#include "chromeos/services/secure_channel/fake_pending_connection_manager.h" #include "chromeos/services/secure_channel/fake_pending_connection_manager.h"
#include "chromeos/services/secure_channel/fake_timer_factory.h" #include "chromeos/services/secure_channel/fake_timer_factory.h"
#include "chromeos/services/secure_channel/nearby_connection_manager_impl.h"
#include "chromeos/services/secure_channel/pending_connection_manager_impl.h" #include "chromeos/services/secure_channel/pending_connection_manager_impl.h"
#include "chromeos/services/secure_channel/public/cpp/shared/connection_priority.h" #include "chromeos/services/secure_channel/public/cpp/shared/connection_priority.h"
#include "chromeos/services/secure_channel/public/mojom/secure_channel.mojom.h" #include "chromeos/services/secure_channel/public/mojom/secure_channel.mojom.h"
...@@ -236,13 +238,39 @@ class FakeBleConnectionManagerFactory ...@@ -236,13 +238,39 @@ class FakeBleConnectionManagerFactory
DISALLOW_COPY_AND_ASSIGN(FakeBleConnectionManagerFactory); DISALLOW_COPY_AND_ASSIGN(FakeBleConnectionManagerFactory);
}; };
class FakeNearbyConnectionManagerFactory
: public NearbyConnectionManagerImpl::Factory {
public:
FakeNearbyConnectionManagerFactory() = default;
~FakeNearbyConnectionManagerFactory() override = default;
FakeNearbyConnectionManager* instance() { return instance_; }
private:
// NearbyConnectionManagerImpl::Factory:
std::unique_ptr<NearbyConnectionManager> CreateInstance() override {
EXPECT_FALSE(instance_);
auto instance = std::make_unique<FakeNearbyConnectionManager>();
instance_ = instance.get();
return instance;
}
FakeNearbyConnectionManager* instance_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(FakeNearbyConnectionManagerFactory);
};
class FakePendingConnectionManagerFactory class FakePendingConnectionManagerFactory
: public PendingConnectionManagerImpl::Factory { : public PendingConnectionManagerImpl::Factory {
public: public:
FakePendingConnectionManagerFactory( FakePendingConnectionManagerFactory(
FakeBleConnectionManagerFactory* fake_ble_connection_manager_factory) FakeBleConnectionManagerFactory* fake_ble_connection_manager_factory,
FakeNearbyConnectionManagerFactory*
fake_nearby_connection_manager_factory)
: fake_ble_connection_manager_factory_( : fake_ble_connection_manager_factory_(
fake_ble_connection_manager_factory) {} fake_ble_connection_manager_factory),
fake_nearby_connection_manager_factory_(
fake_nearby_connection_manager_factory) {}
~FakePendingConnectionManagerFactory() override = default; ~FakePendingConnectionManagerFactory() override = default;
...@@ -253,10 +281,13 @@ class FakePendingConnectionManagerFactory ...@@ -253,10 +281,13 @@ class FakePendingConnectionManagerFactory
std::unique_ptr<PendingConnectionManager> CreateInstance( std::unique_ptr<PendingConnectionManager> CreateInstance(
PendingConnectionManager::Delegate* delegate, PendingConnectionManager::Delegate* delegate,
BleConnectionManager* ble_connection_manager, BleConnectionManager* ble_connection_manager,
NearbyConnectionManager* nearby_connection_manager,
scoped_refptr<device::BluetoothAdapter> bluetooth_adapter) override { scoped_refptr<device::BluetoothAdapter> bluetooth_adapter) override {
EXPECT_FALSE(instance_); EXPECT_FALSE(instance_);
EXPECT_EQ(fake_ble_connection_manager_factory_->instance(), EXPECT_EQ(fake_ble_connection_manager_factory_->instance(),
ble_connection_manager); ble_connection_manager);
EXPECT_EQ(fake_nearby_connection_manager_factory_->instance(),
nearby_connection_manager);
auto instance = std::make_unique<FakePendingConnectionManager>(delegate); auto instance = std::make_unique<FakePendingConnectionManager>(delegate);
instance_ = instance.get(); instance_ = instance.get();
...@@ -264,6 +295,7 @@ class FakePendingConnectionManagerFactory ...@@ -264,6 +295,7 @@ class FakePendingConnectionManagerFactory
} }
FakeBleConnectionManagerFactory* fake_ble_connection_manager_factory_; FakeBleConnectionManagerFactory* fake_ble_connection_manager_factory_;
FakeNearbyConnectionManagerFactory* fake_nearby_connection_manager_factory_;
FakePendingConnectionManager* instance_ = nullptr; FakePendingConnectionManager* instance_ = nullptr;
...@@ -447,9 +479,15 @@ class SecureChannelServiceTest : public testing::Test { ...@@ -447,9 +479,15 @@ class SecureChannelServiceTest : public testing::Test {
BleConnectionManagerImpl::Factory::SetFactoryForTesting( BleConnectionManagerImpl::Factory::SetFactoryForTesting(
fake_ble_connection_manager_factory_.get()); fake_ble_connection_manager_factory_.get());
fake_nearby_connection_manager_factory_ =
std::make_unique<FakeNearbyConnectionManagerFactory>();
NearbyConnectionManagerImpl::Factory::SetFactoryForTesting(
fake_nearby_connection_manager_factory_.get());
fake_pending_connection_manager_factory_ = fake_pending_connection_manager_factory_ =
std::make_unique<FakePendingConnectionManagerFactory>( std::make_unique<FakePendingConnectionManagerFactory>(
fake_ble_connection_manager_factory_.get()); fake_ble_connection_manager_factory_.get(),
fake_nearby_connection_manager_factory_.get());
PendingConnectionManagerImpl::Factory::SetFactoryForTesting( PendingConnectionManagerImpl::Factory::SetFactoryForTesting(
fake_pending_connection_manager_factory_.get()); fake_pending_connection_manager_factory_.get());
...@@ -481,6 +519,7 @@ class SecureChannelServiceTest : public testing::Test { ...@@ -481,6 +519,7 @@ class SecureChannelServiceTest : public testing::Test {
BleSynchronizer::Factory::SetFactoryForTesting(nullptr); BleSynchronizer::Factory::SetFactoryForTesting(nullptr);
BleScannerImpl::Factory::SetFactoryForTesting(nullptr); BleScannerImpl::Factory::SetFactoryForTesting(nullptr);
BleConnectionManagerImpl::Factory::SetFactoryForTesting(nullptr); BleConnectionManagerImpl::Factory::SetFactoryForTesting(nullptr);
NearbyConnectionManagerImpl::Factory::SetFactoryForTesting(nullptr);
PendingConnectionManagerImpl::Factory::SetFactoryForTesting(nullptr); PendingConnectionManagerImpl::Factory::SetFactoryForTesting(nullptr);
ActiveConnectionManagerImpl::Factory::SetFactoryForTesting(nullptr); ActiveConnectionManagerImpl::Factory::SetFactoryForTesting(nullptr);
SecureChannelInitializer::Factory::SetFactoryForTesting(nullptr); SecureChannelInitializer::Factory::SetFactoryForTesting(nullptr);
...@@ -957,6 +996,8 @@ class SecureChannelServiceTest : public testing::Test { ...@@ -957,6 +996,8 @@ class SecureChannelServiceTest : public testing::Test {
std::unique_ptr<FakeBleScannerFactory> fake_ble_scanner_factory_; std::unique_ptr<FakeBleScannerFactory> fake_ble_scanner_factory_;
std::unique_ptr<FakeBleConnectionManagerFactory> std::unique_ptr<FakeBleConnectionManagerFactory>
fake_ble_connection_manager_factory_; fake_ble_connection_manager_factory_;
std::unique_ptr<FakeNearbyConnectionManagerFactory>
fake_nearby_connection_manager_factory_;
std::unique_ptr<FakePendingConnectionManagerFactory> std::unique_ptr<FakePendingConnectionManagerFactory>
fake_pending_connection_manager_factory_; fake_pending_connection_manager_factory_;
std::unique_ptr<FakeActiveConnectionManagerFactory> std::unique_ptr<FakeActiveConnectionManagerFactory>
......
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