Commit a4f6695e authored by Daniel Classon's avatar Daniel Classon Committed by Commit Bot

[MultideviceStubs] Refactor stubbed device sync and use in Linux CrOS

Refactors the stub device sync to fix a conflict with the fake device
sync (used in testing). Renames SetForTesting method to reflect it being
used in non-testing code. Enables the use of stub device sync when in
Linux CrOS, i.e. while running on emulator.

Fixed: 1085459
Change-Id: Ib075405e39d323a9e04954f0dfb7a6259136da87
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2406855
Commit-Queue: Daniel Classon <dclasson@google.com>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809565}
parent 4e791c49
...@@ -13,9 +13,11 @@ ...@@ -13,9 +13,11 @@
#include "chrome/browser/gcm/gcm_profile_service_factory.h" #include "chrome/browser/gcm/gcm_profile_service_factory.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/identity_manager_factory.h" #include "chrome/browser/signin/identity_manager_factory.h"
#include "chromeos/components/multidevice/stub_multidevice_util.h"
#include "chromeos/services/device_sync/device_sync_impl.h" #include "chromeos/services/device_sync/device_sync_impl.h"
#include "chromeos/services/device_sync/public/cpp/device_sync_client.h" #include "chromeos/services/device_sync/public/cpp/device_sync_client.h"
#include "chromeos/services/device_sync/public/cpp/device_sync_client_impl.h" #include "chromeos/services/device_sync/public/cpp/device_sync_client_impl.h"
#include "chromeos/services/device_sync/stub_device_sync.h"
#include "chromeos/services/multidevice_setup/public/cpp/prefs.h" #include "chromeos/services/multidevice_setup/public/cpp/prefs.h"
#include "components/gcm_driver/gcm_profile_service.h" #include "components/gcm_driver/gcm_profile_service.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h" #include "components/keyed_service/content/browser_context_dependency_manager.h"
...@@ -85,6 +87,14 @@ DeviceSyncClientFactory::DeviceSyncClientFactory() ...@@ -85,6 +87,14 @@ DeviceSyncClientFactory::DeviceSyncClientFactory()
BrowserContextDependencyManager::GetInstance()) { BrowserContextDependencyManager::GetInstance()) {
DependsOn(IdentityManagerFactory::GetInstance()); DependsOn(IdentityManagerFactory::GetInstance());
DependsOn(gcm::GCMProfileServiceFactory::GetInstance()); DependsOn(gcm::GCMProfileServiceFactory::GetInstance());
// If ShouldUseMultideviceStubs() is true, set a stub factory to facilitate
// fake devices for testing in the Linux Chrome OS build. Note that this is
// not done when a custom factory has already been set.
if (multidevice::ShouldUseMultideviceStubs() &&
!DeviceSyncImpl::Factory::IsCustomFactorySet()) {
SetStubDeviceSyncFactory();
}
} }
DeviceSyncClientFactory::~DeviceSyncClientFactory() {} DeviceSyncClientFactory::~DeviceSyncClientFactory() {}
......
...@@ -301,7 +301,7 @@ void InProcessBrowserTest::SetUp() { ...@@ -301,7 +301,7 @@ void InProcessBrowserTest::SetUp() {
chrome_browser_net::NetErrorTabHelper::TESTING_FORCE_DISABLED); chrome_browser_net::NetErrorTabHelper::TESTING_FORCE_DISABLED);
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
chromeos::device_sync::DeviceSyncImpl::Factory::SetFactoryForTesting( chromeos::device_sync::DeviceSyncImpl::Factory::SetCustomFactory(
GetFakeDeviceSyncImplFactory()); GetFakeDeviceSyncImplFactory());
// On Chrome OS, access to files via file: scheme is restricted. Enable // On Chrome OS, access to files via file: scheme is restricted. Enable
...@@ -353,7 +353,7 @@ void InProcessBrowserTest::TearDown() { ...@@ -353,7 +353,7 @@ void InProcessBrowserTest::TearDown() {
#endif #endif
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
chromeos::device_sync::DeviceSyncImpl::Factory::SetFactoryForTesting(nullptr); chromeos::device_sync::DeviceSyncImpl::Factory::SetCustomFactory(nullptr);
#endif #endif
} }
......
...@@ -240,7 +240,7 @@ void RecordForceSyncNowResult(ForceCryptAuthOperationResult result) { ...@@ -240,7 +240,7 @@ void RecordForceSyncNowResult(ForceCryptAuthOperationResult result) {
} // namespace } // namespace
// static // static
DeviceSyncImpl::Factory* DeviceSyncImpl::Factory::test_factory_instance_ = DeviceSyncImpl::Factory* DeviceSyncImpl::Factory::custom_factory_instance_ =
nullptr; nullptr;
// static // static
...@@ -252,8 +252,8 @@ std::unique_ptr<DeviceSyncBase> DeviceSyncImpl::Factory::Create( ...@@ -252,8 +252,8 @@ std::unique_ptr<DeviceSyncBase> DeviceSyncImpl::Factory::Create(
ClientAppMetadataProvider* client_app_metadata_provider, ClientAppMetadataProvider* client_app_metadata_provider,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory, scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
std::unique_ptr<base::OneShotTimer> timer) { std::unique_ptr<base::OneShotTimer> timer) {
if (test_factory_instance_) { if (custom_factory_instance_) {
return test_factory_instance_->CreateInstance( return custom_factory_instance_->CreateInstance(
identity_manager, gcm_driver, profile_prefs, gcm_device_info_provider, identity_manager, gcm_driver, profile_prefs, gcm_device_info_provider,
client_app_metadata_provider, std::move(url_loader_factory), client_app_metadata_provider, std::move(url_loader_factory),
std::move(timer)); std::move(timer));
...@@ -266,8 +266,13 @@ std::unique_ptr<DeviceSyncBase> DeviceSyncImpl::Factory::Create( ...@@ -266,8 +266,13 @@ std::unique_ptr<DeviceSyncBase> DeviceSyncImpl::Factory::Create(
} }
// static // static
void DeviceSyncImpl::Factory::SetFactoryForTesting(Factory* test_factory) { void DeviceSyncImpl::Factory::SetCustomFactory(Factory* custom_factory) {
test_factory_instance_ = test_factory; custom_factory_instance_ = custom_factory;
}
// static
bool DeviceSyncImpl::Factory::IsCustomFactorySet() {
return custom_factory_instance_ != nullptr;
} }
DeviceSyncImpl::Factory::~Factory() = default; DeviceSyncImpl::Factory::~Factory() = default;
......
...@@ -84,7 +84,8 @@ class DeviceSyncImpl : public DeviceSyncBase, ...@@ -84,7 +84,8 @@ class DeviceSyncImpl : public DeviceSyncBase,
ClientAppMetadataProvider* client_app_metadata_provider, ClientAppMetadataProvider* client_app_metadata_provider,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory, scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
std::unique_ptr<base::OneShotTimer> timer); std::unique_ptr<base::OneShotTimer> timer);
static void SetFactoryForTesting(Factory* test_factory); static void SetCustomFactory(Factory* custom_factory);
static bool IsCustomFactorySet();
protected: protected:
virtual ~Factory(); virtual ~Factory();
...@@ -98,7 +99,7 @@ class DeviceSyncImpl : public DeviceSyncBase, ...@@ -98,7 +99,7 @@ class DeviceSyncImpl : public DeviceSyncBase,
std::unique_ptr<base::OneShotTimer> timer) = 0; std::unique_ptr<base::OneShotTimer> timer) = 0;
private: private:
static Factory* test_factory_instance_; static Factory* custom_factory_instance_;
}; };
~DeviceSyncImpl() override; ~DeviceSyncImpl() override;
......
...@@ -855,7 +855,7 @@ class DeviceSyncServiceTest ...@@ -855,7 +855,7 @@ class DeviceSyncServiceTest
fake_device_sync_impl_factory_ = fake_device_sync_impl_factory_ =
std::make_unique<FakeDeviceSyncImplFactory>(std::move(mock_timer), std::make_unique<FakeDeviceSyncImplFactory>(std::move(mock_timer),
simple_test_clock_.get()); simple_test_clock_.get());
DeviceSyncImpl::Factory::SetFactoryForTesting( DeviceSyncImpl::Factory::SetCustomFactory(
fake_device_sync_impl_factory_.get()); fake_device_sync_impl_factory_.get());
fake_gcm_device_info_provider_ = fake_gcm_device_info_provider_ =
...@@ -870,7 +870,7 @@ class DeviceSyncServiceTest ...@@ -870,7 +870,7 @@ class DeviceSyncServiceTest
CryptAuthEnrollmentManagerImpl::Factory::SetFactoryForTesting(nullptr); CryptAuthEnrollmentManagerImpl::Factory::SetFactoryForTesting(nullptr);
RemoteDeviceProviderImpl::Factory::SetFactoryForTesting(nullptr); RemoteDeviceProviderImpl::Factory::SetFactoryForTesting(nullptr);
SoftwareFeatureManagerImpl::Factory::SetFactoryForTesting(nullptr); SoftwareFeatureManagerImpl::Factory::SetFactoryForTesting(nullptr);
DeviceSyncImpl::Factory::SetFactoryForTesting(nullptr); DeviceSyncImpl::Factory::SetCustomFactory(nullptr);
NetworkHandler::Shutdown(); NetworkHandler::Shutdown();
DBusThreadManager::Shutdown(); DBusThreadManager::Shutdown();
......
...@@ -166,7 +166,7 @@ class DeviceSyncClientImplTest : public testing::Test { ...@@ -166,7 +166,7 @@ class DeviceSyncClientImplTest : public testing::Test {
fake_device_sync_impl_factory_ = fake_device_sync_impl_factory_ =
std::make_unique<FakeDeviceSyncImplFactory>( std::make_unique<FakeDeviceSyncImplFactory>(
std::move(fake_device_sync)); std::move(fake_device_sync));
DeviceSyncImpl::Factory::SetFactoryForTesting( DeviceSyncImpl::Factory::SetCustomFactory(
fake_device_sync_impl_factory_.get()); fake_device_sync_impl_factory_.get());
auto shared_url_loader_factory = auto shared_url_loader_factory =
...@@ -303,7 +303,7 @@ class DeviceSyncClientImplTest : public testing::Test { ...@@ -303,7 +303,7 @@ class DeviceSyncClientImplTest : public testing::Test {
} }
void TearDown() override { void TearDown() override {
DeviceSyncImpl::Factory::SetFactoryForTesting(nullptr); DeviceSyncImpl::Factory::SetCustomFactory(nullptr);
client_->RemoveObserver(test_observer_.get()); client_->RemoveObserver(test_observer_.get());
} }
......
...@@ -5,58 +5,13 @@ ...@@ -5,58 +5,13 @@
#ifndef CHROMEOS_SERVICES_DEVICE_SYNC_STUB_DEVICE_SYNC_H_ #ifndef CHROMEOS_SERVICES_DEVICE_SYNC_STUB_DEVICE_SYNC_H_
#define CHROMEOS_SERVICES_DEVICE_SYNC_STUB_DEVICE_SYNC_H_ #define CHROMEOS_SERVICES_DEVICE_SYNC_STUB_DEVICE_SYNC_H_
#include <vector>
#include "chromeos/components/multidevice/remote_device.h"
#include "chromeos/services/device_sync/device_sync_base.h"
namespace chromeos { namespace chromeos {
namespace device_sync { namespace device_sync {
// Stub Device Sync implementation for Linux CrOS build. Creates two // Creates a stub DeviceSync factory that initializes a stub DeviceSync, then
// fake devices, a fake phone and a fake computer. // sets that factory as the DeviceSyncImpl custom factory.
class StubDeviceSync : public DeviceSyncBase { void SetStubDeviceSyncFactory();
public:
StubDeviceSync();
~StubDeviceSync() override;
protected:
// mojom::DeviceSync:
void ForceEnrollmentNow(ForceEnrollmentNowCallback callback) override;
void ForceSyncNow(ForceSyncNowCallback callback) override;
void GetLocalDeviceMetadata(GetLocalDeviceMetadataCallback callback) override;
void GetSyncedDevices(GetSyncedDevicesCallback callback) override;
void SetSoftwareFeatureState(
const std::string& device_public_key,
multidevice::SoftwareFeature software_feature,
bool enabled,
bool is_exclusive,
SetSoftwareFeatureStateCallback callback) override;
void SetFeatureStatus(const std::string& device_instance_id,
multidevice::SoftwareFeature feature,
FeatureStatusChange status_change,
SetFeatureStatusCallback callback) override;
void FindEligibleDevices(multidevice::SoftwareFeature software_feature,
FindEligibleDevicesCallback callback) override;
void NotifyDevices(const std::vector<std::string>& device_instance_ids,
cryptauthv2::TargetService target_service,
multidevice::SoftwareFeature feature,
NotifyDevicesCallback callback) override;
void GetDebugInfo(GetDebugInfoCallback callback) override;
void GetDevicesActivityStatus(
GetDevicesActivityStatusCallback callback) override;
private:
// Returns the synced device that has a matching |device_public_key| or a
// matching |device_instance_id|, otherwise returns nullptr.
multidevice::RemoteDevice* GetRemoteDevice(
const base::Optional<std::string>& device_public_key,
const base::Optional<std::string>& device_instance_id);
std::vector<multidevice::RemoteDevice> synced_devices_;
base::Optional<multidevice::RemoteDevice> local_device_metadata_;
};
} // namespace device_sync } // namespace device_sync
......
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