Commit 25e8d1bb authored by khorimoto's avatar khorimoto Committed by Commit Bot

[CrOS Tether] Move LocalDeviceDataProvider from //chromeos/components/tether...

[CrOS Tether] Move LocalDeviceDataProvider from //chromeos/components/tether to //components/cryptauth.

This functionality is not logically coupled to the Tether component and will be used in other CryptAuth-related projects.

See a sample usage of this change as part of https://codereview.chromium.org/2953863002.

BUG=672263

Review-Url: https://codereview.chromium.org/2951303002
Cr-Commit-Position: refs/heads/master@{#481753}
parent a2da610a
...@@ -45,8 +45,6 @@ static_library("tether") { ...@@ -45,8 +45,6 @@ static_library("tether") {
"keep_alive_operation.h", "keep_alive_operation.h",
"keep_alive_scheduler.cc", "keep_alive_scheduler.cc",
"keep_alive_scheduler.h", "keep_alive_scheduler.h",
"local_device_data_provider.cc",
"local_device_data_provider.h",
"message_transfer_operation.cc", "message_transfer_operation.cc",
"message_transfer_operation.h", "message_transfer_operation.h",
"message_wrapper.cc", "message_wrapper.cc",
...@@ -111,8 +109,6 @@ static_library("test_support") { ...@@ -111,8 +109,6 @@ static_library("test_support") {
"fake_tether_host_fetcher.h", "fake_tether_host_fetcher.h",
"fake_wifi_hotspot_connector.cc", "fake_wifi_hotspot_connector.cc",
"fake_wifi_hotspot_connector.h", "fake_wifi_hotspot_connector.h",
"mock_local_device_data_provider.cc",
"mock_local_device_data_provider.h",
"mock_tether_host_response_recorder.cc", "mock_tether_host_response_recorder.cc",
"mock_tether_host_response_recorder.h", "mock_tether_host_response_recorder.h",
"proto_test_util.cc", "proto_test_util.cc",
...@@ -155,7 +151,6 @@ source_set("unit_tests") { ...@@ -155,7 +151,6 @@ source_set("unit_tests") {
"initializer_unittest.cc", "initializer_unittest.cc",
"keep_alive_operation_unittest.cc", "keep_alive_operation_unittest.cc",
"keep_alive_scheduler_unittest.cc", "keep_alive_scheduler_unittest.cc",
"local_device_data_provider_unittest.cc",
"message_transfer_operation_unittest.cc", "message_transfer_operation_unittest.cc",
"message_wrapper_unittest.cc", "message_wrapper_unittest.cc",
"network_configuration_remover_unittest.cc", "network_configuration_remover_unittest.cc",
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "chromeos/components/tether/ble_constants.h" #include "chromeos/components/tether/ble_constants.h"
#include "chromeos/components/tether/local_device_data_provider.h" #include "components/cryptauth/local_device_data_provider.h"
#include "components/cryptauth/proto/cryptauth_api.pb.h" #include "components/cryptauth/proto/cryptauth_api.pb.h"
#include "components/cryptauth/remote_beacon_seed_fetcher.h" #include "components/cryptauth/remote_beacon_seed_fetcher.h"
#include "components/proximity_auth/logging/logging.h" #include "components/proximity_auth/logging/logging.h"
...@@ -145,7 +145,7 @@ BleAdvertiser::IndividualAdvertisement::CreateServiceData() const { ...@@ -145,7 +145,7 @@ BleAdvertiser::IndividualAdvertisement::CreateServiceData() const {
BleAdvertiser::BleAdvertiser( BleAdvertiser::BleAdvertiser(
scoped_refptr<device::BluetoothAdapter> adapter, scoped_refptr<device::BluetoothAdapter> adapter,
const LocalDeviceDataProvider* local_device_data_provider, const cryptauth::LocalDeviceDataProvider* local_device_data_provider,
const cryptauth::RemoteBeaconSeedFetcher* remote_beacon_seed_fetcher) const cryptauth::RemoteBeaconSeedFetcher* remote_beacon_seed_fetcher)
: BleAdvertiser(adapter, : BleAdvertiser(adapter,
base::MakeUnique<cryptauth::ForegroundEidGenerator>(), base::MakeUnique<cryptauth::ForegroundEidGenerator>(),
...@@ -158,7 +158,7 @@ BleAdvertiser::BleAdvertiser( ...@@ -158,7 +158,7 @@ BleAdvertiser::BleAdvertiser(
scoped_refptr<device::BluetoothAdapter> adapter, scoped_refptr<device::BluetoothAdapter> adapter,
std::unique_ptr<cryptauth::ForegroundEidGenerator> eid_generator, std::unique_ptr<cryptauth::ForegroundEidGenerator> eid_generator,
const cryptauth::RemoteBeaconSeedFetcher* remote_beacon_seed_fetcher, const cryptauth::RemoteBeaconSeedFetcher* remote_beacon_seed_fetcher,
const LocalDeviceDataProvider* local_device_data_provider) const cryptauth::LocalDeviceDataProvider* local_device_data_provider)
: adapter_(adapter), : adapter_(adapter),
eid_generator_(std::move(eid_generator)), eid_generator_(std::move(eid_generator)),
remote_beacon_seed_fetcher_(remote_beacon_seed_fetcher), remote_beacon_seed_fetcher_(remote_beacon_seed_fetcher),
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "device/bluetooth/bluetooth_advertisement.h" #include "device/bluetooth/bluetooth_advertisement.h"
namespace cryptauth { namespace cryptauth {
class LocalDeviceDataProvider;
class RemoteBeaconSeedFetcher; class RemoteBeaconSeedFetcher;
} }
...@@ -22,8 +23,6 @@ namespace chromeos { ...@@ -22,8 +23,6 @@ namespace chromeos {
namespace tether { namespace tether {
class LocalDeviceDataProvider;
// Advertises to a given device. When StartAdvertisingToDevice() is called, a // Advertises to a given device. When StartAdvertisingToDevice() is called, a
// device-specific EID value is computed deterministically and is set as the // device-specific EID value is computed deterministically and is set as the
// service data of the advertisement. If that device is nearby and scanning, // service data of the advertisement. If that device is nearby and scanning,
...@@ -33,7 +32,7 @@ class BleAdvertiser { ...@@ -33,7 +32,7 @@ class BleAdvertiser {
public: public:
BleAdvertiser( BleAdvertiser(
scoped_refptr<device::BluetoothAdapter> adapter, scoped_refptr<device::BluetoothAdapter> adapter,
const LocalDeviceDataProvider* local_device_data_provider, const cryptauth::LocalDeviceDataProvider* local_device_data_provider,
const cryptauth::RemoteBeaconSeedFetcher* remote_beacon_seed_fetcher); const cryptauth::RemoteBeaconSeedFetcher* remote_beacon_seed_fetcher);
virtual ~BleAdvertiser(); virtual ~BleAdvertiser();
...@@ -95,14 +94,14 @@ class BleAdvertiser { ...@@ -95,14 +94,14 @@ class BleAdvertiser {
scoped_refptr<device::BluetoothAdapter> adapter, scoped_refptr<device::BluetoothAdapter> adapter,
std::unique_ptr<cryptauth::ForegroundEidGenerator> eid_generator, std::unique_ptr<cryptauth::ForegroundEidGenerator> eid_generator,
const cryptauth::RemoteBeaconSeedFetcher* remote_beacon_seed_fetcher, const cryptauth::RemoteBeaconSeedFetcher* remote_beacon_seed_fetcher,
const LocalDeviceDataProvider* local_device_data_provider); const cryptauth::LocalDeviceDataProvider* local_device_data_provider);
scoped_refptr<device::BluetoothAdapter> adapter_; scoped_refptr<device::BluetoothAdapter> adapter_;
std::unique_ptr<cryptauth::ForegroundEidGenerator> eid_generator_; std::unique_ptr<cryptauth::ForegroundEidGenerator> eid_generator_;
// Not owned by this instance and must outlive it. // Not owned by this instance and must outlive it.
const cryptauth::RemoteBeaconSeedFetcher* remote_beacon_seed_fetcher_; const cryptauth::RemoteBeaconSeedFetcher* remote_beacon_seed_fetcher_;
const LocalDeviceDataProvider* local_device_data_provider_; const cryptauth::LocalDeviceDataProvider* local_device_data_provider_;
std::map<std::string, std::unique_ptr<IndividualAdvertisement>> std::map<std::string, std::unique_ptr<IndividualAdvertisement>>
device_id_to_advertisement_map_; device_id_to_advertisement_map_;
......
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
#include "base/logging.h" #include "base/logging.h"
#include "chromeos/components/tether/ble_constants.h" #include "chromeos/components/tether/ble_constants.h"
#include "chromeos/components/tether/mock_local_device_data_provider.h"
#include "components/cryptauth/mock_foreground_eid_generator.h" #include "components/cryptauth/mock_foreground_eid_generator.h"
#include "components/cryptauth/mock_local_device_data_provider.h"
#include "components/cryptauth/mock_remote_beacon_seed_fetcher.h" #include "components/cryptauth/mock_remote_beacon_seed_fetcher.h"
#include "components/cryptauth/proto/cryptauth_api.pb.h" #include "components/cryptauth/proto/cryptauth_api.pb.h"
#include "components/cryptauth/remote_device_test_util.h" #include "components/cryptauth/remote_device_test_util.h"
...@@ -148,7 +148,8 @@ class BleAdvertiserTest : public testing::Test { ...@@ -148,7 +148,8 @@ class BleAdvertiserTest : public testing::Test {
mock_seed_fetcher_->SetSeedsForDevice(fake_devices_[2], mock_seed_fetcher_->SetSeedsForDevice(fake_devices_[2],
&device_2_beacon_seeds); &device_2_beacon_seeds);
mock_local_data_provider_ = base::MakeUnique<MockLocalDeviceDataProvider>(); mock_local_data_provider_ =
base::MakeUnique<cryptauth::MockLocalDeviceDataProvider>();
mock_local_data_provider_->SetPublicKey( mock_local_data_provider_->SetPublicKey(
base::MakeUnique<std::string>(kFakePublicKey)); base::MakeUnique<std::string>(kFakePublicKey));
...@@ -233,7 +234,8 @@ class BleAdvertiserTest : public testing::Test { ...@@ -233,7 +234,8 @@ class BleAdvertiserTest : public testing::Test {
mock_adapter_; mock_adapter_;
cryptauth::MockForegroundEidGenerator* mock_eid_generator_; cryptauth::MockForegroundEidGenerator* mock_eid_generator_;
std::unique_ptr<cryptauth::MockRemoteBeaconSeedFetcher> mock_seed_fetcher_; std::unique_ptr<cryptauth::MockRemoteBeaconSeedFetcher> mock_seed_fetcher_;
std::unique_ptr<MockLocalDeviceDataProvider> mock_local_data_provider_; std::unique_ptr<cryptauth::MockLocalDeviceDataProvider>
mock_local_data_provider_;
std::vector<scoped_refptr<RegisterAdvertisementArgs>> std::vector<scoped_refptr<RegisterAdvertisementArgs>>
register_advertisement_args_; register_advertisement_args_;
......
...@@ -169,7 +169,7 @@ void BleConnectionManager::ConnectionMetadata::OnMessageReceived( ...@@ -169,7 +169,7 @@ void BleConnectionManager::ConnectionMetadata::OnMessageReceived(
BleConnectionManager::BleConnectionManager( BleConnectionManager::BleConnectionManager(
cryptauth::CryptAuthService* cryptauth_service, cryptauth::CryptAuthService* cryptauth_service,
scoped_refptr<device::BluetoothAdapter> adapter, scoped_refptr<device::BluetoothAdapter> adapter,
const LocalDeviceDataProvider* local_device_data_provider, const cryptauth::LocalDeviceDataProvider* local_device_data_provider,
const cryptauth::RemoteBeaconSeedFetcher* remote_beacon_seed_fetcher, const cryptauth::RemoteBeaconSeedFetcher* remote_beacon_seed_fetcher,
cryptauth::BluetoothThrottler* bluetooth_throttler) cryptauth::BluetoothThrottler* bluetooth_throttler)
: BleConnectionManager( : BleConnectionManager(
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
namespace cryptauth { namespace cryptauth {
class BluetoothThrottler; class BluetoothThrottler;
class CryptAuthService; class CryptAuthService;
class LocalDeviceDataProvider;
} // namespace cryptauth } // namespace cryptauth
namespace chromeos { namespace chromeos {
...@@ -71,7 +72,7 @@ class BleConnectionManager : public BleScanner::Observer { ...@@ -71,7 +72,7 @@ class BleConnectionManager : public BleScanner::Observer {
BleConnectionManager( BleConnectionManager(
cryptauth::CryptAuthService* cryptauth_service, cryptauth::CryptAuthService* cryptauth_service,
scoped_refptr<device::BluetoothAdapter> adapter, scoped_refptr<device::BluetoothAdapter> adapter,
const LocalDeviceDataProvider* local_device_data_provider, const cryptauth::LocalDeviceDataProvider* local_device_data_provider,
const cryptauth::RemoteBeaconSeedFetcher* remote_beacon_seed_fetcher, const cryptauth::RemoteBeaconSeedFetcher* remote_beacon_seed_fetcher,
cryptauth::BluetoothThrottler* bluetooth_throttler); cryptauth::BluetoothThrottler* bluetooth_throttler);
virtual ~BleConnectionManager(); virtual ~BleConnectionManager();
......
...@@ -46,7 +46,7 @@ BleScanner::ServiceDataProviderImpl::GetServiceDataForUUID( ...@@ -46,7 +46,7 @@ BleScanner::ServiceDataProviderImpl::GetServiceDataForUUID(
BleScanner::BleScanner( BleScanner::BleScanner(
scoped_refptr<device::BluetoothAdapter> adapter, scoped_refptr<device::BluetoothAdapter> adapter,
const LocalDeviceDataProvider* local_device_data_provider) const cryptauth::LocalDeviceDataProvider* local_device_data_provider)
: BleScanner(base::MakeUnique<ServiceDataProviderImpl>(), : BleScanner(base::MakeUnique<ServiceDataProviderImpl>(),
adapter, adapter,
base::WrapUnique(new cryptauth::ForegroundEidGenerator()), base::WrapUnique(new cryptauth::ForegroundEidGenerator()),
...@@ -56,7 +56,7 @@ BleScanner::BleScanner( ...@@ -56,7 +56,7 @@ BleScanner::BleScanner(
std::unique_ptr<ServiceDataProvider> service_data_provider, std::unique_ptr<ServiceDataProvider> service_data_provider,
scoped_refptr<device::BluetoothAdapter> adapter, scoped_refptr<device::BluetoothAdapter> adapter,
std::unique_ptr<cryptauth::ForegroundEidGenerator> eid_generator, std::unique_ptr<cryptauth::ForegroundEidGenerator> eid_generator,
const LocalDeviceDataProvider* local_device_data_provider) const cryptauth::LocalDeviceDataProvider* local_device_data_provider)
: service_data_provider_(std::move(service_data_provider)), : service_data_provider_(std::move(service_data_provider)),
adapter_(adapter), adapter_(adapter),
eid_generator_(std::move(eid_generator)), eid_generator_(std::move(eid_generator)),
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/observer_list.h" #include "base/observer_list.h"
#include "chromeos/components/tether/local_device_data_provider.h"
#include "components/cryptauth/foreground_eid_generator.h" #include "components/cryptauth/foreground_eid_generator.h"
#include "components/cryptauth/local_device_data_provider.h"
#include "device/bluetooth/bluetooth_adapter.h" #include "device/bluetooth/bluetooth_adapter.h"
#include "device/bluetooth/bluetooth_adapter_factory.h" #include "device/bluetooth/bluetooth_adapter_factory.h"
...@@ -33,8 +33,9 @@ class BleScanner : public device::BluetoothAdapter::Observer { ...@@ -33,8 +33,9 @@ class BleScanner : public device::BluetoothAdapter::Observer {
cryptauth::RemoteDevice remote_device) = 0; cryptauth::RemoteDevice remote_device) = 0;
}; };
BleScanner(scoped_refptr<device::BluetoothAdapter> adapter, BleScanner(
const LocalDeviceDataProvider* local_device_data_provider); scoped_refptr<device::BluetoothAdapter> adapter,
const cryptauth::LocalDeviceDataProvider* local_device_data_provider);
~BleScanner() override; ~BleScanner() override;
virtual bool RegisterScanFilterForDevice( virtual bool RegisterScanFilterForDevice(
...@@ -76,10 +77,11 @@ class BleScanner : public device::BluetoothAdapter::Observer { ...@@ -76,10 +77,11 @@ class BleScanner : public device::BluetoothAdapter::Observer {
device::BluetoothDevice* bluetooth_device) override; device::BluetoothDevice* bluetooth_device) override;
}; };
BleScanner(std::unique_ptr<ServiceDataProvider> service_data_provider, BleScanner(
scoped_refptr<device::BluetoothAdapter> adapter, std::unique_ptr<ServiceDataProvider> service_data_provider,
std::unique_ptr<cryptauth::ForegroundEidGenerator> eid_generator, scoped_refptr<device::BluetoothAdapter> adapter,
const LocalDeviceDataProvider* local_device_data_provider); std::unique_ptr<cryptauth::ForegroundEidGenerator> eid_generator,
const cryptauth::LocalDeviceDataProvider* local_device_data_provider);
void UpdateDiscoveryStatus(); void UpdateDiscoveryStatus();
void StartDiscoverySession(); void StartDiscoverySession();
...@@ -98,7 +100,7 @@ class BleScanner : public device::BluetoothAdapter::Observer { ...@@ -98,7 +100,7 @@ class BleScanner : public device::BluetoothAdapter::Observer {
std::unique_ptr<cryptauth::ForegroundEidGenerator> eid_generator_; std::unique_ptr<cryptauth::ForegroundEidGenerator> eid_generator_;
// |local_device_data_provider_| is not owned by this instance and must // |local_device_data_provider_| is not owned by this instance and must
// outlive it. // outlive it.
const LocalDeviceDataProvider* local_device_data_provider_; const cryptauth::LocalDeviceDataProvider* local_device_data_provider_;
bool is_initializing_discovery_session_; bool is_initializing_discovery_session_;
std::unique_ptr<device::BluetoothDiscoverySession> discovery_session_; std::unique_ptr<device::BluetoothDiscoverySession> discovery_session_;
......
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
#include "base/logging.h" #include "base/logging.h"
#include "chromeos/components/tether/ble_constants.h" #include "chromeos/components/tether/ble_constants.h"
#include "chromeos/components/tether/mock_local_device_data_provider.h"
#include "components/cryptauth/mock_foreground_eid_generator.h" #include "components/cryptauth/mock_foreground_eid_generator.h"
#include "components/cryptauth/mock_local_device_data_provider.h"
#include "components/cryptauth/proto/cryptauth_api.pb.h" #include "components/cryptauth/proto/cryptauth_api.pb.h"
#include "components/cryptauth/remote_device_test_util.h" #include "components/cryptauth/remote_device_test_util.h"
#include "device/bluetooth/test/mock_bluetooth_adapter.h" #include "device/bluetooth/test/mock_bluetooth_adapter.h"
...@@ -159,7 +159,7 @@ class BleScannerTest : public testing::Test { ...@@ -159,7 +159,7 @@ class BleScannerTest : public testing::Test {
CreateFakeBackgroundScanFilter()); CreateFakeBackgroundScanFilter());
mock_local_device_data_provider_ = mock_local_device_data_provider_ =
base::MakeUnique<MockLocalDeviceDataProvider>(); base::MakeUnique<cryptauth::MockLocalDeviceDataProvider>();
mock_local_device_data_provider_->SetPublicKey( mock_local_device_data_provider_->SetPublicKey(
base::MakeUnique<std::string>(fake_local_public_key)); base::MakeUnique<std::string>(fake_local_public_key));
mock_local_device_data_provider_->SetBeaconSeeds( mock_local_device_data_provider_->SetBeaconSeeds(
...@@ -226,7 +226,8 @@ class BleScannerTest : public testing::Test { ...@@ -226,7 +226,8 @@ class BleScannerTest : public testing::Test {
TestServiceDataProvider* test_service_data_provider_; TestServiceDataProvider* test_service_data_provider_;
cryptauth::MockForegroundEidGenerator* mock_eid_generator_; cryptauth::MockForegroundEidGenerator* mock_eid_generator_;
std::unique_ptr<MockLocalDeviceDataProvider> mock_local_device_data_provider_; std::unique_ptr<cryptauth::MockLocalDeviceDataProvider>
mock_local_device_data_provider_;
scoped_refptr<NiceMock<device::MockBluetoothAdapter>> mock_adapter_; scoped_refptr<NiceMock<device::MockBluetoothAdapter>> mock_adapter_;
device::MockBluetoothDiscoverySession* mock_discovery_session_; device::MockBluetoothDiscoverySession* mock_discovery_session_;
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include "chromeos/components/tether/host_scan_scheduler.h" #include "chromeos/components/tether/host_scan_scheduler.h"
#include "chromeos/components/tether/host_scanner.h" #include "chromeos/components/tether/host_scanner.h"
#include "chromeos/components/tether/keep_alive_scheduler.h" #include "chromeos/components/tether/keep_alive_scheduler.h"
#include "chromeos/components/tether/local_device_data_provider.h"
#include "chromeos/components/tether/network_configuration_remover.h" #include "chromeos/components/tether/network_configuration_remover.h"
#include "chromeos/components/tether/network_connection_handler_tether_delegate.h" #include "chromeos/components/tether/network_connection_handler_tether_delegate.h"
#include "chromeos/components/tether/notification_presenter.h" #include "chromeos/components/tether/notification_presenter.h"
...@@ -30,6 +29,7 @@ ...@@ -30,6 +29,7 @@
#include "chromeos/network/network_state_handler.h" #include "chromeos/network/network_state_handler.h"
#include "components/cryptauth/bluetooth_throttler_impl.h" #include "components/cryptauth/bluetooth_throttler_impl.h"
#include "components/cryptauth/cryptauth_service.h" #include "components/cryptauth/cryptauth_service.h"
#include "components/cryptauth/local_device_data_provider.h"
#include "components/cryptauth/remote_beacon_seed_fetcher.h" #include "components/cryptauth/remote_beacon_seed_fetcher.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/proximity_auth/logging/logging.h" #include "components/proximity_auth/logging/logging.h"
...@@ -174,7 +174,7 @@ void Initializer::OnBluetoothAdapterAdvertisingIntervalSet( ...@@ -174,7 +174,7 @@ void Initializer::OnBluetoothAdapterAdvertisingIntervalSet(
tether_host_fetcher_ = tether_host_fetcher_ =
base::MakeUnique<TetherHostFetcher>(cryptauth_service_); base::MakeUnique<TetherHostFetcher>(cryptauth_service_);
local_device_data_provider_ = local_device_data_provider_ =
base::MakeUnique<LocalDeviceDataProvider>(cryptauth_service_); base::MakeUnique<cryptauth::LocalDeviceDataProvider>(cryptauth_service_);
remote_beacon_seed_fetcher_ = remote_beacon_seed_fetcher_ =
base::MakeUnique<cryptauth::RemoteBeaconSeedFetcher>( base::MakeUnique<cryptauth::RemoteBeaconSeedFetcher>(
cryptauth_service_->GetCryptAuthDeviceManager()); cryptauth_service_->GetCryptAuthDeviceManager());
......
...@@ -21,6 +21,7 @@ class PrefService; ...@@ -21,6 +21,7 @@ class PrefService;
namespace cryptauth { namespace cryptauth {
class CryptAuthService; class CryptAuthService;
class LocalDeviceDataProvider;
class RemoteBeaconSeedFetcher; class RemoteBeaconSeedFetcher;
} }
...@@ -43,7 +44,6 @@ class HostScanner; ...@@ -43,7 +44,6 @@ class HostScanner;
class HostScanScheduler; class HostScanScheduler;
class HostScanDevicePrioritizerImpl; class HostScanDevicePrioritizerImpl;
class KeepAliveScheduler; class KeepAliveScheduler;
class LocalDeviceDataProvider;
class NetworkConfigurationRemover; class NetworkConfigurationRemover;
class NotificationPresenter; class NotificationPresenter;
class TetherConnector; class TetherConnector;
...@@ -113,7 +113,8 @@ class Initializer : public OAuth2TokenService::Observer { ...@@ -113,7 +113,8 @@ class Initializer : public OAuth2TokenService::Observer {
// initialization to ensure that they are destroyed in the correct order. This // initialization to ensure that they are destroyed in the correct order. This
// order will be enforced by InitializerTest.TestCreateAndDestroy. // order will be enforced by InitializerTest.TestCreateAndDestroy.
std::unique_ptr<TetherHostFetcher> tether_host_fetcher_; std::unique_ptr<TetherHostFetcher> tether_host_fetcher_;
std::unique_ptr<LocalDeviceDataProvider> local_device_data_provider_; std::unique_ptr<cryptauth::LocalDeviceDataProvider>
local_device_data_provider_;
std::unique_ptr<cryptauth::RemoteBeaconSeedFetcher> std::unique_ptr<cryptauth::RemoteBeaconSeedFetcher>
remote_beacon_seed_fetcher_; remote_beacon_seed_fetcher_;
std::unique_ptr<BleConnectionManager> ble_connection_manager_; std::unique_ptr<BleConnectionManager> ble_connection_manager_;
......
...@@ -50,6 +50,8 @@ static_library("cryptauth") { ...@@ -50,6 +50,8 @@ static_library("cryptauth") {
"device_to_device_secure_context.h", "device_to_device_secure_context.h",
"foreground_eid_generator.cc", "foreground_eid_generator.cc",
"foreground_eid_generator.h", "foreground_eid_generator.h",
"local_device_data_provider.cc",
"local_device_data_provider.h",
"pref_names.cc", "pref_names.cc",
"pref_names.h", "pref_names.h",
"raw_eid_generator.h", "raw_eid_generator.h",
...@@ -124,6 +126,8 @@ static_library("test_support") { ...@@ -124,6 +126,8 @@ static_library("test_support") {
"mock_cryptauth_client.h", "mock_cryptauth_client.h",
"mock_foreground_eid_generator.cc", "mock_foreground_eid_generator.cc",
"mock_foreground_eid_generator.h", "mock_foreground_eid_generator.h",
"mock_local_device_data_provider.cc",
"mock_local_device_data_provider.h",
"mock_remote_beacon_seed_fetcher.cc", "mock_remote_beacon_seed_fetcher.cc",
"mock_remote_beacon_seed_fetcher.h", "mock_remote_beacon_seed_fetcher.h",
"mock_sync_scheduler.cc", "mock_sync_scheduler.cc",
...@@ -162,6 +166,7 @@ source_set("unit_tests") { ...@@ -162,6 +166,7 @@ source_set("unit_tests") {
"device_to_device_secure_context_unittest.cc", "device_to_device_secure_context_unittest.cc",
"fake_secure_message_delegate_unittest.cc", "fake_secure_message_delegate_unittest.cc",
"foreground_eid_generator_unittest.cc", "foreground_eid_generator_unittest.cc",
"local_device_data_provider_unittest.cc",
"raw_eid_generator_impl_unittest.cc", "raw_eid_generator_impl_unittest.cc",
"remote_beacon_seed_fetcher_unittest.cc", "remote_beacon_seed_fetcher_unittest.cc",
"remote_device_loader_unittest.cc", "remote_device_loader_unittest.cc",
......
...@@ -2,26 +2,24 @@ ...@@ -2,26 +2,24 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chromeos/components/tether/local_device_data_provider.h" #include "components/cryptauth/local_device_data_provider.h"
#include "components/cryptauth/cryptauth_device_manager.h" #include "components/cryptauth/cryptauth_device_manager.h"
#include "components/cryptauth/cryptauth_enrollment_manager.h" #include "components/cryptauth/cryptauth_enrollment_manager.h"
#include "components/cryptauth/cryptauth_service.h" #include "components/cryptauth/cryptauth_service.h"
#include "components/cryptauth/proto/cryptauth_api.pb.h" #include "components/cryptauth/proto/cryptauth_api.pb.h"
namespace chromeos { namespace cryptauth {
namespace tether {
LocalDeviceDataProvider::LocalDeviceDataProvider( LocalDeviceDataProvider::LocalDeviceDataProvider(
cryptauth::CryptAuthService* cryptauth_service) CryptAuthService* cryptauth_service)
: cryptauth_service_(cryptauth_service) {} : cryptauth_service_(cryptauth_service) {}
LocalDeviceDataProvider::~LocalDeviceDataProvider() {} LocalDeviceDataProvider::~LocalDeviceDataProvider() {}
bool LocalDeviceDataProvider::GetLocalDeviceData( bool LocalDeviceDataProvider::GetLocalDeviceData(
std::string* public_key_out, std::string* public_key_out,
std::vector<cryptauth::BeaconSeed>* beacon_seeds_out) const { std::vector<BeaconSeed>* beacon_seeds_out) const {
DCHECK(public_key_out || beacon_seeds_out); DCHECK(public_key_out || beacon_seeds_out);
std::string public_key = std::string public_key =
...@@ -30,7 +28,7 @@ bool LocalDeviceDataProvider::GetLocalDeviceData( ...@@ -30,7 +28,7 @@ bool LocalDeviceDataProvider::GetLocalDeviceData(
return false; return false;
} }
std::vector<cryptauth::ExternalDeviceInfo> synced_devices = std::vector<ExternalDeviceInfo> synced_devices =
cryptauth_service_->GetCryptAuthDeviceManager()->GetSyncedDevices(); cryptauth_service_->GetCryptAuthDeviceManager()->GetSyncedDevices();
for (const auto& device : synced_devices) { for (const auto& device : synced_devices) {
if (device.has_public_key() && device.public_key() == public_key && if (device.has_public_key() && device.public_key() == public_key &&
...@@ -53,6 +51,4 @@ bool LocalDeviceDataProvider::GetLocalDeviceData( ...@@ -53,6 +51,4 @@ bool LocalDeviceDataProvider::GetLocalDeviceData(
return false; return false;
} }
} // namespace tether } // namespace cryptauth
} // namespace chromeos
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROMEOS_COMPONENTS_TETHER_LOCAL_DEVICE_DATA_PROVIDER_H_ #ifndef COMPONENTS_CRYPTAUTH_LOCAL_DEVICE_DATA_PROVIDER_H_
#define CHROMEOS_COMPONENTS_TETHER_LOCAL_DEVICE_DATA_PROVIDER_H_ #define COMPONENTS_CRYPTAUTH_LOCAL_DEVICE_DATA_PROVIDER_H_
#include <memory> #include <memory>
#include <string> #include <string>
...@@ -13,20 +13,15 @@ ...@@ -13,20 +13,15 @@
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
namespace cryptauth { namespace cryptauth {
class BeaconSeed; class BeaconSeed;
class CryptAuthService; class CryptAuthService;
}
namespace chromeos {
namespace tether {
// Fetches CryptAuth data about the local device (i.e., the device on which this // Fetches CryptAuth data about the local device (i.e., the device on which this
// code is running) for the current user (i.e., the one which is logged-in). // code is running) for the current user (i.e., the one which is logged-in).
class LocalDeviceDataProvider { class LocalDeviceDataProvider {
public: public:
explicit LocalDeviceDataProvider( explicit LocalDeviceDataProvider(CryptAuthService* cryptauth_service);
cryptauth::CryptAuthService* cryptauth_service);
virtual ~LocalDeviceDataProvider(); virtual ~LocalDeviceDataProvider();
// Fetches the public key and/or the beacon seeds for the local device. // Fetches the public key and/or the beacon seeds for the local device.
...@@ -34,18 +29,16 @@ class LocalDeviceDataProvider { ...@@ -34,18 +29,16 @@ class LocalDeviceDataProvider {
// parameter, the associated data will not be fetched. // parameter, the associated data will not be fetched.
virtual bool GetLocalDeviceData( virtual bool GetLocalDeviceData(
std::string* public_key_out, std::string* public_key_out,
std::vector<cryptauth::BeaconSeed>* beacon_seeds_out) const; std::vector<BeaconSeed>* beacon_seeds_out) const;
private: private:
friend class LocalDeviceDataProviderTest; friend class LocalDeviceDataProviderTest;
cryptauth::CryptAuthService* cryptauth_service_; CryptAuthService* cryptauth_service_;
DISALLOW_COPY_AND_ASSIGN(LocalDeviceDataProvider); DISALLOW_COPY_AND_ASSIGN(LocalDeviceDataProvider);
}; };
} // namespace tether } // namespace cryptauth
} // namespace chromeos
#endif // CHROMEOS_COMPONENTS_TETHER_LOCAL_DEVICE_DATA_PROVIDER_H_ #endif // COMPONENTS_CRYPTAUTH_LOCAL_DEVICE_DATA_PROVIDER_H_
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chromeos/components/tether/local_device_data_provider.h" #include "components/cryptauth/local_device_data_provider.h"
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -22,9 +22,7 @@ ...@@ -22,9 +22,7 @@
using testing::NiceMock; using testing::NiceMock;
using testing::Return; using testing::Return;
namespace chromeos { namespace cryptauth {
namespace tether {
namespace { namespace {
...@@ -38,36 +36,33 @@ const char kBeaconSeed2Data[] = "beaconSeed2Data"; ...@@ -38,36 +36,33 @@ const char kBeaconSeed2Data[] = "beaconSeed2Data";
const int64_t kBeaconSeed2StartMs = 2000L; const int64_t kBeaconSeed2StartMs = 2000L;
const int64_t kBeaconSeed2EndMs = 3000L; const int64_t kBeaconSeed2EndMs = 3000L;
class MockCryptAuthDeviceManager : public cryptauth::CryptAuthDeviceManager { class MockCryptAuthDeviceManager : public CryptAuthDeviceManager {
public: public:
MockCryptAuthDeviceManager() {} MockCryptAuthDeviceManager() {}
~MockCryptAuthDeviceManager() override {} ~MockCryptAuthDeviceManager() override {}
MOCK_CONST_METHOD0(GetSyncedDevices, MOCK_CONST_METHOD0(GetSyncedDevices, std::vector<ExternalDeviceInfo>());
std::vector<cryptauth::ExternalDeviceInfo>());
}; };
class MockCryptAuthEnrollmentManager class MockCryptAuthEnrollmentManager : public CryptAuthEnrollmentManager {
: public cryptauth::CryptAuthEnrollmentManager {
public: public:
explicit MockCryptAuthEnrollmentManager( explicit MockCryptAuthEnrollmentManager(
cryptauth::FakeCryptAuthGCMManager* fake_cryptauth_gcm_manager) FakeCryptAuthGCMManager* fake_cryptauth_gcm_manager)
: cryptauth::CryptAuthEnrollmentManager( : CryptAuthEnrollmentManager(nullptr /* clock */,
nullptr /* clock */, nullptr /* enroller_factory */,
nullptr /* enroller_factory */, nullptr /* secure_message_delegate */,
nullptr /* secure_message_delegate */, GcmDeviceInfo(),
cryptauth::GcmDeviceInfo(), fake_cryptauth_gcm_manager,
fake_cryptauth_gcm_manager, nullptr /* pref_service */) {}
nullptr /* pref_service */) {}
~MockCryptAuthEnrollmentManager() override {} ~MockCryptAuthEnrollmentManager() override {}
MOCK_CONST_METHOD0(GetUserPublicKey, std::string()); MOCK_CONST_METHOD0(GetUserPublicKey, std::string());
}; };
cryptauth::BeaconSeed CreateBeaconSeed(const std::string& data, BeaconSeed CreateBeaconSeed(const std::string& data,
int64_t start_ms, int64_t start_ms,
int64_t end_ms) { int64_t end_ms) {
cryptauth::BeaconSeed seed; BeaconSeed seed;
seed.set_data(data); seed.set_data(data);
seed.set_start_time_millis(start_ms); seed.set_start_time_millis(start_ms);
seed.set_end_time_millis(end_ms); seed.set_end_time_millis(end_ms);
...@@ -85,11 +80,11 @@ class LocalDeviceDataProviderTest : public testing::Test { ...@@ -85,11 +80,11 @@ class LocalDeviceDataProviderTest : public testing::Test {
kBeaconSeed2Data, kBeaconSeed2StartMs, kBeaconSeed2EndMs)); kBeaconSeed2Data, kBeaconSeed2StartMs, kBeaconSeed2EndMs));
// Has no public key and no BeaconSeeds. // Has no public key and no BeaconSeeds.
cryptauth::ExternalDeviceInfo synced_device1; ExternalDeviceInfo synced_device1;
fake_synced_devices_.push_back(synced_device1); fake_synced_devices_.push_back(synced_device1);
// Has no public key and some BeaconSeeds. // Has no public key and some BeaconSeeds.
cryptauth::ExternalDeviceInfo synced_device2; ExternalDeviceInfo synced_device2;
synced_device2.add_beacon_seeds()->CopyFrom(CreateBeaconSeed( synced_device2.add_beacon_seeds()->CopyFrom(CreateBeaconSeed(
kBeaconSeed1Data, kBeaconSeed1StartMs, kBeaconSeed1EndMs)); kBeaconSeed1Data, kBeaconSeed1StartMs, kBeaconSeed1EndMs));
synced_device2.add_beacon_seeds()->CopyFrom(CreateBeaconSeed( synced_device2.add_beacon_seeds()->CopyFrom(CreateBeaconSeed(
...@@ -97,12 +92,12 @@ class LocalDeviceDataProviderTest : public testing::Test { ...@@ -97,12 +92,12 @@ class LocalDeviceDataProviderTest : public testing::Test {
fake_synced_devices_.push_back(synced_device2); fake_synced_devices_.push_back(synced_device2);
// Has another different public key and no BeaconSeeds. // Has another different public key and no BeaconSeeds.
cryptauth::ExternalDeviceInfo synced_device3; ExternalDeviceInfo synced_device3;
synced_device3.set_public_key("anotherPublicKey"); synced_device3.set_public_key("anotherPublicKey");
fake_synced_devices_.push_back(synced_device3); fake_synced_devices_.push_back(synced_device3);
// Has different public key and BeaconSeeds. // Has different public key and BeaconSeeds.
cryptauth::ExternalDeviceInfo synced_device4; ExternalDeviceInfo synced_device4;
synced_device4.set_public_key("otherPublicKey"); synced_device4.set_public_key("otherPublicKey");
synced_device4.add_beacon_seeds()->CopyFrom(CreateBeaconSeed( synced_device4.add_beacon_seeds()->CopyFrom(CreateBeaconSeed(
kBeaconSeed1Data, kBeaconSeed1StartMs, kBeaconSeed1EndMs)); kBeaconSeed1Data, kBeaconSeed1StartMs, kBeaconSeed1EndMs));
...@@ -111,12 +106,12 @@ class LocalDeviceDataProviderTest : public testing::Test { ...@@ -111,12 +106,12 @@ class LocalDeviceDataProviderTest : public testing::Test {
fake_synced_devices_.push_back(synced_device4); fake_synced_devices_.push_back(synced_device4);
// Has public key but no BeaconSeeds. // Has public key but no BeaconSeeds.
cryptauth::ExternalDeviceInfo synced_device5; ExternalDeviceInfo synced_device5;
synced_device5.set_public_key(kDefaultPublicKey); synced_device5.set_public_key(kDefaultPublicKey);
fake_synced_devices_.push_back(synced_device5); fake_synced_devices_.push_back(synced_device5);
// Has public key and BeaconSeeds. // Has public key and BeaconSeeds.
cryptauth::ExternalDeviceInfo synced_device6; ExternalDeviceInfo synced_device6;
synced_device6.set_public_key(kDefaultPublicKey); synced_device6.set_public_key(kDefaultPublicKey);
synced_device6.add_beacon_seeds()->CopyFrom(CreateBeaconSeed( synced_device6.add_beacon_seeds()->CopyFrom(CreateBeaconSeed(
kBeaconSeed1Data, kBeaconSeed1StartMs, kBeaconSeed1EndMs)); kBeaconSeed1Data, kBeaconSeed1StartMs, kBeaconSeed1EndMs));
...@@ -129,13 +124,12 @@ class LocalDeviceDataProviderTest : public testing::Test { ...@@ -129,13 +124,12 @@ class LocalDeviceDataProviderTest : public testing::Test {
mock_device_manager_ = mock_device_manager_ =
base::WrapUnique(new NiceMock<MockCryptAuthDeviceManager>()); base::WrapUnique(new NiceMock<MockCryptAuthDeviceManager>());
fake_cryptauth_gcm_manager_ = fake_cryptauth_gcm_manager_ =
base::MakeUnique<cryptauth::FakeCryptAuthGCMManager>("registrationId"); base::MakeUnique<FakeCryptAuthGCMManager>("registrationId");
mock_enrollment_manager_ = mock_enrollment_manager_ =
base::WrapUnique(new NiceMock<MockCryptAuthEnrollmentManager>( base::WrapUnique(new NiceMock<MockCryptAuthEnrollmentManager>(
fake_cryptauth_gcm_manager_.get())); fake_cryptauth_gcm_manager_.get()));
fake_cryptauth_service_ = fake_cryptauth_service_ = base::MakeUnique<FakeCryptAuthService>();
base::MakeUnique<cryptauth::FakeCryptAuthService>();
fake_cryptauth_service_->set_cryptauth_device_manager( fake_cryptauth_service_->set_cryptauth_device_manager(
mock_device_manager_.get()); mock_device_manager_.get());
fake_cryptauth_service_->set_cryptauth_enrollment_manager( fake_cryptauth_service_->set_cryptauth_enrollment_manager(
...@@ -145,15 +139,14 @@ class LocalDeviceDataProviderTest : public testing::Test { ...@@ -145,15 +139,14 @@ class LocalDeviceDataProviderTest : public testing::Test {
new LocalDeviceDataProvider(fake_cryptauth_service_.get())); new LocalDeviceDataProvider(fake_cryptauth_service_.get()));
} }
std::vector<cryptauth::BeaconSeed> fake_beacon_seeds_; std::vector<BeaconSeed> fake_beacon_seeds_;
std::vector<cryptauth::ExternalDeviceInfo> fake_synced_devices_; std::vector<ExternalDeviceInfo> fake_synced_devices_;
std::unique_ptr<cryptauth::FakeCryptAuthGCMManager> std::unique_ptr<FakeCryptAuthGCMManager> fake_cryptauth_gcm_manager_;
fake_cryptauth_gcm_manager_;
std::unique_ptr<NiceMock<MockCryptAuthDeviceManager>> mock_device_manager_; std::unique_ptr<NiceMock<MockCryptAuthDeviceManager>> mock_device_manager_;
std::unique_ptr<NiceMock<MockCryptAuthEnrollmentManager>> std::unique_ptr<NiceMock<MockCryptAuthEnrollmentManager>>
mock_enrollment_manager_; mock_enrollment_manager_;
std::unique_ptr<cryptauth::FakeCryptAuthService> fake_cryptauth_service_; std::unique_ptr<FakeCryptAuthService> fake_cryptauth_service_;
std::unique_ptr<LocalDeviceDataProvider> provider_; std::unique_ptr<LocalDeviceDataProvider> provider_;
...@@ -168,7 +161,7 @@ TEST_F(LocalDeviceDataProviderTest, TestGetLocalDeviceData_NoPublicKey) { ...@@ -168,7 +161,7 @@ TEST_F(LocalDeviceDataProviderTest, TestGetLocalDeviceData_NoPublicKey) {
.WillByDefault(Return(fake_synced_devices_)); .WillByDefault(Return(fake_synced_devices_));
std::string public_key; std::string public_key;
std::vector<cryptauth::BeaconSeed> beacon_seeds; std::vector<BeaconSeed> beacon_seeds;
EXPECT_FALSE(provider_->GetLocalDeviceData(&public_key, &beacon_seeds)); EXPECT_FALSE(provider_->GetLocalDeviceData(&public_key, &beacon_seeds));
} }
...@@ -177,10 +170,10 @@ TEST_F(LocalDeviceDataProviderTest, TestGetLocalDeviceData_NoSyncedDevices) { ...@@ -177,10 +170,10 @@ TEST_F(LocalDeviceDataProviderTest, TestGetLocalDeviceData_NoSyncedDevices) {
ON_CALL(*mock_enrollment_manager_, GetUserPublicKey()) ON_CALL(*mock_enrollment_manager_, GetUserPublicKey())
.WillByDefault(Return(kDefaultPublicKey)); .WillByDefault(Return(kDefaultPublicKey));
ON_CALL(*mock_device_manager_, GetSyncedDevices()) ON_CALL(*mock_device_manager_, GetSyncedDevices())
.WillByDefault(Return(std::vector<cryptauth::ExternalDeviceInfo>())); .WillByDefault(Return(std::vector<ExternalDeviceInfo>()));
std::string public_key; std::string public_key;
std::vector<cryptauth::BeaconSeed> beacon_seeds; std::vector<BeaconSeed> beacon_seeds;
EXPECT_FALSE(provider_->GetLocalDeviceData(&public_key, &beacon_seeds)); EXPECT_FALSE(provider_->GetLocalDeviceData(&public_key, &beacon_seeds));
} }
...@@ -190,12 +183,12 @@ TEST_F(LocalDeviceDataProviderTest, ...@@ -190,12 +183,12 @@ TEST_F(LocalDeviceDataProviderTest,
ON_CALL(*mock_enrollment_manager_, GetUserPublicKey()) ON_CALL(*mock_enrollment_manager_, GetUserPublicKey())
.WillByDefault(Return(kDefaultPublicKey)); .WillByDefault(Return(kDefaultPublicKey));
ON_CALL(*mock_device_manager_, GetSyncedDevices()) ON_CALL(*mock_device_manager_, GetSyncedDevices())
.WillByDefault(Return(std::vector<cryptauth::ExternalDeviceInfo>{ .WillByDefault(Return(std::vector<ExternalDeviceInfo>{
fake_synced_devices_[0], fake_synced_devices_[1], fake_synced_devices_[0], fake_synced_devices_[1],
fake_synced_devices_[2], fake_synced_devices_[3]})); fake_synced_devices_[2], fake_synced_devices_[3]}));
std::string public_key; std::string public_key;
std::vector<cryptauth::BeaconSeed> beacon_seeds; std::vector<BeaconSeed> beacon_seeds;
EXPECT_FALSE(provider_->GetLocalDeviceData(&public_key, &beacon_seeds)); EXPECT_FALSE(provider_->GetLocalDeviceData(&public_key, &beacon_seeds));
} }
...@@ -205,12 +198,12 @@ TEST_F(LocalDeviceDataProviderTest, ...@@ -205,12 +198,12 @@ TEST_F(LocalDeviceDataProviderTest,
ON_CALL(*mock_enrollment_manager_, GetUserPublicKey()) ON_CALL(*mock_enrollment_manager_, GetUserPublicKey())
.WillByDefault(Return(kDefaultPublicKey)); .WillByDefault(Return(kDefaultPublicKey));
ON_CALL(*mock_device_manager_, GetSyncedDevices()) ON_CALL(*mock_device_manager_, GetSyncedDevices())
.WillByDefault(Return(std::vector<cryptauth::ExternalDeviceInfo>{ .WillByDefault(Return(std::vector<ExternalDeviceInfo>{
fake_synced_devices_[4], fake_synced_devices_[4],
})); }));
std::string public_key; std::string public_key;
std::vector<cryptauth::BeaconSeed> beacon_seeds; std::vector<BeaconSeed> beacon_seeds;
EXPECT_FALSE(provider_->GetLocalDeviceData(&public_key, &beacon_seeds)); EXPECT_FALSE(provider_->GetLocalDeviceData(&public_key, &beacon_seeds));
} }
...@@ -222,7 +215,7 @@ TEST_F(LocalDeviceDataProviderTest, TestGetLocalDeviceData_Success) { ...@@ -222,7 +215,7 @@ TEST_F(LocalDeviceDataProviderTest, TestGetLocalDeviceData_Success) {
.WillByDefault(Return(fake_synced_devices_)); .WillByDefault(Return(fake_synced_devices_));
std::string public_key; std::string public_key;
std::vector<cryptauth::BeaconSeed> beacon_seeds; std::vector<BeaconSeed> beacon_seeds;
EXPECT_TRUE(provider_->GetLocalDeviceData(&public_key, &beacon_seeds)); EXPECT_TRUE(provider_->GetLocalDeviceData(&public_key, &beacon_seeds));
...@@ -232,14 +225,12 @@ TEST_F(LocalDeviceDataProviderTest, TestGetLocalDeviceData_Success) { ...@@ -232,14 +225,12 @@ TEST_F(LocalDeviceDataProviderTest, TestGetLocalDeviceData_Success) {
for (size_t i = 0; i < fake_beacon_seeds_.size(); i++) { for (size_t i = 0; i < fake_beacon_seeds_.size(); i++) {
// Note: google::protobuf::util::MessageDifferencer can only be used to diff // Note: google::protobuf::util::MessageDifferencer can only be used to diff
// Message, but BeaconSeed derives from the incompatible MessageLite class. // Message, but BeaconSeed derives from the incompatible MessageLite class.
cryptauth::BeaconSeed expected = fake_beacon_seeds_[i]; BeaconSeed expected = fake_beacon_seeds_[i];
cryptauth::BeaconSeed actual = beacon_seeds[i]; BeaconSeed actual = beacon_seeds[i];
EXPECT_EQ(expected.data(), actual.data()); EXPECT_EQ(expected.data(), actual.data());
EXPECT_EQ(expected.start_time_millis(), actual.start_time_millis()); EXPECT_EQ(expected.start_time_millis(), actual.start_time_millis());
EXPECT_EQ(expected.end_time_millis(), actual.end_time_millis()); EXPECT_EQ(expected.end_time_millis(), actual.end_time_millis());
} }
} }
} // namespace tether } // namespace cryptauth
} // namespace chromeos
...@@ -2,15 +2,13 @@ ...@@ -2,15 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chromeos/components/tether/mock_local_device_data_provider.h" #include "components/cryptauth/mock_local_device_data_provider.h"
#include "components/cryptauth/cryptauth_device_manager.h" #include "components/cryptauth/cryptauth_device_manager.h"
#include "components/cryptauth/cryptauth_enrollment_manager.h" #include "components/cryptauth/cryptauth_enrollment_manager.h"
#include "components/cryptauth/proto/cryptauth_api.pb.h" #include "components/cryptauth/proto/cryptauth_api.pb.h"
namespace chromeos { namespace cryptauth {
namespace tether {
MockLocalDeviceDataProvider::MockLocalDeviceDataProvider() MockLocalDeviceDataProvider::MockLocalDeviceDataProvider()
: LocalDeviceDataProvider(nullptr /* cryptauth_service */) {} : LocalDeviceDataProvider(nullptr /* cryptauth_service */) {}
...@@ -27,7 +25,7 @@ void MockLocalDeviceDataProvider::SetPublicKey( ...@@ -27,7 +25,7 @@ void MockLocalDeviceDataProvider::SetPublicKey(
} }
void MockLocalDeviceDataProvider::SetBeaconSeeds( void MockLocalDeviceDataProvider::SetBeaconSeeds(
std::unique_ptr<std::vector<cryptauth::BeaconSeed>> beacon_seeds) { std::unique_ptr<std::vector<BeaconSeed>> beacon_seeds) {
if (beacon_seeds) { if (beacon_seeds) {
beacon_seeds_ = std::move(beacon_seeds); beacon_seeds_ = std::move(beacon_seeds);
} else { } else {
...@@ -37,7 +35,7 @@ void MockLocalDeviceDataProvider::SetBeaconSeeds( ...@@ -37,7 +35,7 @@ void MockLocalDeviceDataProvider::SetBeaconSeeds(
bool MockLocalDeviceDataProvider::GetLocalDeviceData( bool MockLocalDeviceDataProvider::GetLocalDeviceData(
std::string* public_key_out, std::string* public_key_out,
std::vector<cryptauth::BeaconSeed>* beacon_seeds_out) const { std::vector<BeaconSeed>* beacon_seeds_out) const {
bool success = false; bool success = false;
if (public_key_ && public_key_out) { if (public_key_ && public_key_out) {
...@@ -53,6 +51,4 @@ bool MockLocalDeviceDataProvider::GetLocalDeviceData( ...@@ -53,6 +51,4 @@ bool MockLocalDeviceDataProvider::GetLocalDeviceData(
return success; return success;
} }
} // namespace tether } // namespace cryptauth
} // namespace chromeos
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROMEOS_COMPONENTS_TETHER_MOCK_LOCAL_DEVICE_DATA_PROVIDER_H_ #ifndef COMPONENTS_CRYPTAUTH_MOCK_LOCAL_DEVICE_DATA_PROVIDER_H_
#define CHROMEOS_COMPONENTS_TETHER_MOCK_LOCAL_DEVICE_DATA_PROVIDER_H_ #define COMPONENTS_CRYPTAUTH_MOCK_LOCAL_DEVICE_DATA_PROVIDER_H_
#include <memory> #include <memory>
#include <string> #include <string>
...@@ -11,15 +11,11 @@ ...@@ -11,15 +11,11 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "chromeos/components/tether/local_device_data_provider.h" #include "components/cryptauth/local_device_data_provider.h"
namespace cryptauth { namespace cryptauth {
class BeaconSeed;
}
namespace chromeos {
namespace tether { class BeaconSeed;
// Test double for LocalDeviceDataProvider. // Test double for LocalDeviceDataProvider.
class MockLocalDeviceDataProvider : public LocalDeviceDataProvider { class MockLocalDeviceDataProvider : public LocalDeviceDataProvider {
...@@ -28,23 +24,20 @@ class MockLocalDeviceDataProvider : public LocalDeviceDataProvider { ...@@ -28,23 +24,20 @@ class MockLocalDeviceDataProvider : public LocalDeviceDataProvider {
~MockLocalDeviceDataProvider() override; ~MockLocalDeviceDataProvider() override;
void SetPublicKey(std::unique_ptr<std::string> public_key); void SetPublicKey(std::unique_ptr<std::string> public_key);
void SetBeaconSeeds( void SetBeaconSeeds(std::unique_ptr<std::vector<BeaconSeed>> beacon_seeds);
std::unique_ptr<std::vector<cryptauth::BeaconSeed>> beacon_seeds);
// LocalDeviceDataProvider: // LocalDeviceDataProvider:
bool GetLocalDeviceData( bool GetLocalDeviceData(
std::string* public_key_out, std::string* public_key_out,
std::vector<cryptauth::BeaconSeed>* beacon_seeds_out) const override; std::vector<BeaconSeed>* beacon_seeds_out) const override;
private: private:
std::unique_ptr<std::string> public_key_; std::unique_ptr<std::string> public_key_;
std::unique_ptr<std::vector<cryptauth::BeaconSeed>> beacon_seeds_; std::unique_ptr<std::vector<BeaconSeed>> beacon_seeds_;
DISALLOW_COPY_AND_ASSIGN(MockLocalDeviceDataProvider); DISALLOW_COPY_AND_ASSIGN(MockLocalDeviceDataProvider);
}; };
} // namespace tether } // namespace cryptauth
} // namespace chromeos
#endif // CHROMEOS_COMPONENTS_TETHER_MOCK_LOCAL_DEVICE_DATA_PROVIDER_H_ #endif // COMPONENTS_CRYPTAUTH_MOCK_LOCAL_DEVICE_DATA_PROVIDER_H_
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