[CrOS MultiDevice] Move appropriate CryptAuth files to DeviceSync.
This is part of the ongoing effort to clean up the directory structure
of multi-device code. The files moved are only relevant to the
DeviceSync service, so they belong within the service implementation.
See go/multidevice-directory-structure-cleanup for details.
Bug: 912743
Change-Id: Icce398a4aa93110fbd790c364bba29bf461a83e4
Reviewed-on: https://chromium-review.googlesource.com/c/1372648
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Matt Menke <mmenke@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Ryan Hansberry <hansberry@chromium.org>
Commit-Queue: Kyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#616056}
diff --git a/chrome/browser/chromeos/BUILD.gn b/chrome/browser/chromeos/BUILD.gn
index 594393a..8339b3b 100644
--- a/chrome/browser/chromeos/BUILD.gn
+++ b/chrome/browser/chromeos/BUILD.gn
@@ -96,7 +96,9 @@
"//chromeos/components/proximity_auth/logging",
"//chromeos/components/tether",
"//chromeos/network",
+ "//chromeos/services/device_sync",
"//chromeos/services/device_sync/proto",
+ "//chromeos/services/device_sync/proto:util",
"//chromeos/services/device_sync/public/cpp",
"//chromeos/services/machine_learning/public/cpp",
"//chromeos/services/machine_learning/public/mojom",
@@ -119,6 +121,7 @@
"//components/crash/content/app",
"//components/crx_file",
"//components/cryptauth",
+ "//components/cryptauth:secure_message",
"//components/device_event_log",
"//components/download/content/public",
"//components/drive",
diff --git a/chrome/browser/chromeos/cryptauth/chrome_cryptauth_service.cc b/chrome/browser/chromeos/cryptauth/chrome_cryptauth_service.cc
index e64b321..9bf66c3 100644
--- a/chrome/browser/chromeos/cryptauth/chrome_cryptauth_service.cc
+++ b/chrome/browser/chromeos/cryptauth/chrome_cryptauth_service.cc
@@ -19,17 +19,16 @@
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/common/pref_names.h"
#include "chromeos/components/proximity_auth/logging/logging.h"
+#include "chromeos/services/device_sync/cryptauth_client.h"
+#include "chromeos/services/device_sync/cryptauth_client_impl.h"
+#include "chromeos/services/device_sync/cryptauth_device_manager_impl.h"
+#include "chromeos/services/device_sync/cryptauth_enroller.h"
+#include "chromeos/services/device_sync/cryptauth_enroller_impl.h"
+#include "chromeos/services/device_sync/cryptauth_enrollment_manager_impl.h"
+#include "chromeos/services/device_sync/cryptauth_gcm_manager_impl.h"
#include "chromeos/services/device_sync/proto/cryptauth_api.pb.h"
+#include "chromeos/services/device_sync/proto/device_classifier_util.h"
#include "chromeos/services/multidevice_setup/public/cpp/prefs.h"
-#include "components/cryptauth/cryptauth_client.h"
-#include "components/cryptauth/cryptauth_client_impl.h"
-#include "components/cryptauth/cryptauth_device_manager_impl.h"
-#include "components/cryptauth/cryptauth_enroller.h"
-#include "components/cryptauth/cryptauth_enroller_impl.h"
-#include "components/cryptauth/cryptauth_enrollment_manager_impl.h"
-#include "components/cryptauth/cryptauth_enrollment_utils.h"
-#include "components/cryptauth/cryptauth_gcm_manager_impl.h"
-#include "components/cryptauth/device_classifier_util.h"
#include "components/cryptauth/secure_message_delegate_impl.h"
#include "components/gcm_driver/gcm_profile_service.h"
#include "components/prefs/pref_service.h"
@@ -41,29 +40,29 @@
namespace {
-std::unique_ptr<cryptauth::CryptAuthClientFactory>
+std::unique_ptr<device_sync::CryptAuthClientFactory>
CreateCryptAuthClientFactoryImpl(Profile* profile) {
- return std::make_unique<cryptauth::CryptAuthClientFactoryImpl>(
+ return std::make_unique<device_sync::CryptAuthClientFactoryImpl>(
IdentityManagerFactory::GetForProfile(profile),
profile->GetURLLoaderFactory(),
- cryptauth::device_classifier_util::GetDeviceClassifier());
+ device_sync::device_classifier_util::GetDeviceClassifier());
}
class CryptAuthEnrollerFactoryImpl
- : public cryptauth::CryptAuthEnrollerFactory {
+ : public device_sync::CryptAuthEnrollerFactory {
public:
explicit CryptAuthEnrollerFactoryImpl(
- cryptauth::CryptAuthClientFactory* client_factory)
+ device_sync::CryptAuthClientFactory* client_factory)
: client_factory_(client_factory) {}
- std::unique_ptr<cryptauth::CryptAuthEnroller> CreateInstance() override {
- return std::make_unique<cryptauth::CryptAuthEnrollerImpl>(
+ std::unique_ptr<device_sync::CryptAuthEnroller> CreateInstance() override {
+ return std::make_unique<device_sync::CryptAuthEnrollerImpl>(
client_factory_,
cryptauth::SecureMessageDelegateImpl::Factory::NewInstance());
}
private:
- cryptauth::CryptAuthClientFactory* client_factory_;
+ device_sync::CryptAuthClientFactory* client_factory_;
};
} // namespace
@@ -71,21 +70,21 @@
// static
std::unique_ptr<ChromeCryptAuthService> ChromeCryptAuthService::Create(
Profile* profile) {
- std::unique_ptr<cryptauth::CryptAuthClientFactory> client_factory =
+ std::unique_ptr<device_sync::CryptAuthClientFactory> client_factory =
CreateCryptAuthClientFactoryImpl(profile);
- std::unique_ptr<cryptauth::CryptAuthGCMManager> gcm_manager =
- cryptauth::CryptAuthGCMManagerImpl::Factory::NewInstance(
+ std::unique_ptr<device_sync::CryptAuthGCMManager> gcm_manager =
+ device_sync::CryptAuthGCMManagerImpl::Factory::NewInstance(
gcm::GCMProfileServiceFactory::GetForProfile(profile)->driver(),
profile->GetPrefs());
- std::unique_ptr<cryptauth::CryptAuthDeviceManager> device_manager =
- cryptauth::CryptAuthDeviceManagerImpl::Factory::NewInstance(
+ std::unique_ptr<device_sync::CryptAuthDeviceManager> device_manager =
+ device_sync::CryptAuthDeviceManagerImpl::Factory::NewInstance(
base::DefaultClock::GetInstance(), client_factory.get(),
gcm_manager.get(), profile->GetPrefs());
- std::unique_ptr<cryptauth::CryptAuthEnrollmentManager> enrollment_manager =
- cryptauth::CryptAuthEnrollmentManagerImpl::Factory::NewInstance(
+ std::unique_ptr<device_sync::CryptAuthEnrollmentManager> enrollment_manager =
+ device_sync::CryptAuthEnrollmentManagerImpl::Factory::NewInstance(
base::DefaultClock::GetInstance(),
std::make_unique<CryptAuthEnrollerFactoryImpl>(client_factory.get()),
cryptauth::SecureMessageDelegateImpl::Factory::NewInstance(),
@@ -104,10 +103,10 @@
}
ChromeCryptAuthService::ChromeCryptAuthService(
- std::unique_ptr<cryptauth::CryptAuthClientFactory> client_factory,
- std::unique_ptr<cryptauth::CryptAuthGCMManager> gcm_manager,
- std::unique_ptr<cryptauth::CryptAuthDeviceManager> device_manager,
- std::unique_ptr<cryptauth::CryptAuthEnrollmentManager> enrollment_manager,
+ std::unique_ptr<device_sync::CryptAuthClientFactory> client_factory,
+ std::unique_ptr<device_sync::CryptAuthGCMManager> gcm_manager,
+ std::unique_ptr<device_sync::CryptAuthDeviceManager> device_manager,
+ std::unique_ptr<device_sync::CryptAuthEnrollmentManager> enrollment_manager,
Profile* profile,
identity::IdentityManager* identity_manager)
: KeyedService(),
@@ -150,25 +149,25 @@
gcm_manager_.reset();
}
-cryptauth::CryptAuthDeviceManager*
+device_sync::CryptAuthDeviceManager*
ChromeCryptAuthService::GetCryptAuthDeviceManager() {
return device_manager_.get();
}
-cryptauth::CryptAuthEnrollmentManager*
+device_sync::CryptAuthEnrollmentManager*
ChromeCryptAuthService::GetCryptAuthEnrollmentManager() {
return enrollment_manager_.get();
}
cryptauth::DeviceClassifier ChromeCryptAuthService::GetDeviceClassifier() {
- return cryptauth::device_classifier_util::GetDeviceClassifier();
+ return device_sync::device_classifier_util::GetDeviceClassifier();
}
std::string ChromeCryptAuthService::GetAccountId() {
return identity_manager_->GetPrimaryAccountId();
}
-std::unique_ptr<cryptauth::CryptAuthClientFactory>
+std::unique_ptr<device_sync::CryptAuthClientFactory>
ChromeCryptAuthService::CreateCryptAuthClientFactory() {
return CreateCryptAuthClientFactoryImpl(profile_);
}
diff --git a/chrome/browser/chromeos/cryptauth/chrome_cryptauth_service.h b/chrome/browser/chromeos/cryptauth/chrome_cryptauth_service.h
index 56725767..c032ccb 100644
--- a/chrome/browser/chromeos/cryptauth/chrome_cryptauth_service.h
+++ b/chrome/browser/chromeos/cryptauth/chrome_cryptauth_service.h
@@ -9,8 +9,8 @@
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
+#include "chromeos/services/device_sync/cryptauth_enrollment_manager.h"
#include "chromeos/services/device_sync/proto/cryptauth_api.pb.h"
-#include "components/cryptauth/cryptauth_enrollment_manager.h"
#include "components/cryptauth/cryptauth_service.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/prefs/pref_change_registrar.h"
@@ -18,17 +18,17 @@
class Profile;
-namespace cryptauth {
-class CryptAuthGCMManager;
-} // namespace cryptauth
-
namespace chromeos {
+namespace device_sync {
+class CryptAuthGCMManager;
+} // namespace device_sync
+
// Implementation of cryptauth::CryptAuthService.
class ChromeCryptAuthService
: public KeyedService,
public cryptauth::CryptAuthService,
- public cryptauth::CryptAuthEnrollmentManager::Observer,
+ public device_sync::CryptAuthEnrollmentManager::Observer,
public identity::IdentityManager::Observer {
public:
static std::unique_ptr<ChromeCryptAuthService> Create(Profile* profile);
@@ -38,25 +38,26 @@
void Shutdown() override;
// cryptauth::CryptAuthService:
- cryptauth::CryptAuthDeviceManager* GetCryptAuthDeviceManager() override;
- cryptauth::CryptAuthEnrollmentManager* GetCryptAuthEnrollmentManager()
+ device_sync::CryptAuthDeviceManager* GetCryptAuthDeviceManager() override;
+ device_sync::CryptAuthEnrollmentManager* GetCryptAuthEnrollmentManager()
override;
cryptauth::DeviceClassifier GetDeviceClassifier() override;
std::string GetAccountId() override;
- std::unique_ptr<cryptauth::CryptAuthClientFactory>
+ std::unique_ptr<device_sync::CryptAuthClientFactory>
CreateCryptAuthClientFactory() override;
- // cryptauth::CryptAuthEnrollmentManager::Observer:
+ // device_sync::CryptAuthEnrollmentManager::Observer:
void OnEnrollmentFinished(bool success) override;
protected:
// Note: ChromeCryptAuthServiceFactory DependsOn(OAuth2TokenServiceFactory),
// so |token_service| is guaranteed to outlast this service.
ChromeCryptAuthService(
- std::unique_ptr<cryptauth::CryptAuthClientFactory> client_factory,
- std::unique_ptr<cryptauth::CryptAuthGCMManager> gcm_manager,
- std::unique_ptr<cryptauth::CryptAuthDeviceManager> device_manager,
- std::unique_ptr<cryptauth::CryptAuthEnrollmentManager> enrollment_manager,
+ std::unique_ptr<device_sync::CryptAuthClientFactory> client_factory,
+ std::unique_ptr<device_sync::CryptAuthGCMManager> gcm_manager,
+ std::unique_ptr<device_sync::CryptAuthDeviceManager> device_manager,
+ std::unique_ptr<device_sync::CryptAuthEnrollmentManager>
+ enrollment_manager,
Profile* profile,
identity::IdentityManager* identity_manager);
@@ -70,10 +71,10 @@
void PerformEnrollmentAndDeviceSyncIfPossible();
void OnPrefsChanged();
- std::unique_ptr<cryptauth::CryptAuthClientFactory> client_factory_;
- std::unique_ptr<cryptauth::CryptAuthGCMManager> gcm_manager_;
- std::unique_ptr<cryptauth::CryptAuthEnrollmentManager> enrollment_manager_;
- std::unique_ptr<cryptauth::CryptAuthDeviceManager> device_manager_;
+ std::unique_ptr<device_sync::CryptAuthClientFactory> client_factory_;
+ std::unique_ptr<device_sync::CryptAuthGCMManager> gcm_manager_;
+ std::unique_ptr<device_sync::CryptAuthEnrollmentManager> enrollment_manager_;
+ std::unique_ptr<device_sync::CryptAuthDeviceManager> device_manager_;
Profile* profile_;
identity::IdentityManager* identity_manager_;
PrefChangeRegistrar registrar_;
diff --git a/chrome/browser/chromeos/cryptauth/cryptauth_device_id_provider_impl.h b/chrome/browser/chromeos/cryptauth/cryptauth_device_id_provider_impl.h
index 222ec92..f43f1ff 100644
--- a/chrome/browser/chromeos/cryptauth/cryptauth_device_id_provider_impl.h
+++ b/chrome/browser/chromeos/cryptauth/cryptauth_device_id_provider_impl.h
@@ -9,7 +9,7 @@
#include "base/macros.h"
#include "base/no_destructor.h"
-#include "components/cryptauth/cryptauth_device_id_provider.h"
+#include "chromeos/services/device_sync/public/cpp/cryptauth_device_id_provider.h"
class PrefRegistrySimple;
@@ -17,7 +17,8 @@
// Concrete CryptAuthDeviceIdProvider implementation which stores the device ID
// in the browser process' local state PrefStore.
-class CryptAuthDeviceIdProviderImpl : public CryptAuthDeviceIdProvider {
+class CryptAuthDeviceIdProviderImpl
+ : public chromeos::device_sync::CryptAuthDeviceIdProvider {
public:
// Registers the prefs used by this class. |registry| must be associated
// with browser local storage, not an individual profile.
diff --git a/chrome/browser/chromeos/cryptauth/gcm_device_info_provider_impl.cc b/chrome/browser/chromeos/cryptauth/gcm_device_info_provider_impl.cc
index 62de495..076d778 100644
--- a/chrome/browser/chromeos/cryptauth/gcm_device_info_provider_impl.cc
+++ b/chrome/browser/chromeos/cryptauth/gcm_device_info_provider_impl.cc
@@ -4,18 +4,45 @@
#include "chrome/browser/chromeos/cryptauth/gcm_device_info_provider_impl.h"
+#include <stddef.h>
+#include <stdint.h>
+#include <string>
+
#include "base/linux_util.h"
+#include "base/md5.h"
#include "base/no_destructor.h"
#include "base/system/sys_info.h"
#include "base/version.h"
#include "chrome/browser/chrome_content_browser_client.h"
#include "chrome/browser/chromeos/cryptauth/cryptauth_device_id_provider_impl.h"
#include "chromeos/chromeos_features.h"
-#include "components/cryptauth/cryptauth_enrollment_utils.h"
#include "components/version_info/version_info.h"
namespace chromeos {
+namespace {
+
+int64_t HashStringToInt64(const std::string& string) {
+ base::MD5Context context;
+ base::MD5Init(&context);
+ base::MD5Update(&context, string);
+
+ base::MD5Digest digest;
+ base::MD5Final(&digest, &context);
+
+ // Fold the digest into an int64_t value. |digest.a| is a 16-byte array, so we
+ // sum the two 8-byte halves of the digest to create the hash.
+ int64_t hash = 0;
+ for (size_t i = 0; i < sizeof(digest.a); ++i) {
+ uint8_t byte = digest.a[i];
+ hash += static_cast<int64_t>(byte) << (i % sizeof(int64_t));
+ }
+
+ return hash;
+}
+
+} // namespace
+
// static
const GcmDeviceInfoProviderImpl* GcmDeviceInfoProviderImpl::GetInstance() {
static const base::NoDestructor<GcmDeviceInfoProviderImpl> provider;
@@ -26,7 +53,7 @@
const {
static const base::NoDestructor<cryptauth::GcmDeviceInfo> gcm_device_info([] {
static const google::protobuf::int64 kSoftwareVersionCode =
- cryptauth::HashStringToInt64(version_info::GetLastChange());
+ HashStringToInt64(version_info::GetLastChange());
cryptauth::GcmDeviceInfo gcm_device_info;
diff --git a/chrome/browser/chromeos/cryptauth/gcm_device_info_provider_impl.h b/chrome/browser/chromeos/cryptauth/gcm_device_info_provider_impl.h
index 95d4d8b4..a90e53c 100644
--- a/chrome/browser/chromeos/cryptauth/gcm_device_info_provider_impl.h
+++ b/chrome/browser/chromeos/cryptauth/gcm_device_info_provider_impl.h
@@ -8,16 +8,16 @@
#include "base/macros.h"
#include "base/no_destructor.h"
#include "chromeos/services/device_sync/proto/cryptauth_api.pb.h"
-#include "components/cryptauth/gcm_device_info_provider.h"
+#include "chromeos/services/device_sync/public/cpp/gcm_device_info_provider.h"
namespace chromeos {
// Concrete GcmDeviceInfoProvider implementation.
-class GcmDeviceInfoProviderImpl : public cryptauth::GcmDeviceInfoProvider {
+class GcmDeviceInfoProviderImpl : public device_sync::GcmDeviceInfoProvider {
public:
static const GcmDeviceInfoProviderImpl* GetInstance();
- // cryptauth::GcmDeviceInfoProvider:
+ // device_sync::GcmDeviceInfoProvider:
const cryptauth::GcmDeviceInfo& GetGcmDeviceInfo() const override;
private:
diff --git a/chrome/browser/chromeos/login/easy_unlock/chrome_proximity_auth_client.cc b/chrome/browser/chromeos/login/easy_unlock/chrome_proximity_auth_client.cc
index e4a163f..db3d86a2 100644
--- a/chrome/browser/chromeos/login/easy_unlock/chrome_proximity_auth_client.cc
+++ b/chrome/browser/chromeos/login/easy_unlock/chrome_proximity_auth_client.cc
@@ -20,10 +20,10 @@
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chromeos/chromeos_features.h"
#include "chromeos/components/proximity_auth/logging/logging.h"
+#include "chromeos/services/device_sync/cryptauth_client_impl.h"
+#include "chromeos/services/device_sync/cryptauth_device_manager.h"
+#include "chromeos/services/device_sync/cryptauth_enrollment_manager.h"
#include "chromeos/services/device_sync/public/cpp/device_sync_client.h"
-#include "components/cryptauth/cryptauth_client_impl.h"
-#include "components/cryptauth/cryptauth_device_manager.h"
-#include "components/cryptauth/cryptauth_enrollment_manager.h"
#include "components/prefs/pref_service.h"
#include "components/version_info/version_info.h"
#include "services/identity/public/cpp/identity_manager.h"
diff --git a/chrome/browser/chromeos/login/easy_unlock/easy_unlock_service.cc b/chrome/browser/chromeos/login/easy_unlock/easy_unlock_service.cc
index c5f0e5a..9a120f85 100644
--- a/chrome/browser/chromeos/login/easy_unlock/easy_unlock_service.cc
+++ b/chrome/browser/chromeos/login/easy_unlock/easy_unlock_service.cc
@@ -40,10 +40,10 @@
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/power_manager_client.h"
#include "chromeos/login/auth/user_context.h"
+#include "chromeos/services/device_sync/cryptauth_client_impl.h"
+#include "chromeos/services/device_sync/cryptauth_device_manager.h"
+#include "chromeos/services/device_sync/cryptauth_enrollment_manager.h"
#include "components/account_id/account_id.h"
-#include "components/cryptauth/cryptauth_client_impl.h"
-#include "components/cryptauth/cryptauth_device_manager.h"
-#include "components/cryptauth/cryptauth_enrollment_manager.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
diff --git a/chrome/browser/chromeos/login/easy_unlock/easy_unlock_service_regular.cc b/chrome/browser/chromeos/login/easy_unlock/easy_unlock_service_regular.cc
index 2f59116..6b456c94 100644
--- a/chrome/browser/chromeos/login/easy_unlock/easy_unlock_service_regular.cc
+++ b/chrome/browser/chromeos/login/easy_unlock/easy_unlock_service_regular.cc
@@ -44,10 +44,9 @@
#include "chromeos/components/proximity_auth/screenlock_bridge.h"
#include "chromeos/components/proximity_auth/smart_lock_metrics_recorder.h"
#include "chromeos/components/proximity_auth/switches.h"
-#include "components/cryptauth/cryptauth_enrollment_manager.h"
-#include "components/cryptauth/cryptauth_enrollment_utils.h"
-#include "components/cryptauth/cryptauth_gcm_manager_impl.h"
-#include "components/cryptauth/remote_device_loader.h"
+#include "chromeos/services/device_sync/cryptauth_enrollment_manager.h"
+#include "chromeos/services/device_sync/cryptauth_gcm_manager_impl.h"
+#include "chromeos/services/device_sync/remote_device_loader.h"
#include "components/cryptauth/secure_message_delegate_impl.h"
#include "components/gcm_driver/gcm_profile_service.h"
#include "components/pref_registry/pref_registry_syncable.h"
diff --git a/chrome/browser/chromeos/login/easy_unlock/easy_unlock_service_regular.h b/chrome/browser/chromeos/login/easy_unlock/easy_unlock_service_regular.h
index cfe1dd5..8a41f5f 100644
--- a/chrome/browser/chromeos/login/easy_unlock/easy_unlock_service_regular.h
+++ b/chrome/browser/chromeos/login/easy_unlock/easy_unlock_service_regular.h
@@ -17,19 +17,16 @@
#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_service.h"
#include "chromeos/components/multidevice/remote_device_ref.h"
#include "chromeos/components/proximity_auth/screenlock_bridge.h"
+#include "chromeos/services/device_sync/cryptauth_device_manager.h"
+#include "chromeos/services/device_sync/network_request_error.h"
#include "chromeos/services/device_sync/public/cpp/device_sync_client.h"
#include "chromeos/services/multidevice_setup/public/cpp/multidevice_setup_client.h"
-#include "components/cryptauth/network_request_error.h"
#include "components/prefs/pref_change_registrar.h"
namespace base {
class ListValue;
} // namespace base
-namespace cryptauth {
-class RemoteDeviceLoader;
-} // namespace cryptauth
-
namespace proximity_auth {
class ProximityAuthProfilePrefManager;
} // namespace proximity_auth
@@ -38,6 +35,10 @@
namespace chromeos {
+namespace device_sync {
+class RemoteDeviceLoader;
+} // namespace device_sync
+
namespace secure_channel {
class SecureChannelClient;
} // namespace secure_channel
@@ -151,7 +152,7 @@
pref_manager_;
// Loads the RemoteDevice instances from CryptAuth and local data.
- std::unique_ptr<cryptauth::RemoteDeviceLoader> remote_device_loader_;
+ std::unique_ptr<device_sync::RemoteDeviceLoader> remote_device_loader_;
// If a new RemoteDevice was synced while the screen is locked, we defer
// loading the RemoteDevice until the screen is unlocked. For security,
diff --git a/chrome/browser/chromeos/tether/tether_service.cc b/chrome/browser/chromeos/tether/tether_service.cc
index 756ec7d..cdcb431 100644
--- a/chrome/browser/chromeos/tether/tether_service.cc
+++ b/chrome/browser/chromeos/tether/tether_service.cc
@@ -25,9 +25,9 @@
#include "chromeos/network/device_state.h"
#include "chromeos/network/network_connect.h"
#include "chromeos/network/network_type_pattern.h"
+#include "chromeos/services/device_sync/cryptauth_enrollment_manager.h"
#include "chromeos/services/multidevice_setup/public/cpp/prefs.h"
#include "chromeos/services/secure_channel/public/cpp/client/secure_channel_client.h"
-#include "components/cryptauth/cryptauth_enrollment_manager.h"
#include "components/cryptauth/cryptauth_service.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h"
diff --git a/chrome/browser/chromeos/tether/tether_service.h b/chrome/browser/chromeos/tether/tether_service.h
index c029f16..92347b4 100644
--- a/chrome/browser/chromeos/tether/tether_service.h
+++ b/chrome/browser/chromeos/tether/tether_service.h
@@ -16,9 +16,9 @@
#include "chromeos/dbus/power_manager_client.h"
#include "chromeos/network/network_state_handler.h"
#include "chromeos/network/network_state_handler_observer.h"
+#include "chromeos/services/device_sync/cryptauth_device_manager.h"
#include "chromeos/services/device_sync/public/cpp/device_sync_client.h"
#include "chromeos/services/multidevice_setup/public/cpp/multidevice_setup_client.h"
-#include "components/cryptauth/cryptauth_device_manager.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/prefs/pref_change_registrar.h"
#include "device/bluetooth/bluetooth_adapter.h"
diff --git a/chrome/browser/chromeos/tether/tether_service_unittest.cc b/chrome/browser/chromeos/tether/tether_service_unittest.cc
index 7f72b1c..80211ad 100644
--- a/chrome/browser/chromeos/tether/tether_service_unittest.cc
+++ b/chrome/browser/chromeos/tether/tether_service_unittest.cc
@@ -40,20 +40,20 @@
#include "chromeos/network/network_state_handler.h"
#include "chromeos/network/network_state_test.h"
#include "chromeos/network/network_type_pattern.h"
+#include "chromeos/services/device_sync/cryptauth_device_manager.h"
+#include "chromeos/services/device_sync/cryptauth_enroller.h"
+#include "chromeos/services/device_sync/cryptauth_enrollment_manager.h"
+#include "chromeos/services/device_sync/fake_cryptauth_enrollment_manager.h"
+#include "chromeos/services/device_sync/fake_remote_device_provider.h"
#include "chromeos/services/device_sync/public/cpp/device_sync_client_impl.h"
#include "chromeos/services/device_sync/public/cpp/fake_device_sync_client.h"
+#include "chromeos/services/device_sync/remote_device_provider_impl.h"
#include "chromeos/services/multidevice_setup/public/cpp/fake_multidevice_setup_client.h"
#include "chromeos/services/multidevice_setup/public/cpp/multidevice_setup_client_impl.h"
#include "chromeos/services/multidevice_setup/public/cpp/prefs.h"
#include "chromeos/services/secure_channel/public/cpp/client/fake_secure_channel_client.h"
#include "chromeos/services/secure_channel/public/cpp/client/secure_channel_client_impl.h"
-#include "components/cryptauth/cryptauth_device_manager.h"
-#include "components/cryptauth/cryptauth_enroller.h"
-#include "components/cryptauth/cryptauth_enrollment_manager.h"
-#include "components/cryptauth/fake_cryptauth_enrollment_manager.h"
#include "components/cryptauth/fake_cryptauth_service.h"
-#include "components/cryptauth/fake_remote_device_provider.h"
-#include "components/cryptauth/remote_device_provider_impl.h"
#include "components/prefs/testing_pref_service.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "components/user_manager/scoped_user_manager.h"
@@ -218,17 +218,17 @@
};
class FakeRemoteDeviceProviderFactory
- : public cryptauth::RemoteDeviceProviderImpl::Factory {
+ : public chromeos::device_sync::RemoteDeviceProviderImpl::Factory {
public:
FakeRemoteDeviceProviderFactory() = default;
~FakeRemoteDeviceProviderFactory() override = default;
- // cryptauth::RemoteDeviceProviderImpl::Factory:
- std::unique_ptr<cryptauth::RemoteDeviceProvider> BuildInstance(
- cryptauth::CryptAuthDeviceManager* device_manager,
+ // chromeos::device_sync::RemoteDeviceProviderImpl::Factory:
+ std::unique_ptr<chromeos::device_sync::RemoteDeviceProvider> BuildInstance(
+ chromeos::device_sync::CryptAuthDeviceManager* device_manager,
const std::string& user_id,
const std::string& user_private_key) override {
- return std::make_unique<cryptauth::FakeRemoteDeviceProvider>();
+ return std::make_unique<chromeos::device_sync::FakeRemoteDeviceProvider>();
}
};
@@ -376,8 +376,8 @@
fake_cryptauth_service_ =
std::make_unique<cryptauth::FakeCryptAuthService>();
- fake_enrollment_manager_ =
- std::make_unique<cryptauth::FakeCryptAuthEnrollmentManager>();
+ fake_enrollment_manager_ = std::make_unique<
+ chromeos::device_sync::FakeCryptAuthEnrollmentManager>();
fake_enrollment_manager_->set_user_private_key(kTestUserPrivateKey);
fake_cryptauth_service_->set_cryptauth_enrollment_manager(
fake_enrollment_manager_.get());
@@ -400,8 +400,8 @@
fake_remote_device_provider_factory_ =
base::WrapUnique(new FakeRemoteDeviceProviderFactory());
- cryptauth::RemoteDeviceProviderImpl::Factory::SetInstanceForTesting(
- fake_remote_device_provider_factory_.get());
+ chromeos::device_sync::RemoteDeviceProviderImpl::Factory::
+ SetInstanceForTesting(fake_remote_device_provider_factory_.get());
fake_tether_host_fetcher_factory_ =
base::WrapUnique(new FakeTetherHostFetcherFactory(test_devices_));
@@ -604,7 +604,7 @@
std::unique_ptr<FakeMultiDeviceSetupClientImplFactory>
fake_multidevice_setup_client_impl_factory_;
std::unique_ptr<cryptauth::FakeCryptAuthService> fake_cryptauth_service_;
- std::unique_ptr<cryptauth::FakeCryptAuthEnrollmentManager>
+ std::unique_ptr<chromeos::device_sync::FakeCryptAuthEnrollmentManager>
fake_enrollment_manager_;
chromeos::multidevice_setup::mojom::FeatureState initial_feature_state_;
diff --git a/chrome/test/base/in_process_browser_test.cc b/chrome/test/base/in_process_browser_test.cc
index 8db662d..f1cd4de 100644
--- a/chrome/test/base/in_process_browser_test.cc
+++ b/chrome/test/base/in_process_browser_test.cc
@@ -130,7 +130,8 @@
identity::IdentityManager* identity_manager,
gcm::GCMDriver* gcm_driver,
service_manager::Connector* connector,
- const cryptauth::GcmDeviceInfoProvider* gcm_device_info_provider,
+ const chromeos::device_sync::GcmDeviceInfoProvider*
+ gcm_device_info_provider,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
std::unique_ptr<base::OneShotTimer> timer) override {
return std::make_unique<chromeos::device_sync::FakeDeviceSync>();
diff --git a/chromeos/components/proximity_auth/BUILD.gn b/chromeos/components/proximity_auth/BUILD.gn
index 42d1221..b3291c2 100644
--- a/chromeos/components/proximity_auth/BUILD.gn
+++ b/chromeos/components/proximity_auth/BUILD.gn
@@ -93,6 +93,7 @@
"//chromeos/components/multidevice",
"//chromeos/components/multidevice:test_support",
"//chromeos/components/proximity_auth/logging",
+ "//chromeos/services/device_sync",
"//chromeos/services/secure_channel/public/cpp/client",
"//components/cryptauth:test_support",
"//testing/gmock",
diff --git a/chromeos/components/proximity_auth/mock_proximity_auth_client.h b/chromeos/components/proximity_auth/mock_proximity_auth_client.h
index 2ce5256..61d5df4 100644
--- a/chromeos/components/proximity_auth/mock_proximity_auth_client.h
+++ b/chromeos/components/proximity_auth/mock_proximity_auth_client.h
@@ -10,11 +10,17 @@
#include "base/callback.h"
#include "base/macros.h"
#include "chromeos/components/proximity_auth/proximity_auth_client.h"
-#include "components/cryptauth/cryptauth_client.h"
-#include "components/cryptauth/cryptauth_device_manager.h"
-#include "components/cryptauth/cryptauth_enrollment_manager.h"
+#include "chromeos/services/device_sync/cryptauth_client.h"
+#include "chromeos/services/device_sync/cryptauth_device_manager.h"
+#include "chromeos/services/device_sync/cryptauth_enrollment_manager.h"
#include "testing/gmock/include/gmock/gmock.h"
+namespace chromeos {
+namespace device_sync {
+class CryptAuthClientFactory;
+} // namespace device_sync
+} // namespace chromeos
+
namespace proximity_auth {
// Mock implementation of ProximityAuthClient.
@@ -39,7 +45,7 @@
// Proxy mock methods because implementation requires returning scoped_ptr.
MOCK_METHOD0(CreateCryptAuthClientFactoryPtr,
- cryptauth::CryptAuthClientFactory*(void));
+ chromeos::device_sync::CryptAuthClientFactory*(void));
private:
DISALLOW_COPY_AND_ASSIGN(MockProximityAuthClient);
diff --git a/chromeos/components/proximity_auth/webui/proximity_auth_webui_handler.h b/chromeos/components/proximity_auth/webui/proximity_auth_webui_handler.h
index 255421c..401aae5c 100644
--- a/chromeos/components/proximity_auth/webui/proximity_auth_webui_handler.h
+++ b/chromeos/components/proximity_auth/webui/proximity_auth_webui_handler.h
@@ -16,7 +16,6 @@
#include "chromeos/components/proximity_auth/remote_device_life_cycle.h"
#include "chromeos/services/device_sync/public/cpp/device_sync_client.h"
#include "chromeos/services/secure_channel/public/cpp/client/secure_channel_client.h"
-#include "components/cryptauth/network_request_error.h"
#include "content/public/browser/web_ui_message_handler.h"
namespace base {
diff --git a/chromeos/components/tether/BUILD.gn b/chromeos/components/tether/BUILD.gn
index 9de800d..684fdc7 100644
--- a/chromeos/components/tether/BUILD.gn
+++ b/chromeos/components/tether/BUILD.gn
@@ -127,6 +127,7 @@
"//chromeos",
"//chromeos/components/proximity_auth/logging",
"//chromeos/components/tether/proto",
+ "//chromeos/services/device_sync",
"//chromeos/services/device_sync/public/cpp",
"//chromeos/services/multidevice_setup/public/cpp:cpp",
"//chromeos/services/multidevice_setup/public/mojom:mojom",
@@ -295,6 +296,9 @@
"//chromeos/components/multidevice",
"//chromeos/components/multidevice:test_support",
"//chromeos/components/tether/proto",
+ "//chromeos/services/device_sync",
+ "//chromeos/services/device_sync:test_support",
+ "//chromeos/services/device_sync/public/cpp",
"//chromeos/services/device_sync/public/cpp:test_support",
# TODO(hansberry): Remove //chromeos/services/secure_channel dependency when
@@ -307,6 +311,7 @@
"//chromeos/services/secure_channel/public/cpp/client:test_support",
"//chromeos/services/secure_channel/public/cpp/shared",
"//components/cryptauth",
+ "//components/cryptauth:secure_message_test_support",
"//components/cryptauth:test_support",
"//components/cryptauth/ble",
"//components/cryptauth/ble:test_support",
diff --git a/chromeos/components/tether/asynchronous_shutdown_object_container_impl_unittest.cc b/chromeos/components/tether/asynchronous_shutdown_object_container_impl_unittest.cc
index 4bfff8b..d1a291a 100644
--- a/chromeos/components/tether/asynchronous_shutdown_object_container_impl_unittest.cc
+++ b/chromeos/components/tether/asynchronous_shutdown_object_container_impl_unittest.cc
@@ -13,10 +13,10 @@
#include "chromeos/components/tether/fake_disconnect_tethering_request_sender.h"
#include "chromeos/components/tether/fake_tether_host_fetcher.h"
#include "chromeos/components/tether/tether_component_impl.h"
+#include "chromeos/services/device_sync/fake_remote_device_provider.h"
#include "chromeos/services/device_sync/public/cpp/fake_device_sync_client.h"
+#include "chromeos/services/device_sync/remote_device_provider_impl.h"
#include "chromeos/services/secure_channel/public/cpp/client/fake_secure_channel_client.h"
-#include "components/cryptauth/fake_remote_device_provider.h"
-#include "components/cryptauth/remote_device_provider_impl.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -32,17 +32,17 @@
namespace {
class FakeRemoteDeviceProviderFactory
- : public cryptauth::RemoteDeviceProviderImpl::Factory {
+ : public device_sync::RemoteDeviceProviderImpl::Factory {
public:
FakeRemoteDeviceProviderFactory() = default;
~FakeRemoteDeviceProviderFactory() override = default;
- // cryptauth::RemoteDeviceProviderImpl::Factory:
- std::unique_ptr<cryptauth::RemoteDeviceProvider> BuildInstance(
- cryptauth::CryptAuthDeviceManager* device_manager,
+ // device_sync::RemoteDeviceProviderImpl::Factory:
+ std::unique_ptr<device_sync::RemoteDeviceProvider> BuildInstance(
+ device_sync::CryptAuthDeviceManager* device_manager,
const std::string& user_id,
const std::string& user_private_key) override {
- return std::make_unique<cryptauth::FakeRemoteDeviceProvider>();
+ return std::make_unique<device_sync::FakeRemoteDeviceProvider>();
}
};
@@ -58,7 +58,7 @@
fake_remote_device_provider_factory_ =
base::WrapUnique(new FakeRemoteDeviceProviderFactory());
- cryptauth::RemoteDeviceProviderImpl::Factory::SetInstanceForTesting(
+ device_sync::RemoteDeviceProviderImpl::Factory::SetInstanceForTesting(
fake_remote_device_provider_factory_.get());
fake_device_sync_client_ =
diff --git a/chromeos/components/tether/host_scan_scheduler_impl_unittest.cc b/chromeos/components/tether/host_scan_scheduler_impl_unittest.cc
index 8f463484..7e9637b 100644
--- a/chromeos/components/tether/host_scan_scheduler_impl_unittest.cc
+++ b/chromeos/components/tether/host_scan_scheduler_impl_unittest.cc
@@ -22,7 +22,7 @@
#include "chromeos/network/network_state_handler.h"
#include "chromeos/network/network_state_test.h"
#include "chromeos/network/network_type_pattern.h"
-#include "components/cryptauth/cryptauth_device_manager.h"
+#include "chromeos/services/device_sync/cryptauth_device_manager.h"
#include "components/session_manager/core/session_manager.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
diff --git a/chromeos/components/tether/host_scanner_impl.cc b/chromeos/components/tether/host_scanner_impl.cc
index ca5f85f..bfac072 100644
--- a/chromeos/components/tether/host_scanner_impl.cc
+++ b/chromeos/components/tether/host_scanner_impl.cc
@@ -17,7 +17,7 @@
#include "chromeos/components/tether/master_host_scan_cache.h"
#include "chromeos/components/tether/tether_host_fetcher.h"
#include "chromeos/network/network_state.h"
-#include "components/cryptauth/remote_device_loader.h"
+#include "chromeos/services/device_sync/remote_device_loader.h"
#include "components/session_manager/core/session_manager.h"
namespace chromeos {
diff --git a/chromeos/services/device_sync/BUILD.gn b/chromeos/services/device_sync/BUILD.gn
index db14f694..5d8ae8fa 100644
--- a/chromeos/services/device_sync/BUILD.gn
+++ b/chromeos/services/device_sync/BUILD.gn
@@ -8,8 +8,28 @@
static_library("device_sync") {
sources = [
+ "cryptauth_api_call_flow.cc",
+ "cryptauth_api_call_flow.h",
+ "cryptauth_client.h",
+ "cryptauth_client_impl.cc",
+ "cryptauth_client_impl.h",
+ "cryptauth_device_manager.cc",
+ "cryptauth_device_manager.h",
+ "cryptauth_device_manager_impl.cc",
+ "cryptauth_device_manager_impl.h",
+ "cryptauth_enroller.h",
"cryptauth_enroller_factory_impl.cc",
"cryptauth_enroller_factory_impl.h",
+ "cryptauth_enroller_impl.cc",
+ "cryptauth_enroller_impl.h",
+ "cryptauth_enrollment_manager.cc",
+ "cryptauth_enrollment_manager.h",
+ "cryptauth_enrollment_manager_impl.cc",
+ "cryptauth_enrollment_manager_impl.h",
+ "cryptauth_gcm_manager.cc",
+ "cryptauth_gcm_manager.h",
+ "cryptauth_gcm_manager_impl.cc",
+ "cryptauth_gcm_manager_impl.h",
"device_sync_base.cc",
"device_sync_base.h",
"device_sync_impl.cc",
@@ -18,13 +38,31 @@
"device_sync_service.h",
"device_sync_type_converters.cc",
"device_sync_type_converters.h",
+ "network_request_error.cc",
+ "network_request_error.h",
+ "pref_names.cc",
+ "pref_names.h",
+ "remote_device_loader.cc",
+ "remote_device_loader.h",
+ "remote_device_provider.cc",
+ "remote_device_provider.h",
+ "remote_device_provider_impl.cc",
+ "remote_device_provider_impl.h",
+ "software_feature_manager.h",
+ "software_feature_manager_impl.cc",
+ "software_feature_manager_impl.h",
+ "switches.cc",
+ "switches.h",
+ "sync_scheduler.cc",
+ "sync_scheduler.h",
+ "sync_scheduler_impl.cc",
+ "sync_scheduler_impl.h",
]
public_deps = [
"//chromeos/components/multidevice",
"//chromeos/components/proximity_auth/logging",
"//chromeos/services/device_sync/public/mojom",
- "//components/cryptauth",
"//services/identity/public/mojom",
"//services/service_manager/public/cpp",
]
@@ -32,7 +70,10 @@
deps = [
"//base",
"//chromeos/components/proximity_auth/logging",
+ "//chromeos/services/device_sync/proto:util",
+ "//chromeos/services/device_sync/public/cpp",
"//chromeos/services/device_sync/public/mojom",
+ "//components/cryptauth:secure_message",
"//components/gcm_driver",
"//net",
"//services/identity/public/cpp",
@@ -50,10 +91,24 @@
testonly = true
sources = [
+ "fake_cryptauth_device_manager.cc",
+ "fake_cryptauth_device_manager.h",
+ "fake_cryptauth_enrollment_manager.cc",
+ "fake_cryptauth_enrollment_manager.h",
+ "fake_cryptauth_gcm_manager.cc",
+ "fake_cryptauth_gcm_manager.h",
"fake_device_sync.cc",
"fake_device_sync.h",
"fake_device_sync_observer.cc",
"fake_device_sync_observer.h",
+ "fake_remote_device_provider.cc",
+ "fake_remote_device_provider.h",
+ "fake_software_feature_manager.cc",
+ "fake_software_feature_manager.h",
+ "mock_cryptauth_client.cc",
+ "mock_cryptauth_client.h",
+ "mock_sync_scheduler.cc",
+ "mock_sync_scheduler.h",
]
public_deps = [
@@ -65,6 +120,7 @@
"//base",
"//chromeos/services/device_sync/public/cpp",
"//chromeos/services/device_sync/public/mojom",
+ "//testing/gmock",
"//testing/gtest",
]
}
@@ -73,7 +129,17 @@
testonly = true
sources = [
+ "cryptauth_api_call_flow_unittest.cc",
+ "cryptauth_client_impl_unittest.cc",
+ "cryptauth_device_manager_impl_unittest.cc",
+ "cryptauth_enroller_impl_unittest.cc",
+ "cryptauth_enrollment_manager_impl_unittest.cc",
+ "cryptauth_gcm_manager_impl_unittest.cc",
"device_sync_service_unittest.cc",
+ "remote_device_loader_unittest.cc",
+ "remote_device_provider_impl_unittest.cc",
+ "software_feature_manager_impl_unittest.cc",
+ "sync_scheduler_impl_unittest.cc",
]
deps = [
@@ -84,15 +150,19 @@
"//chromeos",
"//chromeos/components/multidevice",
"//chromeos/components/multidevice:test_support",
+ "//chromeos/services/device_sync/proto:util",
+ "//chromeos/services/device_sync/public/cpp:test_support",
"//chromeos/services/device_sync/public/cpp:unit_tests",
"//chromeos/services/device_sync/public/mojom",
- "//components/cryptauth",
- "//components/cryptauth:test_support",
+ "//components/cryptauth:secure_message",
+ "//components/cryptauth:secure_message_test_support",
"//components/gcm_driver:test_support",
"//components/prefs:test_support",
+ "//net/traffic_annotation:test_support",
"//services/identity/public/cpp:test_support",
"//services/network:test_support",
"//services/service_manager/public/cpp/test:test_support",
+ "//testing/gmock",
"//testing/gtest",
]
}
diff --git a/chromeos/services/device_sync/DEPS b/chromeos/services/device_sync/DEPS
index 5694619..eb4da29 100644
--- a/chromeos/services/device_sync/DEPS
+++ b/chromeos/services/device_sync/DEPS
@@ -3,10 +3,12 @@
"+components/gcm_driver",
"+components/proximity_auth/logging",
"+components/signin/core/browser",
+ "+components/version_info",
"+google_apis/gaia",
"+mojo/public/cpp",
- "+net/url_request",
"+services/identity",
+ "+services/network/public",
+ "+services/network/test",
"+services/preferences/public",
"+services/service_manager/public/cpp",
"+components/cryptauth"
diff --git a/components/cryptauth/cryptauth_api_call_flow.cc b/chromeos/services/device_sync/cryptauth_api_call_flow.cc
similarity index 91%
rename from components/cryptauth/cryptauth_api_call_flow.cc
rename to chromeos/services/device_sync/cryptauth_api_call_flow.cc
index c64885a..6ff5341 100644
--- a/components/cryptauth/cryptauth_api_call_flow.cc
+++ b/chromeos/services/device_sync/cryptauth_api_call_flow.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/cryptauth/cryptauth_api_call_flow.h"
+#include "chromeos/services/device_sync/cryptauth_api_call_flow.h"
#include "base/optional.h"
#include "base/strings/string_number_conversions.h"
@@ -10,7 +10,9 @@
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
namespace {
@@ -34,11 +36,9 @@
} // namespace
-CryptAuthApiCallFlow::CryptAuthApiCallFlow() {
-}
+CryptAuthApiCallFlow::CryptAuthApiCallFlow() {}
-CryptAuthApiCallFlow::~CryptAuthApiCallFlow() {
-}
+CryptAuthApiCallFlow::~CryptAuthApiCallFlow() {}
void CryptAuthApiCallFlow::Start(
const GURL& request_url,
@@ -110,4 +110,6 @@
return *partial_network_annotation_.get();
}
-} // namespace cryptauth
+} // namespace device_sync
+
+} // namespace chromeos
diff --git a/components/cryptauth/cryptauth_api_call_flow.h b/chromeos/services/device_sync/cryptauth_api_call_flow.h
similarity index 89%
rename from components/cryptauth/cryptauth_api_call_flow.h
rename to chromeos/services/device_sync/cryptauth_api_call_flow.h
index 521d64cd..94239f49 100644
--- a/components/cryptauth/cryptauth_api_call_flow.h
+++ b/chromeos/services/device_sync/cryptauth_api_call_flow.h
@@ -2,18 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef COMPONENTS_CRYPTAUTH_CRYPTAUTH_API_CALL_FLOW_H_
-#define COMPONENTS_CRYPTAUTH_CRYPTAUTH_API_CALL_FLOW_H_
+#ifndef CHROMEOS_SERVICES_DEVICE_SYNC_CRYPTAUTH_API_CALL_FLOW_H_
+#define CHROMEOS_SERVICES_DEVICE_SYNC_CRYPTAUTH_API_CALL_FLOW_H_
#include <string>
#include "base/callback.h"
#include "base/macros.h"
-#include "components/cryptauth/network_request_error.h"
+#include "chromeos/services/device_sync/network_request_error.h"
#include "google_apis/gaia/oauth2_api_call_flow.h"
#include "services/network/public/cpp/resource_response.h"
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
// Google API call flow implementation underlying all CryptAuth API calls.
// CryptAuth is a Google service that manages authorization and cryptographic
@@ -89,6 +91,8 @@
DISALLOW_COPY_AND_ASSIGN(CryptAuthApiCallFlow);
};
-} // namespace cryptauth
+} // namespace device_sync
-#endif // COMPONENTS_CRYPTAUTH_CRYPTAUTH_API_CALL_FLOW_H_
+} // namespace chromeos
+
+#endif // CHROMEOS_SERVICES_DEVICE_SYNC_CRYPTAUTH_API_CALL_FLOW_H_
diff --git a/components/cryptauth/cryptauth_api_call_flow_unittest.cc b/chromeos/services/device_sync/cryptauth_api_call_flow_unittest.cc
similarity index 80%
rename from components/cryptauth/cryptauth_api_call_flow_unittest.cc
rename to chromeos/services/device_sync/cryptauth_api_call_flow_unittest.cc
index ffb543a2..9939c838 100644
--- a/components/cryptauth/cryptauth_api_call_flow_unittest.cc
+++ b/chromeos/services/device_sync/cryptauth_api_call_flow_unittest.cc
@@ -2,13 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/cryptauth/cryptauth_api_call_flow.h"
+#include "chromeos/services/device_sync/cryptauth_api_call_flow.h"
#include <memory>
#include "base/macros.h"
#include "base/test/scoped_task_environment.h"
-#include "components/cryptauth/network_request_error.h"
+#include "chromeos/services/device_sync/network_request_error.h"
#include "net/base/net_errors.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
@@ -16,7 +16,9 @@
#include "services/network/test/test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
namespace {
@@ -26,9 +28,9 @@
} // namespace
-class CryptAuthApiCallFlowTest : public testing::Test {
+class DeviceSyncCryptAuthApiCallFlowTest : public testing::Test {
protected:
- CryptAuthApiCallFlowTest()
+ DeviceSyncCryptAuthApiCallFlowTest()
: shared_factory_(
base::MakeRefCounted<network::WeakWrapperSharedURLLoaderFactory>(
&test_url_loader_factory_)) {
@@ -41,10 +43,12 @@
}
void StartApiCallFlowWithRequest(const std::string& serialized_request) {
- flow_.Start(
- GURL(kRequestUrl), shared_factory_, "access_token", serialized_request,
- base::Bind(&CryptAuthApiCallFlowTest::OnResult, base::Unretained(this)),
- base::Bind(&CryptAuthApiCallFlowTest::OnError, base::Unretained(this)));
+ flow_.Start(GURL(kRequestUrl), shared_factory_, "access_token",
+ serialized_request,
+ base::Bind(&DeviceSyncCryptAuthApiCallFlowTest::OnResult,
+ base::Unretained(this)),
+ base::Bind(&DeviceSyncCryptAuthApiCallFlowTest::OnError,
+ base::Unretained(this)));
// A pending fetch for the API request should be created.
CheckCryptAuthHttpRequest(serialized_request);
}
@@ -102,24 +106,24 @@
CryptAuthApiCallFlow flow_;
- DISALLOW_COPY_AND_ASSIGN(CryptAuthApiCallFlowTest);
+ DISALLOW_COPY_AND_ASSIGN(DeviceSyncCryptAuthApiCallFlowTest);
};
-TEST_F(CryptAuthApiCallFlowTest, RequestSuccess) {
+TEST_F(DeviceSyncCryptAuthApiCallFlowTest, RequestSuccess) {
StartApiCallFlow();
CompleteCurrentRequest(net::OK, net::HTTP_OK, kSerializedResponseProto);
EXPECT_EQ(kSerializedResponseProto, *result_);
EXPECT_FALSE(network_error_);
}
-TEST_F(CryptAuthApiCallFlowTest, RequestFailure) {
+TEST_F(DeviceSyncCryptAuthApiCallFlowTest, RequestFailure) {
StartApiCallFlow();
CompleteCurrentRequest(net::ERR_FAILED, 0, std::string());
EXPECT_FALSE(result_);
EXPECT_EQ(NetworkRequestError::kOffline, *network_error_);
}
-TEST_F(CryptAuthApiCallFlowTest, RequestStatus500) {
+TEST_F(DeviceSyncCryptAuthApiCallFlowTest, RequestStatus500) {
StartApiCallFlow();
CompleteCurrentRequest(net::OK, net::HTTP_INTERNAL_SERVER_ERROR,
"CryptAuth Meltdown.");
@@ -128,7 +132,7 @@
}
// The empty string is a valid protocol buffer message serialization.
-TEST_F(CryptAuthApiCallFlowTest, RequestWithNoBody) {
+TEST_F(DeviceSyncCryptAuthApiCallFlowTest, RequestWithNoBody) {
StartApiCallFlowWithRequest(std::string());
CompleteCurrentRequest(net::OK, net::HTTP_OK, kSerializedResponseProto);
EXPECT_EQ(kSerializedResponseProto, *result_);
@@ -136,11 +140,13 @@
}
// The empty string is a valid protocol buffer message serialization.
-TEST_F(CryptAuthApiCallFlowTest, ResponseWithNoBody) {
+TEST_F(DeviceSyncCryptAuthApiCallFlowTest, ResponseWithNoBody) {
StartApiCallFlow();
CompleteCurrentRequest(net::OK, net::HTTP_OK, std::string());
EXPECT_EQ(std::string(), *result_);
EXPECT_FALSE(network_error_);
}
-} // namespace cryptauth
+} // namespace device_sync
+
+} // namespace chromeos
diff --git a/components/cryptauth/cryptauth_client.h b/chromeos/services/device_sync/cryptauth_client.h
similarity index 72%
rename from components/cryptauth/cryptauth_client.h
rename to chromeos/services/device_sync/cryptauth_client.h
index 8830141..953eb6e 100644
--- a/components/cryptauth/cryptauth_client.h
+++ b/chromeos/services/device_sync/cryptauth_client.h
@@ -2,15 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef COMPONENTS_CRYPTAUTH_CRYPTAUTH_CLIENT_H_
-#define COMPONENTS_CRYPTAUTH_CRYPTAUTH_CLIENT_H_
+#ifndef CHROMEOS_SERVICES_DEVICE_SYNC_CRYPTAUTH_CLIENT_H_
+#define CHROMEOS_SERVICES_DEVICE_SYNC_CRYPTAUTH_CLIENT_H_
#include <memory>
#include <string>
#include "base/callback_forward.h"
#include "base/macros.h"
-#include "components/cryptauth/network_request_error.h"
+#include "chromeos/services/device_sync/network_request_error.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
namespace cryptauth {
@@ -28,9 +28,11 @@
class FinishEnrollmentResponse;
class FindEligibleForPromotionRequest;
class FindEligibleForPromotionResponse;
-}
+} // namespace cryptauth
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
// Interface for making API requests to the CryptAuth service, which
// manages cryptographic credentials (ie. public keys) for a user's devices.
@@ -45,9 +47,9 @@
virtual ~CryptAuthClient() {}
// GetMyDevices
- typedef base::Callback<void(const GetMyDevicesResponse&)>
+ typedef base::Callback<void(const cryptauth::GetMyDevicesResponse&)>
GetMyDevicesCallback;
- virtual void GetMyDevices(const GetMyDevicesRequest& request,
+ virtual void GetMyDevices(const cryptauth::GetMyDevicesRequest& request,
const GetMyDevicesCallback& callback,
const ErrorCallback& error_callback,
const net::PartialNetworkTrafficAnnotationTag&
@@ -55,51 +57,52 @@
// FindEligibleUnlockDevices
typedef base::Callback<void(
- const FindEligibleUnlockDevicesResponse&)>
+ const cryptauth::FindEligibleUnlockDevicesResponse&)>
FindEligibleUnlockDevicesCallback;
virtual void FindEligibleUnlockDevices(
- const FindEligibleUnlockDevicesRequest& request,
+ const cryptauth::FindEligibleUnlockDevicesRequest& request,
const FindEligibleUnlockDevicesCallback& callback,
const ErrorCallback& error_callback) = 0;
// FindEligibleForPromotion
- typedef base::Callback<void(const FindEligibleForPromotionResponse&)>
+ typedef base::Callback<void(
+ const cryptauth::FindEligibleForPromotionResponse&)>
FindEligibleForPromotionCallback;
virtual void FindEligibleForPromotion(
- const FindEligibleForPromotionRequest& request,
+ const cryptauth::FindEligibleForPromotionRequest& request,
const FindEligibleForPromotionCallback& callback,
const ErrorCallback& error_callback) = 0;
// SendDeviceSyncTickle
- typedef base::Callback<void(const SendDeviceSyncTickleResponse&)>
+ typedef base::Callback<void(const cryptauth::SendDeviceSyncTickleResponse&)>
SendDeviceSyncTickleCallback;
virtual void SendDeviceSyncTickle(
- const SendDeviceSyncTickleRequest& request,
+ const cryptauth::SendDeviceSyncTickleRequest& request,
const SendDeviceSyncTickleCallback& callback,
const ErrorCallback& error_callback,
const net::PartialNetworkTrafficAnnotationTag&
partial_traffic_annotation) = 0;
// ToggleEasyUnlock
- typedef base::Callback<void(const ToggleEasyUnlockResponse&)>
+ typedef base::Callback<void(const cryptauth::ToggleEasyUnlockResponse&)>
ToggleEasyUnlockCallback;
virtual void ToggleEasyUnlock(
- const ToggleEasyUnlockRequest& request,
+ const cryptauth::ToggleEasyUnlockRequest& request,
const ToggleEasyUnlockCallback& callback,
const ErrorCallback& error_callback) = 0;
// SetupEnrollment
- typedef base::Callback<void(const SetupEnrollmentResponse&)>
+ typedef base::Callback<void(const cryptauth::SetupEnrollmentResponse&)>
SetupEnrollmentCallback;
- virtual void SetupEnrollment(const SetupEnrollmentRequest& request,
+ virtual void SetupEnrollment(const cryptauth::SetupEnrollmentRequest& request,
const SetupEnrollmentCallback& callback,
const ErrorCallback& error_callback) = 0;
// FinishEnrollment
- typedef base::Callback<void(const FinishEnrollmentResponse&)>
+ typedef base::Callback<void(const cryptauth::FinishEnrollmentResponse&)>
FinishEnrollmentCallback;
virtual void FinishEnrollment(
- const FinishEnrollmentRequest& request,
+ const cryptauth::FinishEnrollmentRequest& request,
const FinishEnrollmentCallback& callback,
const ErrorCallback& error_callback) = 0;
@@ -118,6 +121,8 @@
virtual std::unique_ptr<CryptAuthClient> CreateInstance() = 0;
};
-} // namespace cryptauth
+} // namespace device_sync
-#endif // COMPONENTS_CRYPTAUTH_CRYPTAUTH_CLIENT_H_
+} // namespace chromeos
+
+#endif // CHROMEOS_SERVICES_DEVICE_SYNC_CRYPTAUTH_CLIENT_H_
diff --git a/components/cryptauth/cryptauth_client_impl.cc b/chromeos/services/device_sync/cryptauth_client_impl.cc
similarity index 94%
rename from components/cryptauth/cryptauth_client_impl.cc
rename to chromeos/services/device_sync/cryptauth_client_impl.cc
index 6425c86..615f4ba 100644
--- a/components/cryptauth/cryptauth_client_impl.cc
+++ b/chromeos/services/device_sync/cryptauth_client_impl.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/cryptauth/cryptauth_client_impl.h"
+#include "chromeos/services/device_sync/cryptauth_client_impl.h"
#include <memory>
#include <utility>
@@ -11,12 +11,14 @@
#include "base/command_line.h"
#include "base/memory/ptr_util.h"
#include "chromeos/components/proximity_auth/logging/logging.h"
-#include "components/cryptauth/switches.h"
+#include "chromeos/services/device_sync/switches.h"
#include "services/identity/public/cpp/identity_manager.h"
#include "services/identity/public/cpp/primary_account_access_token_fetcher.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
namespace {
@@ -58,7 +60,7 @@
std::unique_ptr<CryptAuthApiCallFlow> api_call_flow,
identity::IdentityManager* identity_manager,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
- const DeviceClassifier& device_classifier)
+ const cryptauth::DeviceClassifier& device_classifier)
: api_call_flow_(std::move(api_call_flow)),
identity_manager_(identity_manager),
url_loader_factory_(std::move(url_loader_factory)),
@@ -69,7 +71,7 @@
CryptAuthClientImpl::~CryptAuthClientImpl() {}
void CryptAuthClientImpl::GetMyDevices(
- const GetMyDevicesRequest& request,
+ const cryptauth::GetMyDevicesRequest& request,
const GetMyDevicesCallback& callback,
const ErrorCallback& error_callback,
const net::PartialNetworkTrafficAnnotationTag& partial_traffic_annotation) {
@@ -78,7 +80,7 @@
}
void CryptAuthClientImpl::FindEligibleUnlockDevices(
- const FindEligibleUnlockDevicesRequest& request,
+ const cryptauth::FindEligibleUnlockDevicesRequest& request,
const FindEligibleUnlockDevicesCallback& callback,
const ErrorCallback& error_callback) {
net::PartialNetworkTrafficAnnotationTag partial_traffic_annotation =
@@ -111,7 +113,7 @@
}
void CryptAuthClientImpl::FindEligibleForPromotion(
- const FindEligibleForPromotionRequest& request,
+ const cryptauth::FindEligibleForPromotionRequest& request,
const FindEligibleForPromotionCallback& callback,
const ErrorCallback& error_callback) {
net::PartialNetworkTrafficAnnotationTag partial_traffic_annotation =
@@ -141,7 +143,7 @@
}
void CryptAuthClientImpl::SendDeviceSyncTickle(
- const SendDeviceSyncTickleRequest& request,
+ const cryptauth::SendDeviceSyncTickleRequest& request,
const SendDeviceSyncTickleCallback& callback,
const ErrorCallback& error_callback,
const net::PartialNetworkTrafficAnnotationTag& partial_traffic_annotation) {
@@ -150,7 +152,7 @@
}
void CryptAuthClientImpl::ToggleEasyUnlock(
- const ToggleEasyUnlockRequest& request,
+ const cryptauth::ToggleEasyUnlockRequest& request,
const ToggleEasyUnlockCallback& callback,
const ErrorCallback& error_callback) {
net::PartialNetworkTrafficAnnotationTag partial_traffic_annotation =
@@ -181,7 +183,7 @@
}
void CryptAuthClientImpl::SetupEnrollment(
- const SetupEnrollmentRequest& request,
+ const cryptauth::SetupEnrollmentRequest& request,
const SetupEnrollmentCallback& callback,
const ErrorCallback& error_callback) {
net::PartialNetworkTrafficAnnotationTag partial_traffic_annotation =
@@ -215,7 +217,7 @@
}
void CryptAuthClientImpl::FinishEnrollment(
- const FinishEnrollmentRequest& request,
+ const cryptauth::FinishEnrollmentRequest& request,
const FinishEnrollmentCallback& callback,
const ErrorCallback& error_callback) {
net::PartialNetworkTrafficAnnotationTag partial_traffic_annotation =
@@ -327,7 +329,7 @@
return;
}
result_callback.Run(response);
-};
+}
void CryptAuthClientImpl::OnApiCallFailed(NetworkRequestError error) {
error_callback_.Run(error);
@@ -337,7 +339,7 @@
CryptAuthClientFactoryImpl::CryptAuthClientFactoryImpl(
identity::IdentityManager* identity_manager,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
- const DeviceClassifier& device_classifier)
+ const cryptauth::DeviceClassifier& device_classifier)
: identity_manager_(identity_manager),
url_loader_factory_(std::move(url_loader_factory)),
device_classifier_(device_classifier) {}
@@ -350,4 +352,6 @@
url_loader_factory_, device_classifier_);
}
-} // namespace cryptauth
+} // namespace device_sync
+
+} // namespace chromeos
diff --git a/components/cryptauth/cryptauth_client_impl.h b/chromeos/services/device_sync/cryptauth_client_impl.h
similarity index 80%
rename from components/cryptauth/cryptauth_client_impl.h
rename to chromeos/services/device_sync/cryptauth_client_impl.h
index 88d7c891..a7e5ad4 100644
--- a/components/cryptauth/cryptauth_client_impl.h
+++ b/chromeos/services/device_sync/cryptauth_client_impl.h
@@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef COMPONENTS_CRYPTAUTH_CRYPTAUTH_CLIENT_IMPL_H_
-#define COMPONENTS_CRYPTAUTH_CRYPTAUTH_CLIENT_IMPL_H_
+#ifndef CHROMEOS_SERVICES_DEVICE_SYNC_CRYPTAUTH_CLIENT_IMPL_H_
+#define CHROMEOS_SERVICES_DEVICE_SYNC_CRYPTAUTH_CLIENT_IMPL_H_
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
+#include "chromeos/services/device_sync/cryptauth_api_call_flow.h"
+#include "chromeos/services/device_sync/cryptauth_client.h"
#include "chromeos/services/device_sync/proto/cryptauth_api.pb.h"
-#include "components/cryptauth/cryptauth_api_call_flow.h"
-#include "components/cryptauth/cryptauth_client.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/identity/public/cpp/access_token_info.h"
@@ -24,7 +24,9 @@
class GoogleServiceAuthError;
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
// Implementation of CryptAuthClient.
// Note: There is no need to set the |device_classifier| field in request
@@ -38,35 +40,36 @@
std::unique_ptr<CryptAuthApiCallFlow> api_call_flow,
identity::IdentityManager* identity_manager,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
- const DeviceClassifier& device_classifier);
+ const cryptauth::DeviceClassifier& device_classifier);
~CryptAuthClientImpl() override;
// CryptAuthClient:
- void GetMyDevices(const GetMyDevicesRequest& request,
+ void GetMyDevices(const cryptauth::GetMyDevicesRequest& request,
const GetMyDevicesCallback& callback,
const ErrorCallback& error_callback,
const net::PartialNetworkTrafficAnnotationTag&
partial_traffic_annotation) override;
void FindEligibleUnlockDevices(
- const FindEligibleUnlockDevicesRequest& request,
+ const cryptauth::FindEligibleUnlockDevicesRequest& request,
const FindEligibleUnlockDevicesCallback& callback,
const ErrorCallback& error_callback) override;
void FindEligibleForPromotion(
- const FindEligibleForPromotionRequest& request,
+ const cryptauth::FindEligibleForPromotionRequest& request,
const FindEligibleForPromotionCallback& callback,
const ErrorCallback& error_callback) override;
- void SendDeviceSyncTickle(const SendDeviceSyncTickleRequest& request,
- const SendDeviceSyncTickleCallback& callback,
- const ErrorCallback& error_callback,
- const net::PartialNetworkTrafficAnnotationTag&
- partial_traffic_annotation) override;
- void ToggleEasyUnlock(const ToggleEasyUnlockRequest& request,
+ void SendDeviceSyncTickle(
+ const cryptauth::SendDeviceSyncTickleRequest& request,
+ const SendDeviceSyncTickleCallback& callback,
+ const ErrorCallback& error_callback,
+ const net::PartialNetworkTrafficAnnotationTag& partial_traffic_annotation)
+ override;
+ void ToggleEasyUnlock(const cryptauth::ToggleEasyUnlockRequest& request,
const ToggleEasyUnlockCallback& callback,
const ErrorCallback& error_callback) override;
- void SetupEnrollment(const SetupEnrollmentRequest& request,
+ void SetupEnrollment(const cryptauth::SetupEnrollmentRequest& request,
const SetupEnrollmentCallback& callback,
const ErrorCallback& error_callback) override;
- void FinishEnrollment(const FinishEnrollmentRequest& request,
+ void FinishEnrollment(const cryptauth::FinishEnrollmentRequest& request,
const FinishEnrollmentCallback& callback,
const ErrorCallback& error_callback) override;
std::string GetAccessTokenUsed() override;
@@ -116,7 +119,7 @@
// Contains basic device info of the client making the request that is sent to
// CryptAuth with each API call.
- const DeviceClassifier device_classifier_;
+ const cryptauth::DeviceClassifier device_classifier_;
// True if an API call has been started. Remains true even after the API call
// completes.
@@ -146,7 +149,7 @@
CryptAuthClientFactoryImpl(
identity::IdentityManager* identity_manager,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
- const DeviceClassifier& device_classifier);
+ const cryptauth::DeviceClassifier& device_classifier);
~CryptAuthClientFactoryImpl() override;
// CryptAuthClientFactory:
@@ -155,11 +158,13 @@
private:
identity::IdentityManager* identity_manager_;
const scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
- const DeviceClassifier device_classifier_;
+ const cryptauth::DeviceClassifier device_classifier_;
DISALLOW_COPY_AND_ASSIGN(CryptAuthClientFactoryImpl);
};
-} // namespace cryptauth
+} // namespace device_sync
-#endif // COMPONENTS_CRYPTAUTH_CRYPTAUTH_CLIENT_IMPL_H_
+} // namespace chromeos
+
+#endif // CHROMEOS_SERVICES_DEVICE_SYNC_CRYPTAUTH_CLIENT_IMPL_H_
diff --git a/components/cryptauth/cryptauth_client_impl_unittest.cc b/chromeos/services/device_sync/cryptauth_client_impl_unittest.cc
similarity index 77%
rename from components/cryptauth/cryptauth_client_impl_unittest.cc
rename to chromeos/services/device_sync/cryptauth_client_impl_unittest.cc
index e09da9c..8c27197 100644
--- a/components/cryptauth/cryptauth_client_impl_unittest.cc
+++ b/chromeos/services/device_sync/cryptauth_client_impl_unittest.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/cryptauth/cryptauth_client_impl.h"
+#include "chromeos/services/device_sync/cryptauth_client_impl.h"
#include "base/command_line.h"
#include "base/macros.h"
@@ -10,10 +10,10 @@
#include "base/test/gtest_util.h"
#include "base/test/null_task_runner.h"
#include "base/test/scoped_task_environment.h"
+#include "chromeos/services/device_sync/cryptauth_api_call_flow.h"
#include "chromeos/services/device_sync/proto/cryptauth_api.pb.h"
#include "chromeos/services/device_sync/proto/enum_util.h"
-#include "components/cryptauth/cryptauth_api_call_flow.h"
-#include "components/cryptauth/switches.h"
+#include "chromeos/services/device_sync/switches.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "services/identity/public/cpp/identity_test_environment.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
@@ -27,7 +27,9 @@
using testing::SaveArg;
using testing::StrictMock;
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
namespace {
@@ -43,7 +45,7 @@
const int kDeviceOsVersionCode = 100;
const int kDeviceSoftwareVersionCode = 200;
const char kDeviceSoftwarePackage[] = "cryptauth_client_unittest";
-const DeviceType kDeviceType = CHROME;
+const cryptauth::DeviceType kDeviceType = cryptauth::CHROME;
// Mock CryptAuthApiCallFlow, which handles the HTTP requests to CryptAuth.
class MockCryptAuthApiCallFlow : public CryptAuthApiCallFlow {
@@ -109,13 +111,12 @@
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kCryptAuthHTTPHost, kTestGoogleApisUrl);
- DeviceClassifier device_classifier;
+ cryptauth::DeviceClassifier device_classifier;
device_classifier.set_device_os_version_code(kDeviceOsVersionCode);
device_classifier.set_device_software_version_code(
kDeviceSoftwareVersionCode);
device_classifier.set_device_software_package(kDeviceSoftwarePackage);
- device_classifier.set_device_type(
- cryptauth::DeviceTypeEnumToString(kDeviceType));
+ device_classifier.set_device_type(DeviceTypeEnumToString(kDeviceType));
identity_test_environment_.MakePrimaryAccountAvailable(kEmail);
@@ -168,30 +169,31 @@
"https://www.testgoogleapis.com/cryptauth/v1/deviceSync/"
"getmydevices?alt=proto");
- GetMyDevicesResponse result_proto;
- GetMyDevicesRequest request_proto;
+ cryptauth::GetMyDevicesResponse result_proto;
+ cryptauth::GetMyDevicesRequest request_proto;
request_proto.set_allow_stale_read(true);
client_->GetMyDevices(
request_proto,
- base::Bind(&SaveResultConstRef<GetMyDevicesResponse>, &result_proto),
+ base::Bind(&SaveResultConstRef<cryptauth::GetMyDevicesResponse>,
+ &result_proto),
base::Bind(&NotCalled<NetworkRequestError>),
PARTIAL_TRAFFIC_ANNOTATION_FOR_TESTS);
identity_test_environment_
.WaitForAccessTokenRequestIfNecessaryAndRespondWithToken(
kAccessToken, base::Time::Max());
- GetMyDevicesRequest expected_request;
+ cryptauth::GetMyDevicesRequest expected_request;
EXPECT_TRUE(expected_request.ParseFromString(serialized_request_));
EXPECT_TRUE(expected_request.allow_stale_read());
// Return two devices, one unlock key and one unlockable device.
{
- GetMyDevicesResponse response_proto;
+ cryptauth::GetMyDevicesResponse response_proto;
response_proto.add_devices();
response_proto.mutable_devices(0)->set_public_key(kPublicKey1);
response_proto.mutable_devices(0)->set_unlock_key(true);
- response_proto.mutable_devices(0)
- ->set_bluetooth_address(kBluetoothAddress1);
+ response_proto.mutable_devices(0)->set_bluetooth_address(
+ kBluetoothAddress1);
response_proto.add_devices();
response_proto.mutable_devices(1)->set_public_key(kPublicKey2);
response_proto.mutable_devices(1)->set_unlockable(true);
@@ -213,10 +215,11 @@
"getmydevices?alt=proto");
NetworkRequestError error;
- client_->GetMyDevices(GetMyDevicesRequest(),
- base::Bind(&NotCalledConstRef<GetMyDevicesResponse>),
- base::Bind(&SaveResult<NetworkRequestError>, &error),
- PARTIAL_TRAFFIC_ANNOTATION_FOR_TESTS);
+ client_->GetMyDevices(
+ cryptauth::GetMyDevicesRequest(),
+ base::Bind(&NotCalledConstRef<cryptauth::GetMyDevicesResponse>),
+ base::Bind(&SaveResult<NetworkRequestError>, &error),
+ PARTIAL_TRAFFIC_ANNOTATION_FOR_TESTS);
identity_test_environment_
.WaitForAccessTokenRequestIfNecessaryAndRespondWithToken(
kAccessToken, base::Time::Max());
@@ -230,24 +233,25 @@
"https://www.testgoogleapis.com/cryptauth/v1/deviceSync/"
"findeligibleunlockdevices?alt=proto");
- FindEligibleUnlockDevicesResponse result_proto;
- FindEligibleUnlockDevicesRequest request_proto;
+ cryptauth::FindEligibleUnlockDevicesResponse result_proto;
+ cryptauth::FindEligibleUnlockDevicesRequest request_proto;
request_proto.set_callback_bluetooth_address(kBluetoothAddress2);
client_->FindEligibleUnlockDevices(
request_proto,
- base::Bind(&SaveResultConstRef<FindEligibleUnlockDevicesResponse>,
- &result_proto),
+ base::Bind(
+ &SaveResultConstRef<cryptauth::FindEligibleUnlockDevicesResponse>,
+ &result_proto),
base::Bind(&NotCalled<NetworkRequestError>));
identity_test_environment_
.WaitForAccessTokenRequestIfNecessaryAndRespondWithToken(
kAccessToken, base::Time::Max());
- FindEligibleUnlockDevicesRequest expected_request;
+ cryptauth::FindEligibleUnlockDevicesRequest expected_request;
EXPECT_TRUE(expected_request.ParseFromString(serialized_request_));
EXPECT_EQ(kBluetoothAddress2, expected_request.callback_bluetooth_address());
// Return a response proto with one eligible and one ineligible device.
- FindEligibleUnlockDevicesResponse response_proto;
+ cryptauth::FindEligibleUnlockDevicesResponse response_proto;
response_proto.add_eligible_devices();
response_proto.mutable_eligible_devices(0)->set_public_key(kPublicKey1);
@@ -257,8 +261,8 @@
response_proto.mutable_ineligible_devices(0)
->mutable_device()
->set_public_key(kPublicKey2);
- response_proto.mutable_ineligible_devices(0)
- ->add_reasons(kIneligibilityReason);
+ response_proto.mutable_ineligible_devices(0)->add_reasons(
+ kIneligibilityReason);
FinishApiCallFlow(&response_proto);
// Check that the result received in callback is the same as the response.
@@ -278,11 +282,12 @@
"findeligibleunlockdevices?alt=proto");
NetworkRequestError error;
- FindEligibleUnlockDevicesRequest request_proto;
+ cryptauth::FindEligibleUnlockDevicesRequest request_proto;
request_proto.set_callback_bluetooth_address(kBluetoothAddress1);
client_->FindEligibleUnlockDevices(
request_proto,
- base::Bind(&NotCalledConstRef<FindEligibleUnlockDevicesResponse>),
+ base::Bind(
+ &NotCalledConstRef<cryptauth::FindEligibleUnlockDevicesResponse>),
base::Bind(&SaveResult<NetworkRequestError>, &error));
identity_test_environment_
.WaitForAccessTokenRequestIfNecessaryAndRespondWithToken(
@@ -297,20 +302,21 @@
"https://www.testgoogleapis.com/cryptauth/v1/deviceSync/"
"findeligibleforpromotion?alt=proto");
- FindEligibleForPromotionResponse result_proto;
+ cryptauth::FindEligibleForPromotionResponse result_proto;
client_->FindEligibleForPromotion(
- FindEligibleForPromotionRequest(),
- base::Bind(&SaveResultConstRef<FindEligibleForPromotionResponse>,
- &result_proto),
+ cryptauth::FindEligibleForPromotionRequest(),
+ base::Bind(
+ &SaveResultConstRef<cryptauth::FindEligibleForPromotionResponse>,
+ &result_proto),
base::Bind(&NotCalled<NetworkRequestError>));
identity_test_environment_
.WaitForAccessTokenRequestIfNecessaryAndRespondWithToken(
kAccessToken, base::Time::Max());
- FindEligibleForPromotionRequest expected_request;
+ cryptauth::FindEligibleForPromotionRequest expected_request;
EXPECT_TRUE(expected_request.ParseFromString(serialized_request_));
- FindEligibleForPromotionResponse response_proto;
+ cryptauth::FindEligibleForPromotionResponse response_proto;
FinishApiCallFlow(&response_proto);
}
@@ -319,10 +325,10 @@
"https://www.testgoogleapis.com/cryptauth/v1/deviceSync/"
"senddevicesynctickle?alt=proto");
- SendDeviceSyncTickleResponse result_proto;
+ cryptauth::SendDeviceSyncTickleResponse result_proto;
client_->SendDeviceSyncTickle(
- SendDeviceSyncTickleRequest(),
- base::Bind(&SaveResultConstRef<SendDeviceSyncTickleResponse>,
+ cryptauth::SendDeviceSyncTickleRequest(),
+ base::Bind(&SaveResultConstRef<cryptauth::SendDeviceSyncTickleResponse>,
&result_proto),
base::Bind(&NotCalled<NetworkRequestError>),
PARTIAL_TRAFFIC_ANNOTATION_FOR_TESTS);
@@ -330,10 +336,10 @@
.WaitForAccessTokenRequestIfNecessaryAndRespondWithToken(
kAccessToken, base::Time::Max());
- SendDeviceSyncTickleRequest expected_request;
+ cryptauth::SendDeviceSyncTickleRequest expected_request;
EXPECT_TRUE(expected_request.ParseFromString(serialized_request_));
- SendDeviceSyncTickleResponse response_proto;
+ cryptauth::SendDeviceSyncTickleResponse response_proto;
FinishApiCallFlow(&response_proto);
}
@@ -342,26 +348,27 @@
"https://www.testgoogleapis.com/cryptauth/v1/deviceSync/"
"toggleeasyunlock?alt=proto");
- ToggleEasyUnlockResponse result_proto;
- ToggleEasyUnlockRequest request_proto;
+ cryptauth::ToggleEasyUnlockResponse result_proto;
+ cryptauth::ToggleEasyUnlockRequest request_proto;
request_proto.set_enable(true);
request_proto.set_apply_to_all(false);
request_proto.set_public_key(kPublicKey1);
client_->ToggleEasyUnlock(
request_proto,
- base::Bind(&SaveResultConstRef<ToggleEasyUnlockResponse>, &result_proto),
+ base::Bind(&SaveResultConstRef<cryptauth::ToggleEasyUnlockResponse>,
+ &result_proto),
base::Bind(&NotCalled<NetworkRequestError>));
identity_test_environment_
.WaitForAccessTokenRequestIfNecessaryAndRespondWithToken(
kAccessToken, base::Time::Max());
- ToggleEasyUnlockRequest expected_request;
+ cryptauth::ToggleEasyUnlockRequest expected_request;
EXPECT_TRUE(expected_request.ParseFromString(serialized_request_));
EXPECT_TRUE(expected_request.enable());
EXPECT_EQ(kPublicKey1, expected_request.public_key());
EXPECT_FALSE(expected_request.apply_to_all());
- ToggleEasyUnlockResponse response_proto;
+ cryptauth::ToggleEasyUnlockResponse response_proto;
FinishApiCallFlow(&response_proto);
}
@@ -375,20 +382,21 @@
supported_protocols.push_back("gcmV1");
supported_protocols.push_back("testProtocol");
- SetupEnrollmentResponse result_proto;
- SetupEnrollmentRequest request_proto;
+ cryptauth::SetupEnrollmentResponse result_proto;
+ cryptauth::SetupEnrollmentRequest request_proto;
request_proto.set_application_id(kApplicationId);
request_proto.add_types("gcmV1");
request_proto.add_types("testProtocol");
client_->SetupEnrollment(
request_proto,
- base::Bind(&SaveResultConstRef<SetupEnrollmentResponse>, &result_proto),
+ base::Bind(&SaveResultConstRef<cryptauth::SetupEnrollmentResponse>,
+ &result_proto),
base::Bind(&NotCalled<NetworkRequestError>));
identity_test_environment_
.WaitForAccessTokenRequestIfNecessaryAndRespondWithToken(
kAccessToken, base::Time::Max());
- SetupEnrollmentRequest expected_request;
+ cryptauth::SetupEnrollmentRequest expected_request;
EXPECT_TRUE(expected_request.ParseFromString(serialized_request_));
EXPECT_EQ(kApplicationId, expected_request.application_id());
ASSERT_EQ(2, expected_request.types_size());
@@ -397,7 +405,7 @@
// Return a fake enrollment session.
{
- SetupEnrollmentResponse response_proto;
+ cryptauth::SetupEnrollmentResponse response_proto;
response_proto.set_status("OK");
response_proto.add_infos();
response_proto.mutable_infos(0)->set_type("gcmV1");
@@ -422,27 +430,28 @@
const char kEnrollmentSessionId[] = "enrollment_session_id";
const char kEnrollmentMessage[] = "enrollment_message";
const char kDeviceEphemeralKey[] = "device_ephermal_key";
- FinishEnrollmentResponse result_proto;
- FinishEnrollmentRequest request_proto;
+ cryptauth::FinishEnrollmentResponse result_proto;
+ cryptauth::FinishEnrollmentRequest request_proto;
request_proto.set_enrollment_session_id(kEnrollmentSessionId);
request_proto.set_enrollment_message(kEnrollmentMessage);
request_proto.set_device_ephemeral_key(kDeviceEphemeralKey);
client_->FinishEnrollment(
request_proto,
- base::Bind(&SaveResultConstRef<FinishEnrollmentResponse>, &result_proto),
+ base::Bind(&SaveResultConstRef<cryptauth::FinishEnrollmentResponse>,
+ &result_proto),
base::Bind(&NotCalled<NetworkRequestError>));
identity_test_environment_
.WaitForAccessTokenRequestIfNecessaryAndRespondWithToken(
kAccessToken, base::Time::Max());
- FinishEnrollmentRequest expected_request;
+ cryptauth::FinishEnrollmentRequest expected_request;
EXPECT_TRUE(expected_request.ParseFromString(serialized_request_));
EXPECT_EQ(kEnrollmentSessionId, expected_request.enrollment_session_id());
EXPECT_EQ(kEnrollmentMessage, expected_request.enrollment_message());
EXPECT_EQ(kDeviceEphemeralKey, expected_request.device_ephemeral_key());
{
- FinishEnrollmentResponse response_proto;
+ cryptauth::FinishEnrollmentResponse response_proto;
response_proto.set_status("OK");
FinishApiCallFlow(&response_proto);
}
@@ -451,10 +460,11 @@
TEST_F(CryptAuthClientTest, FetchAccessTokenFailure) {
NetworkRequestError error;
- client_->GetMyDevices(GetMyDevicesRequest(),
- base::Bind(&NotCalledConstRef<GetMyDevicesResponse>),
- base::Bind(&SaveResult<NetworkRequestError>, &error),
- PARTIAL_TRAFFIC_ANNOTATION_FOR_TESTS);
+ client_->GetMyDevices(
+ cryptauth::GetMyDevicesRequest(),
+ base::Bind(&NotCalledConstRef<cryptauth::GetMyDevicesResponse>),
+ base::Bind(&SaveResult<NetworkRequestError>, &error),
+ PARTIAL_TRAFFIC_ANNOTATION_FOR_TESTS);
identity_test_environment_
.WaitForAccessTokenRequestIfNecessaryAndRespondWithError(
GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_UNAVAILABLE));
@@ -468,10 +478,11 @@
"getmydevices?alt=proto");
NetworkRequestError error;
- client_->GetMyDevices(GetMyDevicesRequest(),
- base::Bind(&NotCalledConstRef<GetMyDevicesResponse>),
- base::Bind(&SaveResult<NetworkRequestError>, &error),
- PARTIAL_TRAFFIC_ANNOTATION_FOR_TESTS);
+ client_->GetMyDevices(
+ cryptauth::GetMyDevicesRequest(),
+ base::Bind(&NotCalledConstRef<cryptauth::GetMyDevicesResponse>),
+ base::Bind(&SaveResult<NetworkRequestError>, &error),
+ PARTIAL_TRAFFIC_ANNOTATION_FOR_TESTS);
identity_test_environment_
.WaitForAccessTokenRequestIfNecessaryAndRespondWithToken(
kAccessToken, base::Time::Max());
@@ -480,17 +491,17 @@
EXPECT_EQ(NetworkRequestError::kResponseMalformed, error);
}
-TEST_F(CryptAuthClientTest,
- MakeSecondRequestBeforeFirstRequestSucceeds) {
+TEST_F(CryptAuthClientTest, MakeSecondRequestBeforeFirstRequestSucceeds) {
ExpectRequest(
"https://www.testgoogleapis.com/cryptauth/v1/deviceSync/"
"getmydevices?alt=proto");
// Make first request.
- GetMyDevicesResponse result_proto;
+ cryptauth::GetMyDevicesResponse result_proto;
client_->GetMyDevices(
- GetMyDevicesRequest(),
- base::Bind(&SaveResultConstRef<GetMyDevicesResponse>, &result_proto),
+ cryptauth::GetMyDevicesRequest(),
+ base::Bind(&SaveResultConstRef<cryptauth::GetMyDevicesResponse>,
+ &result_proto),
base::Bind(&NotCalled<NetworkRequestError>),
PARTIAL_TRAFFIC_ANNOTATION_FOR_TESTS);
identity_test_environment_
@@ -501,14 +512,15 @@
{
NetworkRequestError error;
EXPECT_DCHECK_DEATH(client_->FindEligibleUnlockDevices(
- FindEligibleUnlockDevicesRequest(),
- base::Bind(&NotCalledConstRef<FindEligibleUnlockDevicesResponse>),
+ cryptauth::FindEligibleUnlockDevicesRequest(),
+ base::Bind(
+ &NotCalledConstRef<cryptauth::FindEligibleUnlockDevicesResponse>),
base::Bind(&SaveResult<NetworkRequestError>, &error)));
}
// Complete first request.
{
- GetMyDevicesResponse response_proto;
+ cryptauth::GetMyDevicesResponse response_proto;
response_proto.add_devices();
response_proto.mutable_devices(0)->set_public_key(kPublicKey1);
FinishApiCallFlow(&response_proto);
@@ -518,24 +530,24 @@
EXPECT_EQ(kPublicKey1, result_proto.devices(0).public_key());
}
-TEST_F(CryptAuthClientTest,
- MakeSecondRequestAfterFirstRequestSucceeds) {
+TEST_F(CryptAuthClientTest, MakeSecondRequestAfterFirstRequestSucceeds) {
// Make first request successfully.
{
ExpectRequest(
"https://www.testgoogleapis.com/cryptauth/v1/deviceSync/"
"getmydevices?alt=proto");
- GetMyDevicesResponse result_proto;
+ cryptauth::GetMyDevicesResponse result_proto;
client_->GetMyDevices(
- GetMyDevicesRequest(),
- base::Bind(&SaveResultConstRef<GetMyDevicesResponse>, &result_proto),
+ cryptauth::GetMyDevicesRequest(),
+ base::Bind(&SaveResultConstRef<cryptauth::GetMyDevicesResponse>,
+ &result_proto),
base::Bind(&NotCalled<NetworkRequestError>),
PARTIAL_TRAFFIC_ANNOTATION_FOR_TESTS);
identity_test_environment_
.WaitForAccessTokenRequestIfNecessaryAndRespondWithToken(
kAccessToken, base::Time::Max());
- GetMyDevicesResponse response_proto;
+ cryptauth::GetMyDevicesResponse response_proto;
response_proto.add_devices();
response_proto.mutable_devices(0)->set_public_key(kPublicKey1);
FinishApiCallFlow(&response_proto);
@@ -547,8 +559,9 @@
{
NetworkRequestError error;
EXPECT_DCHECK_DEATH(client_->FindEligibleUnlockDevices(
- FindEligibleUnlockDevicesRequest(),
- base::Bind(&NotCalledConstRef<FindEligibleUnlockDevicesResponse>),
+ cryptauth::FindEligibleUnlockDevicesRequest(),
+ base::Bind(
+ &NotCalledConstRef<cryptauth::FindEligibleUnlockDevicesResponse>),
base::Bind(&SaveResult<NetworkRequestError>, &error)));
}
}
@@ -558,21 +571,22 @@
"https://www.testgoogleapis.com/cryptauth/v1/deviceSync/"
"getmydevices?alt=proto");
- GetMyDevicesResponse result_proto;
- GetMyDevicesRequest request_proto;
+ cryptauth::GetMyDevicesResponse result_proto;
+ cryptauth::GetMyDevicesRequest request_proto;
request_proto.set_allow_stale_read(true);
client_->GetMyDevices(
request_proto,
- base::Bind(&SaveResultConstRef<GetMyDevicesResponse>, &result_proto),
+ base::Bind(&SaveResultConstRef<cryptauth::GetMyDevicesResponse>,
+ &result_proto),
base::Bind(&NotCalled<NetworkRequestError>),
PARTIAL_TRAFFIC_ANNOTATION_FOR_TESTS);
identity_test_environment_
.WaitForAccessTokenRequestIfNecessaryAndRespondWithToken(
kAccessToken, base::Time::Max());
- GetMyDevicesRequest expected_request;
+ cryptauth::GetMyDevicesRequest expected_request;
EXPECT_TRUE(expected_request.ParseFromString(serialized_request_));
- const DeviceClassifier& device_classifier =
+ const cryptauth::DeviceClassifier& device_classifier =
expected_request.device_classifier();
EXPECT_EQ(kDeviceOsVersionCode, device_classifier.device_os_version_code());
EXPECT_EQ(kDeviceSoftwareVersionCode,
@@ -580,7 +594,7 @@
EXPECT_EQ(kDeviceSoftwarePackage,
device_classifier.device_software_package());
EXPECT_EQ(kDeviceType,
- cryptauth::DeviceTypeStringToEnum(device_classifier.device_type()));
+ DeviceTypeStringToEnum(device_classifier.device_type()));
}
TEST_F(CryptAuthClientTest, GetAccessTokenUsed) {
@@ -590,12 +604,13 @@
"https://www.testgoogleapis.com/cryptauth/v1/deviceSync/"
"getmydevices?alt=proto");
- GetMyDevicesResponse result_proto;
- GetMyDevicesRequest request_proto;
+ cryptauth::GetMyDevicesResponse result_proto;
+ cryptauth::GetMyDevicesRequest request_proto;
request_proto.set_allow_stale_read(true);
client_->GetMyDevices(
request_proto,
- base::Bind(&SaveResultConstRef<GetMyDevicesResponse>, &result_proto),
+ base::Bind(&SaveResultConstRef<cryptauth::GetMyDevicesResponse>,
+ &result_proto),
base::Bind(&NotCalled<NetworkRequestError>),
PARTIAL_TRAFFIC_ANNOTATION_FOR_TESTS);
identity_test_environment_
@@ -605,4 +620,6 @@
EXPECT_EQ(kAccessToken, client_->GetAccessTokenUsed());
}
-} // namespace cryptauth
+} // namespace device_sync
+
+} // namespace chromeos
diff --git a/components/cryptauth/cryptauth_device_manager.cc b/chromeos/services/device_sync/cryptauth_device_manager.cc
similarity index 81%
rename from components/cryptauth/cryptauth_device_manager.cc
rename to chromeos/services/device_sync/cryptauth_device_manager.cc
index dd522ee..311462e 100644
--- a/components/cryptauth/cryptauth_device_manager.cc
+++ b/chromeos/services/device_sync/cryptauth_device_manager.cc
@@ -2,12 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/cryptauth/cryptauth_device_manager.h"
+#include "chromeos/services/device_sync/cryptauth_device_manager.h"
-#include "components/cryptauth/pref_names.h"
+#include "chromeos/services/device_sync/pref_names.h"
#include "components/prefs/pref_registry_simple.h"
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
// static
void CryptAuthDeviceManager::RegisterPrefs(PrefRegistrySimple* registry) {
@@ -16,7 +18,7 @@
registry->RegisterBooleanPref(
prefs::kCryptAuthDeviceSyncIsRecoveringFromFailure, false);
registry->RegisterIntegerPref(prefs::kCryptAuthDeviceSyncReason,
- INVOCATION_REASON_UNKNOWN);
+ cryptauth::INVOCATION_REASON_UNKNOWN);
registry->RegisterListPref(prefs::kCryptAuthDeviceSyncUnlockKeys);
}
@@ -44,4 +46,6 @@
observer.OnSyncFinished(sync_result, device_change_result);
}
-} // namespace cryptauth
+} // namespace device_sync
+
+} // namespace chromeos
diff --git a/components/cryptauth/cryptauth_device_manager.h b/chromeos/services/device_sync/cryptauth_device_manager.h
similarity index 80%
rename from components/cryptauth/cryptauth_device_manager.h
rename to chromeos/services/device_sync/cryptauth_device_manager.h
index 4ccb140d..1ef47c3 100644
--- a/components/cryptauth/cryptauth_device_manager.h
+++ b/chromeos/services/device_sync/cryptauth_device_manager.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef COMPONENTS_CRYPTAUTH_CRYPTAUTH_DEVICE_MANAGER_H_
-#define COMPONENTS_CRYPTAUTH_CRYPTAUTH_DEVICE_MANAGER_H_
+#ifndef CHROMEOS_SERVICES_DEVICE_SYNC_CRYPTAUTH_DEVICE_MANAGER_H_
+#define CHROMEOS_SERVICES_DEVICE_SYNC_CRYPTAUTH_DEVICE_MANAGER_H_
#include <memory>
@@ -13,7 +13,9 @@
class PrefRegistrySimple;
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
// Manages syncing and storing the user's devices that are registered with
// CryptAuth.
@@ -63,7 +65,7 @@
// sync attempt is already in progress, this function does nothing.
// |invocation_reason| specifies the reason that the sync was triggered,
// which is upload to the server.
- virtual void ForceSyncNow(InvocationReason invocation_reason) = 0;
+ virtual void ForceSyncNow(cryptauth::InvocationReason invocation_reason) = 0;
// Returns the timestamp of the last successful sync. If no sync
// has ever been made, then returns a null base::Time object.
@@ -81,17 +83,20 @@
virtual bool IsRecoveringFromFailure() const = 0;
// Returns a list of all remote devices that have been synced.
- virtual std::vector<ExternalDeviceInfo> GetSyncedDevices() const = 0;
+ virtual std::vector<cryptauth::ExternalDeviceInfo> GetSyncedDevices()
+ const = 0;
// Returns a list of remote devices that can unlock the user's other devices.
- virtual std::vector<ExternalDeviceInfo> GetUnlockKeys() const = 0;
+ virtual std::vector<cryptauth::ExternalDeviceInfo> GetUnlockKeys() const = 0;
// Like GetUnlockKeys(), but only returns Pixel devices.
- virtual std::vector<ExternalDeviceInfo> GetPixelUnlockKeys() const = 0;
+ virtual std::vector<cryptauth::ExternalDeviceInfo> GetPixelUnlockKeys()
+ const = 0;
// Returns a list of remote devices that can host tether hotspots.
- virtual std::vector<ExternalDeviceInfo> GetTetherHosts() const = 0;
+ virtual std::vector<cryptauth::ExternalDeviceInfo> GetTetherHosts() const = 0;
// Like GetTetherHosts(), but only returns Pixel devices.
- virtual std::vector<ExternalDeviceInfo> GetPixelTetherHosts() const = 0;
+ virtual std::vector<cryptauth::ExternalDeviceInfo> GetPixelTetherHosts()
+ const = 0;
protected:
// Invokes OnSyncStarted() on all observers.
@@ -108,6 +113,8 @@
DISALLOW_COPY_AND_ASSIGN(CryptAuthDeviceManager);
};
-} // namespace cryptauth
+} // namespace device_sync
-#endif // COMPONENTS_CRYPTAUTH_CRYPTAUTH_DEVICE_MANAGER_H_
+} // namespace chromeos
+
+#endif // CHROMEOS_SERVICES_DEVICE_SYNC_CRYPTAUTH_DEVICE_MANAGER_H_
diff --git a/components/cryptauth/cryptauth_device_manager_impl.cc b/chromeos/services/device_sync/cryptauth_device_manager_impl.cc
similarity index 85%
rename from components/cryptauth/cryptauth_device_manager_impl.cc
rename to chromeos/services/device_sync/cryptauth_device_manager_impl.cc
index 91af0011..077a4418f 100644
--- a/components/cryptauth/cryptauth_device_manager_impl.cc
+++ b/chromeos/services/device_sync/cryptauth_device_manager_impl.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/cryptauth/cryptauth_device_manager_impl.h"
+#include "chromeos/services/device_sync/cryptauth_device_manager_impl.h"
#include <stddef.h>
#include <stdexcept>
@@ -16,16 +16,18 @@
#include "base/strings/string_number_conversions.h"
#include "chromeos/components/multidevice/software_feature_state.h"
#include "chromeos/components/proximity_auth/logging/logging.h"
+#include "chromeos/services/device_sync/cryptauth_client.h"
+#include "chromeos/services/device_sync/pref_names.h"
#include "chromeos/services/device_sync/proto/enum_util.h"
-#include "components/cryptauth/cryptauth_client.h"
-#include "components/cryptauth/pref_names.h"
-#include "components/cryptauth/sync_scheduler_impl.h"
+#include "chromeos/services/device_sync/sync_scheduler_impl.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
namespace {
@@ -40,7 +42,8 @@
// The bound on the amount to jitter the period between syncs.
const double kDeviceSyncMaxJitterRatio = 0.2;
-// Keys for ExternalDeviceInfo dictionaries that are stored in the user's prefs.
+// Keys for cryptauth::ExternalDeviceInfo dictionaries that are stored in the
+// user's prefs.
const char kExternalDeviceKeyPublicKey[] = "public_key";
const char kExternalDeviceKeyDeviceName[] = "device_name";
const char kExternalDeviceKeyBluetoothAddress[] = "bluetooth_address";
@@ -54,21 +57,22 @@
const char kExternalDeviceKeyArcPlusPlus[] = "arc_plus_plus";
const char kExternalDeviceKeyPixelPhone[] = "pixel_phone";
-// Keys for ExternalDeviceInfo's BeaconSeed.
+// Keys for cryptauth::ExternalDeviceInfo's BeaconSeed.
const char kExternalDeviceKeyBeaconSeedData[] = "beacon_seed_data";
const char kExternalDeviceKeyBeaconSeedStartMs[] = "beacon_seed_start_ms";
const char kExternalDeviceKeyBeaconSeedEndMs[] = "beacon_seed_end_ms";
-// Keys specific to the dictionary which stores ExternalDeviceInfo info.
+// Keys specific to the dictionary which stores cryptauth::ExternalDeviceInfo
+// info.
const char kDictionaryKeySoftwareFeatures[] = "software_features";
// Converts BeaconSeed protos to a list value that can be stored in user prefs.
std::unique_ptr<base::ListValue> BeaconSeedsToListValue(
- const google::protobuf::RepeatedPtrField<BeaconSeed>& seeds) {
+ const google::protobuf::RepeatedPtrField<cryptauth::BeaconSeed>& seeds) {
std::unique_ptr<base::ListValue> list(new base::ListValue());
for (int i = 0; i < seeds.size(); i++) {
- BeaconSeed seed = seeds.Get(i);
+ cryptauth::BeaconSeed seed = seeds.Get(i);
if (!seed.has_data() || !seed.has_start_time_millis() ||
!seed.has_end_time_millis()) {
@@ -204,7 +208,7 @@
// Converts an unlock key proto to a dictionary that can be stored in user
// prefs.
std::unique_ptr<base::DictionaryValue> UnlockKeyToDictionary(
- const ExternalDeviceInfo& device) {
+ const cryptauth::ExternalDeviceInfo& device) {
// The device public key is a required value.
if (!device.has_public_key())
return nullptr;
@@ -248,11 +252,10 @@
}
if (device.has_device_type() &&
- DeviceType_IsValid(
- cryptauth::DeviceTypeStringToEnum(device.device_type()))) {
- dictionary->SetInteger(
- kExternalDeviceKeyDeviceType,
- cryptauth::DeviceTypeStringToEnum(device.device_type()));
+ cryptauth::DeviceType_IsValid(
+ DeviceTypeStringToEnum(device.device_type()))) {
+ dictionary->SetInteger(kExternalDeviceKeyDeviceType,
+ DeviceTypeStringToEnum(device.device_type()));
}
dictionary->Set(kExternalDeviceKeyBeaconSeeds,
@@ -284,8 +287,9 @@
return dictionary;
}
-void AddBeaconSeedsToExternalDevice(const base::ListValue& beacon_seeds,
- ExternalDeviceInfo* external_device) {
+void AddBeaconSeedsToExternalDevice(
+ const base::ListValue& beacon_seeds,
+ cryptauth::ExternalDeviceInfo* external_device) {
for (size_t i = 0; i < beacon_seeds.GetSize(); i++) {
const base::DictionaryValue* seed_dictionary = nullptr;
if (!beacon_seeds.GetDictionary(i, &seed_dictionary)) {
@@ -323,7 +327,7 @@
continue;
}
- BeaconSeed* seed = external_device->add_beacon_seeds();
+ cryptauth::BeaconSeed* seed = external_device->add_beacon_seeds();
seed->set_data(seed_data);
seed->set_start_time_millis(start_time_millis);
seed->set_end_time_millis(end_time_millis);
@@ -332,13 +336,13 @@
void AddSoftwareFeaturesToExternalDevice(
const base::DictionaryValue& software_features_dictionary,
- ExternalDeviceInfo* external_device,
+ cryptauth::ExternalDeviceInfo* external_device,
bool old_unlock_key_value_from_prefs,
bool old_mobile_hotspot_supported_from_prefs) {
for (const auto& it : software_features_dictionary.DictItems()) {
std::string software_feature = it.first;
if (SoftwareFeatureStringToEnum(software_feature) ==
- SoftwareFeature::UNKNOWN_FEATURE) {
+ cryptauth::SoftwareFeature::UNKNOWN_FEATURE) {
// SoftwareFeatures were previously stored in prefs as ints. Now,
// SoftwareFeatures are stored as full string values, e.g.,
// "betterTogetherHost". If |it.first| is not recognized by
@@ -347,7 +351,7 @@
// representation using SoftwareFeatureEnumToString();
int software_feature_int = std::atoi(software_feature.c_str());
software_feature = SoftwareFeatureEnumToString(
- static_cast<SoftwareFeature>(software_feature_int));
+ static_cast<cryptauth::SoftwareFeature>(software_feature_int));
}
int software_feature_state;
@@ -369,40 +373,46 @@
}
}
- // ExternalDeviceInfos's |unlock_key| and |mobile_hotspot_supported| fields
- // are deprecated, but it may be the case that after an update to Chrome, the
- // prefs reflect the old style of using these deprecated fields, instead of
- // software features. To work around this, these pref values are migrated to
- // software features locally.
+ // cryptauth::ExternalDeviceInfos's |unlock_key| and
+ // |mobile_hotspot_supported| fields are deprecated, but it may be the case
+ // that after an update to Chrome, the prefs reflect the old style of using
+ // these deprecated fields, instead of software features. To work around this,
+ // these pref values are migrated to software features locally.
if (old_unlock_key_value_from_prefs) {
if (!base::ContainsValue(
external_device->supported_software_features(),
- SoftwareFeatureEnumToString(SoftwareFeature::EASY_UNLOCK_HOST))) {
+ SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::EASY_UNLOCK_HOST))) {
external_device->add_supported_software_features(
- SoftwareFeatureEnumToString(SoftwareFeature::EASY_UNLOCK_HOST));
+ SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::EASY_UNLOCK_HOST));
}
if (!base::ContainsValue(
external_device->enabled_software_features(),
- SoftwareFeatureEnumToString(SoftwareFeature::EASY_UNLOCK_HOST))) {
+ SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::EASY_UNLOCK_HOST))) {
external_device->add_enabled_software_features(
- SoftwareFeatureEnumToString(SoftwareFeature::EASY_UNLOCK_HOST));
+ SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::EASY_UNLOCK_HOST));
}
}
if (old_mobile_hotspot_supported_from_prefs) {
if (!base::ContainsValue(
external_device->supported_software_features(),
- SoftwareFeatureEnumToString(SoftwareFeature::MAGIC_TETHER_HOST))) {
+ SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::MAGIC_TETHER_HOST))) {
external_device->add_supported_software_features(
- SoftwareFeatureEnumToString(SoftwareFeature::MAGIC_TETHER_HOST));
+ SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::MAGIC_TETHER_HOST));
}
}
}
// Converts an unlock key dictionary stored in user prefs to an
-// ExternalDeviceInfo proto. Returns true if the dictionary is valid, and the
-// parsed proto is written to |external_device|.
+// cryptauth::ExternalDeviceInfo proto. Returns true if the dictionary is valid,
+// and the parsed proto is written to |external_device|.
bool DictionaryToUnlockKey(const base::DictionaryValue& dictionary,
- ExternalDeviceInfo* external_device) {
+ cryptauth::ExternalDeviceInfo* external_device) {
std::string public_key_b64;
if (!dictionary.GetString(kExternalDeviceKeyPublicKey, &public_key_b64)) {
// The public key is a required field, so if it is absent, there is no
@@ -462,9 +472,9 @@
int device_type;
if (dictionary.GetInteger(kExternalDeviceKeyDeviceType, &device_type) &&
- DeviceType_IsValid(device_type)) {
- external_device->set_device_type(cryptauth::DeviceTypeEnumToString(
- static_cast<DeviceType>(device_type)));
+ cryptauth::DeviceType_IsValid(device_type)) {
+ external_device->set_device_type(DeviceTypeEnumToString(
+ static_cast<cryptauth::DeviceType>(device_type)));
}
const base::ListValue* beacon_seeds;
@@ -585,7 +595,7 @@
}
void CryptAuthDeviceManagerImpl::ForceSyncNow(
- InvocationReason invocation_reason) {
+ cryptauth::InvocationReason invocation_reason) {
pref_service_->SetInteger(prefs::kCryptAuthDeviceSyncReason,
invocation_reason);
scheduler_->ForceSync();
@@ -610,31 +620,33 @@
SyncScheduler::Strategy::AGGRESSIVE_RECOVERY;
}
-std::vector<ExternalDeviceInfo> CryptAuthDeviceManagerImpl::GetSyncedDevices()
- const {
+std::vector<cryptauth::ExternalDeviceInfo>
+CryptAuthDeviceManagerImpl::GetSyncedDevices() const {
return synced_devices_;
}
-std::vector<ExternalDeviceInfo> CryptAuthDeviceManagerImpl::GetUnlockKeys()
- const {
- std::vector<ExternalDeviceInfo> unlock_keys;
+std::vector<cryptauth::ExternalDeviceInfo>
+CryptAuthDeviceManagerImpl::GetUnlockKeys() const {
+ std::vector<cryptauth::ExternalDeviceInfo> unlock_keys;
for (const auto& device : synced_devices_) {
if (base::ContainsValue(
device.enabled_software_features(),
- SoftwareFeatureEnumToString(SoftwareFeature::EASY_UNLOCK_HOST))) {
+ SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::EASY_UNLOCK_HOST))) {
unlock_keys.push_back(device);
}
}
return unlock_keys;
}
-std::vector<ExternalDeviceInfo> CryptAuthDeviceManagerImpl::GetPixelUnlockKeys()
- const {
- std::vector<ExternalDeviceInfo> unlock_keys;
+std::vector<cryptauth::ExternalDeviceInfo>
+CryptAuthDeviceManagerImpl::GetPixelUnlockKeys() const {
+ std::vector<cryptauth::ExternalDeviceInfo> unlock_keys;
for (const auto& device : synced_devices_) {
if (base::ContainsValue(
device.enabled_software_features(),
- SoftwareFeatureEnumToString(SoftwareFeature::EASY_UNLOCK_HOST)) &&
+ SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::EASY_UNLOCK_HOST)) &&
device.pixel_phone()) {
unlock_keys.push_back(device);
}
@@ -642,26 +654,28 @@
return unlock_keys;
}
-std::vector<ExternalDeviceInfo> CryptAuthDeviceManagerImpl::GetTetherHosts()
- const {
- std::vector<ExternalDeviceInfo> tether_hosts;
+std::vector<cryptauth::ExternalDeviceInfo>
+CryptAuthDeviceManagerImpl::GetTetherHosts() const {
+ std::vector<cryptauth::ExternalDeviceInfo> tether_hosts;
for (const auto& device : synced_devices_) {
if (base::ContainsValue(
device.supported_software_features(),
- SoftwareFeatureEnumToString(SoftwareFeature::MAGIC_TETHER_HOST))) {
+ SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::MAGIC_TETHER_HOST))) {
tether_hosts.push_back(device);
}
}
return tether_hosts;
}
-std::vector<ExternalDeviceInfo>
+std::vector<cryptauth::ExternalDeviceInfo>
CryptAuthDeviceManagerImpl::GetPixelTetherHosts() const {
- std::vector<ExternalDeviceInfo> tether_hosts;
+ std::vector<cryptauth::ExternalDeviceInfo> tether_hosts;
for (const auto& device : synced_devices_) {
if (base::ContainsValue(
device.supported_software_features(),
- SoftwareFeatureEnumToString(SoftwareFeature::MAGIC_TETHER_HOST)) &&
+ SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::MAGIC_TETHER_HOST)) &&
device.pixel_phone())
tether_hosts.push_back(device);
}
@@ -669,7 +683,7 @@
}
void CryptAuthDeviceManagerImpl::OnGetMyDevicesSuccess(
- const GetMyDevicesResponse& response) {
+ const cryptauth::GetMyDevicesResponse& response) {
// Update the synced devices stored in the user's prefs.
std::unique_ptr<base::ListValue> devices_as_list(new base::ListValue());
@@ -707,7 +721,7 @@
pref_service_->SetDouble(prefs::kCryptAuthDeviceSyncLastSyncTimeSeconds,
clock_->Now().ToDoubleT());
pref_service_->SetInteger(prefs::kCryptAuthDeviceSyncReason,
- INVOCATION_REASON_UNKNOWN);
+ cryptauth::INVOCATION_REASON_UNKNOWN);
sync_request_->OnDidComplete(true);
cryptauth_client_.reset();
@@ -730,7 +744,7 @@
}
void CryptAuthDeviceManagerImpl::OnResyncMessage() {
- ForceSyncNow(INVOCATION_REASON_SERVER_INITIATED);
+ ForceSyncNow(cryptauth::INVOCATION_REASON_SERVER_INITIATED);
}
void CryptAuthDeviceManagerImpl::UpdateUnlockKeysFromPrefs() {
@@ -740,7 +754,7 @@
for (size_t i = 0; i < unlock_key_list->GetSize(); ++i) {
const base::DictionaryValue* unlock_key_dictionary;
if (unlock_key_list->GetDictionary(i, &unlock_key_dictionary)) {
- ExternalDeviceInfo unlock_key;
+ cryptauth::ExternalDeviceInfo unlock_key;
if (DictionaryToUnlockKey(*unlock_key_dictionary, &unlock_key)) {
synced_devices_.push_back(unlock_key);
} else {
@@ -769,7 +783,8 @@
sync_request_ = std::move(sync_request);
cryptauth_client_ = cryptauth_client_factory_->CreateInstance();
- InvocationReason invocation_reason = INVOCATION_REASON_UNKNOWN;
+ cryptauth::InvocationReason invocation_reason =
+ cryptauth::INVOCATION_REASON_UNKNOWN;
int reason_stored_in_prefs =
pref_service_->GetInteger(prefs::kCryptAuthDeviceSyncReason);
@@ -778,20 +793,21 @@
// a cached copy of the user's devices, rather taking a database hit for the
// freshest data.
bool is_sync_speculative =
- reason_stored_in_prefs != INVOCATION_REASON_UNKNOWN;
+ reason_stored_in_prefs != cryptauth::INVOCATION_REASON_UNKNOWN;
- if (InvocationReason_IsValid(reason_stored_in_prefs) &&
- reason_stored_in_prefs != INVOCATION_REASON_UNKNOWN) {
- invocation_reason = static_cast<InvocationReason>(reason_stored_in_prefs);
+ if (cryptauth::InvocationReason_IsValid(reason_stored_in_prefs) &&
+ reason_stored_in_prefs != cryptauth::INVOCATION_REASON_UNKNOWN) {
+ invocation_reason =
+ static_cast<cryptauth::InvocationReason>(reason_stored_in_prefs);
} else if (GetLastSyncTime().is_null()) {
- invocation_reason = INVOCATION_REASON_INITIALIZATION;
+ invocation_reason = cryptauth::INVOCATION_REASON_INITIALIZATION;
} else if (IsRecoveringFromFailure()) {
- invocation_reason = INVOCATION_REASON_FAILURE_RECOVERY;
+ invocation_reason = cryptauth::INVOCATION_REASON_FAILURE_RECOVERY;
} else {
- invocation_reason = INVOCATION_REASON_PERIODIC;
+ invocation_reason = cryptauth::INVOCATION_REASON_PERIODIC;
}
- GetMyDevicesRequest request;
+ cryptauth::GetMyDevicesRequest request;
request.set_invocation_reason(invocation_reason);
request.set_allow_stale_read(is_sync_speculative);
net::PartialNetworkTrafficAnnotationTag partial_traffic_annotation =
@@ -828,4 +844,6 @@
partial_traffic_annotation);
}
-} // namespace cryptauth
+} // namespace device_sync
+
+} // namespace chromeos
diff --git a/components/cryptauth/cryptauth_device_manager_impl.h b/chromeos/services/device_sync/cryptauth_device_manager_impl.h
similarity index 76%
rename from components/cryptauth/cryptauth_device_manager_impl.h
rename to chromeos/services/device_sync/cryptauth_device_manager_impl.h
index 484c55b3..40a418e 100644
--- a/components/cryptauth/cryptauth_device_manager_impl.h
+++ b/chromeos/services/device_sync/cryptauth_device_manager_impl.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef COMPONENTS_CRYPTAUTH_CRYPTAUTH_DEVICE_MANAGER_IMPL_H_
-#define COMPONENTS_CRYPTAUTH_CRYPTAUTH_DEVICE_MANAGER_IMPL_H_
+#ifndef CHROMEOS_SERVICES_DEVICE_SYNC_CRYPTAUTH_DEVICE_MANAGER_IMPL_H_
+#define CHROMEOS_SERVICES_DEVICE_SYNC_CRYPTAUTH_DEVICE_MANAGER_IMPL_H_
#include <memory>
@@ -11,15 +11,17 @@
#include "base/memory/weak_ptr.h"
#include "base/time/clock.h"
#include "base/time/time.h"
+#include "chromeos/services/device_sync/cryptauth_device_manager.h"
+#include "chromeos/services/device_sync/cryptauth_gcm_manager.h"
+#include "chromeos/services/device_sync/network_request_error.h"
#include "chromeos/services/device_sync/proto/cryptauth_api.pb.h"
-#include "components/cryptauth/cryptauth_device_manager.h"
-#include "components/cryptauth/cryptauth_gcm_manager.h"
-#include "components/cryptauth/network_request_error.h"
-#include "components/cryptauth/sync_scheduler.h"
+#include "chromeos/services/device_sync/sync_scheduler.h"
class PrefService;
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
class CryptAuthClient;
class CryptAuthClientFactory;
@@ -54,16 +56,18 @@
// CryptAuthDeviceManager:
void Start() override;
- void ForceSyncNow(InvocationReason invocation_reason) override;
+ void ForceSyncNow(cryptauth::InvocationReason invocation_reason) override;
base::Time GetLastSyncTime() const override;
base::TimeDelta GetTimeToNextAttempt() const override;
bool IsSyncInProgress() const override;
bool IsRecoveringFromFailure() const override;
- std::vector<ExternalDeviceInfo> GetSyncedDevices() const override;
- std::vector<ExternalDeviceInfo> GetUnlockKeys() const override;
- std::vector<ExternalDeviceInfo> GetPixelUnlockKeys() const override;
- std::vector<ExternalDeviceInfo> GetTetherHosts() const override;
- std::vector<ExternalDeviceInfo> GetPixelTetherHosts() const override;
+ std::vector<cryptauth::ExternalDeviceInfo> GetSyncedDevices() const override;
+ std::vector<cryptauth::ExternalDeviceInfo> GetUnlockKeys() const override;
+ std::vector<cryptauth::ExternalDeviceInfo> GetPixelUnlockKeys()
+ const override;
+ std::vector<cryptauth::ExternalDeviceInfo> GetTetherHosts() const override;
+ std::vector<cryptauth::ExternalDeviceInfo> GetPixelTetherHosts()
+ const override;
protected:
// Creates the manager:
@@ -94,7 +98,7 @@
std::unique_ptr<SyncScheduler::SyncRequest> sync_request) override;
// Callback when |cryptauth_client_| completes with the response.
- void OnGetMyDevicesSuccess(const GetMyDevicesResponse& response);
+ void OnGetMyDevicesSuccess(const cryptauth::GetMyDevicesResponse& response);
void OnGetMyDevicesFailure(NetworkRequestError error);
// Used to determine the time.
@@ -113,7 +117,7 @@
PrefService* const pref_service_;
// All devices currently synced from CryptAuth.
- std::vector<ExternalDeviceInfo> synced_devices_;
+ std::vector<cryptauth::ExternalDeviceInfo> synced_devices_;
// Schedules the time between device sync attempts.
std::unique_ptr<SyncScheduler> scheduler_;
@@ -131,6 +135,8 @@
DISALLOW_COPY_AND_ASSIGN(CryptAuthDeviceManagerImpl);
};
-} // namespace cryptauth
+} // namespace device_sync
-#endif // COMPONENTS_CRYPTAUTH_CRYPTAUTH_DEVICE_MANAGER_IMPL_H_
+} // namespace chromeos
+
+#endif // CHROMEOS_SERVICES_DEVICE_SYNC_CRYPTAUTH_DEVICE_MANAGER_IMPL_H_
diff --git a/components/cryptauth/cryptauth_device_manager_impl_unittest.cc b/chromeos/services/device_sync/cryptauth_device_manager_impl_unittest.cc
similarity index 75%
rename from components/cryptauth/cryptauth_device_manager_impl_unittest.cc
rename to chromeos/services/device_sync/cryptauth_device_manager_impl_unittest.cc
index 5f54707..27f05b6 100644
--- a/components/cryptauth/cryptauth_device_manager_impl_unittest.cc
+++ b/chromeos/services/device_sync/cryptauth_device_manager_impl_unittest.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/cryptauth/cryptauth_device_manager_impl.h"
+#include "chromeos/services/device_sync/cryptauth_device_manager_impl.h"
#include <stddef.h>
@@ -18,12 +18,12 @@
#include "base/test/metrics/histogram_tester.h"
#include "base/test/simple_test_clock.h"
#include "chromeos/components/multidevice/software_feature_state.h"
+#include "chromeos/services/device_sync/fake_cryptauth_gcm_manager.h"
+#include "chromeos/services/device_sync/mock_cryptauth_client.h"
+#include "chromeos/services/device_sync/mock_sync_scheduler.h"
+#include "chromeos/services/device_sync/network_request_error.h"
+#include "chromeos/services/device_sync/pref_names.h"
#include "chromeos/services/device_sync/proto/enum_util.h"
-#include "components/cryptauth/fake_cryptauth_gcm_manager.h"
-#include "components/cryptauth/mock_cryptauth_client.h"
-#include "components/cryptauth/mock_sync_scheduler.h"
-#include "components/cryptauth/network_request_error.h"
-#include "components/cryptauth/pref_names.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "components/prefs/testing_pref_service.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
@@ -36,7 +36,10 @@
using ::testing::Return;
using ::testing::SaveArg;
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
+
namespace {
// The initial "Now" time for testing.
@@ -54,7 +57,7 @@
const char kStoredBluetoothAddress[] = "12:34:56:78:90:AB";
const bool kStoredUnlockable = false;
-// ExternalDeviceInfo fields for the synced unlock key.
+// cryptauth::ExternalDeviceInfo fields for the synced unlock key.
const char kPublicKey1[] = "GOOG";
const char kDeviceName1[] = "Pixel XL";
const char kBluetoothAddress1[] = "aa:bb:cc:ee:dd:ff";
@@ -68,7 +71,7 @@
const bool kArcPlusPlus1 = true;
const bool kPixelPhone1 = true;
-// ExternalDeviceInfo fields for a non-synced unlockable device.
+// cryptauth::ExternalDeviceInfo fields for a non-synced unlockable device.
const char kPublicKey2[] = "CROS";
const char kDeviceName2[] = "Pixelbook";
const bool kUnlockable2 = true;
@@ -83,8 +86,8 @@
// Validates that |devices| is equal to |expected_devices|.
void ExpectSyncedDevicesAreEqual(
- const std::vector<ExternalDeviceInfo>& expected_devices,
- const std::vector<ExternalDeviceInfo>& devices) {
+ const std::vector<cryptauth::ExternalDeviceInfo>& expected_devices,
+ const std::vector<cryptauth::ExternalDeviceInfo>& devices) {
ASSERT_EQ(expected_devices.size(), devices.size());
for (size_t i = 0; i < devices.size(); ++i) {
SCOPED_TRACE(
@@ -125,8 +128,9 @@
ASSERT_EQ(expected_device.beacon_seeds_size(), device.beacon_seeds_size());
for (int i = 0; i < expected_device.beacon_seeds_size(); i++) {
- const BeaconSeed expected_seed = expected_device.beacon_seeds(i);
- const BeaconSeed seed = device.beacon_seeds(i);
+ const cryptauth::BeaconSeed expected_seed =
+ expected_device.beacon_seeds(i);
+ const cryptauth::BeaconSeed seed = device.beacon_seeds(i);
EXPECT_TRUE(expected_seed.has_data());
EXPECT_TRUE(seed.has_data());
EXPECT_EQ(expected_seed.data(), seed.data());
@@ -167,8 +171,8 @@
// Validates that |devices| and the corresponding preferences stored by
// |pref_service| are equal to |expected_devices|.
void ExpectSyncedDevicesAndPrefAreEqual(
- const std::vector<ExternalDeviceInfo>& expected_devices,
- const std::vector<ExternalDeviceInfo>& devices,
+ const std::vector<cryptauth::ExternalDeviceInfo>& expected_devices,
+ const std::vector<cryptauth::ExternalDeviceInfo>& devices,
const PrefService& pref_service) {
ExpectSyncedDevicesAreEqual(expected_devices, devices);
@@ -256,9 +260,8 @@
int device_type;
if (device_dictionary->GetInteger("device_type", &device_type)) {
EXPECT_TRUE(expected_device.has_device_type());
- EXPECT_EQ(
- cryptauth::DeviceTypeStringToEnum(expected_device.device_type()),
- device_type);
+ EXPECT_EQ(DeviceTypeStringToEnum(expected_device.device_type()),
+ device_type);
} else {
EXPECT_FALSE(expected_device.has_device_type());
}
@@ -276,7 +279,8 @@
EXPECT_TRUE(seed->GetString("beacon_seed_start_ms", &start_ms));
EXPECT_TRUE(seed->GetString("beacon_seed_end_ms", &end_ms));
- const BeaconSeed& expected_seed = expected_device.beacon_seeds((int)i);
+ const cryptauth::BeaconSeed& expected_seed =
+ expected_device.beacon_seeds((int)i);
std::string data;
EXPECT_TRUE(base::Base64UrlDecode(
@@ -313,14 +317,14 @@
const base::DictionaryValue* software_features_from_prefs;
if (device_dictionary->GetDictionary("software_features",
&software_features_from_prefs)) {
- std::vector<SoftwareFeature> supported_software_features;
- std::vector<SoftwareFeature> enabled_software_features;
+ std::vector<cryptauth::SoftwareFeature> supported_software_features;
+ std::vector<cryptauth::SoftwareFeature> enabled_software_features;
for (const auto& it : software_features_from_prefs->DictItems()) {
int software_feature_state;
ASSERT_TRUE(it.second.GetAsInteger(&software_feature_state));
- SoftwareFeature software_feature =
+ cryptauth::SoftwareFeature software_feature =
SoftwareFeatureStringToEnum(it.first);
switch (static_cast<chromeos::multidevice::SoftwareFeatureState>(
software_feature_state)) {
@@ -398,68 +402,72 @@
} // namespace
-class CryptAuthDeviceManagerImplTest
+class DeviceSyncCryptAuthDeviceManagerImplTest
: public testing::Test,
public CryptAuthDeviceManager::Observer,
public MockCryptAuthClientFactory::Observer {
protected:
- CryptAuthDeviceManagerImplTest()
+ DeviceSyncCryptAuthDeviceManagerImplTest()
: client_factory_(std::make_unique<MockCryptAuthClientFactory>(
MockCryptAuthClientFactory::MockType::MAKE_STRICT_MOCKS)),
gcm_manager_("existing gcm registration id") {
client_factory_->AddObserver(this);
- ExternalDeviceInfo unlock_key;
+ cryptauth::ExternalDeviceInfo unlock_key;
unlock_key.set_public_key(kPublicKey1);
unlock_key.set_friendly_device_name(kDeviceName1);
unlock_key.set_bluetooth_address(kBluetoothAddress1);
unlock_key.set_unlockable(kUnlockable1);
- BeaconSeed* seed1 = unlock_key.add_beacon_seeds();
+ cryptauth::BeaconSeed* seed1 = unlock_key.add_beacon_seeds();
seed1->set_data(kBeaconSeed1Data);
seed1->set_start_time_millis(kBeaconSeed1StartTime);
seed1->set_end_time_millis(kBeaconSeed1EndTime);
- BeaconSeed* seed2 = unlock_key.add_beacon_seeds();
+ cryptauth::BeaconSeed* seed2 = unlock_key.add_beacon_seeds();
seed2->set_data(kBeaconSeed2Data);
seed2->set_start_time_millis(kBeaconSeed2StartTime);
seed2->set_end_time_millis(kBeaconSeed2EndTime);
unlock_key.set_arc_plus_plus(kArcPlusPlus1);
unlock_key.set_pixel_phone(kPixelPhone1);
- unlock_key.add_supported_software_features(
- SoftwareFeatureEnumToString(SoftwareFeature::EASY_UNLOCK_HOST));
- unlock_key.add_enabled_software_features(
- SoftwareFeatureEnumToString(SoftwareFeature::EASY_UNLOCK_HOST));
- unlock_key.add_supported_software_features(
- SoftwareFeatureEnumToString(SoftwareFeature::BETTER_TOGETHER_HOST));
- unlock_key.add_supported_software_features(
- SoftwareFeatureEnumToString(SoftwareFeature::BETTER_TOGETHER_CLIENT));
- unlock_key.add_enabled_software_features(
- SoftwareFeatureEnumToString(SoftwareFeature::BETTER_TOGETHER_HOST));
+ unlock_key.add_supported_software_features(SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::EASY_UNLOCK_HOST));
+ unlock_key.add_enabled_software_features(SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::EASY_UNLOCK_HOST));
+ unlock_key.add_supported_software_features(SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::BETTER_TOGETHER_HOST));
+ unlock_key.add_supported_software_features(SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::BETTER_TOGETHER_CLIENT));
+ unlock_key.add_enabled_software_features(SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::BETTER_TOGETHER_HOST));
devices_in_response_.push_back(unlock_key);
- ExternalDeviceInfo unlockable_device;
+ cryptauth::ExternalDeviceInfo unlockable_device;
unlockable_device.set_public_key(kPublicKey2);
unlockable_device.set_friendly_device_name(kDeviceName2);
unlockable_device.set_unlockable(kUnlockable2);
- BeaconSeed* seed3 = unlockable_device.add_beacon_seeds();
+ cryptauth::BeaconSeed* seed3 = unlockable_device.add_beacon_seeds();
seed3->set_data(kBeaconSeed3Data);
seed3->set_start_time_millis(kBeaconSeed3StartTime);
seed3->set_end_time_millis(kBeaconSeed3EndTime);
- BeaconSeed* seed4 = unlockable_device.add_beacon_seeds();
+ cryptauth::BeaconSeed* seed4 = unlockable_device.add_beacon_seeds();
seed4->set_data(kBeaconSeed4Data);
seed4->set_start_time_millis(kBeaconSeed4StartTime);
seed4->set_end_time_millis(kBeaconSeed4EndTime);
unlockable_device.set_arc_plus_plus(kArcPlusPlus2);
unlockable_device.set_pixel_phone(kPixelPhone2);
unlockable_device.add_supported_software_features(
- SoftwareFeatureEnumToString(SoftwareFeature::MAGIC_TETHER_HOST));
+ SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::MAGIC_TETHER_HOST));
unlockable_device.add_supported_software_features(
- SoftwareFeatureEnumToString(SoftwareFeature::MAGIC_TETHER_CLIENT));
- unlockable_device.add_enabled_software_features(
- SoftwareFeatureEnumToString(SoftwareFeature::MAGIC_TETHER_HOST));
+ SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::MAGIC_TETHER_CLIENT));
+ unlockable_device.add_enabled_software_features(SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::MAGIC_TETHER_HOST));
devices_in_response_.push_back(unlockable_device);
}
- ~CryptAuthDeviceManagerImplTest() { client_factory_->RemoveObserver(this); }
+ ~DeviceSyncCryptAuthDeviceManagerImplTest() {
+ client_factory_->RemoveObserver(this);
+ }
// testing::Test:
void SetUp() override {
@@ -474,7 +482,7 @@
std::make_unique<base::Value>(kLastSyncTimeSeconds));
pref_service_.SetUserPref(
prefs::kCryptAuthDeviceSyncReason,
- std::make_unique<base::Value>(INVOCATION_REASON_UNKNOWN));
+ std::make_unique<base::Value>(cryptauth::INVOCATION_REASON_UNKNOWN));
std::unique_ptr<base::DictionaryValue> device_dictionary(
new base::DictionaryValue());
@@ -532,7 +540,8 @@
CryptAuthDeviceManager::DeviceChangeResult));
// Simulates firing the SyncScheduler to trigger a device sync attempt.
- void FireSchedulerForSync(InvocationReason expected_invocation_reason) {
+ void FireSchedulerForSync(
+ cryptauth::InvocationReason expected_invocation_reason) {
SyncScheduler::Delegate* delegate =
static_cast<SyncScheduler::Delegate*>(device_manager_.get());
@@ -548,7 +557,7 @@
// The allow_stale_read flag is set if the sync was not forced.
bool allow_stale_read =
pref_service_.GetInteger(prefs::kCryptAuthDeviceSyncReason) !=
- INVOCATION_REASON_UNKNOWN;
+ cryptauth::INVOCATION_REASON_UNKNOWN;
EXPECT_EQ(allow_stale_read, get_my_devices_request_.allow_stale_read());
}
@@ -574,20 +583,20 @@
std::unique_ptr<TestCryptAuthDeviceManager> device_manager_;
- std::vector<ExternalDeviceInfo> devices_in_response_;
+ std::vector<cryptauth::ExternalDeviceInfo> devices_in_response_;
- GetMyDevicesResponse get_my_devices_response_;
+ cryptauth::GetMyDevicesResponse get_my_devices_response_;
- GetMyDevicesRequest get_my_devices_request_;
+ cryptauth::GetMyDevicesRequest get_my_devices_request_;
CryptAuthClient::GetMyDevicesCallback success_callback_;
CryptAuthClient::ErrorCallback error_callback_;
- DISALLOW_COPY_AND_ASSIGN(CryptAuthDeviceManagerImplTest);
+ DISALLOW_COPY_AND_ASSIGN(DeviceSyncCryptAuthDeviceManagerImplTest);
};
-TEST_F(CryptAuthDeviceManagerImplTest, RegisterPrefs) {
+TEST_F(DeviceSyncCryptAuthDeviceManagerImplTest, RegisterPrefs) {
TestingPrefServiceSimple pref_service;
CryptAuthDeviceManager::RegisterPrefs(pref_service.registry());
EXPECT_TRUE(pref_service.FindPreference(
@@ -599,7 +608,7 @@
pref_service.FindPreference(prefs::kCryptAuthDeviceSyncUnlockKeys));
}
-TEST_F(CryptAuthDeviceManagerImplTest, GetSyncState) {
+TEST_F(DeviceSyncCryptAuthDeviceManagerImplTest, GetSyncState) {
device_manager_->Start();
ON_CALL(*sync_scheduler(), GetStrategy())
@@ -624,7 +633,7 @@
EXPECT_FALSE(device_manager_->IsSyncInProgress());
}
-TEST_F(CryptAuthDeviceManagerImplTest, InitWithDefaultPrefs) {
+TEST_F(DeviceSyncCryptAuthDeviceManagerImplTest, InitWithDefaultPrefs) {
base::SimpleTestClock clock;
clock.SetNow(base::Time::FromDoubleT(kInitialTimeNowSeconds));
base::TimeDelta elapsed_time = clock.Now() - base::Time::FromDoubleT(0);
@@ -643,7 +652,7 @@
EXPECT_EQ(0u, device_manager.GetSyncedDevices().size());
}
-TEST_F(CryptAuthDeviceManagerImplTest, InitWithExistingPrefs) {
+TEST_F(DeviceSyncCryptAuthDeviceManagerImplTest, InitWithExistingPrefs) {
EXPECT_CALL(
*sync_scheduler(),
Start(clock_.Now() - base::Time::FromDoubleT(kLastSyncTimeSeconds),
@@ -661,13 +670,13 @@
EXPECT_EQ(kStoredUnlockable, synced_devices[0].unlockable());
}
-// ExternalDeviceInfos's |unlock_key| and |mobile_hotspot_supported| fields
-// are deprecated, but it may be the case that after an update to Chrome, the
-// prefs reflect the old style of using these deprecated fields, instead of
+// cryptauth::ExternalDeviceInfos's |unlock_key| and |mobile_hotspot_supported|
+// fields are deprecated, but it may be the case that after an update to Chrome,
+// the prefs reflect the old style of using these deprecated fields, instead of
// software features. This test ensures the CryptAuthDeviceManager considers
// these deprecated booleans, and populates the correct software features.
TEST_F(
- CryptAuthDeviceManagerImplTest,
+ DeviceSyncCryptAuthDeviceManagerImplTest,
InitWithExistingPrefs_MigrateDeprecateBooleansFromPrefsToSoftwareFeature) {
ListPrefUpdate update_clear(&pref_service_,
prefs::kCryptAuthDeviceSyncUnlockKeys);
@@ -693,7 +702,7 @@
device_manager_->Start();
// Ensure that the deprecated booleans are not exposed in the final
- // ExternalDeviceInfo, but rather in the correct software features.
+ // cryptauth::ExternalDeviceInfo, but rather in the correct software features.
auto synced_devices = device_manager_->GetSyncedDevices();
ASSERT_EQ(1u, synced_devices.size());
EXPECT_EQ(kStoredPublicKey, synced_devices[0].public_key());
@@ -701,23 +710,26 @@
EXPECT_FALSE(synced_devices[0].mobile_hotspot_supported());
EXPECT_EQ(2, synced_devices[0].supported_software_features().size());
- EXPECT_TRUE(base::ContainsValue(
- synced_devices[0].supported_software_features(),
- SoftwareFeatureEnumToString(SoftwareFeature::EASY_UNLOCK_HOST)));
- EXPECT_TRUE(base::ContainsValue(
- synced_devices[0].supported_software_features(),
- SoftwareFeatureEnumToString(SoftwareFeature::MAGIC_TETHER_HOST)));
+ EXPECT_TRUE(
+ base::ContainsValue(synced_devices[0].supported_software_features(),
+ SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::EASY_UNLOCK_HOST)));
+ EXPECT_TRUE(
+ base::ContainsValue(synced_devices[0].supported_software_features(),
+ SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::MAGIC_TETHER_HOST)));
EXPECT_EQ(1, synced_devices[0].enabled_software_features().size());
- EXPECT_TRUE(base::ContainsValue(
- synced_devices[0].enabled_software_features(),
- SoftwareFeatureEnumToString(SoftwareFeature::EASY_UNLOCK_HOST)));
+ EXPECT_TRUE(
+ base::ContainsValue(synced_devices[0].enabled_software_features(),
+ SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::EASY_UNLOCK_HOST)));
}
-TEST_F(CryptAuthDeviceManagerImplTest, SyncSucceedsForFirstTime) {
+TEST_F(DeviceSyncCryptAuthDeviceManagerImplTest, SyncSucceedsForFirstTime) {
pref_service_.ClearPref(prefs::kCryptAuthDeviceSyncLastSyncTimeSeconds);
device_manager_->Start();
- FireSchedulerForSync(INVOCATION_REASON_INITIALIZATION);
+ FireSchedulerForSync(cryptauth::INVOCATION_REASON_INITIALIZATION);
ASSERT_FALSE(success_callback_.is_null());
clock_.SetNow(base::Time::FromDoubleT(kLaterTimeNowSeconds));
@@ -732,13 +744,13 @@
devices_in_response_, device_manager_->GetSyncedDevices(), pref_service_);
}
-TEST_F(CryptAuthDeviceManagerImplTest, ForceSync) {
+TEST_F(DeviceSyncCryptAuthDeviceManagerImplTest, ForceSync) {
device_manager_->Start();
EXPECT_CALL(*sync_scheduler(), ForceSync());
- device_manager_->ForceSyncNow(INVOCATION_REASON_MANUAL);
+ device_manager_->ForceSyncNow(cryptauth::INVOCATION_REASON_MANUAL);
- FireSchedulerForSync(INVOCATION_REASON_MANUAL);
+ FireSchedulerForSync(cryptauth::INVOCATION_REASON_MANUAL);
clock_.SetNow(base::Time::FromDoubleT(kLaterTimeNowSeconds));
EXPECT_CALL(*this, OnSyncFinishedProxy(
@@ -751,7 +763,7 @@
devices_in_response_, device_manager_->GetSyncedDevices(), pref_service_);
}
-TEST_F(CryptAuthDeviceManagerImplTest, ForceSyncFailsThenSucceeds) {
+TEST_F(DeviceSyncCryptAuthDeviceManagerImplTest, ForceSyncFailsThenSucceeds) {
device_manager_->Start();
EXPECT_FALSE(pref_service_.GetBoolean(
prefs::kCryptAuthDeviceSyncIsRecoveringFromFailure));
@@ -759,8 +771,8 @@
// The first force sync fails.
EXPECT_CALL(*sync_scheduler(), ForceSync());
- device_manager_->ForceSyncNow(INVOCATION_REASON_MANUAL);
- FireSchedulerForSync(INVOCATION_REASON_MANUAL);
+ device_manager_->ForceSyncNow(cryptauth::INVOCATION_REASON_MANUAL);
+ FireSchedulerForSync(cryptauth::INVOCATION_REASON_MANUAL);
clock_.SetNow(base::Time::FromDoubleT(kLaterTimeNowSeconds));
EXPECT_CALL(*this,
OnSyncFinishedProxy(
@@ -770,13 +782,13 @@
EXPECT_EQ(old_sync_time, device_manager_->GetLastSyncTime());
EXPECT_TRUE(pref_service_.GetBoolean(
prefs::kCryptAuthDeviceSyncIsRecoveringFromFailure));
- EXPECT_EQ(static_cast<int>(INVOCATION_REASON_MANUAL),
+ EXPECT_EQ(static_cast<int>(cryptauth::INVOCATION_REASON_MANUAL),
pref_service_.GetInteger(prefs::kCryptAuthDeviceSyncReason));
// The second recovery sync succeeds.
ON_CALL(*sync_scheduler(), GetStrategy())
.WillByDefault(Return(SyncScheduler::Strategy::AGGRESSIVE_RECOVERY));
- FireSchedulerForSync(INVOCATION_REASON_MANUAL);
+ FireSchedulerForSync(cryptauth::INVOCATION_REASON_MANUAL);
clock_.SetNow(base::Time::FromDoubleT(kLaterTimeNowSeconds + 30));
EXPECT_CALL(*this, OnSyncFinishedProxy(
CryptAuthDeviceManager::SyncResult::SUCCESS,
@@ -790,18 +802,19 @@
EXPECT_FLOAT_EQ(
clock_.Now().ToDoubleT(),
pref_service_.GetDouble(prefs::kCryptAuthDeviceSyncLastSyncTimeSeconds));
- EXPECT_EQ(static_cast<int>(INVOCATION_REASON_UNKNOWN),
+ EXPECT_EQ(static_cast<int>(cryptauth::INVOCATION_REASON_UNKNOWN),
pref_service_.GetInteger(prefs::kCryptAuthDeviceSyncReason));
EXPECT_FALSE(pref_service_.GetBoolean(
prefs::kCryptAuthDeviceSyncIsRecoveringFromFailure));
}
-TEST_F(CryptAuthDeviceManagerImplTest, PeriodicSyncFailsThenSucceeds) {
+TEST_F(DeviceSyncCryptAuthDeviceManagerImplTest,
+ PeriodicSyncFailsThenSucceeds) {
device_manager_->Start();
base::Time old_sync_time = device_manager_->GetLastSyncTime();
// The first periodic sync fails.
- FireSchedulerForSync(INVOCATION_REASON_PERIODIC);
+ FireSchedulerForSync(cryptauth::INVOCATION_REASON_PERIODIC);
clock_.SetNow(base::Time::FromDoubleT(kLaterTimeNowSeconds));
EXPECT_CALL(*this,
OnSyncFinishedProxy(
@@ -815,7 +828,7 @@
// The second recovery sync succeeds.
ON_CALL(*sync_scheduler(), GetStrategy())
.WillByDefault(Return(SyncScheduler::Strategy::AGGRESSIVE_RECOVERY));
- FireSchedulerForSync(INVOCATION_REASON_FAILURE_RECOVERY);
+ FireSchedulerForSync(cryptauth::INVOCATION_REASON_FAILURE_RECOVERY);
clock_.SetNow(base::Time::FromDoubleT(kLaterTimeNowSeconds + 30));
EXPECT_CALL(*this, OnSyncFinishedProxy(
CryptAuthDeviceManager::SyncResult::SUCCESS,
@@ -833,12 +846,12 @@
prefs::kCryptAuthDeviceSyncIsRecoveringFromFailure));
}
-TEST_F(CryptAuthDeviceManagerImplTest, SyncSameDevice) {
+TEST_F(DeviceSyncCryptAuthDeviceManagerImplTest, SyncSameDevice) {
device_manager_->Start();
auto original_devices = device_manager_->GetSyncedDevices();
// Sync new devices.
- FireSchedulerForSync(INVOCATION_REASON_PERIODIC);
+ FireSchedulerForSync(cryptauth::INVOCATION_REASON_PERIODIC);
ASSERT_FALSE(success_callback_.is_null());
EXPECT_CALL(*this,
OnSyncFinishedProxy(
@@ -846,12 +859,12 @@
CryptAuthDeviceManager::DeviceChangeResult::UNCHANGED));
// Sync the same device.
- ExternalDeviceInfo synced_device;
+ cryptauth::ExternalDeviceInfo synced_device;
synced_device.set_public_key(kStoredPublicKey);
synced_device.set_friendly_device_name(kStoredDeviceName);
synced_device.set_bluetooth_address(kStoredBluetoothAddress);
synced_device.set_unlockable(kStoredUnlockable);
- GetMyDevicesResponse get_my_devices_response;
+ cryptauth::GetMyDevicesResponse get_my_devices_response;
get_my_devices_response.add_devices()->CopyFrom(synced_device);
success_callback_.Run(get_my_devices_response);
@@ -860,38 +873,38 @@
original_devices, device_manager_->GetSyncedDevices(), pref_service_);
}
-TEST_F(CryptAuthDeviceManagerImplTest, SyncEmptyDeviceList) {
- GetMyDevicesResponse empty_response;
+TEST_F(DeviceSyncCryptAuthDeviceManagerImplTest, SyncEmptyDeviceList) {
+ cryptauth::GetMyDevicesResponse empty_response;
device_manager_->Start();
EXPECT_EQ(1u, device_manager_->GetSyncedDevices().size());
- FireSchedulerForSync(INVOCATION_REASON_PERIODIC);
+ FireSchedulerForSync(cryptauth::INVOCATION_REASON_PERIODIC);
ASSERT_FALSE(success_callback_.is_null());
EXPECT_CALL(*this, OnSyncFinishedProxy(
CryptAuthDeviceManager::SyncResult::SUCCESS,
CryptAuthDeviceManager::DeviceChangeResult::CHANGED));
success_callback_.Run(empty_response);
- ExpectSyncedDevicesAndPrefAreEqual(std::vector<ExternalDeviceInfo>(),
- device_manager_->GetSyncedDevices(),
- pref_service_);
+ ExpectSyncedDevicesAndPrefAreEqual(
+ std::vector<cryptauth::ExternalDeviceInfo>(),
+ device_manager_->GetSyncedDevices(), pref_service_);
}
-TEST_F(CryptAuthDeviceManagerImplTest, SyncThreeDevices) {
- GetMyDevicesResponse response(get_my_devices_response_);
- ExternalDeviceInfo synced_device2;
+TEST_F(DeviceSyncCryptAuthDeviceManagerImplTest, SyncThreeDevices) {
+ cryptauth::GetMyDevicesResponse response(get_my_devices_response_);
+ cryptauth::ExternalDeviceInfo synced_device2;
synced_device2.set_public_key("new public key");
synced_device2.set_friendly_device_name("new device name");
synced_device2.set_bluetooth_address("aa:bb:cc:dd:ee:ff");
- synced_device2.add_supported_software_features(
- SoftwareFeatureEnumToString(SoftwareFeature::EASY_UNLOCK_HOST));
- synced_device2.add_enabled_software_features(
- SoftwareFeatureEnumToString(SoftwareFeature::EASY_UNLOCK_HOST));
+ synced_device2.add_supported_software_features(SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::EASY_UNLOCK_HOST));
+ synced_device2.add_enabled_software_features(SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::EASY_UNLOCK_HOST));
response.add_devices()->CopyFrom(synced_device2);
- std::vector<ExternalDeviceInfo> expected_devices;
+ std::vector<cryptauth::ExternalDeviceInfo> expected_devices;
expected_devices.push_back(devices_in_response_[0]);
expected_devices.push_back(devices_in_response_[1]);
expected_devices.push_back(synced_device2);
@@ -902,7 +915,7 @@
1u,
pref_service_.GetList(prefs::kCryptAuthDeviceSyncUnlockKeys)->GetSize());
- FireSchedulerForSync(INVOCATION_REASON_PERIODIC);
+ FireSchedulerForSync(cryptauth::INVOCATION_REASON_PERIODIC);
ASSERT_FALSE(success_callback_.is_null());
EXPECT_CALL(*this, OnSyncFinishedProxy(
CryptAuthDeviceManager::SyncResult::SUCCESS,
@@ -913,13 +926,13 @@
expected_devices, device_manager_->GetSyncedDevices(), pref_service_);
}
-TEST_F(CryptAuthDeviceManagerImplTest, SyncOnGCMPushMessage) {
+TEST_F(DeviceSyncCryptAuthDeviceManagerImplTest, SyncOnGCMPushMessage) {
device_manager_->Start();
EXPECT_CALL(*sync_scheduler(), ForceSync());
gcm_manager_.PushResyncMessage();
- FireSchedulerForSync(INVOCATION_REASON_SERVER_INITIATED);
+ FireSchedulerForSync(cryptauth::INVOCATION_REASON_SERVER_INITIATED);
EXPECT_CALL(*this, OnSyncFinishedProxy(
CryptAuthDeviceManager::SyncResult::SUCCESS,
@@ -930,13 +943,13 @@
devices_in_response_, device_manager_->GetSyncedDevices(), pref_service_);
}
-TEST_F(CryptAuthDeviceManagerImplTest, SyncDeviceWithNoContents) {
+TEST_F(DeviceSyncCryptAuthDeviceManagerImplTest, SyncDeviceWithNoContents) {
device_manager_->Start();
EXPECT_CALL(*sync_scheduler(), ForceSync());
gcm_manager_.PushResyncMessage();
- FireSchedulerForSync(INVOCATION_REASON_SERVER_INITIATED);
+ FireSchedulerForSync(cryptauth::INVOCATION_REASON_SERVER_INITIATED);
EXPECT_CALL(*this, OnSyncFinishedProxy(
CryptAuthDeviceManager::SyncResult::SUCCESS,
@@ -947,35 +960,38 @@
devices_in_response_, device_manager_->GetSyncedDevices(), pref_service_);
}
-TEST_F(CryptAuthDeviceManagerImplTest, SyncFullyDetailedExternalDeviceInfos) {
+TEST_F(DeviceSyncCryptAuthDeviceManagerImplTest,
+ SyncFullyDetailedExternalDeviceInfos) {
// First, use a device with only a public key (a public key is the only
// required field). This ensures devices work properly when they do not have
// all fields filled out.
- ExternalDeviceInfo device_with_only_public_key;
+ cryptauth::ExternalDeviceInfo device_with_only_public_key;
device_with_only_public_key.set_public_key("publicKey1");
device_with_only_public_key.add_supported_software_features(
- SoftwareFeatureEnumToString(SoftwareFeature::EASY_UNLOCK_HOST));
+ SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::EASY_UNLOCK_HOST));
device_with_only_public_key.add_enabled_software_features(
- SoftwareFeatureEnumToString(SoftwareFeature::EASY_UNLOCK_HOST));
+ SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::EASY_UNLOCK_HOST));
// Second, use a device with all fields filled out. This ensures that all
// device details are properly saved.
- ExternalDeviceInfo device_with_all_fields;
+ cryptauth::ExternalDeviceInfo device_with_all_fields;
device_with_all_fields.set_public_key("publicKey2");
device_with_all_fields.set_friendly_device_name("deviceName");
device_with_all_fields.set_bluetooth_address("aa:bb:cc:dd:ee:ff");
device_with_all_fields.set_unlockable(true);
device_with_all_fields.set_last_update_time_millis(123456789L);
device_with_all_fields.set_device_type(
- cryptauth::DeviceTypeEnumToString(ANDROID));
+ DeviceTypeEnumToString(cryptauth::DeviceType::ANDROID));
- BeaconSeed seed1;
+ cryptauth::BeaconSeed seed1;
seed1.set_data(kBeaconSeed1Data);
seed1.set_start_time_millis(kBeaconSeed1StartTime);
seed1.set_end_time_millis(kBeaconSeed1EndTime);
device_with_all_fields.add_beacon_seeds()->CopyFrom(seed1);
- BeaconSeed seed2;
+ cryptauth::BeaconSeed seed2;
seed2.set_data(kBeaconSeed2Data);
seed2.set_start_time_millis(kBeaconSeed2StartTime);
seed2.set_end_time_millis(kBeaconSeed2EndTime);
@@ -985,25 +1001,28 @@
device_with_all_fields.set_pixel_phone(true);
device_with_all_fields.add_supported_software_features(
- SoftwareFeatureEnumToString(SoftwareFeature::EASY_UNLOCK_HOST));
+ SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::EASY_UNLOCK_HOST));
device_with_all_fields.add_supported_software_features(
- SoftwareFeatureEnumToString(SoftwareFeature::MAGIC_TETHER_HOST));
+ SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::MAGIC_TETHER_HOST));
device_with_all_fields.add_enabled_software_features(
- SoftwareFeatureEnumToString(SoftwareFeature::EASY_UNLOCK_HOST));
+ SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::EASY_UNLOCK_HOST));
- std::vector<ExternalDeviceInfo> expected_devices;
+ std::vector<cryptauth::ExternalDeviceInfo> expected_devices;
expected_devices.push_back(device_with_only_public_key);
expected_devices.push_back(device_with_all_fields);
device_manager_->Start();
- FireSchedulerForSync(INVOCATION_REASON_PERIODIC);
+ FireSchedulerForSync(cryptauth::INVOCATION_REASON_PERIODIC);
ASSERT_FALSE(success_callback_.is_null());
EXPECT_CALL(*this, OnSyncFinishedProxy(
CryptAuthDeviceManager::SyncResult::SUCCESS,
CryptAuthDeviceManager::DeviceChangeResult::CHANGED));
- GetMyDevicesResponse response;
+ cryptauth::GetMyDevicesResponse response;
response.add_devices()->CopyFrom(device_with_only_public_key);
response.add_devices()->CopyFrom(device_with_all_fields);
success_callback_.Run(response);
@@ -1012,10 +1031,10 @@
expected_devices, device_manager_->GetSyncedDevices(), pref_service_);
}
-TEST_F(CryptAuthDeviceManagerImplTest, SubsetsOfSyncedDevices) {
+TEST_F(DeviceSyncCryptAuthDeviceManagerImplTest, SubsetsOfSyncedDevices) {
device_manager_->Start();
- FireSchedulerForSync(INVOCATION_REASON_PERIODIC);
+ FireSchedulerForSync(cryptauth::INVOCATION_REASON_PERIODIC);
ASSERT_FALSE(success_callback_.is_null());
EXPECT_CALL(*this, OnSyncFinishedProxy(
CryptAuthDeviceManager::SyncResult::SUCCESS,
@@ -1028,20 +1047,20 @@
// Only unlock keys.
ExpectSyncedDevicesAreEqual(
- std::vector<ExternalDeviceInfo>(1, devices_in_response_[0]),
+ std::vector<cryptauth::ExternalDeviceInfo>(1, devices_in_response_[0]),
device_manager_->GetUnlockKeys());
// Only tether hosts.
ExpectSyncedDevicesAreEqual(
- std::vector<ExternalDeviceInfo>(1, devices_in_response_[1]),
+ std::vector<cryptauth::ExternalDeviceInfo>(1, devices_in_response_[1]),
device_manager_->GetTetherHosts());
}
-TEST_F(CryptAuthDeviceManagerImplTest,
+TEST_F(DeviceSyncCryptAuthDeviceManagerImplTest,
TestDeprecatedBooleansArePersistedOnlyAsSoftwareFeatures) {
device_manager_->Start();
- ExternalDeviceInfo device;
+ cryptauth::ExternalDeviceInfo device;
device.set_public_key("public key");
device.set_friendly_device_name("deprecated device");
device.set_unlock_key(true);
@@ -1050,143 +1069,163 @@
devices_in_response_.push_back(device);
get_my_devices_response_.add_devices()->CopyFrom(device);
- FireSchedulerForSync(INVOCATION_REASON_PERIODIC);
+ FireSchedulerForSync(cryptauth::INVOCATION_REASON_PERIODIC);
ASSERT_FALSE(success_callback_.is_null());
EXPECT_CALL(*this, OnSyncFinishedProxy(
CryptAuthDeviceManager::SyncResult::SUCCESS,
CryptAuthDeviceManager::DeviceChangeResult::CHANGED));
success_callback_.Run(get_my_devices_response_);
- ExternalDeviceInfo synced_device = device_manager_->GetSyncedDevices()[2];
+ cryptauth::ExternalDeviceInfo synced_device =
+ device_manager_->GetSyncedDevices()[2];
EXPECT_FALSE(synced_device.unlock_key());
EXPECT_FALSE(synced_device.mobile_hotspot_supported());
- EXPECT_TRUE(base::ContainsValue(
- synced_device.supported_software_features(),
- SoftwareFeatureEnumToString(SoftwareFeature::EASY_UNLOCK_HOST)));
- EXPECT_TRUE(base::ContainsValue(
- synced_device.enabled_software_features(),
- SoftwareFeatureEnumToString(SoftwareFeature::EASY_UNLOCK_HOST)));
- EXPECT_TRUE(base::ContainsValue(
- synced_device.supported_software_features(),
- SoftwareFeatureEnumToString(SoftwareFeature::MAGIC_TETHER_HOST)));
- EXPECT_FALSE(base::ContainsValue(
- synced_device.enabled_software_features(),
- SoftwareFeatureEnumToString(SoftwareFeature::MAGIC_TETHER_HOST)));
+ EXPECT_TRUE(
+ base::ContainsValue(synced_device.supported_software_features(),
+ SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::EASY_UNLOCK_HOST)));
+ EXPECT_TRUE(
+ base::ContainsValue(synced_device.enabled_software_features(),
+ SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::EASY_UNLOCK_HOST)));
+ EXPECT_TRUE(
+ base::ContainsValue(synced_device.supported_software_features(),
+ SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::MAGIC_TETHER_HOST)));
+ EXPECT_FALSE(
+ base::ContainsValue(synced_device.enabled_software_features(),
+ SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::MAGIC_TETHER_HOST)));
}
-TEST_F(CryptAuthDeviceManagerImplTest,
+TEST_F(DeviceSyncCryptAuthDeviceManagerImplTest,
TestIgnoreDeprecatedBooleansIfSoftwareFeaturesArePresent) {
device_manager_->Start();
- ExternalDeviceInfo device;
+ cryptauth::ExternalDeviceInfo device;
device.set_public_key("public key");
device.set_friendly_device_name("deprecated device");
device.set_unlock_key(false);
device.set_mobile_hotspot_supported(false);
- device.add_supported_software_features(
- SoftwareFeatureEnumToString(SoftwareFeature::EASY_UNLOCK_HOST));
- device.add_enabled_software_features(
- SoftwareFeatureEnumToString(SoftwareFeature::EASY_UNLOCK_HOST));
- device.add_supported_software_features(
- SoftwareFeatureEnumToString(SoftwareFeature::MAGIC_TETHER_HOST));
+ device.add_supported_software_features(SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::EASY_UNLOCK_HOST));
+ device.add_enabled_software_features(SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::EASY_UNLOCK_HOST));
+ device.add_supported_software_features(SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::MAGIC_TETHER_HOST));
devices_in_response_.push_back(device);
get_my_devices_response_.add_devices()->CopyFrom(device);
- FireSchedulerForSync(INVOCATION_REASON_PERIODIC);
+ FireSchedulerForSync(cryptauth::INVOCATION_REASON_PERIODIC);
ASSERT_FALSE(success_callback_.is_null());
EXPECT_CALL(*this, OnSyncFinishedProxy(
CryptAuthDeviceManager::SyncResult::SUCCESS,
CryptAuthDeviceManager::DeviceChangeResult::CHANGED));
success_callback_.Run(get_my_devices_response_);
- ExternalDeviceInfo synced_device = device_manager_->GetSyncedDevices()[2];
+ cryptauth::ExternalDeviceInfo synced_device =
+ device_manager_->GetSyncedDevices()[2];
EXPECT_FALSE(synced_device.unlock_key());
EXPECT_FALSE(synced_device.mobile_hotspot_supported());
- EXPECT_TRUE(base::ContainsValue(
- synced_device.supported_software_features(),
- SoftwareFeatureEnumToString(SoftwareFeature::EASY_UNLOCK_HOST)));
- EXPECT_TRUE(base::ContainsValue(
- synced_device.enabled_software_features(),
- SoftwareFeatureEnumToString(SoftwareFeature::EASY_UNLOCK_HOST)));
- EXPECT_TRUE(base::ContainsValue(
- synced_device.supported_software_features(),
- SoftwareFeatureEnumToString(SoftwareFeature::MAGIC_TETHER_HOST)));
- EXPECT_FALSE(base::ContainsValue(
- synced_device.enabled_software_features(),
- SoftwareFeatureEnumToString(SoftwareFeature::MAGIC_TETHER_HOST)));
+ EXPECT_TRUE(
+ base::ContainsValue(synced_device.supported_software_features(),
+ SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::EASY_UNLOCK_HOST)));
+ EXPECT_TRUE(
+ base::ContainsValue(synced_device.enabled_software_features(),
+ SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::EASY_UNLOCK_HOST)));
+ EXPECT_TRUE(
+ base::ContainsValue(synced_device.supported_software_features(),
+ SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::MAGIC_TETHER_HOST)));
+ EXPECT_FALSE(
+ base::ContainsValue(synced_device.enabled_software_features(),
+ SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::MAGIC_TETHER_HOST)));
}
// Regression test for crbug.com/888031.
-TEST_F(CryptAuthDeviceManagerImplTest,
+TEST_F(DeviceSyncCryptAuthDeviceManagerImplTest,
TestMigrateFromIntToStringSoftwareFeaturePrefRepresentation) {
device_manager_->Start();
- ExternalDeviceInfo device;
+ cryptauth::ExternalDeviceInfo device;
device.set_public_key("public key");
device.set_friendly_device_name("deprecated device");
// Simulate how older client versions persisted SoftwareFeatures as ints.
device.add_supported_software_features(
- std::to_string(SoftwareFeature::EASY_UNLOCK_HOST));
+ std::to_string(cryptauth::SoftwareFeature::EASY_UNLOCK_HOST));
device.add_enabled_software_features(
- std::to_string(SoftwareFeature::EASY_UNLOCK_HOST));
+ std::to_string(cryptauth::SoftwareFeature::EASY_UNLOCK_HOST));
device.add_supported_software_features(
- std::to_string(SoftwareFeature::MAGIC_TETHER_HOST));
+ std::to_string(cryptauth::SoftwareFeature::MAGIC_TETHER_HOST));
devices_in_response_.push_back(device);
get_my_devices_response_.add_devices()->CopyFrom(device);
- FireSchedulerForSync(INVOCATION_REASON_PERIODIC);
+ FireSchedulerForSync(cryptauth::INVOCATION_REASON_PERIODIC);
ASSERT_FALSE(success_callback_.is_null());
EXPECT_CALL(*this, OnSyncFinishedProxy(
CryptAuthDeviceManager::SyncResult::SUCCESS,
CryptAuthDeviceManager::DeviceChangeResult::CHANGED));
success_callback_.Run(get_my_devices_response_);
- ExternalDeviceInfo synced_device = device_manager_->GetSyncedDevices()[2];
+ cryptauth::ExternalDeviceInfo synced_device =
+ device_manager_->GetSyncedDevices()[2];
// CryptAuthDeviceManager should recognize that the SoftwareFeature prefs had
// been stored as refs, and convert them to their full string representations.
- EXPECT_TRUE(base::ContainsValue(
- synced_device.supported_software_features(),
- SoftwareFeatureEnumToString(SoftwareFeature::EASY_UNLOCK_HOST)));
- EXPECT_TRUE(base::ContainsValue(
- synced_device.enabled_software_features(),
- SoftwareFeatureEnumToString(SoftwareFeature::EASY_UNLOCK_HOST)));
- EXPECT_TRUE(base::ContainsValue(
- synced_device.supported_software_features(),
- SoftwareFeatureEnumToString(SoftwareFeature::MAGIC_TETHER_HOST)));
- EXPECT_FALSE(base::ContainsValue(
- synced_device.enabled_software_features(),
- SoftwareFeatureEnumToString(SoftwareFeature::MAGIC_TETHER_HOST)));
+ EXPECT_TRUE(
+ base::ContainsValue(synced_device.supported_software_features(),
+ SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::EASY_UNLOCK_HOST)));
+ EXPECT_TRUE(
+ base::ContainsValue(synced_device.enabled_software_features(),
+ SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::EASY_UNLOCK_HOST)));
+ EXPECT_TRUE(
+ base::ContainsValue(synced_device.supported_software_features(),
+ SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::MAGIC_TETHER_HOST)));
+ EXPECT_FALSE(
+ base::ContainsValue(synced_device.enabled_software_features(),
+ SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::MAGIC_TETHER_HOST)));
}
-TEST_F(CryptAuthDeviceManagerImplTest, MetricsForEnabledAndNotSupported) {
- ExternalDeviceInfo enabled_not_supported_device;
+TEST_F(DeviceSyncCryptAuthDeviceManagerImplTest,
+ MetricsForEnabledAndNotSupported) {
+ cryptauth::ExternalDeviceInfo enabled_not_supported_device;
enabled_not_supported_device.set_public_key("new public key");
enabled_not_supported_device.add_supported_software_features(
- SoftwareFeatureEnumToString(SoftwareFeature::BETTER_TOGETHER_HOST));
+ SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::BETTER_TOGETHER_HOST));
enabled_not_supported_device.add_enabled_software_features(
- SoftwareFeatureEnumToString(SoftwareFeature::BETTER_TOGETHER_HOST));
+ SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::BETTER_TOGETHER_HOST));
// EASY_UNLOCK_HOST is a special case; it is allowed to not be marked as
// supported, but still be set as enabled.
enabled_not_supported_device.add_enabled_software_features(
- SoftwareFeatureEnumToString(SoftwareFeature::EASY_UNLOCK_HOST));
+ SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::EASY_UNLOCK_HOST));
// These will fail because they are not set as supported.
enabled_not_supported_device.add_enabled_software_features(
- SoftwareFeatureEnumToString(SoftwareFeature::MAGIC_TETHER_HOST));
+ SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::MAGIC_TETHER_HOST));
enabled_not_supported_device.add_enabled_software_features(
"MyUnknownFeature");
- GetMyDevicesResponse response;
+ cryptauth::GetMyDevicesResponse response;
response.add_devices()->CopyFrom(enabled_not_supported_device);
device_manager_->Start();
@@ -1197,7 +1236,7 @@
"CryptAuth.DeviceSyncSoftwareFeaturesResult.Failures", 0);
EXPECT_EQ(1u, device_manager_->GetSyncedDevices().size());
- FireSchedulerForSync(INVOCATION_REASON_PERIODIC);
+ FireSchedulerForSync(cryptauth::INVOCATION_REASON_PERIODIC);
ASSERT_FALSE(success_callback_.is_null());
EXPECT_CALL(*this, OnSyncFinishedProxy(
CryptAuthDeviceManager::SyncResult::SUCCESS,
@@ -1227,4 +1266,6 @@
cryptauth::SoftwareFeature::UNKNOWN_FEATURE, 1);
}
-} // namespace cryptauth
+} // namespace device_sync
+
+} // namespace chromeos
diff --git a/components/cryptauth/cryptauth_enroller.h b/chromeos/services/device_sync/cryptauth_enroller.h
similarity index 76%
rename from components/cryptauth/cryptauth_enroller.h
rename to chromeos/services/device_sync/cryptauth_enroller.h
index c62dc6d..2e3caef 100644
--- a/components/cryptauth/cryptauth_enroller.h
+++ b/chromeos/services/device_sync/cryptauth_enroller.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef COMPONENTS_CRYPTAUTH_CRYPTAUTH_ENROLLER_H_
-#define COMPONENTS_CRYPTAUTH_CRYPTAUTH_ENROLLER_H_
+#ifndef CHROMEOS_SERVICES_DEVICE_SYNC_CRYPTAUTH_ENROLLER_H_
+#define CHROMEOS_SERVICES_DEVICE_SYNC_CRYPTAUTH_ENROLLER_H_
#include <memory>
#include <string>
@@ -11,7 +11,9 @@
#include "base/callback_forward.h"
#include "chromeos/services/device_sync/proto/cryptauth_api.pb.h"
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
// Interface for enrolling a device with CryptAuth.
class CryptAuthEnroller {
@@ -29,8 +31,8 @@
typedef base::Callback<void(bool)> EnrollmentFinishedCallback;
virtual void Enroll(const std::string& user_public_key,
const std::string& user_private_key,
- const GcmDeviceInfo& device_info,
- InvocationReason invocation_reason,
+ const cryptauth::GcmDeviceInfo& device_info,
+ cryptauth::InvocationReason invocation_reason,
const EnrollmentFinishedCallback& callback) = 0;
};
@@ -42,6 +44,8 @@
virtual std::unique_ptr<CryptAuthEnroller> CreateInstance() = 0;
};
-} // namespace cryptauth
+} // namespace device_sync
-#endif // COMPONENTS_CRYPTAUTH_CRYPTAUTH_ENROLLER_H_
+} // namespace chromeos
+
+#endif // CHROMEOS_SERVICES_DEVICE_SYNC_CRYPTAUTH_ENROLLER_H_
diff --git a/chromeos/services/device_sync/cryptauth_enroller_factory_impl.cc b/chromeos/services/device_sync/cryptauth_enroller_factory_impl.cc
index 968ff92..09b949a 100644
--- a/chromeos/services/device_sync/cryptauth_enroller_factory_impl.cc
+++ b/chromeos/services/device_sync/cryptauth_enroller_factory_impl.cc
@@ -6,7 +6,7 @@
#include <memory>
-#include "components/cryptauth/cryptauth_enroller_impl.h"
+#include "chromeos/services/device_sync/cryptauth_enroller_impl.h"
#include "components/cryptauth/secure_message_delegate_impl.h"
namespace chromeos {
@@ -14,14 +14,14 @@
namespace device_sync {
CryptAuthEnrollerFactoryImpl::CryptAuthEnrollerFactoryImpl(
- cryptauth::CryptAuthClientFactory* cryptauth_client_factory)
+ CryptAuthClientFactory* cryptauth_client_factory)
: cryptauth_client_factory_(cryptauth_client_factory) {}
CryptAuthEnrollerFactoryImpl::~CryptAuthEnrollerFactoryImpl() = default;
-std::unique_ptr<cryptauth::CryptAuthEnroller>
+std::unique_ptr<CryptAuthEnroller>
CryptAuthEnrollerFactoryImpl::CreateInstance() {
- return std::make_unique<cryptauth::CryptAuthEnrollerImpl>(
+ return std::make_unique<CryptAuthEnrollerImpl>(
cryptauth_client_factory_,
cryptauth::SecureMessageDelegateImpl::Factory::NewInstance());
}
diff --git a/chromeos/services/device_sync/cryptauth_enroller_factory_impl.h b/chromeos/services/device_sync/cryptauth_enroller_factory_impl.h
index d5ae6c6..9b76408 100644
--- a/chromeos/services/device_sync/cryptauth_enroller_factory_impl.h
+++ b/chromeos/services/device_sync/cryptauth_enroller_factory_impl.h
@@ -5,29 +5,26 @@
#ifndef CHROMEOS_SERVICES_DEVICE_SYNC_CRYPTAUTH_ENROLLER_FACTORY_IMPL_H_
#define CHROMEOS_SERVICES_DEVICE_SYNC_CRYPTAUTH_ENROLLER_FACTORY_IMPL_H_
-#include "components/cryptauth/cryptauth_enroller.h"
-
-namespace cryptauth {
-class CryptAuthClientFactory;
-} // namespace cryptauth
+#include "chromeos/services/device_sync/cryptauth_enroller.h"
namespace chromeos {
namespace device_sync {
+class CryptAuthClientFactory;
+
// CryptAuthEnrollerFactory implementation which utilizes IdentityManager.
-class CryptAuthEnrollerFactoryImpl
- : public cryptauth::CryptAuthEnrollerFactory {
+class CryptAuthEnrollerFactoryImpl : public CryptAuthEnrollerFactory {
public:
CryptAuthEnrollerFactoryImpl(
- cryptauth::CryptAuthClientFactory* cryptauth_client_factory);
+ CryptAuthClientFactory* cryptauth_client_factory);
~CryptAuthEnrollerFactoryImpl() override;
- // cryptauth::CryptAuthEnrollerFactory:
- std::unique_ptr<cryptauth::CryptAuthEnroller> CreateInstance() override;
+ // CryptAuthEnrollerFactory:
+ std::unique_ptr<CryptAuthEnroller> CreateInstance() override;
private:
- cryptauth::CryptAuthClientFactory* cryptauth_client_factory_;
+ CryptAuthClientFactory* cryptauth_client_factory_;
};
} // namespace device_sync
diff --git a/components/cryptauth/cryptauth_enroller_impl.cc b/chromeos/services/device_sync/cryptauth_enroller_impl.cc
similarity index 83%
rename from components/cryptauth/cryptauth_enroller_impl.cc
rename to chromeos/services/device_sync/cryptauth_enroller_impl.cc
index de91d95..0e7f9d1 100644
--- a/components/cryptauth/cryptauth_enroller_impl.cc
+++ b/chromeos/services/device_sync/cryptauth_enroller_impl.cc
@@ -2,19 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/cryptauth/cryptauth_enroller_impl.h"
+#include "chromeos/services/device_sync/cryptauth_enroller_impl.h"
#include <utility>
#include "base/bind.h"
#include "base/metrics/histogram_macros.h"
#include "chromeos/components/proximity_auth/logging/logging.h"
-#include "components/cryptauth/cryptauth_client_impl.h"
-#include "components/cryptauth/cryptauth_enrollment_utils.h"
+#include "chromeos/services/device_sync/cryptauth_client_impl.h"
#include "components/cryptauth/secure_message_delegate.h"
#include "crypto/sha2.h"
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
namespace {
@@ -29,14 +30,15 @@
const int kGCMMetadataVersion = 1;
// Returns true if |device_info| contains the required fields for enrollment.
-bool ValidateDeviceInfo(const GcmDeviceInfo& device_info) {
+bool ValidateDeviceInfo(const cryptauth::GcmDeviceInfo& device_info) {
if (!device_info.has_long_device_id()) {
- PA_LOG(ERROR) << "Expected long_device_id field in GcmDeviceInfo.";
+ PA_LOG(ERROR)
+ << "Expected long_device_id field in cryptauth::GcmDeviceInfo.";
return false;
}
if (!device_info.has_device_type()) {
- PA_LOG(ERROR) << "Expected device_type field in GcmDeviceInfo.";
+ PA_LOG(ERROR) << "Expected device_type field in cryptauth::GcmDeviceInfo.";
return false;
}
@@ -46,9 +48,9 @@
// Creates the public metadata to put in the SecureMessage that is sent to the
// server with the FinishEnrollment request.
std::string CreateEnrollmentPublicMetadata() {
- GcmMetadata metadata;
+ cryptauth::GcmMetadata metadata;
metadata.set_version(kGCMMetadataVersion);
- metadata.set_type(MessageType::ENROLLMENT);
+ metadata.set_type(cryptauth::MessageType::ENROLLMENT);
return metadata.SerializeAsString();
}
@@ -60,19 +62,18 @@
CryptAuthEnrollerImpl::CryptAuthEnrollerImpl(
CryptAuthClientFactory* client_factory,
- std::unique_ptr<SecureMessageDelegate> secure_message_delegate)
+ std::unique_ptr<cryptauth::SecureMessageDelegate> secure_message_delegate)
: client_factory_(client_factory),
secure_message_delegate_(std::move(secure_message_delegate)),
weak_ptr_factory_(this) {}
-CryptAuthEnrollerImpl::~CryptAuthEnrollerImpl() {
-}
+CryptAuthEnrollerImpl::~CryptAuthEnrollerImpl() {}
void CryptAuthEnrollerImpl::Enroll(
const std::string& user_public_key,
const std::string& user_private_key,
- const GcmDeviceInfo& device_info,
- InvocationReason invocation_reason,
+ const cryptauth::GcmDeviceInfo& device_info,
+ cryptauth::InvocationReason invocation_reason,
const EnrollmentFinishedCallback& callback) {
if (!callback_.is_null()) {
PA_LOG(ERROR) << "Enroll() already called. Do not reuse.";
@@ -104,18 +105,19 @@
session_private_key_ = private_key;
cryptauth_client_ = client_factory_->CreateInstance();
- SetupEnrollmentRequest request;
+ cryptauth::SetupEnrollmentRequest request;
request.add_types(kSupportedEnrollmentTypeGcmV1);
request.set_invocation_reason(invocation_reason_);
cryptauth_client_->SetupEnrollment(
- request, base::Bind(&CryptAuthEnrollerImpl::OnSetupEnrollmentSuccess,
- weak_ptr_factory_.GetWeakPtr()),
+ request,
+ base::Bind(&CryptAuthEnrollerImpl::OnSetupEnrollmentSuccess,
+ weak_ptr_factory_.GetWeakPtr()),
base::Bind(&CryptAuthEnrollerImpl::OnSetupEnrollmentFailure,
weak_ptr_factory_.GetWeakPtr()));
}
void CryptAuthEnrollerImpl::OnSetupEnrollmentSuccess(
- const SetupEnrollmentResponse& response) {
+ const cryptauth::SetupEnrollmentResponse& response) {
if (response.status() != kResponseStatusOk) {
PA_LOG(WARNING) << "Unexpected status for SetupEnrollment: "
<< response.status();
@@ -165,7 +167,7 @@
PA_LOG(VERBOSE) << "Using access token: " << device_info_.oauth_token();
symmetric_key_ = symmetric_key;
- SecureMessageDelegate::CreateOptions options;
+ cryptauth::SecureMessageDelegate::CreateOptions options;
options.encryption_scheme = securemessage::NONE;
options.signature_scheme = securemessage::ECDSA_P256_SHA256;
options.verification_key_id = user_public_key_;
@@ -186,7 +188,7 @@
return;
}
- SecureMessageDelegate::CreateOptions options;
+ cryptauth::SecureMessageDelegate::CreateOptions options;
options.encryption_scheme = securemessage::AES_256_CBC;
options.signature_scheme = securemessage::HMAC_SHA256;
options.public_metadata = CreateEnrollmentPublicMetadata();
@@ -203,7 +205,7 @@
const std::string& outer_message) {
PA_LOG(VERBOSE) << "SecureMessage created, calling FinishEnrollment API.";
- FinishEnrollmentRequest request;
+ cryptauth::FinishEnrollmentRequest request;
request.set_enrollment_session_id(setup_info_.enrollment_session_id());
request.set_enrollment_message(outer_message);
request.set_device_ephemeral_key(session_public_key_);
@@ -211,14 +213,15 @@
cryptauth_client_ = client_factory_->CreateInstance();
cryptauth_client_->FinishEnrollment(
- request, base::Bind(&CryptAuthEnrollerImpl::OnFinishEnrollmentSuccess,
- weak_ptr_factory_.GetWeakPtr()),
+ request,
+ base::Bind(&CryptAuthEnrollerImpl::OnFinishEnrollmentSuccess,
+ weak_ptr_factory_.GetWeakPtr()),
base::Bind(&CryptAuthEnrollerImpl::OnFinishEnrollmentFailure,
weak_ptr_factory_.GetWeakPtr()));
}
void CryptAuthEnrollerImpl::OnFinishEnrollmentSuccess(
- const FinishEnrollmentResponse& response) {
+ const cryptauth::FinishEnrollmentResponse& response) {
const bool success = response.status() == kResponseStatusOk;
if (!success) {
@@ -237,4 +240,6 @@
callback_.Run(false);
}
-} // namespace cryptauth
+} // namespace device_sync
+
+} // namespace chromeos
diff --git a/components/cryptauth/cryptauth_enroller_impl.h b/chromeos/services/device_sync/cryptauth_enroller_impl.h
similarity index 73%
rename from components/cryptauth/cryptauth_enroller_impl.h
rename to chromeos/services/device_sync/cryptauth_enroller_impl.h
index 32a870d..587499e 100644
--- a/components/cryptauth/cryptauth_enroller_impl.h
+++ b/chromeos/services/device_sync/cryptauth_enroller_impl.h
@@ -2,23 +2,28 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef COMPONENTS_CRYPTAUTH_CRYPTAUTH_ENROLLER_IMPL_H_
-#define COMPONENTS_CRYPTAUTH_CRYPTAUTH_ENROLLER_IMPL_H_
+#ifndef CHROMEOS_SERVICES_DEVICE_SYNC_CRYPTAUTH_ENROLLER_IMPL_H_
+#define CHROMEOS_SERVICES_DEVICE_SYNC_CRYPTAUTH_ENROLLER_IMPL_H_
#include <memory>
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
+#include "chromeos/services/device_sync/cryptauth_enroller.h"
+#include "chromeos/services/device_sync/network_request_error.h"
#include "chromeos/services/device_sync/proto/cryptauth_api.pb.h"
-#include "components/cryptauth/cryptauth_enroller.h"
-#include "components/cryptauth/network_request_error.h"
namespace cryptauth {
+class SecureMessageDelegate;
+} // namespace cryptauth
+
+namespace chromeos {
+
+namespace device_sync {
class CryptAuthClient;
class CryptAuthClientFactory;
-class SecureMessageDelegate;
// Implementation of CryptAuthEnroller to perform enrollment in two steps:
// 1. SetupEnrollment:
@@ -32,27 +37,27 @@
public:
// |client_factory| creates CryptAuthClient instances for making API calls.
// |crypto_delegate| is responsible for SecureMessage operations.
- CryptAuthEnrollerImpl(
- CryptAuthClientFactory* client_factory,
- std::unique_ptr<SecureMessageDelegate> secure_message_delegate);
+ CryptAuthEnrollerImpl(CryptAuthClientFactory* client_factory,
+ std::unique_ptr<cryptauth::SecureMessageDelegate>
+ secure_message_delegate);
~CryptAuthEnrollerImpl() override;
// CryptAuthEnroller:
void Enroll(const std::string& user_public_key,
const std::string& user_private_key,
- const GcmDeviceInfo& device_info,
- InvocationReason invocation_reason,
+ const cryptauth::GcmDeviceInfo& device_info,
+ cryptauth::InvocationReason invocation_reason,
const EnrollmentFinishedCallback& callback) override;
private:
// Callbacks for SetupEnrollment.
void OnSetupEnrollmentSuccess(
- const SetupEnrollmentResponse& response);
+ const cryptauth::SetupEnrollmentResponse& response);
void OnSetupEnrollmentFailure(NetworkRequestError error);
// Callbacks for FinishEnrollment.
void OnFinishEnrollmentSuccess(
- const FinishEnrollmentResponse& response);
+ const cryptauth::FinishEnrollmentResponse& response);
void OnFinishEnrollmentFailure(NetworkRequestError error);
// Callbacks for SecureMessageDelegate operations.
@@ -66,7 +71,7 @@
CryptAuthClientFactory* client_factory_;
// Handles SecureMessage operations.
- std::unique_ptr<SecureMessageDelegate> secure_message_delegate_;
+ std::unique_ptr<cryptauth::SecureMessageDelegate> secure_message_delegate_;
// The CryptAuthClient for the latest request.
std::unique_ptr<CryptAuthClient> cryptauth_client_;
@@ -80,13 +85,13 @@
std::string user_private_key_;
// Contains information of the device to enroll.
- GcmDeviceInfo device_info_;
+ cryptauth::GcmDeviceInfo device_info_;
// The reason telling the server why the enrollment happened.
- InvocationReason invocation_reason_;
+ cryptauth::InvocationReason invocation_reason_;
// The setup information returned from the SetupEnrollment API call.
- SetupEnrollmentInfo setup_info_;
+ cryptauth::SetupEnrollmentInfo setup_info_;
// Callback invoked when the enrollment is done.
EnrollmentFinishedCallback callback_;
@@ -99,6 +104,8 @@
DISALLOW_COPY_AND_ASSIGN(CryptAuthEnrollerImpl);
};
-} // namespace cryptauth
+} // namespace device_sync
-#endif // COMPONENTS_CRYPTAUTH_CRYPTAUTH_ENROLLER_IMPL_H_
+} // namespace chromeos
+
+#endif // CHROMEOS_SERVICES_DEVICE_SYNC_CRYPTAUTH_ENROLLER_IMPL_H_
diff --git a/components/cryptauth/cryptauth_enroller_impl_unittest.cc b/chromeos/services/device_sync/cryptauth_enroller_impl_unittest.cc
similarity index 74%
rename from components/cryptauth/cryptauth_enroller_impl_unittest.cc
rename to chromeos/services/device_sync/cryptauth_enroller_impl_unittest.cc
index 4834502..cd68d08 100644
--- a/components/cryptauth/cryptauth_enroller_impl_unittest.cc
+++ b/chromeos/services/device_sync/cryptauth_enroller_impl_unittest.cc
@@ -2,21 +2,22 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/cryptauth/cryptauth_enroller_impl.h"
+#include "chromeos/services/device_sync/cryptauth_enroller_impl.h"
#include "base/bind.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
-#include "components/cryptauth/cryptauth_enrollment_utils.h"
+#include "chromeos/services/device_sync/mock_cryptauth_client.h"
+#include "chromeos/services/device_sync/network_request_error.h"
#include "components/cryptauth/fake_secure_message_delegate.h"
-#include "components/cryptauth/mock_cryptauth_client.h"
-#include "components/cryptauth/network_request_error.h"
#include "testing/gtest/include/gtest/gtest.h"
using ::testing::_;
using ::testing::Return;
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
namespace {
@@ -25,8 +26,8 @@
const char kClientSessionPublicKey[] = "throw away after one use";
const char kServerSessionPublicKey[] = "disposables are not eco-friendly";
-InvocationReason kInvocationReason =
- INVOCATION_REASON_MANUAL;
+cryptauth::InvocationReason kInvocationReason =
+ cryptauth::INVOCATION_REASON_MANUAL;
const int kGCMMetadataVersion = 1;
const char kSupportedEnrollmentTypeGcmV1[] = "gcmV1";
const char kResponseStatusOk[] = "ok";
@@ -35,41 +36,41 @@
const char kFinishEnrollmentError[] = "A hungry router ate all your packets.";
const char kDeviceId[] = "2015 AD";
-const DeviceType kDeviceType = CHROME;
+const cryptauth::DeviceType kDeviceType = cryptauth::CHROME;
const char kDeviceOsVersion[] = "41.0.0";
-// Creates and returns the GcmDeviceInfo message to be uploaded.
-GcmDeviceInfo GetDeviceInfo() {
- GcmDeviceInfo device_info;
+// Creates and returns the cryptauth::GcmDeviceInfo message to be uploaded.
+cryptauth::GcmDeviceInfo GetDeviceInfo() {
+ cryptauth::GcmDeviceInfo device_info;
device_info.set_long_device_id(kDeviceId);
device_info.set_device_type(kDeviceType);
device_info.set_device_os_version(kDeviceOsVersion);
return device_info;
}
-// Creates and returns the SetupEnrollmentResponse message to be returned to the
-// enroller with the session_. If |success| is false, then a bad response will
-// be returned.
-SetupEnrollmentResponse GetSetupEnrollmentResponse(bool success) {
- SetupEnrollmentResponse response;
+// Creates and returns the cryptauth::SetupEnrollmentResponse message to be
+// returned to the enroller with the session_. If |success| is false, then a bad
+// response will be returned.
+cryptauth::SetupEnrollmentResponse GetSetupEnrollmentResponse(bool success) {
+ cryptauth::SetupEnrollmentResponse response;
if (!success) {
response.set_status(kResponseStatusNotOk);
return response;
}
response.set_status(kResponseStatusOk);
- SetupEnrollmentInfo* info = response.add_infos();
+ cryptauth::SetupEnrollmentInfo* info = response.add_infos();
info->set_type(kSupportedEnrollmentTypeGcmV1);
info->set_enrollment_session_id(kEnrollmentSessionId);
info->set_server_ephemeral_key(kServerSessionPublicKey);
return response;
}
-// Creates and returns the FinishEnrollmentResponse message to be returned to
-// the enroller with the session_. If |success| is false, then a bad response
-// will be returned.
-FinishEnrollmentResponse GetFinishEnrollmentResponse(bool success) {
- FinishEnrollmentResponse response;
+// Creates and returns the cryptauth::FinishEnrollmentResponse message to be
+// returned to the enroller with the session_. If |success| is false, then a bad
+// response will be returned.
+cryptauth::FinishEnrollmentResponse GetFinishEnrollmentResponse(bool success) {
+ cryptauth::FinishEnrollmentResponse response;
if (success) {
response.set_status(kResponseStatusOk);
} else {
@@ -99,31 +100,31 @@
} // namespace
-class CryptAuthEnrollerTest
+class DeviceSyncCryptAuthEnrollerTest
: public testing::Test,
public MockCryptAuthClientFactory::Observer {
public:
- CryptAuthEnrollerTest()
+ DeviceSyncCryptAuthEnrollerTest()
: client_factory_(std::make_unique<MockCryptAuthClientFactory>(
MockCryptAuthClientFactory::MockType::MAKE_NICE_MOCKS)),
- secure_message_delegate_(new FakeSecureMessageDelegate()),
+ secure_message_delegate_(new cryptauth::FakeSecureMessageDelegate()),
enroller_(client_factory_.get(),
base::WrapUnique(secure_message_delegate_)) {
client_factory_->AddObserver(this);
// This call is actually synchronous.
secure_message_delegate_->GenerateKeyPair(
- base::Bind(&CryptAuthEnrollerTest::OnKeyPairGenerated,
+ base::Bind(&DeviceSyncCryptAuthEnrollerTest::OnKeyPairGenerated,
base::Unretained(this)));
}
// Starts the enroller.
- void StartEnroller(const GcmDeviceInfo& device_info) {
+ void StartEnroller(const cryptauth::GcmDeviceInfo& device_info) {
secure_message_delegate_->set_next_public_key(kClientSessionPublicKey);
enroller_result_.reset();
enroller_.Enroll(
user_public_key_, user_private_key_, device_info, kInvocationReason,
- base::Bind(&CryptAuthEnrollerTest::OnEnrollerCompleted,
+ base::Bind(&DeviceSyncCryptAuthEnrollerTest::OnEnrollerCompleted,
base::Unretained(this)));
}
@@ -145,7 +146,7 @@
// Unwrap the outer message.
bool verified;
securemessage::Header header;
- SecureMessageDelegate::UnwrapOptions unwrap_options;
+ cryptauth::SecureMessageDelegate::UnwrapOptions unwrap_options;
unwrap_options.encryption_scheme = securemessage::AES_256_CBC;
unwrap_options.signature_scheme = securemessage::HMAC_SHA256;
secure_message_delegate_->UnwrapSecureMessage(
@@ -153,17 +154,17 @@
base::Bind(&SaveUnwrapResults, &verified, &inner_message, &header));
EXPECT_TRUE(verified);
- GcmMetadata metadata;
+ cryptauth::GcmMetadata metadata;
ASSERT_TRUE(metadata.ParseFromString(header.public_metadata()));
EXPECT_EQ(kGCMMetadataVersion, metadata.version());
- EXPECT_EQ(MessageType::ENROLLMENT, metadata.type());
+ EXPECT_EQ(cryptauth::MessageType::ENROLLMENT, metadata.type());
}
{
// Unwrap inner message.
bool verified;
securemessage::Header header;
- SecureMessageDelegate::UnwrapOptions unwrap_options;
+ cryptauth::SecureMessageDelegate::UnwrapOptions unwrap_options;
unwrap_options.encryption_scheme = securemessage::NONE;
unwrap_options.signature_scheme = securemessage::ECDSA_P256_SHA256;
secure_message_delegate_->UnwrapSecureMessage(
@@ -173,8 +174,8 @@
EXPECT_EQ(user_public_key_, header.verification_key_id());
}
- // Check that the decrypted GcmDeviceInfo is correct.
- GcmDeviceInfo device_info;
+ // Check that the decrypted cryptauth::GcmDeviceInfo is correct.
+ cryptauth::GcmDeviceInfo device_info;
ASSERT_TRUE(device_info.ParseFromString(inner_payload));
EXPECT_EQ(kDeviceId, device_info.long_device_id());
EXPECT_EQ(kDeviceType, device_info.device_type());
@@ -188,12 +189,12 @@
// MockCryptAuthClientFactory::Observer:
void OnCryptAuthClientCreated(MockCryptAuthClient* client) override {
ON_CALL(*client, SetupEnrollment(_, _, _))
- .WillByDefault(Invoke(
- this, &CryptAuthEnrollerTest::OnSetupEnrollment));
+ .WillByDefault(
+ Invoke(this, &DeviceSyncCryptAuthEnrollerTest::OnSetupEnrollment));
ON_CALL(*client, FinishEnrollment(_, _, _))
- .WillByDefault(Invoke(
- this, &CryptAuthEnrollerTest::OnFinishEnrollment));
+ .WillByDefault(
+ Invoke(this, &DeviceSyncCryptAuthEnrollerTest::OnFinishEnrollment));
ON_CALL(*client, GetAccessTokenUsed())
.WillByDefault(Return(kAccessTokenUsed));
@@ -211,7 +212,7 @@
}
void OnSetupEnrollment(
- const SetupEnrollmentRequest& request,
+ const cryptauth::SetupEnrollmentRequest& request,
const CryptAuthClient::SetupEnrollmentCallback& callback,
const CryptAuthClient::ErrorCallback& error_callback) {
// Check that SetupEnrollment is called before FinishEnrollment.
@@ -220,13 +221,13 @@
EXPECT_TRUE(setup_callback_.is_null());
EXPECT_TRUE(error_callback_.is_null());
- setup_request_.reset(new SetupEnrollmentRequest(request));
+ setup_request_.reset(new cryptauth::SetupEnrollmentRequest(request));
setup_callback_ = callback;
error_callback_ = error_callback;
}
void OnFinishEnrollment(
- const FinishEnrollmentRequest& request,
+ const cryptauth::FinishEnrollmentRequest& request,
const CryptAuthClient::FinishEnrollmentCallback& callback,
const CryptAuthClient::ErrorCallback& error_callback) {
// Check that FinishEnrollment is called after SetupEnrollment.
@@ -234,7 +235,7 @@
EXPECT_FALSE(finish_request_.get());
EXPECT_TRUE(finish_callback_.is_null());
- finish_request_.reset(new FinishEnrollmentRequest(request));
+ finish_request_.reset(new cryptauth::FinishEnrollmentRequest(request));
finish_callback_ = callback;
error_callback_ = error_callback;
}
@@ -246,7 +247,7 @@
// Owned by |enroller_|.
std::unique_ptr<MockCryptAuthClientFactory> client_factory_;
// Owned by |enroller_|.
- FakeSecureMessageDelegate* secure_message_delegate_;
+ cryptauth::FakeSecureMessageDelegate* secure_message_delegate_;
// The CryptAuthEnroller under test.
CryptAuthEnrollerImpl enroller_;
@@ -254,16 +255,16 @@
std::unique_ptr<bool> enroller_result_;
// Stored callbacks and requests for SetupEnrollment and FinishEnrollment.
- std::unique_ptr<SetupEnrollmentRequest> setup_request_;
- std::unique_ptr<FinishEnrollmentRequest> finish_request_;
+ std::unique_ptr<cryptauth::SetupEnrollmentRequest> setup_request_;
+ std::unique_ptr<cryptauth::FinishEnrollmentRequest> finish_request_;
CryptAuthClient::SetupEnrollmentCallback setup_callback_;
CryptAuthClient::FinishEnrollmentCallback finish_callback_;
CryptAuthClient::ErrorCallback error_callback_;
- DISALLOW_COPY_AND_ASSIGN(CryptAuthEnrollerTest);
+ DISALLOW_COPY_AND_ASSIGN(DeviceSyncCryptAuthEnrollerTest);
};
-TEST_F(CryptAuthEnrollerTest, EnrollmentSucceeds) {
+TEST_F(DeviceSyncCryptAuthEnrollerTest, EnrollmentSucceeds) {
StartEnroller(GetDeviceInfo());
// Handle SetupEnrollment request.
@@ -288,7 +289,7 @@
EXPECT_TRUE(*enroller_result_);
}
-TEST_F(CryptAuthEnrollerTest, SetupEnrollmentApiCallError) {
+TEST_F(DeviceSyncCryptAuthEnrollerTest, SetupEnrollmentApiCallError) {
StartEnroller(GetDeviceInfo());
EXPECT_TRUE(setup_request_.get());
@@ -300,7 +301,7 @@
EXPECT_FALSE(*enroller_result_);
}
-TEST_F(CryptAuthEnrollerTest, SetupEnrollmentBadStatus) {
+TEST_F(DeviceSyncCryptAuthEnrollerTest, SetupEnrollmentBadStatus) {
StartEnroller(GetDeviceInfo());
EXPECT_TRUE(setup_request_.get());
@@ -311,10 +312,10 @@
EXPECT_FALSE(*enroller_result_);
}
-TEST_F(CryptAuthEnrollerTest, SetupEnrollmentNoInfosReturned) {
+TEST_F(DeviceSyncCryptAuthEnrollerTest, SetupEnrollmentNoInfosReturned) {
StartEnroller(GetDeviceInfo());
EXPECT_TRUE(setup_request_.get());
- SetupEnrollmentResponse response;
+ cryptauth::SetupEnrollmentResponse response;
response.set_status(kResponseStatusOk);
setup_callback_.Run(response);
@@ -323,7 +324,7 @@
EXPECT_FALSE(*enroller_result_);
}
-TEST_F(CryptAuthEnrollerTest, FinishEnrollmentApiCallError) {
+TEST_F(DeviceSyncCryptAuthEnrollerTest, FinishEnrollmentApiCallError) {
StartEnroller(GetDeviceInfo());
setup_callback_.Run(GetSetupEnrollmentResponse(true));
ASSERT_FALSE(error_callback_.is_null());
@@ -332,7 +333,7 @@
EXPECT_FALSE(*enroller_result_);
}
-TEST_F(CryptAuthEnrollerTest, FinishEnrollmentBadStatus) {
+TEST_F(DeviceSyncCryptAuthEnrollerTest, FinishEnrollmentBadStatus) {
StartEnroller(GetDeviceInfo());
setup_callback_.Run(GetSetupEnrollmentResponse(true));
ASSERT_FALSE(finish_callback_.is_null());
@@ -341,7 +342,7 @@
EXPECT_FALSE(*enroller_result_);
}
-TEST_F(CryptAuthEnrollerTest, ReuseEnroller) {
+TEST_F(DeviceSyncCryptAuthEnrollerTest, ReuseEnroller) {
StartEnroller(GetDeviceInfo());
setup_callback_.Run(GetSetupEnrollmentResponse(true));
finish_callback_.Run(GetFinishEnrollmentResponse(true));
@@ -351,10 +352,12 @@
EXPECT_FALSE(*enroller_result_);
}
-TEST_F(CryptAuthEnrollerTest, IncompleteDeviceInfo) {
- StartEnroller(GcmDeviceInfo());
+TEST_F(DeviceSyncCryptAuthEnrollerTest, IncompleteDeviceInfo) {
+ StartEnroller(cryptauth::GcmDeviceInfo());
ASSERT_TRUE(enroller_result_.get());
EXPECT_FALSE(*enroller_result_);
}
-} // namespace cryptauth
+} // namespace device_sync
+
+} // namespace chromeos
diff --git a/components/cryptauth/cryptauth_enrollment_manager.cc b/chromeos/services/device_sync/cryptauth_enrollment_manager.cc
similarity index 82%
rename from components/cryptauth/cryptauth_enrollment_manager.cc
rename to chromeos/services/device_sync/cryptauth_enrollment_manager.cc
index dcb8d91..ab5829a 100644
--- a/components/cryptauth/cryptauth_enrollment_manager.cc
+++ b/chromeos/services/device_sync/cryptauth_enrollment_manager.cc
@@ -2,12 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/cryptauth/cryptauth_enrollment_manager.h"
+#include "chromeos/services/device_sync/cryptauth_enrollment_manager.h"
-#include "components/cryptauth/pref_names.h"
+#include "chromeos/services/device_sync/pref_names.h"
#include "components/prefs/pref_registry_simple.h"
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
// static
void CryptAuthEnrollmentManager::RegisterPrefs(PrefRegistrySimple* registry) {
@@ -16,7 +18,7 @@
registry->RegisterDoublePref(
prefs::kCryptAuthEnrollmentLastEnrollmentTimeSeconds, 0.0);
registry->RegisterIntegerPref(prefs::kCryptAuthEnrollmentReason,
- INVOCATION_REASON_UNKNOWN);
+ cryptauth::INVOCATION_REASON_UNKNOWN);
registry->RegisterStringPref(prefs::kCryptAuthEnrollmentUserPublicKey,
std::string());
registry->RegisterStringPref(prefs::kCryptAuthEnrollmentUserPrivateKey,
@@ -45,4 +47,6 @@
observer.OnEnrollmentFinished(success);
}
-} // namespace cryptauth
+} // namespace device_sync
+
+} // namespace chromeos
diff --git a/components/cryptauth/cryptauth_enrollment_manager.h b/chromeos/services/device_sync/cryptauth_enrollment_manager.h
similarity index 87%
rename from components/cryptauth/cryptauth_enrollment_manager.h
rename to chromeos/services/device_sync/cryptauth_enrollment_manager.h
index cadad1d0..62df4f3 100644
--- a/components/cryptauth/cryptauth_enrollment_manager.h
+++ b/chromeos/services/device_sync/cryptauth_enrollment_manager.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef COMPONENTS_CRYPTAUTH_CRYPTAUTH_ENROLLMENT_MANAGER_H_
-#define COMPONENTS_CRYPTAUTH_CRYPTAUTH_ENROLLMENT_MANAGER_H_
+#ifndef CHROMEOS_SERVICES_DEVICE_SYNC_CRYPTAUTH_ENROLLMENT_MANAGER_H_
+#define CHROMEOS_SERVICES_DEVICE_SYNC_CRYPTAUTH_ENROLLMENT_MANAGER_H_
#include <memory>
@@ -14,7 +14,9 @@
class PrefRegistrySimple;
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
// This class manages the device's enrollment with CryptAuth, periodically
// re-enrolling to keep the state on the server fresh. If an enrollment fails,
@@ -50,7 +52,8 @@
// enrollment is already in progress, this function does nothing.
// |invocation_reason| specifies the reason that the enrollment was triggered,
// which is upload to the server.
- virtual void ForceEnrollmentNow(InvocationReason invocation_reason) = 0;
+ virtual void ForceEnrollmentNow(
+ cryptauth::InvocationReason invocation_reason) = 0;
// Returns true if a successful enrollment has been recorded and this
// enrollment has not expired.
@@ -88,6 +91,8 @@
DISALLOW_COPY_AND_ASSIGN(CryptAuthEnrollmentManager);
};
-} // namespace cryptauth
+} // namespace device_sync
-#endif // COMPONENTS_CRYPTAUTH_CRYPTAUTH_ENROLLMENT_MANAGER_H_
+} // namespace chromeos
+
+#endif // CHROMEOS_SERVICES_DEVICE_SYNC_CRYPTAUTH_ENROLLMENT_MANAGER_H_
diff --git a/components/cryptauth/cryptauth_enrollment_manager_impl.cc b/chromeos/services/device_sync/cryptauth_enrollment_manager_impl.cc
similarity index 85%
rename from components/cryptauth/cryptauth_enrollment_manager_impl.cc
rename to chromeos/services/device_sync/cryptauth_enrollment_manager_impl.cc
index 4f66afa..03d790e 100644
--- a/components/cryptauth/cryptauth_enrollment_manager_impl.cc
+++ b/chromeos/services/device_sync/cryptauth_enrollment_manager_impl.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/cryptauth/cryptauth_enrollment_manager_impl.h"
+#include "chromeos/services/device_sync/cryptauth_enrollment_manager_impl.h"
#include <memory>
#include <sstream>
@@ -13,15 +13,17 @@
#include "base/time/clock.h"
#include "base/time/time.h"
#include "chromeos/components/proximity_auth/logging/logging.h"
+#include "chromeos/services/device_sync/cryptauth_enroller.h"
+#include "chromeos/services/device_sync/pref_names.h"
#include "chromeos/services/device_sync/proto/enum_util.h"
-#include "components/cryptauth/cryptauth_enroller.h"
-#include "components/cryptauth/pref_names.h"
+#include "chromeos/services/device_sync/sync_scheduler_impl.h"
#include "components/cryptauth/secure_message_delegate.h"
-#include "components/cryptauth/sync_scheduler_impl.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
namespace {
@@ -53,7 +55,8 @@
kEnrollmentMaxJitterRatio, "CryptAuth Enrollment");
}
-std::string GenerateSupportedFeaturesString(const GcmDeviceInfo& info) {
+std::string GenerateSupportedFeaturesString(
+ const cryptauth::GcmDeviceInfo& info) {
std::stringstream ss;
ss << "[";
@@ -81,8 +84,8 @@
CryptAuthEnrollmentManagerImpl::Factory::NewInstance(
base::Clock* clock,
std::unique_ptr<CryptAuthEnrollerFactory> enroller_factory,
- std::unique_ptr<SecureMessageDelegate> secure_message_delegate,
- const GcmDeviceInfo& device_info,
+ std::unique_ptr<cryptauth::SecureMessageDelegate> secure_message_delegate,
+ const cryptauth::GcmDeviceInfo& device_info,
CryptAuthGCMManager* gcm_manager,
PrefService* pref_service) {
if (!factory_instance_)
@@ -105,8 +108,8 @@
CryptAuthEnrollmentManagerImpl::Factory::BuildInstance(
base::Clock* clock,
std::unique_ptr<CryptAuthEnrollerFactory> enroller_factory,
- std::unique_ptr<SecureMessageDelegate> secure_message_delegate,
- const GcmDeviceInfo& device_info,
+ std::unique_ptr<cryptauth::SecureMessageDelegate> secure_message_delegate,
+ const cryptauth::GcmDeviceInfo& device_info,
CryptAuthGCMManager* gcm_manager,
PrefService* pref_service) {
return base::WrapUnique(new CryptAuthEnrollmentManagerImpl(
@@ -117,8 +120,8 @@
CryptAuthEnrollmentManagerImpl::CryptAuthEnrollmentManagerImpl(
base::Clock* clock,
std::unique_ptr<CryptAuthEnrollerFactory> enroller_factory,
- std::unique_ptr<SecureMessageDelegate> secure_message_delegate,
- const GcmDeviceInfo& device_info,
+ std::unique_ptr<cryptauth::SecureMessageDelegate> secure_message_delegate,
+ const cryptauth::GcmDeviceInfo& device_info,
CryptAuthGCMManager* gcm_manager,
PrefService* pref_service)
: clock_(clock),
@@ -153,10 +156,11 @@
}
void CryptAuthEnrollmentManagerImpl::ForceEnrollmentNow(
- InvocationReason invocation_reason) {
+ cryptauth::InvocationReason invocation_reason) {
// We store the invocation reason in a preference so that it can persist
// across browser restarts. If the sync fails, the next retry should still use
- // this original reason instead of INVOCATION_REASON_FAILURE_RECOVERY.
+ // this original reason instead of
+ // cryptauth::INVOCATION_REASON_FAILURE_RECOVERY.
pref_service_->SetInteger(prefs::kCryptAuthEnrollmentReason,
invocation_reason);
scheduler_->ForceSync();
@@ -194,7 +198,7 @@
prefs::kCryptAuthEnrollmentLastEnrollmentTimeSeconds,
clock_->Now().ToDoubleT());
pref_service_->SetInteger(prefs::kCryptAuthEnrollmentReason,
- INVOCATION_REASON_UNKNOWN);
+ cryptauth::INVOCATION_REASON_UNKNOWN);
}
pref_service_->SetBoolean(prefs::kCryptAuthEnrollmentIsRecoveringFromFailure,
@@ -271,7 +275,7 @@
}
void CryptAuthEnrollmentManagerImpl::OnReenrollMessage() {
- ForceEnrollmentNow(INVOCATION_REASON_SERVER_INITIATED);
+ ForceEnrollmentNow(cryptauth::INVOCATION_REASON_SERVER_INITIATED);
}
void CryptAuthEnrollmentManagerImpl::OnSyncRequested(
@@ -281,7 +285,7 @@
sync_request_ = std::move(sync_request);
if (gcm_manager_->GetRegistrationId().empty() ||
pref_service_->GetInteger(prefs::kCryptAuthEnrollmentReason) ==
- INVOCATION_REASON_MANUAL) {
+ cryptauth::INVOCATION_REASON_MANUAL) {
gcm_manager_->RegisterWithGCM();
} else {
DoCryptAuthEnrollment();
@@ -300,29 +304,31 @@
void CryptAuthEnrollmentManagerImpl::DoCryptAuthEnrollmentWithKeys() {
DCHECK(sync_request_);
- InvocationReason invocation_reason = INVOCATION_REASON_UNKNOWN;
+ cryptauth::InvocationReason invocation_reason =
+ cryptauth::INVOCATION_REASON_UNKNOWN;
int reason_stored_in_prefs =
pref_service_->GetInteger(prefs::kCryptAuthEnrollmentReason);
- if (InvocationReason_IsValid(reason_stored_in_prefs) &&
- reason_stored_in_prefs != INVOCATION_REASON_UNKNOWN) {
- invocation_reason = static_cast<InvocationReason>(reason_stored_in_prefs);
+ if (cryptauth::InvocationReason_IsValid(reason_stored_in_prefs) &&
+ reason_stored_in_prefs != cryptauth::INVOCATION_REASON_UNKNOWN) {
+ invocation_reason =
+ static_cast<cryptauth::InvocationReason>(reason_stored_in_prefs);
} else if (GetLastEnrollmentTime().is_null()) {
- invocation_reason = INVOCATION_REASON_INITIALIZATION;
+ invocation_reason = cryptauth::INVOCATION_REASON_INITIALIZATION;
} else if (!IsEnrollmentValid()) {
- invocation_reason = INVOCATION_REASON_EXPIRATION;
+ invocation_reason = cryptauth::INVOCATION_REASON_EXPIRATION;
} else if (scheduler_->GetStrategy() ==
SyncScheduler::Strategy::PERIODIC_REFRESH) {
- invocation_reason = INVOCATION_REASON_PERIODIC;
+ invocation_reason = cryptauth::INVOCATION_REASON_PERIODIC;
} else if (scheduler_->GetStrategy() ==
SyncScheduler::Strategy::AGGRESSIVE_RECOVERY) {
- invocation_reason = INVOCATION_REASON_FAILURE_RECOVERY;
+ invocation_reason = cryptauth::INVOCATION_REASON_FAILURE_RECOVERY;
}
// Fill in the current GCM registration id before enrolling, and explicitly
// make sure that the software package is the same as the GCM app id.
- GcmDeviceInfo device_info(device_info_);
+ cryptauth::GcmDeviceInfo device_info(device_info_);
device_info.set_gcm_registration_id(gcm_manager_->GetRegistrationId());
device_info.set_device_software_package(kDeviceSoftwarePackage);
@@ -345,4 +351,6 @@
weak_ptr_factory_.GetWeakPtr()));
}
-} // namespace cryptauth
+} // namespace device_sync
+
+} // namespace chromeos
diff --git a/components/cryptauth/cryptauth_enrollment_manager_impl.h b/chromeos/services/device_sync/cryptauth_enrollment_manager_impl.h
similarity index 81%
rename from components/cryptauth/cryptauth_enrollment_manager_impl.h
rename to chromeos/services/device_sync/cryptauth_enrollment_manager_impl.h
index 34ec300..e3c7ce8 100644
--- a/components/cryptauth/cryptauth_enrollment_manager_impl.h
+++ b/chromeos/services/device_sync/cryptauth_enrollment_manager_impl.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef COMPONENTS_CRYPTAUTH_CRYPTAUTH_ENROLLMENT_MANAGER_IMPL_H_
-#define COMPONENTS_CRYPTAUTH_CRYPTAUTH_ENROLLMENT_MANAGER_IMPL_H_
+#ifndef CHROMEOS_SERVICES_DEVICE_SYNC_CRYPTAUTH_ENROLLMENT_MANAGER_IMPL_H_
+#define CHROMEOS_SERVICES_DEVICE_SYNC_CRYPTAUTH_ENROLLMENT_MANAGER_IMPL_H_
#include <memory>
@@ -11,10 +11,10 @@
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/time/time.h"
+#include "chromeos/services/device_sync/cryptauth_enrollment_manager.h"
+#include "chromeos/services/device_sync/cryptauth_gcm_manager.h"
#include "chromeos/services/device_sync/proto/cryptauth_api.pb.h"
-#include "components/cryptauth/cryptauth_enrollment_manager.h"
-#include "components/cryptauth/cryptauth_gcm_manager.h"
-#include "components/cryptauth/sync_scheduler.h"
+#include "chromeos/services/device_sync/sync_scheduler.h"
class PrefService;
@@ -23,10 +23,15 @@
}
namespace cryptauth {
+class SecureMessageDelegate;
+} // namespace cryptauth
+
+namespace chromeos {
+
+namespace device_sync {
class CryptAuthEnroller;
class CryptAuthEnrollerFactory;
-class SecureMessageDelegate;
// Concrete CryptAuthEnrollmentManager implementation.
class CryptAuthEnrollmentManagerImpl : public CryptAuthEnrollmentManager,
@@ -38,8 +43,9 @@
static std::unique_ptr<CryptAuthEnrollmentManager> NewInstance(
base::Clock* clock,
std::unique_ptr<CryptAuthEnrollerFactory> enroller_factory,
- std::unique_ptr<SecureMessageDelegate> secure_message_delegate,
- const GcmDeviceInfo& device_info,
+ std::unique_ptr<cryptauth::SecureMessageDelegate>
+ secure_message_delegate,
+ const cryptauth::GcmDeviceInfo& device_info,
CryptAuthGCMManager* gcm_manager,
PrefService* pref_service);
@@ -50,8 +56,9 @@
virtual std::unique_ptr<CryptAuthEnrollmentManager> BuildInstance(
base::Clock* clock,
std::unique_ptr<CryptAuthEnrollerFactory> enroller_factory,
- std::unique_ptr<SecureMessageDelegate> secure_message_delegate,
- const GcmDeviceInfo& device_info,
+ std::unique_ptr<cryptauth::SecureMessageDelegate>
+ secure_message_delegate,
+ const cryptauth::GcmDeviceInfo& device_info,
CryptAuthGCMManager* gcm_manager,
PrefService* pref_service);
@@ -63,7 +70,8 @@
// CryptAuthEnrollmentManager:
void Start() override;
- void ForceEnrollmentNow(InvocationReason invocation_reason) override;
+ void ForceEnrollmentNow(
+ cryptauth::InvocationReason invocation_reason) override;
bool IsEnrollmentValid() const override;
base::Time GetLastEnrollmentTime() const override;
base::TimeDelta GetTimeToNextAttempt() const override;
@@ -89,8 +97,8 @@
CryptAuthEnrollmentManagerImpl(
base::Clock* clock,
std::unique_ptr<CryptAuthEnrollerFactory> enroller_factory,
- std::unique_ptr<SecureMessageDelegate> secure_message_delegate,
- const GcmDeviceInfo& device_info,
+ std::unique_ptr<cryptauth::SecureMessageDelegate> secure_message_delegate,
+ const cryptauth::GcmDeviceInfo& device_info,
CryptAuthGCMManager* gcm_manager,
PrefService* pref_service);
@@ -128,10 +136,10 @@
// The SecureMessageDelegate used to generate the user's keypair if it does
// not already exist.
- std::unique_ptr<SecureMessageDelegate> secure_message_delegate_;
+ std::unique_ptr<cryptauth::SecureMessageDelegate> secure_message_delegate_;
// The local device information to upload to CryptAuth.
- const GcmDeviceInfo device_info_;
+ const cryptauth::GcmDeviceInfo device_info_;
// Used to perform GCM registrations and also notifies when GCM push messages
// trigger re-enrollments. Not owned and must outlive this instance.
@@ -158,6 +166,8 @@
DISALLOW_COPY_AND_ASSIGN(CryptAuthEnrollmentManagerImpl);
};
-} // namespace cryptauth
+} // namespace device_sync
-#endif // COMPONENTS_CRYPTAUTH_CRYPTAUTH_ENROLLMENT_MANAGER_IMPL_H_
+} // namespace chromeos
+
+#endif // CHROMEOS_SERVICES_DEVICE_SYNC_CRYPTAUTH_ENROLLMENT_MANAGER_IMPL_H_
diff --git a/components/cryptauth/cryptauth_enrollment_manager_impl_unittest.cc b/chromeos/services/device_sync/cryptauth_enrollment_manager_impl_unittest.cc
similarity index 85%
rename from components/cryptauth/cryptauth_enrollment_manager_impl_unittest.cc
rename to chromeos/services/device_sync/cryptauth_enrollment_manager_impl_unittest.cc
index 1fc83bf..c7f96385 100644
--- a/components/cryptauth/cryptauth_enrollment_manager_impl_unittest.cc
+++ b/chromeos/services/device_sync/cryptauth_enrollment_manager_impl_unittest.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/cryptauth/cryptauth_enrollment_manager_impl.h"
+#include "chromeos/services/device_sync/cryptauth_enrollment_manager_impl.h"
#include <memory>
#include <utility>
@@ -14,11 +14,11 @@
#include "base/test/simple_test_clock.h"
#include "base/time/clock.h"
#include "base/time/time.h"
-#include "components/cryptauth/cryptauth_enroller.h"
-#include "components/cryptauth/fake_cryptauth_gcm_manager.h"
+#include "chromeos/services/device_sync/cryptauth_enroller.h"
+#include "chromeos/services/device_sync/fake_cryptauth_gcm_manager.h"
+#include "chromeos/services/device_sync/mock_sync_scheduler.h"
+#include "chromeos/services/device_sync/pref_names.h"
#include "components/cryptauth/fake_secure_message_delegate.h"
-#include "components/cryptauth/mock_sync_scheduler.h"
-#include "components/cryptauth/pref_names.h"
#include "components/prefs/testing_pref_service.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -28,7 +28,9 @@
using ::testing::Return;
using ::testing::SaveArg;
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
namespace {
@@ -61,8 +63,8 @@
MOCK_METHOD5(Enroll,
void(const std::string& user_public_key,
const std::string& user_private_key,
- const GcmDeviceInfo& device_info,
- InvocationReason invocation_reason,
+ const cryptauth::GcmDeviceInfo& device_info,
+ cryptauth::InvocationReason invocation_reason,
const EnrollmentFinishedCallback& callback));
private:
@@ -102,8 +104,8 @@
TestCryptAuthEnrollmentManager(
base::Clock* clock,
std::unique_ptr<CryptAuthEnrollerFactory> enroller_factory,
- std::unique_ptr<SecureMessageDelegate> secure_message_delegate,
- const GcmDeviceInfo& device_info,
+ std::unique_ptr<cryptauth::SecureMessageDelegate> secure_message_delegate,
+ const cryptauth::GcmDeviceInfo& device_info,
CryptAuthGCMManager* gcm_manager,
PrefService* pref_service)
: CryptAuthEnrollmentManagerImpl(clock,
@@ -139,14 +141,14 @@
} // namespace
-class CryptAuthEnrollmentManagerImplTest
+class DeviceSyncCryptAuthEnrollmentManagerImplTest
: public testing::Test,
public CryptAuthEnrollmentManager::Observer {
protected:
- CryptAuthEnrollmentManagerImplTest()
+ DeviceSyncCryptAuthEnrollmentManagerImplTest()
: public_key_(kUserPublicKey),
enroller_factory_(new MockCryptAuthEnrollerFactory()),
- secure_message_delegate_(new FakeSecureMessageDelegate()),
+ secure_message_delegate_(new cryptauth::FakeSecureMessageDelegate()),
gcm_manager_(kGCMRegistrationId),
enrollment_manager_(&clock_,
base::WrapUnique(enroller_factory_),
@@ -173,7 +175,7 @@
std::make_unique<base::Value>(kLastEnrollmentTimeSeconds));
pref_service_.SetUserPref(
prefs::kCryptAuthEnrollmentReason,
- std::make_unique<base::Value>(INVOCATION_REASON_UNKNOWN));
+ std::make_unique<base::Value>(cryptauth::INVOCATION_REASON_UNKNOWN));
std::string public_key_b64, private_key_b64;
base::Base64UrlEncode(public_key_,
@@ -211,7 +213,7 @@
// Simulates firing the SyncScheduler to trigger an enrollment attempt.
CryptAuthEnroller::EnrollmentFinishedCallback FireSchedulerForEnrollment(
- InvocationReason expected_invocation_reason) {
+ cryptauth::InvocationReason expected_invocation_reason) {
CryptAuthEnroller::EnrollmentFinishedCallback completion_callback;
EXPECT_CALL(
*next_cryptauth_enroller(),
@@ -247,9 +249,9 @@
MockCryptAuthEnrollerFactory* enroller_factory_;
// Ownered by |enrollment_manager_|.
- FakeSecureMessageDelegate* secure_message_delegate_;
+ cryptauth::FakeSecureMessageDelegate* secure_message_delegate_;
- GcmDeviceInfo device_info_;
+ cryptauth::GcmDeviceInfo device_info_;
TestingPrefServiceSimple pref_service_;
@@ -257,10 +259,10 @@
TestCryptAuthEnrollmentManager enrollment_manager_;
- DISALLOW_COPY_AND_ASSIGN(CryptAuthEnrollmentManagerImplTest);
+ DISALLOW_COPY_AND_ASSIGN(DeviceSyncCryptAuthEnrollmentManagerImplTest);
};
-TEST_F(CryptAuthEnrollmentManagerImplTest, RegisterPrefs) {
+TEST_F(DeviceSyncCryptAuthEnrollmentManagerImplTest, RegisterPrefs) {
TestingPrefServiceSimple pref_service;
CryptAuthEnrollmentManager::RegisterPrefs(pref_service.registry());
EXPECT_TRUE(pref_service.FindPreference(
@@ -270,7 +272,7 @@
EXPECT_TRUE(pref_service.FindPreference(prefs::kCryptAuthEnrollmentReason));
}
-TEST_F(CryptAuthEnrollmentManagerImplTest, GetEnrollmentState) {
+TEST_F(DeviceSyncCryptAuthEnrollmentManagerImplTest, GetEnrollmentState) {
enrollment_manager_.Start();
ON_CALL(*sync_scheduler(), GetStrategy())
@@ -295,7 +297,7 @@
EXPECT_FALSE(enrollment_manager_.IsEnrollmentInProgress());
}
-TEST_F(CryptAuthEnrollmentManagerImplTest, InitWithDefaultPrefs) {
+TEST_F(DeviceSyncCryptAuthEnrollmentManagerImplTest, InitWithDefaultPrefs) {
base::SimpleTestClock clock;
clock.SetNow(base::Time::FromDoubleT(kInitialTimeNowSeconds));
base::TimeDelta elapsed_time = clock.Now() - base::Time::FromDoubleT(0);
@@ -305,7 +307,7 @@
TestCryptAuthEnrollmentManager enrollment_manager(
&clock, std::make_unique<MockCryptAuthEnrollerFactory>(),
- std::make_unique<FakeSecureMessageDelegate>(), device_info_,
+ std::make_unique<cryptauth::FakeSecureMessageDelegate>(), device_info_,
&gcm_manager_, &pref_service);
EXPECT_CALL(
@@ -317,7 +319,7 @@
EXPECT_TRUE(enrollment_manager.GetLastEnrollmentTime().is_null());
}
-TEST_F(CryptAuthEnrollmentManagerImplTest, InitWithExistingPrefs) {
+TEST_F(DeviceSyncCryptAuthEnrollmentManagerImplTest, InitWithExistingPrefs) {
EXPECT_CALL(
*sync_scheduler(),
Start(clock_.Now() - base::Time::FromDoubleT(kLastEnrollmentTimeSeconds),
@@ -329,7 +331,8 @@
enrollment_manager_.GetLastEnrollmentTime());
}
-TEST_F(CryptAuthEnrollmentManagerImplTest, InitWithExpiredEnrollment) {
+TEST_F(DeviceSyncCryptAuthEnrollmentManagerImplTest,
+ InitWithExpiredEnrollment) {
pref_service_.SetUserPref(
prefs::kCryptAuthEnrollmentLastEnrollmentTimeSeconds,
std::make_unique<base::Value>(kLastExpiredEnrollmentTimeSeconds));
@@ -345,14 +348,15 @@
enrollment_manager_.GetLastEnrollmentTime());
}
-TEST_F(CryptAuthEnrollmentManagerImplTest, ForceEnrollment) {
+TEST_F(DeviceSyncCryptAuthEnrollmentManagerImplTest, ForceEnrollment) {
enrollment_manager_.Start();
EXPECT_CALL(*sync_scheduler(), ForceSync());
- enrollment_manager_.ForceEnrollmentNow(INVOCATION_REASON_SERVER_INITIATED);
+ enrollment_manager_.ForceEnrollmentNow(
+ cryptauth::INVOCATION_REASON_SERVER_INITIATED);
auto completion_callback =
- FireSchedulerForEnrollment(INVOCATION_REASON_SERVER_INITIATED);
+ FireSchedulerForEnrollment(cryptauth::INVOCATION_REASON_SERVER_INITIATED);
clock_.SetNow(base::Time::FromDoubleT(kLaterTimeNow));
EXPECT_CALL(*this, OnEnrollmentFinishedProxy(true));
@@ -360,7 +364,8 @@
EXPECT_EQ(clock_.Now(), enrollment_manager_.GetLastEnrollmentTime());
}
-TEST_F(CryptAuthEnrollmentManagerImplTest, EnrollmentFailsThenSucceeds) {
+TEST_F(DeviceSyncCryptAuthEnrollmentManagerImplTest,
+ EnrollmentFailsThenSucceeds) {
enrollment_manager_.Start();
base::Time old_enrollment_time = enrollment_manager_.GetLastEnrollmentTime();
@@ -368,7 +373,7 @@
ON_CALL(*sync_scheduler(), GetStrategy())
.WillByDefault(Return(SyncScheduler::Strategy::PERIODIC_REFRESH));
auto completion_callback =
- FireSchedulerForEnrollment(INVOCATION_REASON_PERIODIC);
+ FireSchedulerForEnrollment(cryptauth::INVOCATION_REASON_PERIODIC);
clock_.SetNow(base::Time::FromDoubleT(kLaterTimeNow));
EXPECT_CALL(*this, OnEnrollmentFinishedProxy(false));
completion_callback.Run(false);
@@ -380,7 +385,7 @@
ON_CALL(*sync_scheduler(), GetStrategy())
.WillByDefault(Return(SyncScheduler::Strategy::AGGRESSIVE_RECOVERY));
completion_callback =
- FireSchedulerForEnrollment(INVOCATION_REASON_FAILURE_RECOVERY);
+ FireSchedulerForEnrollment(cryptauth::INVOCATION_REASON_FAILURE_RECOVERY);
clock_.SetNow(base::Time::FromDoubleT(kLaterTimeNow + 30));
EXPECT_CALL(*this, OnEnrollmentFinishedProxy(true));
completion_callback.Run(true);
@@ -389,7 +394,8 @@
prefs::kCryptAuthEnrollmentIsRecoveringFromFailure));
}
-TEST_F(CryptAuthEnrollmentManagerImplTest, EnrollmentSucceedsForFirstTime) {
+TEST_F(DeviceSyncCryptAuthEnrollmentManagerImplTest,
+ EnrollmentSucceedsForFirstTime) {
// Initialize |enrollment_manager_|.
ON_CALL(*sync_scheduler(), GetStrategy())
.WillByDefault(Return(SyncScheduler::Strategy::PERIODIC_REFRESH));
@@ -409,9 +415,9 @@
// Complete GCM registration successfully, and expect an enrollment.
CryptAuthEnroller::EnrollmentFinishedCallback enrollment_callback;
- EXPECT_CALL(
- *next_cryptauth_enroller(),
- Enroll(public_key_, private_key_, _, INVOCATION_REASON_INITIALIZATION, _))
+ EXPECT_CALL(*next_cryptauth_enroller(),
+ Enroll(public_key_, private_key_, _,
+ cryptauth::INVOCATION_REASON_INITIALIZATION, _))
.WillOnce(SaveArg<4>(&enrollment_callback));
ASSERT_TRUE(gcm_manager_.registration_in_progress());
gcm_manager_.CompleteRegistration(kGCMRegistrationId);
@@ -429,7 +435,7 @@
EXPECT_EQ(private_key_, enrollment_manager_.GetUserPrivateKey());
}
-TEST_F(CryptAuthEnrollmentManagerImplTest, GCMRegistrationFails) {
+TEST_F(DeviceSyncCryptAuthEnrollmentManagerImplTest, GCMRegistrationFails) {
// Initialize |enrollment_manager_|.
ON_CALL(*sync_scheduler(), GetStrategy())
.WillByDefault(Return(SyncScheduler::Strategy::PERIODIC_REFRESH));
@@ -448,16 +454,18 @@
gcm_manager_.CompleteRegistration(std::string());
}
-TEST_F(CryptAuthEnrollmentManagerImplTest, ReenrollOnGCMPushMessage) {
+TEST_F(DeviceSyncCryptAuthEnrollmentManagerImplTest, ReenrollOnGCMPushMessage) {
enrollment_manager_.Start();
// Simulate receiving a GCM push message, forcing the device to re-enroll.
gcm_manager_.PushReenrollMessage();
auto completion_callback =
- FireSchedulerForEnrollment(INVOCATION_REASON_SERVER_INITIATED);
+ FireSchedulerForEnrollment(cryptauth::INVOCATION_REASON_SERVER_INITIATED);
EXPECT_CALL(*this, OnEnrollmentFinishedProxy(true));
completion_callback.Run(true);
}
-} // namespace cryptauth
+} // namespace device_sync
+
+} // namespace chromeos
diff --git a/chromeos/services/device_sync/cryptauth_gcm_manager.cc b/chromeos/services/device_sync/cryptauth_gcm_manager.cc
new file mode 100644
index 0000000..fe101f6
--- /dev/null
+++ b/chromeos/services/device_sync/cryptauth_gcm_manager.cc
@@ -0,0 +1,30 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chromeos/services/device_sync/cryptauth_gcm_manager.h"
+
+#include "chromeos/services/device_sync/pref_names.h"
+#include "components/prefs/pref_registry_simple.h"
+
+namespace chromeos {
+
+namespace device_sync {
+
+CryptAuthGCMManager::Observer::~Observer() {}
+
+void CryptAuthGCMManager::Observer::OnGCMRegistrationResult(bool success) {}
+
+void CryptAuthGCMManager::Observer::OnReenrollMessage() {}
+
+void CryptAuthGCMManager::Observer::OnResyncMessage() {}
+
+// static.
+void CryptAuthGCMManager::RegisterPrefs(PrefRegistrySimple* registry) {
+ registry->RegisterStringPref(prefs::kCryptAuthGCMRegistrationId,
+ std::string());
+}
+
+} // namespace device_sync
+
+} // namespace chromeos
diff --git a/components/cryptauth/cryptauth_gcm_manager.h b/chromeos/services/device_sync/cryptauth_gcm_manager.h
similarity index 86%
rename from components/cryptauth/cryptauth_gcm_manager.h
rename to chromeos/services/device_sync/cryptauth_gcm_manager.h
index 5be472da..35effb0 100644
--- a/components/cryptauth/cryptauth_gcm_manager.h
+++ b/chromeos/services/device_sync/cryptauth_gcm_manager.h
@@ -2,14 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef COMPONENTS_CRYPTAUTH_CRYPTAUTH_GCM_MANAGER_H_
-#define COMPONENTS_CRYPTAUTH_CRYPTAUTH_GCM_MANAGER_H_
+#ifndef CHROMEOS_SERVICES_DEVICE_SYNC_CRYPTAUTH_GCM_MANAGER_H_
+#define CHROMEOS_SERVICES_DEVICE_SYNC_CRYPTAUTH_GCM_MANAGER_H_
#include <string>
class PrefRegistrySimple;
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
// Interface for the manager controlling GCM registrations and handling GCM push
// messages for CryptAuth. CryptAuth sends GCM messages to request the local
@@ -59,6 +61,8 @@
virtual void RemoveObserver(Observer* observer) = 0;
};
-} // namespace cryptauth
+} // namespace device_sync
-#endif // COMPONENTS_CRYPTAUTH_CRYPTAUTH_GCM_MANAGER_H_
+} // namespace chromeos
+
+#endif // CHROMEOS_SERVICES_DEVICE_SYNC_CRYPTAUTH_GCM_MANAGER_H_
diff --git a/components/cryptauth/cryptauth_gcm_manager_impl.cc b/chromeos/services/device_sync/cryptauth_gcm_manager_impl.cc
similarity index 94%
rename from components/cryptauth/cryptauth_gcm_manager_impl.cc
rename to chromeos/services/device_sync/cryptauth_gcm_manager_impl.cc
index d71fd6e..4270913d 100644
--- a/components/cryptauth/cryptauth_gcm_manager_impl.cc
+++ b/chromeos/services/device_sync/cryptauth_gcm_manager_impl.cc
@@ -2,17 +2,19 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/cryptauth/cryptauth_gcm_manager_impl.h"
+#include "chromeos/services/device_sync/cryptauth_gcm_manager_impl.h"
#include "base/bind.h"
#include "base/memory/ptr_util.h"
#include "base/strings/string_util.h"
#include "chromeos/components/proximity_auth/logging/logging.h"
-#include "components/cryptauth/pref_names.h"
+#include "chromeos/services/device_sync/pref_names.h"
#include "components/gcm_driver/gcm_driver.h"
#include "components/prefs/pref_service.h"
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
namespace {
@@ -64,8 +66,7 @@
: gcm_driver_(gcm_driver),
pref_service_(pref_service),
registration_in_progress_(false),
- weak_ptr_factory_(this) {
-}
+ weak_ptr_factory_(this) {}
CryptAuthGCMManagerImpl::~CryptAuthGCMManagerImpl() {
if (gcm_driver_->GetAppHandler(kCryptAuthGCMAppId) == this)
@@ -109,8 +110,7 @@
observers_.RemoveObserver(observer);
}
-void CryptAuthGCMManagerImpl::ShutdownHandler() {
-}
+void CryptAuthGCMManagerImpl::ShutdownHandler() {}
void CryptAuthGCMManagerImpl::OnStoreReset() {
// We will automatically re-register to GCM and re-enroll the new registration
@@ -148,8 +148,7 @@
}
}
-void CryptAuthGCMManagerImpl::OnMessagesDeleted(const std::string& app_id) {
-}
+void CryptAuthGCMManagerImpl::OnMessagesDeleted(const std::string& app_id) {}
void CryptAuthGCMManagerImpl::OnSendError(
const std::string& app_id,
@@ -182,4 +181,6 @@
observer.OnGCMRegistrationResult(true);
}
-} // namespace cryptauth
+} // namespace device_sync
+
+} // namespace chromeos
diff --git a/components/cryptauth/cryptauth_gcm_manager_impl.h b/chromeos/services/device_sync/cryptauth_gcm_manager_impl.h
similarity index 87%
rename from components/cryptauth/cryptauth_gcm_manager_impl.h
rename to chromeos/services/device_sync/cryptauth_gcm_manager_impl.h
index ad97776..e539ec0 100644
--- a/components/cryptauth/cryptauth_gcm_manager_impl.h
+++ b/chromeos/services/device_sync/cryptauth_gcm_manager_impl.h
@@ -2,13 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef COMPONENTS_CRYPTAUTH_CRYPTAUTH_GCM_MANAGER_IMPL_H_
-#define COMPONENTS_CRYPTAUTH_CRYPTAUTH_GCM_MANAGER_IMPL_H_
+#ifndef CHROMEOS_SERVICES_DEVICE_SYNC_CRYPTAUTH_GCM_MANAGER_IMPL_H_
+#define CHROMEOS_SERVICES_DEVICE_SYNC_CRYPTAUTH_GCM_MANAGER_IMPL_H_
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
-#include "components/cryptauth/cryptauth_gcm_manager.h"
+#include "chromeos/services/device_sync/cryptauth_gcm_manager.h"
#include "components/gcm_driver/common/gcm_messages.h"
#include "components/gcm_driver/gcm_app_handler.h"
#include "components/gcm_driver/gcm_client.h"
@@ -19,7 +19,9 @@
class GCMDriver;
};
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
// Implementation of CryptAuthGCMManager.
class CryptAuthGCMManagerImpl : public CryptAuthGCMManager,
@@ -63,7 +65,7 @@
PrefService* pref_service);
private:
- friend class CryptAuthGCMManagerImplTest;
+ friend class DeviceSyncCryptAuthGCMManagerImplTest;
// GCMAppHandler:
void ShutdownHandler() override;
@@ -97,6 +99,8 @@
DISALLOW_COPY_AND_ASSIGN(CryptAuthGCMManagerImpl);
};
-} // namespace cryptauth
+} // namespace device_sync
-#endif // COMPONENTS_CRYPTAUTH_CRYPTAUTH_GCM_MANAGER_IMPL_H_
+} // namespace chromeos
+
+#endif // CHROMEOS_SERVICES_DEVICE_SYNC_CRYPTAUTH_GCM_MANAGER_IMPL_H_
diff --git a/components/cryptauth/cryptauth_gcm_manager_impl_unittest.cc b/chromeos/services/device_sync/cryptauth_gcm_manager_impl_unittest.cc
similarity index 86%
rename from components/cryptauth/cryptauth_gcm_manager_impl_unittest.cc
rename to chromeos/services/device_sync/cryptauth_gcm_manager_impl_unittest.cc
index 473a24c0..5d9ce30 100644
--- a/components/cryptauth/cryptauth_gcm_manager_impl_unittest.cc
+++ b/chromeos/services/device_sync/cryptauth_gcm_manager_impl_unittest.cc
@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/cryptauth/cryptauth_gcm_manager_impl.h"
+#include "chromeos/services/device_sync/cryptauth_gcm_manager_impl.h"
#include "base/macros.h"
-#include "components/cryptauth/pref_names.h"
+#include "chromeos/services/device_sync/pref_names.h"
#include "components/gcm_driver/fake_gcm_driver.h"
#include "components/gcm_driver/gcm_client.h"
#include "components/prefs/testing_pref_service.h"
@@ -15,7 +15,9 @@
using ::testing::_;
using ::testing::SaveArg;
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
namespace {
@@ -47,11 +49,11 @@
} // namespace
-class CryptAuthGCMManagerImplTest
+class DeviceSyncCryptAuthGCMManagerImplTest
: public testing::Test,
public CryptAuthGCMManager::Observer {
protected:
- CryptAuthGCMManagerImplTest()
+ DeviceSyncCryptAuthGCMManagerImplTest()
: gcm_manager_(&gcm_driver_, &pref_service_) {}
// testing::Test:
@@ -98,22 +100,22 @@
CryptAuthGCMManagerImpl gcm_manager_;
- DISALLOW_COPY_AND_ASSIGN(CryptAuthGCMManagerImplTest);
+ DISALLOW_COPY_AND_ASSIGN(DeviceSyncCryptAuthGCMManagerImplTest);
};
-TEST_F(CryptAuthGCMManagerImplTest, RegisterPrefs) {
+TEST_F(DeviceSyncCryptAuthGCMManagerImplTest, RegisterPrefs) {
TestingPrefServiceSimple pref_service;
CryptAuthGCMManager::RegisterPrefs(pref_service.registry());
EXPECT_TRUE(pref_service.FindPreference(prefs::kCryptAuthGCMRegistrationId));
}
-TEST_F(CryptAuthGCMManagerImplTest, RegistrationSucceeds) {
+TEST_F(DeviceSyncCryptAuthGCMManagerImplTest, RegistrationSucceeds) {
EXPECT_EQ(std::string(), gcm_manager_.GetRegistrationId());
RegisterWithGCM(gcm::GCMClient::SUCCESS);
EXPECT_EQ(kNewGCMRegistrationId, gcm_manager_.GetRegistrationId());
}
-TEST_F(CryptAuthGCMManagerImplTest,
+TEST_F(DeviceSyncCryptAuthGCMManagerImplTest,
RegistrationSucceedsWithExistingRegistration) {
pref_service_.SetString(prefs::kCryptAuthGCMRegistrationId,
kExistingGCMRegistrationId);
@@ -124,7 +126,7 @@
pref_service_.GetString(prefs::kCryptAuthGCMRegistrationId));
}
-TEST_F(CryptAuthGCMManagerImplTest, RegisterWithGCMFails) {
+TEST_F(DeviceSyncCryptAuthGCMManagerImplTest, RegisterWithGCMFails) {
EXPECT_EQ(std::string(), gcm_manager_.GetRegistrationId());
RegisterWithGCM(gcm::GCMClient::SERVER_ERROR);
EXPECT_EQ(std::string(), gcm_manager_.GetRegistrationId());
@@ -132,7 +134,7 @@
pref_service_.GetString(prefs::kCryptAuthGCMRegistrationId));
}
-TEST_F(CryptAuthGCMManagerImplTest,
+TEST_F(DeviceSyncCryptAuthGCMManagerImplTest,
RegisterWithGCMFailsWithExistingRegistration) {
pref_service_.SetString(prefs::kCryptAuthGCMRegistrationId,
kExistingGCMRegistrationId);
@@ -143,8 +145,7 @@
pref_service_.GetString(prefs::kCryptAuthGCMRegistrationId));
}
-TEST_F(CryptAuthGCMManagerImplTest,
- RegistrationFailsThenSucceeds) {
+TEST_F(DeviceSyncCryptAuthGCMManagerImplTest, RegistrationFailsThenSucceeds) {
EXPECT_EQ(std::string(), gcm_manager_.GetRegistrationId());
RegisterWithGCM(gcm::GCMClient::NETWORK_ERROR);
EXPECT_EQ(std::string(), gcm_manager_.GetRegistrationId());
@@ -152,7 +153,7 @@
EXPECT_EQ(kNewGCMRegistrationId, gcm_manager_.GetRegistrationId());
}
-TEST_F(CryptAuthGCMManagerImplTest, ConcurrentRegistrations) {
+TEST_F(DeviceSyncCryptAuthGCMManagerImplTest, ConcurrentRegistrations) {
// If multiple RegisterWithGCM() calls are made concurrently, only one
// registration attempt should actually be made.
EXPECT_CALL(gcm_driver_, RegisterImpl(kCryptAuthGCMAppId, _));
@@ -166,7 +167,7 @@
EXPECT_EQ(kNewGCMRegistrationId, gcm_manager_.GetRegistrationId());
}
-TEST_F(CryptAuthGCMManagerImplTest, ReenrollmentMessagesReceived) {
+TEST_F(DeviceSyncCryptAuthGCMManagerImplTest, ReenrollmentMessagesReceived) {
EXPECT_CALL(*this, OnReenrollMessageProxy()).Times(2);
gcm::IncomingMessage message;
@@ -181,7 +182,7 @@
gcm_app_handler->OnMessage(kCryptAuthGCMAppId, message);
}
-TEST_F(CryptAuthGCMManagerImplTest, ResyncMessagesReceived) {
+TEST_F(DeviceSyncCryptAuthGCMManagerImplTest, ResyncMessagesReceived) {
EXPECT_CALL(*this, OnResyncMessageProxy()).Times(2);
gcm::IncomingMessage message;
@@ -195,4 +196,6 @@
gcm_app_handler->OnMessage(kCryptAuthGCMAppId, message);
}
-} // namespace cryptauth
+} // namespace device_sync
+
+} // namespace chromeos
diff --git a/chromeos/services/device_sync/device_sync_impl.cc b/chromeos/services/device_sync/device_sync_impl.cc
index 18bd071..9f006dc 100644
--- a/chromeos/services/device_sync/device_sync_impl.cc
+++ b/chromeos/services/device_sync/device_sync_impl.cc
@@ -10,18 +10,18 @@
#include "base/optional.h"
#include "base/time/default_clock.h"
#include "chromeos/components/proximity_auth/logging/logging.h"
+#include "chromeos/services/device_sync/cryptauth_client_impl.h"
+#include "chromeos/services/device_sync/cryptauth_device_manager_impl.h"
#include "chromeos/services/device_sync/cryptauth_enroller_factory_impl.h"
+#include "chromeos/services/device_sync/cryptauth_enrollment_manager_impl.h"
+#include "chromeos/services/device_sync/cryptauth_gcm_manager_impl.h"
#include "chromeos/services/device_sync/device_sync_type_converters.h"
#include "chromeos/services/device_sync/proto/cryptauth_api.pb.h"
-#include "components/cryptauth/cryptauth_client_impl.h"
-#include "components/cryptauth/cryptauth_device_manager_impl.h"
-#include "components/cryptauth/cryptauth_enrollment_manager_impl.h"
-#include "components/cryptauth/cryptauth_gcm_manager_impl.h"
-#include "components/cryptauth/device_classifier_util.h"
-#include "components/cryptauth/gcm_device_info_provider.h"
-#include "components/cryptauth/remote_device_provider_impl.h"
+#include "chromeos/services/device_sync/proto/device_classifier_util.h"
+#include "chromeos/services/device_sync/public/cpp/gcm_device_info_provider.h"
+#include "chromeos/services/device_sync/remote_device_provider_impl.h"
+#include "chromeos/services/device_sync/software_feature_manager_impl.h"
#include "components/cryptauth/secure_message_delegate_impl.h"
-#include "components/cryptauth/software_feature_manager_impl.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "services/identity/public/cpp/identity_manager.h"
@@ -35,9 +35,9 @@
namespace {
void RegisterDeviceSyncPrefs(PrefRegistrySimple* registry) {
- cryptauth::CryptAuthGCMManager::RegisterPrefs(registry);
- cryptauth::CryptAuthDeviceManager::RegisterPrefs(registry);
- cryptauth::CryptAuthEnrollmentManager::RegisterPrefs(registry);
+ CryptAuthGCMManager::RegisterPrefs(registry);
+ CryptAuthDeviceManager::RegisterPrefs(registry);
+ CryptAuthEnrollmentManager::RegisterPrefs(registry);
}
constexpr base::TimeDelta kSetFeatureEnabledTimeout =
@@ -207,7 +207,7 @@
identity::IdentityManager* identity_manager,
gcm::GCMDriver* gcm_driver,
service_manager::Connector* connector,
- const cryptauth::GcmDeviceInfoProvider* gcm_device_info_provider,
+ const GcmDeviceInfoProvider* gcm_device_info_provider,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
std::unique_ptr<base::OneShotTimer> timer) {
return base::WrapUnique(new DeviceSyncImpl(
@@ -238,7 +238,7 @@
const std::string& device_public_key,
multidevice::SoftwareFeature software_feature,
bool enabled,
- cryptauth::RemoteDeviceProvider* remote_device_provider,
+ RemoteDeviceProvider* remote_device_provider,
SetSoftwareFeatureStateCallback callback)
: device_public_key_(device_public_key),
software_feature_(software_feature),
@@ -288,7 +288,7 @@
identity::IdentityManager* identity_manager,
gcm::GCMDriver* gcm_driver,
service_manager::Connector* connector,
- const cryptauth::GcmDeviceInfoProvider* gcm_device_info_provider,
+ const GcmDeviceInfoProvider* gcm_device_info_provider,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
base::Clock* clock,
std::unique_ptr<PrefConnectionDelegate> pref_connection_delegate,
@@ -560,27 +560,24 @@
// Initialize |cryptauth_gcm_manager_| and have it start listening for GCM
// tickles.
- cryptauth_gcm_manager_ =
- cryptauth::CryptAuthGCMManagerImpl::Factory::NewInstance(
- gcm_driver_, pref_service_.get());
+ cryptauth_gcm_manager_ = CryptAuthGCMManagerImpl::Factory::NewInstance(
+ gcm_driver_, pref_service_.get());
cryptauth_gcm_manager_->StartListening();
- cryptauth_client_factory_ =
- std::make_unique<cryptauth::CryptAuthClientFactoryImpl>(
- identity_manager_, url_loader_factory_,
- cryptauth::device_classifier_util::GetDeviceClassifier());
+ cryptauth_client_factory_ = std::make_unique<CryptAuthClientFactoryImpl>(
+ identity_manager_, url_loader_factory_,
+ device_classifier_util::GetDeviceClassifier());
// Initialize |crypauth_device_manager_| and start observing. Start() is not
// called yet since the device has not completed enrollment.
- cryptauth_device_manager_ =
- cryptauth::CryptAuthDeviceManagerImpl::Factory::NewInstance(
- clock_, cryptauth_client_factory_.get(), cryptauth_gcm_manager_.get(),
- pref_service_.get());
+ cryptauth_device_manager_ = CryptAuthDeviceManagerImpl::Factory::NewInstance(
+ clock_, cryptauth_client_factory_.get(), cryptauth_gcm_manager_.get(),
+ pref_service_.get());
// Initialize |cryptauth_enrollment_manager_| and start observing, then call
// Start() immediately to schedule enrollment.
cryptauth_enrollment_manager_ =
- cryptauth::CryptAuthEnrollmentManagerImpl::Factory::NewInstance(
+ CryptAuthEnrollmentManagerImpl::Factory::NewInstance(
clock_,
std::make_unique<CryptAuthEnrollerFactoryImpl>(
cryptauth_client_factory_.get()),
@@ -599,15 +596,13 @@
// with the CryptAuth back-end and can begin monitoring synced devices.
cryptauth_device_manager_->Start();
- remote_device_provider_ =
- cryptauth::RemoteDeviceProviderImpl::Factory::NewInstance(
- cryptauth_device_manager_.get(), primary_account_info_.account_id,
- cryptauth_enrollment_manager_->GetUserPrivateKey());
+ remote_device_provider_ = RemoteDeviceProviderImpl::Factory::NewInstance(
+ cryptauth_device_manager_.get(), primary_account_info_.account_id,
+ cryptauth_enrollment_manager_->GetUserPrivateKey());
remote_device_provider_->AddObserver(this);
- software_feature_manager_ =
- cryptauth::SoftwareFeatureManagerImpl::Factory::NewInstance(
- cryptauth_client_factory_.get());
+ software_feature_manager_ = SoftwareFeatureManagerImpl::Factory::NewInstance(
+ cryptauth_client_factory_.get());
status_ = Status::READY;
@@ -645,7 +640,7 @@
void DeviceSyncImpl::OnSetSoftwareFeatureStateError(
const base::UnguessableToken& request_id,
- cryptauth::NetworkRequestError error) {
+ NetworkRequestError error) {
auto it = id_to_pending_set_software_feature_request_map_.find(request_id);
if (it == id_to_pending_set_software_feature_request_map_.end()) {
PA_LOG(ERROR) << "DeviceSyncImpl::OnSetSoftwareFeatureStateError(): "
@@ -707,7 +702,7 @@
const base::RepeatingCallback<void(mojom::NetworkRequestResult,
mojom::FindEligibleDevicesResponsePtr)>&
callback,
- cryptauth::NetworkRequestError error) {
+ NetworkRequestError error) {
callback.Run(mojo::ConvertTo<mojom::NetworkRequestResult>(error),
nullptr /* response */);
diff --git a/chromeos/services/device_sync/device_sync_impl.h b/chromeos/services/device_sync/device_sync_impl.h
index 1b1fa4d..6e94d1e 100644
--- a/chromeos/services/device_sync/device_sync_impl.h
+++ b/chromeos/services/device_sync/device_sync_impl.h
@@ -10,12 +10,12 @@
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/unguessable_token.h"
+#include "chromeos/services/device_sync/cryptauth_enrollment_manager.h"
+#include "chromeos/services/device_sync/cryptauth_gcm_manager.h"
#include "chromeos/services/device_sync/device_sync_base.h"
+#include "chromeos/services/device_sync/network_request_error.h"
#include "chromeos/services/device_sync/public/mojom/device_sync.mojom.h"
-#include "components/cryptauth/cryptauth_enrollment_manager.h"
-#include "components/cryptauth/cryptauth_gcm_manager.h"
-#include "components/cryptauth/network_request_error.h"
-#include "components/cryptauth/remote_device_provider.h"
+#include "chromeos/services/device_sync/remote_device_provider.h"
#include "components/signin/core/browser/account_info.h"
#include "services/preferences/public/cpp/pref_service_factory.h"
#include "services/preferences/public/mojom/preferences.mojom.h"
@@ -27,13 +27,6 @@
class OneShotTimer;
} // namespace base
-namespace cryptauth {
-class CryptAuthClientFactory;
-class CryptAuthDeviceManager;
-class GcmDeviceInfoProvider;
-class SoftwareFeatureManager;
-} // namespace cryptauth
-
namespace gcm {
class GCMDriver;
} // namespace gcm
@@ -54,6 +47,11 @@
namespace device_sync {
+class CryptAuthClientFactory;
+class CryptAuthDeviceManager;
+class GcmDeviceInfoProvider;
+class SoftwareFeatureManager;
+
// Concrete DeviceSync implementation. When DeviceSyncImpl is constructed, it
// starts an initialization flow with the following steps:
// (1) Verify that the primary user is logged in with a valid account ID.
@@ -62,8 +60,8 @@
// (4) Check enrollment state; if not yet enrolled, enroll the device.
// (5) When enrollment is valid, listen for device sync updates.
class DeviceSyncImpl : public DeviceSyncBase,
- public cryptauth::CryptAuthEnrollmentManager::Observer,
- public cryptauth::RemoteDeviceProvider::Observer {
+ public CryptAuthEnrollmentManager::Observer,
+ public RemoteDeviceProvider::Observer {
public:
class Factory {
public:
@@ -78,7 +76,7 @@
identity::IdentityManager* identity_manager,
gcm::GCMDriver* gcm_driver,
service_manager::Connector* connector,
- const cryptauth::GcmDeviceInfoProvider* gcm_device_info_provider,
+ const GcmDeviceInfoProvider* gcm_device_info_provider,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
std::unique_ptr<base::OneShotTimer> timer);
@@ -104,10 +102,10 @@
FindEligibleDevicesCallback callback) override;
void GetDebugInfo(GetDebugInfoCallback callback) override;
- // cryptauth::CryptAuthEnrollmentManager::Observer:
+ // CryptAuthEnrollmentManager::Observer:
void OnEnrollmentFinished(bool success) override;
- // cryptauth::RemoteDeviceProvider::Observer:
+ // RemoteDeviceProvider::Observer:
void OnSyncDeviceListChanged() override;
private:
@@ -140,7 +138,7 @@
const std::string& device_public_key,
multidevice::SoftwareFeature software_feature,
bool enabled,
- cryptauth::RemoteDeviceProvider* remote_device_provider,
+ RemoteDeviceProvider* remote_device_provider,
SetSoftwareFeatureStateCallback callback);
~PendingSetSoftwareFeatureRequest();
@@ -160,7 +158,7 @@
std::string device_public_key_;
multidevice::SoftwareFeature software_feature_;
bool enabled_;
- cryptauth::RemoteDeviceProvider* remote_device_provider_;
+ RemoteDeviceProvider* remote_device_provider_;
SetSoftwareFeatureStateCallback callback_;
};
@@ -168,7 +166,7 @@
identity::IdentityManager* identity_manager,
gcm::GCMDriver* gcm_driver,
service_manager::Connector* connector,
- const cryptauth::GcmDeviceInfoProvider* gcm_device_info_provider,
+ const GcmDeviceInfoProvider* gcm_device_info_provider,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
base::Clock* clock,
std::unique_ptr<PrefConnectionDelegate> pref_connection_delegate,
@@ -188,7 +186,7 @@
void OnSetSoftwareFeatureStateSuccess();
void OnSetSoftwareFeatureStateError(const base::UnguessableToken& request_id,
- cryptauth::NetworkRequestError error);
+ NetworkRequestError error);
void OnFindEligibleDevicesSuccess(
const base::RepeatingCallback<
void(mojom::NetworkRequestResult,
@@ -199,7 +197,7 @@
const base::RepeatingCallback<
void(mojom::NetworkRequestResult,
mojom::FindEligibleDevicesResponsePtr)>& callback,
- cryptauth::NetworkRequestError error);
+ NetworkRequestError error);
// Note: If the timer is already running, StartSetSoftwareFeatureTimer()
// restarts it.
@@ -212,7 +210,7 @@
identity::IdentityManager* identity_manager_;
gcm::GCMDriver* gcm_driver_;
service_manager::Connector* connector_;
- const cryptauth::GcmDeviceInfoProvider* gcm_device_info_provider_;
+ const GcmDeviceInfoProvider* gcm_device_info_provider_;
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
base::Clock* clock_;
std::unique_ptr<PrefConnectionDelegate> pref_connection_delegate_;
@@ -225,13 +223,12 @@
std::unique_ptr<PendingSetSoftwareFeatureRequest>>
id_to_pending_set_software_feature_request_map_;
- std::unique_ptr<cryptauth::CryptAuthGCMManager> cryptauth_gcm_manager_;
- std::unique_ptr<cryptauth::CryptAuthClientFactory> cryptauth_client_factory_;
- std::unique_ptr<cryptauth::CryptAuthEnrollmentManager>
- cryptauth_enrollment_manager_;
- std::unique_ptr<cryptauth::CryptAuthDeviceManager> cryptauth_device_manager_;
- std::unique_ptr<cryptauth::RemoteDeviceProvider> remote_device_provider_;
- std::unique_ptr<cryptauth::SoftwareFeatureManager> software_feature_manager_;
+ std::unique_ptr<CryptAuthGCMManager> cryptauth_gcm_manager_;
+ std::unique_ptr<CryptAuthClientFactory> cryptauth_client_factory_;
+ std::unique_ptr<CryptAuthEnrollmentManager> cryptauth_enrollment_manager_;
+ std::unique_ptr<CryptAuthDeviceManager> cryptauth_device_manager_;
+ std::unique_ptr<RemoteDeviceProvider> remote_device_provider_;
+ std::unique_ptr<SoftwareFeatureManager> software_feature_manager_;
base::WeakPtrFactory<DeviceSyncImpl> weak_ptr_factory_;
diff --git a/chromeos/services/device_sync/device_sync_service.cc b/chromeos/services/device_sync/device_sync_service.cc
index f80b127..120564b6 100644
--- a/chromeos/services/device_sync/device_sync_service.cc
+++ b/chromeos/services/device_sync/device_sync_service.cc
@@ -17,7 +17,7 @@
DeviceSyncService::DeviceSyncService(
identity::IdentityManager* identity_manager,
gcm::GCMDriver* gcm_driver,
- const cryptauth::GcmDeviceInfoProvider* gcm_device_info_provider,
+ const GcmDeviceInfoProvider* gcm_device_info_provider,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
service_manager::mojom::ServiceRequest request)
: service_binding_(this, std::move(request)),
diff --git a/chromeos/services/device_sync/device_sync_service.h b/chromeos/services/device_sync/device_sync_service.h
index 9cae0d8..083eb19 100644
--- a/chromeos/services/device_sync/device_sync_service.h
+++ b/chromeos/services/device_sync/device_sync_service.h
@@ -13,10 +13,6 @@
#include "services/service_manager/public/cpp/service.h"
#include "services/service_manager/public/cpp/service_binding.h"
-namespace cryptauth {
-class GcmDeviceInfoProvider;
-} // namespace cryptauth
-
namespace gcm {
class GCMDriver;
} // namespace gcm
@@ -34,6 +30,7 @@
namespace device_sync {
class DeviceSyncBase;
+class GcmDeviceInfoProvider;
// Service which provides an implementation for
// device_sync::mojom::DeviceSync. This service creates one
@@ -43,7 +40,7 @@
DeviceSyncService(
identity::IdentityManager* identity_manager,
gcm::GCMDriver* gcm_driver,
- const cryptauth::GcmDeviceInfoProvider* gcm_device_info_provider,
+ const GcmDeviceInfoProvider* gcm_device_info_provider,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
service_manager::mojom::ServiceRequest request);
~DeviceSyncService() override;
@@ -59,7 +56,7 @@
identity::IdentityManager* identity_manager_;
gcm::GCMDriver* gcm_driver_;
- const cryptauth::GcmDeviceInfoProvider* gcm_device_info_provider_;
+ const GcmDeviceInfoProvider* gcm_device_info_provider_;
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
std::unique_ptr<DeviceSyncBase> device_sync_;
diff --git a/chromeos/services/device_sync/device_sync_service_unittest.cc b/chromeos/services/device_sync/device_sync_service_unittest.cc
index c2d1c1f..077ad2c 100644
--- a/chromeos/services/device_sync/device_sync_service_unittest.cc
+++ b/chromeos/services/device_sync/device_sync_service_unittest.cc
@@ -16,22 +16,22 @@
#include "base/timer/mock_timer.h"
#include "chromeos/components/multidevice/remote_device_test_util.h"
#include "chromeos/dbus/dbus_thread_manager.h"
+#include "chromeos/services/device_sync/cryptauth_device_manager_impl.h"
+#include "chromeos/services/device_sync/cryptauth_enrollment_manager_impl.h"
+#include "chromeos/services/device_sync/cryptauth_gcm_manager_impl.h"
#include "chromeos/services/device_sync/device_sync_impl.h"
#include "chromeos/services/device_sync/device_sync_service.h"
+#include "chromeos/services/device_sync/fake_cryptauth_device_manager.h"
+#include "chromeos/services/device_sync/fake_cryptauth_enrollment_manager.h"
+#include "chromeos/services/device_sync/fake_cryptauth_gcm_manager.h"
#include "chromeos/services/device_sync/fake_device_sync_observer.h"
+#include "chromeos/services/device_sync/fake_remote_device_provider.h"
+#include "chromeos/services/device_sync/fake_software_feature_manager.h"
+#include "chromeos/services/device_sync/public/cpp/fake_gcm_device_info_provider.h"
#include "chromeos/services/device_sync/public/mojom/constants.mojom.h"
#include "chromeos/services/device_sync/public/mojom/device_sync.mojom.h"
-#include "components/cryptauth/cryptauth_device_manager_impl.h"
-#include "components/cryptauth/cryptauth_enrollment_manager_impl.h"
-#include "components/cryptauth/cryptauth_gcm_manager_impl.h"
-#include "components/cryptauth/fake_cryptauth_device_manager.h"
-#include "components/cryptauth/fake_cryptauth_enrollment_manager.h"
-#include "components/cryptauth/fake_cryptauth_gcm_manager.h"
-#include "components/cryptauth/fake_gcm_device_info_provider.h"
-#include "components/cryptauth/fake_remote_device_provider.h"
-#include "components/cryptauth/fake_software_feature_manager.h"
-#include "components/cryptauth/remote_device_provider_impl.h"
-#include "components/cryptauth/software_feature_manager_impl.h"
+#include "chromeos/services/device_sync/remote_device_provider_impl.h"
+#include "chromeos/services/device_sync/software_feature_manager_impl.h"
#include "components/gcm_driver/fake_gcm_driver.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/testing_pref_service.h"
@@ -103,7 +103,7 @@
// Delegate which invokes the Closure provided to its constructor when a
// delegate function is invoked.
class FakeSoftwareFeatureManagerDelegate
- : public cryptauth::FakeSoftwareFeatureManager::Delegate {
+ : public FakeSoftwareFeatureManager::Delegate {
public:
explicit FakeSoftwareFeatureManagerDelegate(
base::Closure on_delegate_call_closure)
@@ -111,7 +111,7 @@
~FakeSoftwareFeatureManagerDelegate() override = default;
- // cryptauth::FakeSoftwareFeatureManager::Delegate:
+ // FakeSoftwareFeatureManager::Delegate:
void OnSetSoftwareFeatureStateCalled() override {
on_delegate_call_closure_.Run();
}
@@ -124,8 +124,7 @@
base::Closure on_delegate_call_closure_;
};
-class FakeCryptAuthGCMManagerFactory
- : public cryptauth::CryptAuthGCMManagerImpl::Factory {
+class FakeCryptAuthGCMManagerFactory : public CryptAuthGCMManagerImpl::Factory {
public:
FakeCryptAuthGCMManagerFactory(gcm::FakeGCMDriver* fake_gcm_driver,
TestingPrefServiceSimple* test_pref_service)
@@ -134,10 +133,10 @@
~FakeCryptAuthGCMManagerFactory() override = default;
- cryptauth::FakeCryptAuthGCMManager* instance() { return instance_; }
+ FakeCryptAuthGCMManager* instance() { return instance_; }
- // cryptauth::CryptAuthGCMManagerImpl::Factory:
- std::unique_ptr<cryptauth::CryptAuthGCMManager> BuildInstance(
+ // CryptAuthGCMManagerImpl::Factory:
+ std::unique_ptr<CryptAuthGCMManager> BuildInstance(
gcm::GCMDriver* gcm_driver,
PrefService* pref_service) override {
EXPECT_EQ(fake_gcm_driver_, gcm_driver);
@@ -146,7 +145,7 @@
// Only one instance is expected to be created per test.
EXPECT_FALSE(instance_);
- auto instance = std::make_unique<cryptauth::FakeCryptAuthGCMManager>(
+ auto instance = std::make_unique<FakeCryptAuthGCMManager>(
kTestCryptAuthGCMRegistrationId);
instance_ = instance.get();
@@ -157,11 +156,11 @@
gcm::FakeGCMDriver* fake_gcm_driver_;
TestingPrefServiceSimple* test_pref_service_;
- cryptauth::FakeCryptAuthGCMManager* instance_ = nullptr;
+ FakeCryptAuthGCMManager* instance_ = nullptr;
};
class FakeCryptAuthDeviceManagerFactory
- : public cryptauth::CryptAuthDeviceManagerImpl::Factory {
+ : public CryptAuthDeviceManagerImpl::Factory {
public:
FakeCryptAuthDeviceManagerFactory(
base::SimpleTestClock* simple_test_clock,
@@ -173,13 +172,13 @@
~FakeCryptAuthDeviceManagerFactory() override = default;
- cryptauth::FakeCryptAuthDeviceManager* instance() { return instance_; }
+ FakeCryptAuthDeviceManager* instance() { return instance_; }
- // cryptauth::CryptAuthDeviceManagerImpl::Factory:
- std::unique_ptr<cryptauth::CryptAuthDeviceManager> BuildInstance(
+ // CryptAuthDeviceManagerImpl::Factory:
+ std::unique_ptr<CryptAuthDeviceManager> BuildInstance(
base::Clock* clock,
- cryptauth::CryptAuthClientFactory* client_factory,
- cryptauth::CryptAuthGCMManager* gcm_manager,
+ CryptAuthClientFactory* client_factory,
+ CryptAuthGCMManager* gcm_manager,
PrefService* pref_service) override {
EXPECT_EQ(simple_test_clock_, clock);
EXPECT_EQ(fake_cryptauth_gcm_manager_factory_->instance(), gcm_manager);
@@ -188,7 +187,7 @@
// Only one instance is expected to be created per test.
EXPECT_FALSE(instance_);
- auto instance = std::make_unique<cryptauth::FakeCryptAuthDeviceManager>();
+ auto instance = std::make_unique<FakeCryptAuthDeviceManager>();
instance_ = instance.get();
return std::move(instance);
@@ -199,11 +198,11 @@
FakeCryptAuthGCMManagerFactory* fake_cryptauth_gcm_manager_factory_;
TestingPrefServiceSimple* test_pref_service_;
- cryptauth::FakeCryptAuthDeviceManager* instance_ = nullptr;
+ FakeCryptAuthDeviceManager* instance_ = nullptr;
};
class FakeCryptAuthEnrollmentManagerFactory
- : public cryptauth::CryptAuthEnrollmentManagerImpl::Factory {
+ : public CryptAuthEnrollmentManagerImpl::Factory {
public:
FakeCryptAuthEnrollmentManagerFactory(
base::SimpleTestClock* simple_test_clock,
@@ -221,15 +220,15 @@
device_already_enrolled_in_cryptauth;
}
- cryptauth::FakeCryptAuthEnrollmentManager* instance() { return instance_; }
+ FakeCryptAuthEnrollmentManager* instance() { return instance_; }
- // cryptauth::CryptAuthEnrollmentManagerImpl::Factory:
- std::unique_ptr<cryptauth::CryptAuthEnrollmentManager> BuildInstance(
+ // CryptAuthEnrollmentManagerImpl::Factory:
+ std::unique_ptr<CryptAuthEnrollmentManager> BuildInstance(
base::Clock* clock,
- std::unique_ptr<cryptauth::CryptAuthEnrollerFactory> enroller_factory,
+ std::unique_ptr<CryptAuthEnrollerFactory> enroller_factory,
std::unique_ptr<cryptauth::SecureMessageDelegate> secure_message_delegate,
const cryptauth::GcmDeviceInfo& device_info,
- cryptauth::CryptAuthGCMManager* gcm_manager,
+ CryptAuthGCMManager* gcm_manager,
PrefService* pref_service) override {
EXPECT_EQ(simple_test_clock_, clock);
EXPECT_EQ(kTestGcmDeviceInfoLongDeviceId, device_info.long_device_id());
@@ -239,8 +238,7 @@
// Only one instance is expected to be created per test.
EXPECT_FALSE(instance_);
- auto instance =
- std::make_unique<cryptauth::FakeCryptAuthEnrollmentManager>();
+ auto instance = std::make_unique<FakeCryptAuthEnrollmentManager>();
instance->set_user_public_key(kLocalDevicePublicKey);
instance->set_is_enrollment_valid(device_already_enrolled_in_cryptauth_);
instance_ = instance.get();
@@ -254,11 +252,11 @@
TestingPrefServiceSimple* test_pref_service_;
bool device_already_enrolled_in_cryptauth_ = false;
- cryptauth::FakeCryptAuthEnrollmentManager* instance_ = nullptr;
+ FakeCryptAuthEnrollmentManager* instance_ = nullptr;
};
class FakeRemoteDeviceProviderFactory
- : public cryptauth::RemoteDeviceProviderImpl::Factory {
+ : public RemoteDeviceProviderImpl::Factory {
public:
FakeRemoteDeviceProviderFactory(
const multidevice::RemoteDeviceList& initial_devices,
@@ -275,11 +273,11 @@
~FakeRemoteDeviceProviderFactory() override = default;
- cryptauth::FakeRemoteDeviceProvider* instance() { return instance_; }
+ FakeRemoteDeviceProvider* instance() { return instance_; }
- // cryptauth::RemoteDeviceProviderImpl::Factory:
- std::unique_ptr<cryptauth::RemoteDeviceProvider> BuildInstance(
- cryptauth::CryptAuthDeviceManager* device_manager,
+ // RemoteDeviceProviderImpl::Factory:
+ std::unique_ptr<RemoteDeviceProvider> BuildInstance(
+ CryptAuthDeviceManager* device_manager,
const std::string& user_id,
const std::string& user_private_key) override {
EXPECT_EQ(fake_cryptauth_device_manager_factory_->instance(),
@@ -292,7 +290,7 @@
// Only one instance is expected to be created per test.
EXPECT_FALSE(instance_);
- auto instance = std::make_unique<cryptauth::FakeRemoteDeviceProvider>();
+ auto instance = std::make_unique<FakeRemoteDeviceProvider>();
instance->set_synced_remote_devices(initial_devices_);
instance_ = instance.get();
@@ -307,31 +305,31 @@
FakeCryptAuthEnrollmentManagerFactory*
fake_cryptauth_enrollment_manager_factory_;
- cryptauth::FakeRemoteDeviceProvider* instance_ = nullptr;
+ FakeRemoteDeviceProvider* instance_ = nullptr;
};
class FakeSoftwareFeatureManagerFactory
- : public cryptauth::SoftwareFeatureManagerImpl::Factory {
+ : public SoftwareFeatureManagerImpl::Factory {
public:
FakeSoftwareFeatureManagerFactory() = default;
~FakeSoftwareFeatureManagerFactory() override = default;
- cryptauth::FakeSoftwareFeatureManager* instance() { return instance_; }
+ FakeSoftwareFeatureManager* instance() { return instance_; }
- // cryptauth::SoftwareFeatureManagerImpl::Factory:
- std::unique_ptr<cryptauth::SoftwareFeatureManager> BuildInstance(
- cryptauth::CryptAuthClientFactory* cryptauth_client_factory) override {
+ // SoftwareFeatureManagerImpl::Factory:
+ std::unique_ptr<SoftwareFeatureManager> BuildInstance(
+ CryptAuthClientFactory* cryptauth_client_factory) override {
// Only one instance is expected to be created per test.
EXPECT_FALSE(instance_);
- auto instance = std::make_unique<cryptauth::FakeSoftwareFeatureManager>();
+ auto instance = std::make_unique<FakeSoftwareFeatureManager>();
instance_ = instance.get();
return std::move(instance);
}
private:
- cryptauth::FakeSoftwareFeatureManager* instance_ = nullptr;
+ FakeSoftwareFeatureManager* instance_ = nullptr;
};
} // namespace
@@ -403,7 +401,7 @@
identity::IdentityManager* identity_manager,
gcm::GCMDriver* gcm_driver,
service_manager::Connector* connector,
- const cryptauth::GcmDeviceInfoProvider* gcm_device_info_provider,
+ const GcmDeviceInfoProvider* gcm_device_info_provider,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
std::unique_ptr<base::OneShotTimer> timer) override {
return base::WrapUnique(new DeviceSyncImpl(
@@ -445,21 +443,21 @@
fake_cryptauth_gcm_manager_factory_ =
std::make_unique<FakeCryptAuthGCMManagerFactory>(fake_gcm_driver_.get(),
test_pref_service_);
- cryptauth::CryptAuthGCMManagerImpl::Factory::SetInstanceForTesting(
+ CryptAuthGCMManagerImpl::Factory::SetInstanceForTesting(
fake_cryptauth_gcm_manager_factory_.get());
fake_cryptauth_device_manager_factory_ =
std::make_unique<FakeCryptAuthDeviceManagerFactory>(
simple_test_clock_.get(), fake_cryptauth_gcm_manager_factory_.get(),
test_pref_service_);
- cryptauth::CryptAuthDeviceManagerImpl::Factory::SetInstanceForTesting(
+ CryptAuthDeviceManagerImpl::Factory::SetInstanceForTesting(
fake_cryptauth_device_manager_factory_.get());
fake_cryptauth_enrollment_manager_factory_ =
std::make_unique<FakeCryptAuthEnrollmentManagerFactory>(
simple_test_clock_.get(), fake_cryptauth_gcm_manager_factory_.get(),
test_pref_service_);
- cryptauth::CryptAuthEnrollmentManagerImpl::Factory::SetInstanceForTesting(
+ CryptAuthEnrollmentManagerImpl::Factory::SetInstanceForTesting(
fake_cryptauth_enrollment_manager_factory_.get());
fake_remote_device_provider_factory_ =
@@ -467,12 +465,12 @@
test_devices_, identity_test_environment_->identity_manager(),
fake_cryptauth_device_manager_factory_.get(),
fake_cryptauth_enrollment_manager_factory_.get());
- cryptauth::RemoteDeviceProviderImpl::Factory::SetInstanceForTesting(
+ RemoteDeviceProviderImpl::Factory::SetInstanceForTesting(
fake_remote_device_provider_factory_.get());
fake_software_feature_manager_factory_ =
std::make_unique<FakeSoftwareFeatureManagerFactory>();
- cryptauth::SoftwareFeatureManagerImpl::Factory::SetInstanceForTesting(
+ SoftwareFeatureManagerImpl::Factory::SetInstanceForTesting(
fake_software_feature_manager_factory_.get());
auto fake_pref_connection_delegate =
@@ -491,8 +489,7 @@
fake_device_sync_impl_factory_.get());
fake_gcm_device_info_provider_ =
- std::make_unique<cryptauth::FakeGcmDeviceInfoProvider>(
- GetTestGcmDeviceInfo());
+ std::make_unique<FakeGcmDeviceInfoProvider>(GetTestGcmDeviceInfo());
auto shared_url_loader_factory =
base::MakeRefCounted<network::WeakWrapperSharedURLLoaderFactory>(
@@ -567,7 +564,7 @@
// Simulates an enrollment with success == |success|. If enrollment was not
// yet in progress before this call, it is started before it is completed.
void SimulateEnrollment(bool success) {
- cryptauth::FakeCryptAuthEnrollmentManager* enrollment_manager =
+ FakeCryptAuthEnrollmentManager* enrollment_manager =
fake_cryptauth_enrollment_manager_factory_->instance();
bool had_valid_enrollment_before_call =
@@ -595,18 +592,18 @@
void SimulateSync(bool success,
const multidevice::RemoteDeviceList& updated_devices =
multidevice::RemoteDeviceList()) {
- cryptauth::FakeCryptAuthDeviceManager* device_manager =
+ FakeCryptAuthDeviceManager* device_manager =
fake_cryptauth_device_manager_factory_->instance();
- cryptauth::FakeRemoteDeviceProvider* remote_device_provider =
+ FakeRemoteDeviceProvider* remote_device_provider =
fake_remote_device_provider_factory_->instance();
EXPECT_TRUE(device_manager->IsSyncInProgress());
device_manager->FinishActiveSync(
- success ? cryptauth::CryptAuthDeviceManager::SyncResult::SUCCESS
- : cryptauth::CryptAuthDeviceManager::SyncResult::FAILURE,
+ success ? CryptAuthDeviceManager::SyncResult::SUCCESS
+ : CryptAuthDeviceManager::SyncResult::FAILURE,
updated_devices.empty()
- ? cryptauth::CryptAuthDeviceManager::DeviceChangeResult::UNCHANGED
- : cryptauth::CryptAuthDeviceManager::DeviceChangeResult::CHANGED);
+ ? CryptAuthDeviceManager::DeviceChangeResult::UNCHANGED
+ : CryptAuthDeviceManager::DeviceChangeResult::CHANGED);
if (!updated_devices.empty()) {
remote_device_provider->set_synced_remote_devices(updated_devices);
@@ -648,16 +645,15 @@
base::MockOneShotTimer* mock_timer() { return mock_timer_; }
- cryptauth::FakeCryptAuthEnrollmentManager*
- fake_cryptauth_enrollment_manager() {
+ FakeCryptAuthEnrollmentManager* fake_cryptauth_enrollment_manager() {
return fake_cryptauth_enrollment_manager_factory_->instance();
}
- cryptauth::FakeCryptAuthDeviceManager* fake_cryptauth_device_manager() {
+ FakeCryptAuthDeviceManager* fake_cryptauth_device_manager() {
return fake_cryptauth_device_manager_factory_->instance();
}
- cryptauth::FakeSoftwareFeatureManager* fake_software_feature_manager() {
+ FakeSoftwareFeatureManager* fake_software_feature_manager() {
return fake_software_feature_manager_factory_->instance();
}
@@ -774,8 +770,7 @@
bool enabled,
bool is_exclusive) {
base::RunLoop run_loop;
- cryptauth::FakeSoftwareFeatureManager* manager =
- fake_software_feature_manager();
+ FakeSoftwareFeatureManager* manager = fake_software_feature_manager();
// If the manager has not yet been created, the service has not been
// initialized. SetSoftwareFeatureState() is expected to respond
@@ -805,8 +800,7 @@
void CallFindEligibleDevices(multidevice::SoftwareFeature software_feature) {
base::RunLoop run_loop;
- cryptauth::FakeSoftwareFeatureManager* manager =
- fake_software_feature_manager();
+ FakeSoftwareFeatureManager* manager = fake_software_feature_manager();
// If the manager has not yet been created, the service has not been
// initialized. FindEligibleDevices() is expected to respond synchronously
@@ -942,8 +936,7 @@
std::unique_ptr<identity::IdentityTestEnvironment> identity_test_environment_;
std::unique_ptr<gcm::FakeGCMDriver> fake_gcm_driver_;
- std::unique_ptr<cryptauth::FakeGcmDeviceInfoProvider>
- fake_gcm_device_info_provider_;
+ std::unique_ptr<FakeGcmDeviceInfoProvider> fake_gcm_device_info_provider_;
service_manager::TestConnectorFactory connector_factory_;
std::unique_ptr<DeviceSyncService> service_;
@@ -1253,8 +1246,7 @@
EXPECT_FALSE(GetLastSetSoftwareFeatureStateResponseAndReset());
// Now, invoke the error callback.
- set_software_calls[0]->error_callback.Run(
- cryptauth::NetworkRequestError::kOffline);
+ set_software_calls[0]->error_callback.Run(NetworkRequestError::kOffline);
base::RunLoop().RunUntilIdle();
auto last_response = GetLastSetSoftwareFeatureStateResponseAndReset();
EXPECT_TRUE(last_response);
@@ -1321,8 +1313,7 @@
EXPECT_FALSE(GetLastFindEligibleDevicesResponseAndReset());
// Now, invoke the error callback.
- find_eligible_calls[1]->error_callback.Run(
- cryptauth::NetworkRequestError::kOffline);
+ find_eligible_calls[1]->error_callback.Run(NetworkRequestError::kOffline);
base::RunLoop().RunUntilIdle();
last_response = GetLastFindEligibleDevicesResponseAndReset();
EXPECT_TRUE(last_response);
diff --git a/chromeos/services/device_sync/device_sync_type_converters.cc b/chromeos/services/device_sync/device_sync_type_converters.cc
index 8a29e7e..940e5e706 100644
--- a/chromeos/services/device_sync/device_sync_type_converters.cc
+++ b/chromeos/services/device_sync/device_sync_type_converters.cc
@@ -7,28 +7,28 @@
namespace mojo {
// static
-chromeos::device_sync::mojom::NetworkRequestResult TypeConverter<
- chromeos::device_sync::mojom::NetworkRequestResult,
- cryptauth::NetworkRequestError>::Convert(cryptauth::NetworkRequestError
- type) {
+chromeos::device_sync::mojom::NetworkRequestResult
+TypeConverter<chromeos::device_sync::mojom::NetworkRequestResult,
+ chromeos::device_sync::NetworkRequestError>::
+ Convert(chromeos::device_sync::NetworkRequestError type) {
switch (type) {
- case cryptauth::NetworkRequestError::kOffline:
+ case chromeos::device_sync::NetworkRequestError::kOffline:
return chromeos::device_sync::mojom::NetworkRequestResult::kOffline;
- case cryptauth::NetworkRequestError::kEndpointNotFound:
+ case chromeos::device_sync::NetworkRequestError::kEndpointNotFound:
return chromeos::device_sync::mojom::NetworkRequestResult::
kEndpointNotFound;
- case cryptauth::NetworkRequestError::kAuthenticationError:
+ case chromeos::device_sync::NetworkRequestError::kAuthenticationError:
return chromeos::device_sync::mojom::NetworkRequestResult::
kAuthenticationError;
- case cryptauth::NetworkRequestError::kBadRequest:
+ case chromeos::device_sync::NetworkRequestError::kBadRequest:
return chromeos::device_sync::mojom::NetworkRequestResult::kBadRequest;
- case cryptauth::NetworkRequestError::kResponseMalformed:
+ case chromeos::device_sync::NetworkRequestError::kResponseMalformed:
return chromeos::device_sync::mojom::NetworkRequestResult::
kResponseMalformed;
- case cryptauth::NetworkRequestError::kInternalServerError:
+ case chromeos::device_sync::NetworkRequestError::kInternalServerError:
return chromeos::device_sync::mojom::NetworkRequestResult::
kInternalServerError;
- case cryptauth::NetworkRequestError::kUnknown:
+ case chromeos::device_sync::NetworkRequestError::kUnknown:
return chromeos::device_sync::mojom::NetworkRequestResult::kUnknown;
}
}
diff --git a/chromeos/services/device_sync/device_sync_type_converters.h b/chromeos/services/device_sync/device_sync_type_converters.h
index 756b352..00dd32e 100644
--- a/chromeos/services/device_sync/device_sync_type_converters.h
+++ b/chromeos/services/device_sync/device_sync_type_converters.h
@@ -5,17 +5,17 @@
#ifndef CHROMEOS_SERVICES_DEVICE_SYNC_DEVICE_SYNC_TYPE_CONVERTERS_H_
#define CHROMEOS_SERVICES_DEVICE_SYNC_DEVICE_SYNC_TYPE_CONVERTERS_H_
+#include "chromeos/services/device_sync/network_request_error.h"
#include "chromeos/services/device_sync/public/mojom/device_sync.mojom.h"
-#include "components/cryptauth/network_request_error.h"
#include "mojo/public/cpp/bindings/type_converter.h"
namespace mojo {
template <>
struct TypeConverter<chromeos::device_sync::mojom::NetworkRequestResult,
- cryptauth::NetworkRequestError> {
+ chromeos::device_sync::NetworkRequestError> {
static chromeos::device_sync::mojom::NetworkRequestResult Convert(
- cryptauth::NetworkRequestError type);
+ chromeos::device_sync::NetworkRequestError type);
};
} // namespace mojo
diff --git a/components/cryptauth/fake_cryptauth_device_manager.cc b/chromeos/services/device_sync/fake_cryptauth_device_manager.cc
similarity index 70%
rename from components/cryptauth/fake_cryptauth_device_manager.cc
rename to chromeos/services/device_sync/fake_cryptauth_device_manager.cc
index a622c50..6106f92 100644
--- a/components/cryptauth/fake_cryptauth_device_manager.cc
+++ b/chromeos/services/device_sync/fake_cryptauth_device_manager.cc
@@ -2,11 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/cryptauth/fake_cryptauth_device_manager.h"
+#include "chromeos/services/device_sync/fake_cryptauth_device_manager.h"
#include <memory>
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
FakeCryptAuthDeviceManager::FakeCryptAuthDeviceManager() = default;
@@ -34,7 +36,7 @@
}
void FakeCryptAuthDeviceManager::ForceSyncNow(
- InvocationReason invocation_reason) {
+ cryptauth::InvocationReason invocation_reason) {
is_sync_in_progress_ = true;
NotifySyncStarted();
}
@@ -55,29 +57,31 @@
return is_recovering_from_failure_;
}
-std::vector<ExternalDeviceInfo> FakeCryptAuthDeviceManager::GetSyncedDevices()
- const {
+std::vector<cryptauth::ExternalDeviceInfo>
+FakeCryptAuthDeviceManager::GetSyncedDevices() const {
return synced_devices_;
}
-std::vector<ExternalDeviceInfo> FakeCryptAuthDeviceManager::GetUnlockKeys()
- const {
+std::vector<cryptauth::ExternalDeviceInfo>
+FakeCryptAuthDeviceManager::GetUnlockKeys() const {
return unlock_keys_;
}
-std::vector<ExternalDeviceInfo> FakeCryptAuthDeviceManager::GetPixelUnlockKeys()
- const {
+std::vector<cryptauth::ExternalDeviceInfo>
+FakeCryptAuthDeviceManager::GetPixelUnlockKeys() const {
return pixel_unlock_keys_;
}
-std::vector<ExternalDeviceInfo> FakeCryptAuthDeviceManager::GetTetherHosts()
- const {
+std::vector<cryptauth::ExternalDeviceInfo>
+FakeCryptAuthDeviceManager::GetTetherHosts() const {
return tether_hosts_;
}
-std::vector<ExternalDeviceInfo>
+std::vector<cryptauth::ExternalDeviceInfo>
FakeCryptAuthDeviceManager::GetPixelTetherHosts() const {
return pixel_tether_hosts_;
}
-} // namespace cryptauth
+} // namespace device_sync
+
+} // namespace chromeos
diff --git a/chromeos/services/device_sync/fake_cryptauth_device_manager.h b/chromeos/services/device_sync/fake_cryptauth_device_manager.h
new file mode 100644
index 0000000..d7cb6ec7
--- /dev/null
+++ b/chromeos/services/device_sync/fake_cryptauth_device_manager.h
@@ -0,0 +1,133 @@
+// Copyright 2018 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROMEOS_SERVICES_DEVICE_SYNC_FAKE_CRYPTAUTH_DEVICE_MANAGER_H_
+#define CHROMEOS_SERVICES_DEVICE_SYNC_FAKE_CRYPTAUTH_DEVICE_MANAGER_H_
+
+#include <memory>
+
+#include "base/macros.h"
+#include "chromeos/services/device_sync/cryptauth_device_manager.h"
+#include "chromeos/services/device_sync/proto/cryptauth_api.pb.h"
+
+namespace chromeos {
+
+namespace device_sync {
+
+// Test double for CryptAuthDeviceManager.
+class FakeCryptAuthDeviceManager : public CryptAuthDeviceManager {
+ public:
+ FakeCryptAuthDeviceManager();
+ ~FakeCryptAuthDeviceManager() override;
+
+ bool has_started() { return has_started_; }
+
+ void set_last_sync_time(base::Time last_sync_time) {
+ last_sync_time_ = last_sync_time;
+ }
+
+ void set_time_to_next_attempt(base::TimeDelta time_to_next_attempt) {
+ time_to_next_attempt_ = time_to_next_attempt;
+ }
+
+ std::vector<cryptauth::ExternalDeviceInfo>& synced_devices() {
+ return synced_devices_;
+ }
+
+ void set_synced_devices(
+ std::vector<cryptauth::ExternalDeviceInfo> synced_devices) {
+ synced_devices_ = synced_devices;
+ }
+
+ std::vector<cryptauth::ExternalDeviceInfo>& unlock_keys() {
+ return unlock_keys_;
+ }
+
+ void set_unlock_keys(
+ const std::vector<cryptauth::ExternalDeviceInfo>& unlock_keys) {
+ unlock_keys_ = unlock_keys;
+ }
+
+ std::vector<cryptauth::ExternalDeviceInfo>& pixel_unlock_keys() {
+ return pixel_unlock_keys_;
+ }
+
+ void set_pixel_unlock_keys(
+ const std::vector<cryptauth::ExternalDeviceInfo>& pixel_unlock_keys) {
+ pixel_unlock_keys_ = pixel_unlock_keys;
+ }
+
+ std::vector<cryptauth::ExternalDeviceInfo>& tether_hosts() {
+ return tether_hosts_;
+ }
+
+ void set_tether_hosts(
+ const std::vector<cryptauth::ExternalDeviceInfo>& tether_hosts) {
+ tether_hosts_ = tether_hosts;
+ }
+
+ std::vector<cryptauth::ExternalDeviceInfo>& pixel_tether_hosts() {
+ return pixel_tether_hosts_;
+ }
+
+ void set_pixel_tether_hosts(
+ const std::vector<cryptauth::ExternalDeviceInfo>& pixel_tether_hosts) {
+ pixel_tether_hosts_ = pixel_tether_hosts;
+ }
+
+ void set_is_recovering_from_failure(bool is_recovering_from_failure) {
+ is_recovering_from_failure_ = is_recovering_from_failure;
+ }
+
+ void set_is_sync_in_progress(bool is_sync_in_progress) {
+ is_sync_in_progress_ = is_sync_in_progress;
+ }
+
+ // Finishes the active sync; should only be called if a sync is in progress
+ // due to a previous call to ForceSyncNow(). If |sync_result| is SUCCESS,
+ // |sync_finish_time| will be stored as the last sync time and will be
+ // returned by future calls to GetLastSyncTime().
+ void FinishActiveSync(SyncResult sync_result,
+ DeviceChangeResult device_change_result,
+ base::Time sync_finish_time = base::Time());
+
+ // Make these functions public for testing.
+ using CryptAuthDeviceManager::NotifySyncFinished;
+ using CryptAuthDeviceManager::NotifySyncStarted;
+
+ // CryptAuthDeviceManager:
+ void Start() override;
+ void ForceSyncNow(cryptauth::InvocationReason invocation_reason) override;
+ base::Time GetLastSyncTime() const override;
+ base::TimeDelta GetTimeToNextAttempt() const override;
+ bool IsSyncInProgress() const override;
+ bool IsRecoveringFromFailure() const override;
+ std::vector<cryptauth::ExternalDeviceInfo> GetSyncedDevices() const override;
+ std::vector<cryptauth::ExternalDeviceInfo> GetUnlockKeys() const override;
+ std::vector<cryptauth::ExternalDeviceInfo> GetPixelUnlockKeys()
+ const override;
+ std::vector<cryptauth::ExternalDeviceInfo> GetTetherHosts() const override;
+ std::vector<cryptauth::ExternalDeviceInfo> GetPixelTetherHosts()
+ const override;
+
+ private:
+ bool has_started_ = false;
+ bool is_sync_in_progress_ = false;
+ bool is_recovering_from_failure_ = false;
+ base::Time last_sync_time_;
+ base::TimeDelta time_to_next_attempt_;
+ std::vector<cryptauth::ExternalDeviceInfo> synced_devices_;
+ std::vector<cryptauth::ExternalDeviceInfo> unlock_keys_;
+ std::vector<cryptauth::ExternalDeviceInfo> pixel_unlock_keys_;
+ std::vector<cryptauth::ExternalDeviceInfo> tether_hosts_;
+ std::vector<cryptauth::ExternalDeviceInfo> pixel_tether_hosts_;
+
+ DISALLOW_COPY_AND_ASSIGN(FakeCryptAuthDeviceManager);
+};
+
+} // namespace device_sync
+
+} // namespace chromeos
+
+#endif // CHROMEOS_SERVICES_DEVICE_SYNC_FAKE_CRYPTAUTH_DEVICE_MANAGER_H_
diff --git a/components/cryptauth/fake_cryptauth_enrollment_manager.cc b/chromeos/services/device_sync/fake_cryptauth_enrollment_manager.cc
similarity index 88%
rename from components/cryptauth/fake_cryptauth_enrollment_manager.cc
rename to chromeos/services/device_sync/fake_cryptauth_enrollment_manager.cc
index 413e9fe..72b0fc0 100644
--- a/components/cryptauth/fake_cryptauth_enrollment_manager.cc
+++ b/chromeos/services/device_sync/fake_cryptauth_enrollment_manager.cc
@@ -2,9 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/cryptauth/fake_cryptauth_enrollment_manager.h"
+#include "chromeos/services/device_sync/fake_cryptauth_enrollment_manager.h"
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
FakeCryptAuthEnrollmentManager::FakeCryptAuthEnrollmentManager() = default;
@@ -32,7 +34,7 @@
}
void FakeCryptAuthEnrollmentManager::ForceEnrollmentNow(
- InvocationReason invocation_reason) {
+ cryptauth::InvocationReason invocation_reason) {
is_enrollment_in_progress_ = true;
last_invocation_reason_ = invocation_reason;
NotifyEnrollmentStarted();
@@ -66,4 +68,6 @@
return user_private_key_;
}
-} // namespace cryptauth
+} // namespace device_sync
+
+} // namespace chromeos
diff --git a/components/cryptauth/fake_cryptauth_enrollment_manager.h b/chromeos/services/device_sync/fake_cryptauth_enrollment_manager.h
similarity index 81%
rename from components/cryptauth/fake_cryptauth_enrollment_manager.h
rename to chromeos/services/device_sync/fake_cryptauth_enrollment_manager.h
index 810ba4a5..21e3238 100644
--- a/components/cryptauth/fake_cryptauth_enrollment_manager.h
+++ b/chromeos/services/device_sync/fake_cryptauth_enrollment_manager.h
@@ -2,18 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef COMPONENTS_CRYPTAUTH_FAKE_CRYPTAUTH_ENROLLMENT_MANAGER_H_
-#define COMPONENTS_CRYPTAUTH_FAKE_CRYPTAUTH_ENROLLMENT_MANAGER_H_
+#ifndef CHROMEOS_SERVICES_DEVICE_SYNC_FAKE_CRYPTAUTH_ENROLLMENT_MANAGER_H_
+#define CHROMEOS_SERVICES_DEVICE_SYNC_FAKE_CRYPTAUTH_ENROLLMENT_MANAGER_H_
#include <memory>
#include "base/macros.h"
#include "base/optional.h"
#include "base/time/time.h"
+#include "chromeos/services/device_sync/cryptauth_enrollment_manager.h"
#include "chromeos/services/device_sync/proto/cryptauth_api.pb.h"
-#include "components/cryptauth/cryptauth_enrollment_manager.h"
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
// Test double for CryptAuthEnrollmentManager.
class FakeCryptAuthEnrollmentManager : public CryptAuthEnrollmentManager {
@@ -51,7 +53,7 @@
is_enrollment_in_progress_ = is_enrollment_in_progress;
}
- base::Optional<InvocationReason> last_invocation_reason() {
+ base::Optional<cryptauth::InvocationReason> last_invocation_reason() {
return last_invocation_reason_;
}
@@ -63,12 +65,13 @@
base::Time enrollment_finish_time = base::Time());
// Make these functions public for testing.
- using CryptAuthEnrollmentManager::NotifyEnrollmentStarted;
using CryptAuthEnrollmentManager::NotifyEnrollmentFinished;
+ using CryptAuthEnrollmentManager::NotifyEnrollmentStarted;
// CryptAuthEnrollmentManager:
void Start() override;
- void ForceEnrollmentNow(InvocationReason invocation_reason) override;
+ void ForceEnrollmentNow(
+ cryptauth::InvocationReason invocation_reason) override;
bool IsEnrollmentValid() const override;
base::Time GetLastEnrollmentTime() const override;
base::TimeDelta GetTimeToNextAttempt() const override;
@@ -82,7 +85,7 @@
bool is_enrollment_in_progress_ = false;
bool is_recovering_from_failure_ = false;
bool is_enrollment_valid_ = false;
- base::Optional<InvocationReason> last_invocation_reason_;
+ base::Optional<cryptauth::InvocationReason> last_invocation_reason_;
base::Time last_enrollment_time_;
base::TimeDelta time_to_next_attempt_;
std::string user_public_key_;
@@ -91,6 +94,8 @@
DISALLOW_COPY_AND_ASSIGN(FakeCryptAuthEnrollmentManager);
};
-} // namespace cryptauth
+} // namespace device_sync
-#endif // COMPONENTS_CRYPTAUTH_FAKE_CRYPTAUTH_ENROLLMENT_MANAGER_H_
+} // namespace chromeos
+
+#endif // CHROMEOS_SERVICES_DEVICE_SYNC_FAKE_CRYPTAUTH_ENROLLMENT_MANAGER_H_
diff --git a/components/cryptauth/fake_cryptauth_gcm_manager.cc b/chromeos/services/device_sync/fake_cryptauth_gcm_manager.cc
similarity index 88%
rename from components/cryptauth/fake_cryptauth_gcm_manager.cc
rename to chromeos/services/device_sync/fake_cryptauth_gcm_manager.cc
index 4904799..b8603b6 100644
--- a/components/cryptauth/fake_cryptauth_gcm_manager.cc
+++ b/chromeos/services/device_sync/fake_cryptauth_gcm_manager.cc
@@ -2,9 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/cryptauth/fake_cryptauth_gcm_manager.h"
+#include "chromeos/services/device_sync/fake_cryptauth_gcm_manager.h"
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
FakeCryptAuthGCMManager::FakeCryptAuthGCMManager(
const std::string& registration_id)
@@ -52,4 +54,6 @@
observer.OnResyncMessage();
}
-} // namespace cryptauth
+} // namespace device_sync
+
+} // namespace chromeos
diff --git a/components/cryptauth/fake_cryptauth_gcm_manager.h b/chromeos/services/device_sync/fake_cryptauth_gcm_manager.h
similarity index 83%
rename from components/cryptauth/fake_cryptauth_gcm_manager.h
rename to chromeos/services/device_sync/fake_cryptauth_gcm_manager.h
index 20ea4d9..2368fc4 100644
--- a/components/cryptauth/fake_cryptauth_gcm_manager.h
+++ b/chromeos/services/device_sync/fake_cryptauth_gcm_manager.h
@@ -2,14 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef COMPONENTS_CRYPTAUTH_FAKE_CRYPTAUTH_GCM_MANAGER_H_
-#define COMPONENTS_CRYPTAUTH_FAKE_CRYPTAUTH_GCM_MANAGER_H_
+#ifndef CHROMEOS_SERVICES_DEVICE_SYNC_FAKE_CRYPTAUTH_GCM_MANAGER_H_
+#define CHROMEOS_SERVICES_DEVICE_SYNC_FAKE_CRYPTAUTH_GCM_MANAGER_H_
#include "base/macros.h"
#include "base/observer_list.h"
-#include "components/cryptauth/cryptauth_gcm_manager.h"
+#include "chromeos/services/device_sync/cryptauth_gcm_manager.h"
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
// CryptAuthGCMManager implementation for testing purposes.
class FakeCryptAuthGCMManager : public CryptAuthGCMManager {
@@ -59,6 +61,8 @@
DISALLOW_COPY_AND_ASSIGN(FakeCryptAuthGCMManager);
};
-} // namespace cryptauth
+} // namespace device_sync
-#endif // COMPONENTS_CRYPTAUTH_FAKE_CRYPTAUTH_GCM_MANAGER_H_
+} // namespace chromeos
+
+#endif // CHROMEOS_SERVICES_DEVICE_SYNC_FAKE_CRYPTAUTH_GCM_MANAGER_H_
diff --git a/components/cryptauth/fake_remote_device_provider.cc b/chromeos/services/device_sync/fake_remote_device_provider.cc
similarity index 76%
rename from components/cryptauth/fake_remote_device_provider.cc
rename to chromeos/services/device_sync/fake_remote_device_provider.cc
index a0e2177..f28f89a 100644
--- a/components/cryptauth/fake_remote_device_provider.cc
+++ b/chromeos/services/device_sync/fake_remote_device_provider.cc
@@ -2,9 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/cryptauth/fake_remote_device_provider.h"
+#include "chromeos/services/device_sync/fake_remote_device_provider.h"
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
FakeRemoteDeviceProvider::FakeRemoteDeviceProvider() = default;
@@ -19,4 +21,6 @@
return synced_remote_devices_;
}
-} // namespace cryptauth
+} // namespace device_sync
+
+} // namespace chromeos
diff --git a/components/cryptauth/fake_remote_device_provider.h b/chromeos/services/device_sync/fake_remote_device_provider.h
similarity index 68%
rename from components/cryptauth/fake_remote_device_provider.h
rename to chromeos/services/device_sync/fake_remote_device_provider.h
index 2763421..9206b0399 100644
--- a/components/cryptauth/fake_remote_device_provider.h
+++ b/chromeos/services/device_sync/fake_remote_device_provider.h
@@ -2,12 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef COMPONENTS_CRYPTAUTH_FAKE_REMOTE_DEVICE_PROVIDER_H_
-#define COMPONENTS_CRYPTAUTH_FAKE_REMOTE_DEVICE_PROVIDER_H_
+#ifndef CHROMEOS_SERVICES_DEVICE_SYNC_FAKE_REMOTE_DEVICE_PROVIDER_H_
+#define CHROMEOS_SERVICES_DEVICE_SYNC_FAKE_REMOTE_DEVICE_PROVIDER_H_
-#include "components/cryptauth/remote_device_provider.h"
+#include "chromeos/services/device_sync/remote_device_provider.h"
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
// Test double for RemoteDeviceProvider.
class FakeRemoteDeviceProvider : public RemoteDeviceProvider {
@@ -32,6 +34,8 @@
DISALLOW_COPY_AND_ASSIGN(FakeRemoteDeviceProvider);
};
-} // namespace cryptauth
+} // namespace device_sync
-#endif // COMPONENTS_CRYPTAUTH_FAKE_REMOTE_DEVICE_PROVIDER_H_
+} // namespace chromeos
+
+#endif // CHROMEOS_SERVICES_DEVICE_SYNC_FAKE_REMOTE_DEVICE_PROVIDER_H_
diff --git a/components/cryptauth/fake_software_feature_manager.cc b/chromeos/services/device_sync/fake_software_feature_manager.cc
similarity index 82%
rename from components/cryptauth/fake_software_feature_manager.cc
rename to chromeos/services/device_sync/fake_software_feature_manager.cc
index 8ef3ffe..a2e3cee 100644
--- a/components/cryptauth/fake_software_feature_manager.cc
+++ b/chromeos/services/device_sync/fake_software_feature_manager.cc
@@ -2,9 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/cryptauth/fake_software_feature_manager.h"
+#include "chromeos/services/device_sync/fake_software_feature_manager.h"
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
FakeSoftwareFeatureManager::SetSoftwareFeatureStateArgs::
SetSoftwareFeatureStateArgs(
@@ -26,8 +28,8 @@
FakeSoftwareFeatureManager::FindEligibleDevicesArgs::FindEligibleDevicesArgs(
chromeos::multidevice::SoftwareFeature software_feature,
- const base::Callback<void(const std::vector<ExternalDeviceInfo>&,
- const std::vector<IneligibleDevice>&)>&
+ const base::Callback<void(const std::vector<cryptauth::ExternalDeviceInfo>&,
+ const std::vector<cryptauth::IneligibleDevice>&)>&
success_callback,
const base::Callback<void(NetworkRequestError)>& error_callback)
: software_feature(software_feature),
@@ -59,8 +61,8 @@
void FakeSoftwareFeatureManager::FindEligibleDevices(
chromeos::multidevice::SoftwareFeature software_feature,
- const base::Callback<void(const std::vector<ExternalDeviceInfo>&,
- const std::vector<IneligibleDevice>&)>&
+ const base::Callback<void(const std::vector<cryptauth::ExternalDeviceInfo>&,
+ const std::vector<cryptauth::IneligibleDevice>&)>&
success_callback,
const base::Callback<void(NetworkRequestError)>& error_callback) {
find_eligible_multidevice_host_calls_.emplace_back(
@@ -71,4 +73,6 @@
delegate_->OnFindEligibleDevicesCalled();
}
-} // namespace cryptauth
+} // namespace device_sync
+
+} // namespace chromeos
diff --git a/components/cryptauth/fake_software_feature_manager.h b/chromeos/services/device_sync/fake_software_feature_manager.h
similarity index 75%
rename from components/cryptauth/fake_software_feature_manager.h
rename to chromeos/services/device_sync/fake_software_feature_manager.h
index 2a1e5b2..4cae305 100644
--- a/components/cryptauth/fake_software_feature_manager.h
+++ b/chromeos/services/device_sync/fake_software_feature_manager.h
@@ -2,18 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef COMPONENTS_CRYPTAUTH_FAKE_SOFTWARE_FEATURE_MANAGER_H_
-#define COMPONENTS_CRYPTAUTH_FAKE_SOFTWARE_FEATURE_MANAGER_H_
+#ifndef CHROMEOS_SERVICES_DEVICE_SYNC_FAKE_SOFTWARE_FEATURE_MANAGER_H_
+#define CHROMEOS_SERVICES_DEVICE_SYNC_FAKE_SOFTWARE_FEATURE_MANAGER_H_
#include <string>
#include <vector>
#include "base/callback.h"
#include "chromeos/components/multidevice/software_feature.h"
-#include "components/cryptauth/network_request_error.h"
-#include "components/cryptauth/software_feature_manager.h"
+#include "chromeos/services/device_sync/network_request_error.h"
+#include "chromeos/services/device_sync/software_feature_manager.h"
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
// Test implementation of SoftwareFeatureManager.
class FakeSoftwareFeatureManager : public SoftwareFeatureManager {
@@ -49,15 +51,15 @@
struct FindEligibleDevicesArgs {
FindEligibleDevicesArgs(
chromeos::multidevice::SoftwareFeature software_feature,
- const base::Callback<void(const std::vector<ExternalDeviceInfo>&,
- const std::vector<IneligibleDevice>&)>&
- success_callback,
+ const base::Callback<void(
+ const std::vector<cryptauth::ExternalDeviceInfo>&,
+ const std::vector<cryptauth::IneligibleDevice>&)>& success_callback,
const base::Callback<void(NetworkRequestError)>& error_callback);
~FindEligibleDevicesArgs();
chromeos::multidevice::SoftwareFeature software_feature;
- base::Callback<void(const std::vector<ExternalDeviceInfo>&,
- const std::vector<IneligibleDevice>&)>
+ base::Callback<void(const std::vector<cryptauth::ExternalDeviceInfo>&,
+ const std::vector<cryptauth::IneligibleDevice>&)>
success_callback;
base::Callback<void(NetworkRequestError)> error_callback;
@@ -90,9 +92,9 @@
bool is_exclusive = false) override;
void FindEligibleDevices(
chromeos::multidevice::SoftwareFeature software_feature,
- const base::Callback<void(const std::vector<ExternalDeviceInfo>&,
- const std::vector<IneligibleDevice>&)>&
- success_callback,
+ const base::Callback<void(
+ const std::vector<cryptauth::ExternalDeviceInfo>&,
+ const std::vector<cryptauth::IneligibleDevice>&)>& success_callback,
const base::Callback<void(NetworkRequestError)>& error_callback) override;
private:
@@ -106,6 +108,8 @@
DISALLOW_COPY_AND_ASSIGN(FakeSoftwareFeatureManager);
};
-} // namespace cryptauth
+} // namespace device_sync
-#endif // COMPONENTS_CRYPTAUTH_FAKE_SOFTWARE_FEATURE_MANAGER_H_
+} // namespace chromeos
+
+#endif // CHROMEOS_SERVICES_DEVICE_SYNC_FAKE_SOFTWARE_FEATURE_MANAGER_H_
diff --git a/components/cryptauth/mock_cryptauth_client.cc b/chromeos/services/device_sync/mock_cryptauth_client.cc
similarity index 73%
rename from components/cryptauth/mock_cryptauth_client.cc
rename to chromeos/services/device_sync/mock_cryptauth_client.cc
index e10d2ef..daf8b2c 100644
--- a/components/cryptauth/mock_cryptauth_client.cc
+++ b/chromeos/services/device_sync/mock_cryptauth_client.cc
@@ -2,26 +2,24 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/cryptauth/mock_cryptauth_client.h"
+#include "chromeos/services/device_sync/mock_cryptauth_client.h"
#include <utility>
#include "base/callback.h"
-namespace cryptauth {
+namespace chromeos {
-MockCryptAuthClient::MockCryptAuthClient() {
-}
+namespace device_sync {
-MockCryptAuthClient::~MockCryptAuthClient() {
-}
+MockCryptAuthClient::MockCryptAuthClient() {}
+
+MockCryptAuthClient::~MockCryptAuthClient() {}
MockCryptAuthClientFactory::MockCryptAuthClientFactory(MockType mock_type)
- : mock_type_(mock_type) {
-}
+ : mock_type_(mock_type) {}
-MockCryptAuthClientFactory::~MockCryptAuthClientFactory() {
-}
+MockCryptAuthClientFactory::~MockCryptAuthClientFactory() {}
std::unique_ptr<CryptAuthClient> MockCryptAuthClientFactory::CreateInstance() {
std::unique_ptr<MockCryptAuthClient> client;
@@ -43,4 +41,6 @@
observer_list_.RemoveObserver(observer);
}
-} // namespace cryptauth
+} // namespace device_sync
+
+} // namespace chromeos
diff --git a/components/cryptauth/mock_cryptauth_client.h b/chromeos/services/device_sync/mock_cryptauth_client.h
similarity index 77%
rename from components/cryptauth/mock_cryptauth_client.h
rename to chromeos/services/device_sync/mock_cryptauth_client.h
index 9592265..61c447a 100644
--- a/components/cryptauth/mock_cryptauth_client.h
+++ b/chromeos/services/device_sync/mock_cryptauth_client.h
@@ -2,16 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef COMPONENTS_CRYPTAUTH_MOCK_CRYPTAUTH_CLIENT_H_
-#define COMPONENTS_CRYPTAUTH_MOCK_CRYPTAUTH_CLIENT_H_
+#ifndef CHROMEOS_SERVICES_DEVICE_SYNC_MOCK_CRYPTAUTH_CLIENT_H_
+#define CHROMEOS_SERVICES_DEVICE_SYNC_MOCK_CRYPTAUTH_CLIENT_H_
#include "base/macros.h"
#include "base/observer_list.h"
+#include "chromeos/services/device_sync/cryptauth_client.h"
#include "chromeos/services/device_sync/proto/cryptauth_api.pb.h"
-#include "components/cryptauth/cryptauth_client.h"
#include "testing/gmock/include/gmock/gmock.h"
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
class MockCryptAuthClient : public CryptAuthClient {
public:
@@ -20,35 +22,35 @@
// CryptAuthClient:
MOCK_METHOD4(GetMyDevices,
- void(const GetMyDevicesRequest& request,
+ void(const cryptauth::GetMyDevicesRequest& request,
const GetMyDevicesCallback& callback,
const ErrorCallback& error_callback,
const net::PartialNetworkTrafficAnnotationTag&
partial_traffic_annotation));
MOCK_METHOD3(FindEligibleUnlockDevices,
- void(const FindEligibleUnlockDevicesRequest& request,
+ void(const cryptauth::FindEligibleUnlockDevicesRequest& request,
const FindEligibleUnlockDevicesCallback& callback,
const ErrorCallback& error_callback));
MOCK_METHOD3(FindEligibleForPromotion,
- void(const FindEligibleForPromotionRequest& request,
+ void(const cryptauth::FindEligibleForPromotionRequest& request,
const FindEligibleForPromotionCallback& callback,
const ErrorCallback& error_callback));
MOCK_METHOD4(SendDeviceSyncTickle,
- void(const SendDeviceSyncTickleRequest& request,
+ void(const cryptauth::SendDeviceSyncTickleRequest& request,
const SendDeviceSyncTickleCallback& callback,
const ErrorCallback& error_callback,
const net::PartialNetworkTrafficAnnotationTag&
partial_traffic_annotation));
MOCK_METHOD3(ToggleEasyUnlock,
- void(const ToggleEasyUnlockRequest& request,
+ void(const cryptauth::ToggleEasyUnlockRequest& request,
const ToggleEasyUnlockCallback& callback,
const ErrorCallback& error_callback));
MOCK_METHOD3(SetupEnrollment,
- void(const SetupEnrollmentRequest& request,
+ void(const cryptauth::SetupEnrollmentRequest& request,
const SetupEnrollmentCallback& callback,
const ErrorCallback& error_callback));
MOCK_METHOD3(FinishEnrollment,
- void(const FinishEnrollmentRequest& request,
+ void(const cryptauth::FinishEnrollmentRequest& request,
const FinishEnrollmentCallback& callback,
const ErrorCallback& error_callback));
MOCK_METHOD0(GetAccessTokenUsed, std::string());
@@ -91,6 +93,8 @@
DISALLOW_COPY_AND_ASSIGN(MockCryptAuthClientFactory);
};
-} // namespace cryptauth
+} // namespace device_sync
-#endif // COMPONENTS_CRYPTAUTH_MOCK_CRYPTAUTH_CLIENT_H_
+} // namespace chromeos
+
+#endif // CHROMEOS_SERVICES_DEVICE_SYNC_MOCK_CRYPTAUTH_CLIENT_H_
diff --git a/chromeos/services/device_sync/mock_sync_scheduler.cc b/chromeos/services/device_sync/mock_sync_scheduler.cc
new file mode 100644
index 0000000..c2f4329
--- /dev/null
+++ b/chromeos/services/device_sync/mock_sync_scheduler.cc
@@ -0,0 +1,17 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chromeos/services/device_sync/mock_sync_scheduler.h"
+
+namespace chromeos {
+
+namespace device_sync {
+
+MockSyncScheduler::MockSyncScheduler() {}
+
+MockSyncScheduler::~MockSyncScheduler() {}
+
+} // namespace device_sync
+
+} // namespace chromeos
diff --git a/components/cryptauth/mock_sync_scheduler.h b/chromeos/services/device_sync/mock_sync_scheduler.h
similarity index 71%
rename from components/cryptauth/mock_sync_scheduler.h
rename to chromeos/services/device_sync/mock_sync_scheduler.h
index b3fd9b33..67f022df 100644
--- a/components/cryptauth/mock_sync_scheduler.h
+++ b/chromeos/services/device_sync/mock_sync_scheduler.h
@@ -2,14 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef COMPONENTS_CRYPTAUTH_MOCK_SYNC_SCHEDULER_H_
-#define COMPONENTS_CRYPTAUTH_MOCK_SYNC_SCHEDULER_H_
+#ifndef CHROMEOS_SERVICES_DEVICE_SYNC_MOCK_SYNC_SCHEDULER_H_
+#define CHROMEOS_SERVICES_DEVICE_SYNC_MOCK_SYNC_SCHEDULER_H_
#include "base/macros.h"
-#include "components/cryptauth/sync_scheduler.h"
+#include "chromeos/services/device_sync/sync_scheduler.h"
#include "testing/gmock/include/gmock/gmock.h"
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
// Mock implementation of SyncScheduler.
class MockSyncScheduler : public SyncScheduler {
@@ -31,6 +33,8 @@
DISALLOW_COPY_AND_ASSIGN(MockSyncScheduler);
};
-} // namespace cryptauth
+} // namespace device_sync
-#endif // COMPONENTS_CRYPTAUTH_MOCK_SYNC_SCHEDULER_H_
+} // namespace chromeos
+
+#endif // CHROMEOS_SERVICES_DEVICE_SYNC_MOCK_SYNC_SCHEDULER_H_
diff --git a/components/cryptauth/network_request_error.cc b/chromeos/services/device_sync/network_request_error.cc
similarity index 85%
rename from components/cryptauth/network_request_error.cc
rename to chromeos/services/device_sync/network_request_error.cc
index 3ce2b161..5450b67 100644
--- a/components/cryptauth/network_request_error.cc
+++ b/chromeos/services/device_sync/network_request_error.cc
@@ -2,9 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/cryptauth/network_request_error.h"
+#include "chromeos/services/device_sync/network_request_error.h"
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
std::ostream& operator<<(std::ostream& stream,
const NetworkRequestError& error) {
@@ -34,4 +36,6 @@
return stream;
}
-} // namespace cryptauth
+} // namespace device_sync
+
+} // namespace chromeos
diff --git a/components/cryptauth/network_request_error.h b/chromeos/services/device_sync/network_request_error.h
similarity index 73%
rename from components/cryptauth/network_request_error.h
rename to chromeos/services/device_sync/network_request_error.h
index 51d011fd..d24d0a2 100644
--- a/components/cryptauth/network_request_error.h
+++ b/chromeos/services/device_sync/network_request_error.h
@@ -2,12 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef COMPONENTS_CRYPTAUTH_NETWORK_REQUEST_ERROR_H_
-#define COMPONENTS_CRYPTAUTH_NETWORK_REQUEST_ERROR_H_
+#ifndef CHROMEOS_SERVICES_DEVICE_SYNC_NETWORK_REQUEST_ERROR_H_
+#define CHROMEOS_SERVICES_DEVICE_SYNC_NETWORK_REQUEST_ERROR_H_
#include <ostream>
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
enum class NetworkRequestError {
// Request could not be completed because the device is offline or has issues
@@ -36,6 +38,8 @@
std::ostream& operator<<(std::ostream& stream,
const NetworkRequestError& error);
-} // namespace cryptauth
+} // namespace device_sync
-#endif // COMPONENTS_CRYPTAUTH_NETWORK_REQUEST_ERROR_H_
+} // namespace chromeos
+
+#endif // CHROMEOS_SERVICES_DEVICE_SYNC_NETWORK_REQUEST_ERROR_H_
diff --git a/components/cryptauth/pref_names.cc b/chromeos/services/device_sync/pref_names.cc
similarity index 89%
rename from components/cryptauth/pref_names.cc
rename to chromeos/services/device_sync/pref_names.cc
index b0675aa..f8d852431 100644
--- a/components/cryptauth/pref_names.cc
+++ b/chromeos/services/device_sync/pref_names.cc
@@ -2,9 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/cryptauth/pref_names.h"
+#include "chromeos/services/device_sync/pref_names.h"
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
+
namespace prefs {
// Whether the system is scheduling device_syncs more aggressively to recover
@@ -17,7 +20,7 @@
"cryptauth.device_sync.last_device_sync_time_seconds";
// The reason that the next device_sync is performed. This should be one of the
-// enum values of InvocationReason in
+// enum values of cryptauth::InvocationReason in
// chromeos/services/device_sync/proto/cryptauth_api.proto.
const char kCryptAuthDeviceSyncReason[] = "cryptauth.device_sync.reason";
@@ -37,7 +40,7 @@
"cryptauth.enrollment.last_enrollment_time_seconds";
// The reason that the next enrollment is performed. This should be one of the
-// enum values of InvocationReason in
+// enum values of cryptauth::InvocationReason in
// chromeos/services/device_sync/proto/cryptauth_api.proto.
const char kCryptAuthEnrollmentReason[] = "cryptauth.enrollment.reason";
@@ -53,4 +56,7 @@
const char kCryptAuthGCMRegistrationId[] = "cryptauth.gcm_registration_id";
} // namespace prefs
-} // namespace cryptauth
+
+} // namespace device_sync
+
+} // namespace chromeos
diff --git a/components/cryptauth/pref_names.h b/chromeos/services/device_sync/pref_names.h
similarity index 74%
rename from components/cryptauth/pref_names.h
rename to chromeos/services/device_sync/pref_names.h
index dfc3803..d6b30a9 100644
--- a/components/cryptauth/pref_names.h
+++ b/chromeos/services/device_sync/pref_names.h
@@ -2,10 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef COMPONENTS_CRYPTAUTH_PREF_NAMES_H_
-#define COMPONENTS_CRYPTAUTH_PREF_NAMES_H_
+#ifndef CHROMEOS_SERVICES_DEVICE_SYNC_PREF_NAMES_H_
+#define CHROMEOS_SERVICES_DEVICE_SYNC_PREF_NAMES_H_
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
+
namespace prefs {
extern const char kCryptAuthDeviceSyncLastSyncTimeSeconds[];
@@ -20,6 +23,9 @@
extern const char kCryptAuthGCMRegistrationId[];
} // namespace prefs
-} // namespace cryptauth
-#endif // COMPONENTS_CRYPTAUTH_PREF_NAMES_H_
+} // namespace device_sync
+
+} // namespace chromeos
+
+#endif // CHROMEOS_SERVICES_DEVICE_SYNC_PREF_NAMES_H_
diff --git a/chromeos/services/device_sync/proto/BUILD.gn b/chromeos/services/device_sync/proto/BUILD.gn
index 650449fd..bc423dd 100644
--- a/chromeos/services/device_sync/proto/BUILD.gn
+++ b/chromeos/services/device_sync/proto/BUILD.gn
@@ -13,6 +13,8 @@
static_library("util") {
sources = [
+ "device_classifier_util.cc",
+ "device_classifier_util.h",
"enum_util.cc",
"enum_util.h",
]
@@ -23,5 +25,6 @@
deps = [
"//base",
+ "//components/version_info",
]
}
diff --git a/components/cryptauth/device_classifier_util.cc b/chromeos/services/device_sync/proto/device_classifier_util.cc
similarity index 83%
rename from components/cryptauth/device_classifier_util.cc
rename to chromeos/services/device_sync/proto/device_classifier_util.cc
index 0040099..c85f5e6 100644
--- a/components/cryptauth/device_classifier_util.cc
+++ b/chromeos/services/device_sync/proto/device_classifier_util.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/cryptauth/device_classifier_util.h"
+#include "chromeos/services/device_sync/proto/device_classifier_util.h"
#include <vector>
@@ -12,7 +12,9 @@
#include "chromeos/services/device_sync/proto/enum_util.h"
#include "components/version_info/version_info.h"
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
namespace device_classifier_util {
@@ -26,8 +28,7 @@
base::SysInfo::OperatingSystemVersionNumbers(&major_version, &minor_version,
&bugfix_version);
classifier.set_device_os_version_code(major_version);
- classifier.set_device_type(
- cryptauth::DeviceTypeEnumToString(cryptauth::CHROME));
+ classifier.set_device_type(DeviceTypeEnumToString(cryptauth::CHROME));
const std::vector<uint32_t>& version_components =
version_info::GetVersion().components();
@@ -45,4 +46,6 @@
} // namespace device_classifier_util
-} // namespace cryptauth
+} // namespace device_sync
+
+} // namespace chromeos
diff --git a/chromeos/services/device_sync/proto/device_classifier_util.h b/chromeos/services/device_sync/proto/device_classifier_util.h
new file mode 100644
index 0000000..06ec1307
--- /dev/null
+++ b/chromeos/services/device_sync/proto/device_classifier_util.h
@@ -0,0 +1,24 @@
+// Copyright 2018 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROMEOS_SERVICES_DEVICE_SYNC_PROTO_DEVICE_CLASSIFIER_UTIL_H_
+#define CHROMEOS_SERVICES_DEVICE_SYNC_PROTO_DEVICE_CLASSIFIER_UTIL_H_
+
+#include "chromeos/services/device_sync/proto/cryptauth_api.pb.h"
+
+namespace chromeos {
+
+namespace device_sync {
+
+namespace device_classifier_util {
+
+const cryptauth::DeviceClassifier& GetDeviceClassifier();
+
+} // namespace device_classifier_util
+
+} // namespace device_sync
+
+} // namespace chromeos
+
+#endif // CHROMEOS_SERVICES_DEVICE_SYNC_PROTO_DEVICE_CLASSIFIER_UTIL_H_
diff --git a/chromeos/services/device_sync/proto/enum_util.cc b/chromeos/services/device_sync/proto/enum_util.cc
index c72cca2..9ecda47f 100644
--- a/chromeos/services/device_sync/proto/enum_util.cc
+++ b/chromeos/services/device_sync/proto/enum_util.cc
@@ -4,20 +4,23 @@
#include "chromeos/services/device_sync/proto/enum_util.h"
-namespace cryptauth {
+namespace chromeos {
-std::ostream& operator<<(std::ostream& stream, const DeviceType& device_type) {
+namespace device_sync {
+
+std::ostream& operator<<(std::ostream& stream,
+ const cryptauth::DeviceType& device_type) {
switch (device_type) {
- case DeviceType::ANDROID:
+ case cryptauth::DeviceType::ANDROID:
stream << "[Android]";
break;
- case DeviceType::CHROME:
+ case cryptauth::DeviceType::CHROME:
stream << "[Chrome]";
break;
- case DeviceType::IOS:
+ case cryptauth::DeviceType::IOS:
stream << "[iOS]";
break;
- case DeviceType::BROWSER:
+ case cryptauth::DeviceType::BROWSER:
stream << "[Browser]";
break;
default:
@@ -56,30 +59,30 @@
}
std::ostream& operator<<(std::ostream& stream,
- const SoftwareFeature& software_feature) {
+ const cryptauth::SoftwareFeature& software_feature) {
switch (software_feature) {
- case SoftwareFeature::BETTER_TOGETHER_HOST:
+ case cryptauth::SoftwareFeature::BETTER_TOGETHER_HOST:
stream << "[Better Together host]";
break;
- case SoftwareFeature::BETTER_TOGETHER_CLIENT:
+ case cryptauth::SoftwareFeature::BETTER_TOGETHER_CLIENT:
stream << "[Better Together client]";
break;
- case SoftwareFeature::EASY_UNLOCK_HOST:
+ case cryptauth::SoftwareFeature::EASY_UNLOCK_HOST:
stream << "[EasyUnlock host]";
break;
- case SoftwareFeature::EASY_UNLOCK_CLIENT:
+ case cryptauth::SoftwareFeature::EASY_UNLOCK_CLIENT:
stream << "[EasyUnlock client]";
break;
- case SoftwareFeature::MAGIC_TETHER_HOST:
+ case cryptauth::SoftwareFeature::MAGIC_TETHER_HOST:
stream << "[Instant Tethering host]";
break;
- case SoftwareFeature::MAGIC_TETHER_CLIENT:
+ case cryptauth::SoftwareFeature::MAGIC_TETHER_CLIENT:
stream << "[Instant Tethering client]";
break;
- case SoftwareFeature::SMS_CONNECT_HOST:
+ case cryptauth::SoftwareFeature::SMS_CONNECT_HOST:
stream << "[SMS Connect host]";
break;
- case SoftwareFeature::SMS_CONNECT_CLIENT:
+ case cryptauth::SoftwareFeature::SMS_CONNECT_CLIENT:
stream << "[SMS Connect client]";
break;
default:
@@ -114,21 +117,21 @@
std::string SoftwareFeatureEnumToString(
cryptauth::SoftwareFeature software_feature) {
switch (software_feature) {
- case SoftwareFeature::BETTER_TOGETHER_HOST:
+ case cryptauth::SoftwareFeature::BETTER_TOGETHER_HOST:
return "betterTogetherHost";
- case SoftwareFeature::BETTER_TOGETHER_CLIENT:
+ case cryptauth::SoftwareFeature::BETTER_TOGETHER_CLIENT:
return "betterTogetherClient";
- case SoftwareFeature::EASY_UNLOCK_HOST:
+ case cryptauth::SoftwareFeature::EASY_UNLOCK_HOST:
return "easyUnlockHost";
- case SoftwareFeature::EASY_UNLOCK_CLIENT:
+ case cryptauth::SoftwareFeature::EASY_UNLOCK_CLIENT:
return "easyUnlockClient";
- case SoftwareFeature::MAGIC_TETHER_HOST:
+ case cryptauth::SoftwareFeature::MAGIC_TETHER_HOST:
return "magicTetherHost";
- case SoftwareFeature::MAGIC_TETHER_CLIENT:
+ case cryptauth::SoftwareFeature::MAGIC_TETHER_CLIENT:
return "magicTetherClient";
- case SoftwareFeature::SMS_CONNECT_HOST:
+ case cryptauth::SoftwareFeature::SMS_CONNECT_HOST:
return "smsConnectHost";
- case SoftwareFeature::SMS_CONNECT_CLIENT:
+ case cryptauth::SoftwareFeature::SMS_CONNECT_CLIENT:
return "smsConnectClient";
default:
return "unknownFeature";
@@ -138,25 +141,27 @@
std::string SoftwareFeatureEnumToStringAllCaps(
cryptauth::SoftwareFeature software_feature) {
switch (software_feature) {
- case SoftwareFeature::BETTER_TOGETHER_HOST:
+ case cryptauth::SoftwareFeature::BETTER_TOGETHER_HOST:
return "BETTER_TOGETHER_HOST";
- case SoftwareFeature::BETTER_TOGETHER_CLIENT:
+ case cryptauth::SoftwareFeature::BETTER_TOGETHER_CLIENT:
return "BETTER_TOGETHER_CLIENT";
- case SoftwareFeature::EASY_UNLOCK_HOST:
+ case cryptauth::SoftwareFeature::EASY_UNLOCK_HOST:
return "EASY_UNLOCK_HOST";
- case SoftwareFeature::EASY_UNLOCK_CLIENT:
+ case cryptauth::SoftwareFeature::EASY_UNLOCK_CLIENT:
return "EASY_UNLOCK_CLIENT";
- case SoftwareFeature::MAGIC_TETHER_HOST:
+ case cryptauth::SoftwareFeature::MAGIC_TETHER_HOST:
return "MAGIC_TETHER_HOST";
- case SoftwareFeature::MAGIC_TETHER_CLIENT:
+ case cryptauth::SoftwareFeature::MAGIC_TETHER_CLIENT:
return "MAGIC_TETHER_CLIENT";
- case SoftwareFeature::SMS_CONNECT_HOST:
+ case cryptauth::SoftwareFeature::SMS_CONNECT_HOST:
return "SMS_CONNECT_HOST";
- case SoftwareFeature::SMS_CONNECT_CLIENT:
+ case cryptauth::SoftwareFeature::SMS_CONNECT_CLIENT:
return "SMS_CONNECT_CLIENT";
default:
return "UNKNOWN_FEATURE";
}
}
-} // namespace cryptauth
+} // namespace device_sync
+
+} // namespace chromeos
diff --git a/chromeos/services/device_sync/proto/enum_util.h b/chromeos/services/device_sync/proto/enum_util.h
index 4ae512ee..806fc03 100644
--- a/chromeos/services/device_sync/proto/enum_util.h
+++ b/chromeos/services/device_sync/proto/enum_util.h
@@ -9,10 +9,12 @@
#include "chromeos/services/device_sync/proto/cryptauth_api.pb.h"
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
std::ostream& operator<<(std::ostream& stream,
- const SoftwareFeature& software_fature);
+ const cryptauth::SoftwareFeature& software_fature);
// Converts the string representation of a SoftwareFeature to its associated
// Proto enum value. Some Proto messages are sent to Apiary endpoints, which
@@ -36,7 +38,8 @@
std::string SoftwareFeatureEnumToStringAllCaps(
cryptauth::SoftwareFeature software_feature);
-std::ostream& operator<<(std::ostream& stream, const DeviceType& device_type);
+std::ostream& operator<<(std::ostream& stream,
+ const cryptauth::DeviceType& device_type);
// Converts the string representation of a DeviceType to its associated
// Proto enum value. Some Proto messages are sent to Apiary endpoints, which
@@ -53,6 +56,8 @@
// strings to enums after receiving them.
std::string DeviceTypeEnumToString(cryptauth::DeviceType device_type);
-} // namespace cryptauth
+} // namespace device_sync
+
+} // namespace chromeos
#endif // CHROMEOS_SERVICES_DEVICE_SYNC_PROTO_ENUM_UTIL_H_
diff --git a/chromeos/services/device_sync/public/cpp/BUILD.gn b/chromeos/services/device_sync/public/cpp/BUILD.gn
index 9c63165..f90cedcbf 100644
--- a/chromeos/services/device_sync/public/cpp/BUILD.gn
+++ b/chromeos/services/device_sync/public/cpp/BUILD.gn
@@ -4,10 +4,12 @@
source_set("cpp") {
sources = [
+ "cryptauth_device_id_provider.h",
"device_sync_client.cc",
"device_sync_client.h",
"device_sync_client_impl.cc",
"device_sync_client_impl.h",
+ "gcm_device_info_provider.h",
]
public_deps = [
@@ -29,6 +31,8 @@
sources = [
"fake_device_sync_client.cc",
"fake_device_sync_client.h",
+ "fake_gcm_device_info_provider.cc",
+ "fake_gcm_device_info_provider.h",
]
public_deps = [
diff --git a/chromeos/services/device_sync/public/cpp/cryptauth_device_id_provider.h b/chromeos/services/device_sync/public/cpp/cryptauth_device_id_provider.h
new file mode 100644
index 0000000..396c1b47
--- /dev/null
+++ b/chromeos/services/device_sync/public/cpp/cryptauth_device_id_provider.h
@@ -0,0 +1,34 @@
+// Copyright 2018 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROMEOS_SERVICES_DEVICE_SYNC_PUBLIC_CPP_CRYPTAUTH_DEVICE_ID_PROVIDER_H_
+#define CHROMEOS_SERVICES_DEVICE_SYNC_PUBLIC_CPP_CRYPTAUTH_DEVICE_ID_PROVIDER_H_
+
+#include <string>
+
+#include "base/macros.h"
+
+namespace chromeos {
+
+namespace device_sync {
+
+// Provides the ID of the current device. In this context, "device ID" refers to
+// the |long_device_id| field of the cryptauth::GcmDeviceInfo proto which is
+// sent to the CryptAuth back-end during device enrollment.
+class CryptAuthDeviceIdProvider {
+ public:
+ CryptAuthDeviceIdProvider() = default;
+ virtual ~CryptAuthDeviceIdProvider() = default;
+
+ virtual std::string GetDeviceId() const = 0;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(CryptAuthDeviceIdProvider);
+};
+
+} // namespace device_sync
+
+} // namespace chromeos
+
+#endif // CHROMEOS_SERVICES_DEVICE_SYNC_PUBLIC_CPP_CRYPTAUTH_DEVICE_ID_PROVIDER_H_
diff --git a/chromeos/services/device_sync/public/cpp/device_sync_client_impl_unittest.cc b/chromeos/services/device_sync/public/cpp/device_sync_client_impl_unittest.cc
index 63d0326..53fd792e 100644
--- a/chromeos/services/device_sync/public/cpp/device_sync_client_impl_unittest.cc
+++ b/chromeos/services/device_sync/public/cpp/device_sync_client_impl_unittest.cc
@@ -20,9 +20,9 @@
#include "chromeos/services/device_sync/device_sync_impl.h"
#include "chromeos/services/device_sync/device_sync_service.h"
#include "chromeos/services/device_sync/fake_device_sync.h"
+#include "chromeos/services/device_sync/public/cpp/fake_gcm_device_info_provider.h"
#include "chromeos/services/device_sync/public/mojom/constants.mojom.h"
#include "chromeos/services/device_sync/public/mojom/device_sync.mojom.h"
-#include "components/cryptauth/fake_gcm_device_info_provider.h"
#include "components/gcm_driver/fake_gcm_driver.h"
#include "services/identity/public/cpp/identity_test_environment.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
@@ -62,7 +62,7 @@
identity::IdentityManager* identity_manager,
gcm::GCMDriver* gcm_driver,
service_manager::Connector* connector,
- const cryptauth::GcmDeviceInfoProvider* gcm_device_info_provider,
+ const GcmDeviceInfoProvider* gcm_device_info_provider,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
std::unique_ptr<base::OneShotTimer> timer) override {
EXPECT_TRUE(fake_device_sync_);
@@ -144,7 +144,7 @@
void SetUp() override {
fake_gcm_driver_ = std::make_unique<gcm::FakeGCMDriver>();
fake_gcm_device_info_provider_ =
- std::make_unique<cryptauth::FakeGcmDeviceInfoProvider>(
+ std::make_unique<device_sync::FakeGcmDeviceInfoProvider>(
GetTestGcmDeviceInfo());
identity_test_environment_ =
@@ -421,7 +421,7 @@
std::unique_ptr<identity::IdentityTestEnvironment> identity_test_environment_;
std::unique_ptr<gcm::FakeGCMDriver> fake_gcm_driver_;
- std::unique_ptr<cryptauth::FakeGcmDeviceInfoProvider>
+ std::unique_ptr<device_sync::FakeGcmDeviceInfoProvider>
fake_gcm_device_info_provider_;
FakeDeviceSync* fake_device_sync_;
std::unique_ptr<FakeDeviceSyncImplFactory> fake_device_sync_impl_factory_;
diff --git a/chromeos/services/device_sync/public/cpp/fake_gcm_device_info_provider.cc b/chromeos/services/device_sync/public/cpp/fake_gcm_device_info_provider.cc
new file mode 100644
index 0000000..318e0fb
--- /dev/null
+++ b/chromeos/services/device_sync/public/cpp/fake_gcm_device_info_provider.cc
@@ -0,0 +1,24 @@
+// Copyright 2018 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chromeos/services/device_sync/public/cpp/fake_gcm_device_info_provider.h"
+
+namespace chromeos {
+
+namespace device_sync {
+
+FakeGcmDeviceInfoProvider::FakeGcmDeviceInfoProvider(
+ const cryptauth::GcmDeviceInfo& gcm_device_info)
+ : gcm_device_info_(gcm_device_info) {}
+
+FakeGcmDeviceInfoProvider::~FakeGcmDeviceInfoProvider() = default;
+
+const cryptauth::GcmDeviceInfo& FakeGcmDeviceInfoProvider::GetGcmDeviceInfo()
+ const {
+ return gcm_device_info_;
+}
+
+} // namespace device_sync
+
+} // namespace chromeos
diff --git a/chromeos/services/device_sync/public/cpp/fake_gcm_device_info_provider.h b/chromeos/services/device_sync/public/cpp/fake_gcm_device_info_provider.h
new file mode 100644
index 0000000..f5d9d58
--- /dev/null
+++ b/chromeos/services/device_sync/public/cpp/fake_gcm_device_info_provider.h
@@ -0,0 +1,36 @@
+// Copyright 2018 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROMEOS_SERVICES_DEVICE_SYNC_PUBLIC_CPP_FAKE_GCM_DEVICE_INFO_PROVIDER_H_
+#define CHROMEOS_SERVICES_DEVICE_SYNC_PUBLIC_CPP_FAKE_GCM_DEVICE_INFO_PROVIDER_H_
+
+#include "base/macros.h"
+#include "chromeos/services/device_sync/proto/cryptauth_api.pb.h"
+#include "chromeos/services/device_sync/public/cpp/gcm_device_info_provider.h"
+
+namespace chromeos {
+
+namespace device_sync {
+
+// Test GcmDeviceInfoProvider implementation.
+class FakeGcmDeviceInfoProvider : public GcmDeviceInfoProvider {
+ public:
+ explicit FakeGcmDeviceInfoProvider(
+ const cryptauth::GcmDeviceInfo& gcm_device_info);
+ ~FakeGcmDeviceInfoProvider() override;
+
+ // GcmDeviceInfoProvider:
+ const cryptauth::GcmDeviceInfo& GetGcmDeviceInfo() const override;
+
+ private:
+ const cryptauth::GcmDeviceInfo gcm_device_info_;
+
+ DISALLOW_COPY_AND_ASSIGN(FakeGcmDeviceInfoProvider);
+};
+
+} // namespace device_sync
+
+} // namespace chromeos
+
+#endif // CHROMEOS_SERVICES_DEVICE_SYNC_PUBLIC_CPP_FAKE_GCM_DEVICE_INFO_PROVIDER_H_
diff --git a/chromeos/services/device_sync/public/cpp/gcm_device_info_provider.h b/chromeos/services/device_sync/public/cpp/gcm_device_info_provider.h
new file mode 100644
index 0000000..89884c9
--- /dev/null
+++ b/chromeos/services/device_sync/public/cpp/gcm_device_info_provider.h
@@ -0,0 +1,33 @@
+// Copyright 2018 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROMEOS_SERVICES_DEVICE_SYNC_PUBLIC_CPP_GCM_DEVICE_INFO_PROVIDER_H_
+#define CHROMEOS_SERVICES_DEVICE_SYNC_PUBLIC_CPP_GCM_DEVICE_INFO_PROVIDER_H_
+
+#include "base/macros.h"
+#include "chromeos/services/device_sync/proto/cryptauth_api.pb.h"
+
+namespace chromeos {
+
+namespace device_sync {
+
+// Provides the cryptauth::GcmDeviceInfo object associated with the current
+// device. cryptauth::GcmDeviceInfo describes properties of this Chromebook and
+// is not expected to change except when the OS version is updated.
+class GcmDeviceInfoProvider {
+ public:
+ GcmDeviceInfoProvider() = default;
+ virtual ~GcmDeviceInfoProvider() = default;
+
+ virtual const cryptauth::GcmDeviceInfo& GetGcmDeviceInfo() const = 0;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(GcmDeviceInfoProvider);
+};
+
+} // namespace device_sync
+
+} // namespace chromeos
+
+#endif // CHROMEOS_SERVICES_DEVICE_SYNC_PUBLIC_CPP_GCM_DEVICE_INFO_PROVIDER_H_
diff --git a/components/cryptauth/remote_device_loader.cc b/chromeos/services/device_sync/remote_device_loader.cc
similarity index 87%
rename from components/cryptauth/remote_device_loader.cc
rename to chromeos/services/device_sync/remote_device_loader.cc
index 04143c58..c2332832 100644
--- a/components/cryptauth/remote_device_loader.cc
+++ b/chromeos/services/device_sync/remote_device_loader.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/cryptauth/remote_device_loader.h"
+#include "chromeos/services/device_sync/remote_device_loader.h"
#include <algorithm>
#include <utility>
@@ -17,7 +17,9 @@
#include "chromeos/services/device_sync/proto/enum_util.h"
#include "components/cryptauth/secure_message_delegate.h"
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
namespace {
@@ -31,7 +33,7 @@
for (int i = 0; i < device.supported_software_features_size(); ++i) {
cryptauth::SoftwareFeature feature =
SoftwareFeatureStringToEnum(device.supported_software_features(i));
- if (feature == UNKNOWN_FEATURE)
+ if (feature == cryptauth::UNKNOWN_FEATURE)
continue;
software_feature_to_state_map[chromeos::multidevice::FromCryptAuthFeature(
@@ -41,7 +43,7 @@
for (int i = 0; i < device.enabled_software_features_size(); ++i) {
cryptauth::SoftwareFeature feature =
SoftwareFeatureStringToEnum(device.enabled_software_features(i));
- if (feature == UNKNOWN_FEATURE)
+ if (feature == cryptauth::UNKNOWN_FEATURE)
continue;
software_feature_to_state_map[chromeos::multidevice::FromCryptAuthFeature(
@@ -66,8 +68,7 @@
if (!factory_instance_) {
factory_instance_ = new Factory();
}
- return factory_instance_->BuildInstance(device_info_list,
- user_id,
+ return factory_instance_->BuildInstance(device_info_list, user_id,
user_private_key,
std::move(secure_message_delegate));
}
@@ -83,9 +84,7 @@
const std::string& user_private_key,
std::unique_ptr<cryptauth::SecureMessageDelegate> secure_message_delegate) {
return base::WrapUnique(
- new RemoteDeviceLoader(device_info_list,
- user_id,
- user_private_key,
+ new RemoteDeviceLoader(device_info_list, user_id, user_private_key,
std::move(secure_message_delegate)));
}
@@ -128,17 +127,17 @@
const cryptauth::ExternalDeviceInfo& device,
const std::string& psk) {
std::string public_key = device.public_key();
- auto iterator = std::find_if(
- remaining_devices_.begin(), remaining_devices_.end(),
- [&public_key](const cryptauth::ExternalDeviceInfo& device) {
- return device.public_key() == public_key;
- });
+ auto iterator =
+ std::find_if(remaining_devices_.begin(), remaining_devices_.end(),
+ [&public_key](const cryptauth::ExternalDeviceInfo& device) {
+ return device.public_key() == public_key;
+ });
DCHECK(iterator != remaining_devices_.end());
remaining_devices_.erase(iterator);
std::vector<chromeos::multidevice::BeaconSeed> multidevice_beacon_seeds;
- for (const BeaconSeed& cryptauth_beacon_seed : device.beacon_seeds()) {
+ for (const auto& cryptauth_beacon_seed : device.beacon_seeds()) {
multidevice_beacon_seeds.push_back(
chromeos::multidevice::FromCryptAuthSeed(cryptauth_beacon_seed));
}
@@ -157,4 +156,6 @@
}
}
-} // namespace cryptauth
+} // namespace device_sync
+
+} // namespace chromeos
diff --git a/components/cryptauth/remote_device_loader.h b/chromeos/services/device_sync/remote_device_loader.h
similarity index 85%
rename from components/cryptauth/remote_device_loader.h
rename to chromeos/services/device_sync/remote_device_loader.h
index 937e1f6..8a54146 100644
--- a/components/cryptauth/remote_device_loader.h
+++ b/chromeos/services/device_sync/remote_device_loader.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef COMPONENTS_CRYPTAUTH_REMOTE_DEVICE_LOADER_H_
-#define COMPONENTS_CRYPTAUTH_REMOTE_DEVICE_LOADER_H_
+#ifndef CHROMEOS_SERVICES_DEVICE_SYNC_REMOTE_DEVICE_LOADER_H_
+#define CHROMEOS_SERVICES_DEVICE_SYNC_REMOTE_DEVICE_LOADER_H_
#include <memory>
#include <string>
@@ -15,13 +15,17 @@
#include "chromeos/services/device_sync/proto/cryptauth_api.pb.h"
namespace cryptauth {
-
class SecureMessageDelegate;
+} // namespace cryptauth
+
+namespace chromeos {
+
+namespace device_sync {
// Loads a collection of chromeos::multidevice::RemoteDevice objects from the
-// given ExternalDeviceInfo protos that were synced from CryptAuth. We need to
-// derive the PSK, which is a symmetric key used to authenticate each remote
-// device.
+// given cryptauth::ExternalDeviceInfo protos that were synced from CryptAuth.
+// We need to derive the PSK, which is a symmetric key used to authenticate each
+// remote device.
class RemoteDeviceLoader {
public:
class Factory {
@@ -48,7 +52,7 @@
};
// Creates the instance:
- // |device_info_list|: The ExternalDeviceInfo objects to convert to
+ // |device_info_list|: The cryptauth::ExternalDeviceInfo objects to convert to
// chromeos::multidevice::RemoteDevice.
// |user_private_key|: The private key of the user's local device. Used to
// derive the PSK.
@@ -97,6 +101,8 @@
DISALLOW_COPY_AND_ASSIGN(RemoteDeviceLoader);
};
-} // namespace cryptauth
+} // namespace device_sync
-#endif // COMPONENTS_CRYPTAUTH_REMOTE_DEVICE_LOADER_H_
+} // namespace chromeos
+
+#endif // CHROMEOS_SERVICES_DEVICE_SYNC_REMOTE_DEVICE_LOADER_H_
diff --git a/components/cryptauth/remote_device_loader_unittest.cc b/chromeos/services/device_sync/remote_device_loader_unittest.cc
similarity index 78%
rename from components/cryptauth/remote_device_loader_unittest.cc
rename to chromeos/services/device_sync/remote_device_loader_unittest.cc
index ac2a1fc9..b77ad440 100644
--- a/components/cryptauth/remote_device_loader_unittest.cc
+++ b/chromeos/services/device_sync/remote_device_loader_unittest.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/cryptauth/remote_device_loader.h"
+#include "chromeos/services/device_sync/remote_device_loader.h"
#include <stddef.h>
@@ -16,7 +16,10 @@
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
+
namespace {
// Prefixes for chromeos::multidevice::RemoteDevice fields.
@@ -34,14 +37,14 @@
const int64_t kBeaconSeedEndTimeMs = 2000;
const char kBeaconSeedData[] = "Beacon Seed Data";
-// Creates and returns an ExternalDeviceInfo proto with the fields appended with
-// |suffix|.
+// Creates and returns an cryptauth::ExternalDeviceInfo proto with the fields
+// appended with |suffix|.
cryptauth::ExternalDeviceInfo CreateDeviceInfo(const std::string& suffix) {
cryptauth::ExternalDeviceInfo device_info;
device_info.set_friendly_device_name(std::string(kDeviceNamePrefix) + suffix);
device_info.set_public_key(std::string(kPublicKeyPrefix) + suffix);
device_info.add_beacon_seeds();
- BeaconSeed* beacon_seed = device_info.mutable_beacon_seeds(0);
+ cryptauth::BeaconSeed* beacon_seed = device_info.mutable_beacon_seeds(0);
beacon_seed->set_start_time_millis(kBeaconSeedStartTimeMs);
beacon_seed->set_end_time_millis(kBeaconSeedEndTimeMs);
beacon_seed->set_data(kBeaconSeedData);
@@ -50,14 +53,14 @@
} // namespace
-class CryptAuthRemoteDeviceLoaderTest : public testing::Test {
+class DeviceSyncRemoteDeviceLoaderTest : public testing::Test {
public:
- CryptAuthRemoteDeviceLoaderTest()
+ DeviceSyncRemoteDeviceLoaderTest()
: secure_message_delegate_(new cryptauth::FakeSecureMessageDelegate()),
user_private_key_(secure_message_delegate_->GetPrivateKeyForPublicKey(
kUserPublicKey)) {}
- ~CryptAuthRemoteDeviceLoaderTest() {}
+ ~DeviceSyncRemoteDeviceLoaderTest() {}
void OnRemoteDevicesLoaded(
const chromeos::multidevice::RemoteDeviceList& remote_devices) {
@@ -79,23 +82,23 @@
// Stores the result of the chromeos::multidevice::RemoteDeviceLoader.
chromeos::multidevice::RemoteDeviceList remote_devices_;
- DISALLOW_COPY_AND_ASSIGN(CryptAuthRemoteDeviceLoaderTest);
+ DISALLOW_COPY_AND_ASSIGN(DeviceSyncRemoteDeviceLoaderTest);
};
-TEST_F(CryptAuthRemoteDeviceLoaderTest, LoadZeroDevices) {
+TEST_F(DeviceSyncRemoteDeviceLoaderTest, LoadZeroDevices) {
std::vector<cryptauth::ExternalDeviceInfo> device_infos;
RemoteDeviceLoader loader(device_infos, user_private_key_, kUserId,
std::move(secure_message_delegate_));
EXPECT_CALL(*this, LoadCompleted());
loader.Load(
- base::Bind(&CryptAuthRemoteDeviceLoaderTest::OnRemoteDevicesLoaded,
+ base::Bind(&DeviceSyncRemoteDeviceLoaderTest::OnRemoteDevicesLoaded,
base::Unretained(this)));
EXPECT_EQ(0u, remote_devices_.size());
}
-TEST_F(CryptAuthRemoteDeviceLoaderTest, LoadOneDevice) {
+TEST_F(DeviceSyncRemoteDeviceLoaderTest, LoadOneDevice) {
std::vector<cryptauth::ExternalDeviceInfo> device_infos(
1, CreateDeviceInfo("0"));
RemoteDeviceLoader loader(device_infos, user_private_key_, kUserId,
@@ -103,7 +106,7 @@
EXPECT_CALL(*this, LoadCompleted());
loader.Load(
- base::Bind(&CryptAuthRemoteDeviceLoaderTest::OnRemoteDevicesLoaded,
+ base::Bind(&DeviceSyncRemoteDeviceLoaderTest::OnRemoteDevicesLoaded,
base::Unretained(this)));
EXPECT_EQ(1u, remote_devices_.size());
@@ -112,14 +115,15 @@
EXPECT_EQ(device_infos[0].public_key(), remote_devices_[0].public_key);
ASSERT_EQ(1u, remote_devices_[0].beacon_seeds.size());
- const BeaconSeed& beacon_seed = chromeos::multidevice::ToCryptAuthSeed(
- remote_devices_[0].beacon_seeds[0]);
+ const cryptauth::BeaconSeed& beacon_seed =
+ chromeos::multidevice::ToCryptAuthSeed(
+ remote_devices_[0].beacon_seeds[0]);
EXPECT_EQ(kBeaconSeedData, beacon_seed.data());
EXPECT_EQ(kBeaconSeedStartTimeMs, beacon_seed.start_time_millis());
EXPECT_EQ(kBeaconSeedEndTimeMs, beacon_seed.end_time_millis());
}
-TEST_F(CryptAuthRemoteDeviceLoaderTest, LastUpdateTimeMillis) {
+TEST_F(DeviceSyncRemoteDeviceLoaderTest, LastUpdateTimeMillis) {
cryptauth::ExternalDeviceInfo first = CreateDeviceInfo("0");
first.set_last_update_time_millis(1000);
@@ -133,7 +137,7 @@
EXPECT_CALL(*this, LoadCompleted());
loader.Load(
- base::Bind(&CryptAuthRemoteDeviceLoaderTest::OnRemoteDevicesLoaded,
+ base::Bind(&DeviceSyncRemoteDeviceLoaderTest::OnRemoteDevicesLoaded,
base::Unretained(this)));
EXPECT_EQ(2u, remote_devices_.size());
@@ -143,11 +147,11 @@
EXPECT_EQ(2000, remote_devices_[1].last_update_time_millis);
}
-TEST_F(CryptAuthRemoteDeviceLoaderTest, SoftwareFeatures) {
- const std::vector<SoftwareFeature> kSupportedSoftwareFeatures{
- BETTER_TOGETHER_HOST, BETTER_TOGETHER_CLIENT};
- const std::vector<SoftwareFeature> kEnabledSoftwareFeatures{
- BETTER_TOGETHER_HOST};
+TEST_F(DeviceSyncRemoteDeviceLoaderTest, SoftwareFeatures) {
+ const std::vector<cryptauth::SoftwareFeature> kSupportedSoftwareFeatures{
+ cryptauth::BETTER_TOGETHER_HOST, cryptauth::BETTER_TOGETHER_CLIENT};
+ const std::vector<cryptauth::SoftwareFeature> kEnabledSoftwareFeatures{
+ cryptauth::BETTER_TOGETHER_HOST};
cryptauth::ExternalDeviceInfo first = CreateDeviceInfo("0");
for (const auto& software_feature : kSupportedSoftwareFeatures) {
@@ -166,7 +170,7 @@
EXPECT_CALL(*this, LoadCompleted());
loader.Load(
- base::Bind(&CryptAuthRemoteDeviceLoaderTest::OnRemoteDevicesLoaded,
+ base::Bind(&DeviceSyncRemoteDeviceLoaderTest::OnRemoteDevicesLoaded,
base::Unretained(this)));
EXPECT_EQ(1u, remote_devices_.size());
@@ -184,4 +188,6 @@
[chromeos::multidevice::SoftwareFeature::kInstantTetheringHost]);
}
-} // namespace cryptauth
+} // namespace device_sync
+
+} // namespace chromeos
diff --git a/components/cryptauth/remote_device_provider.cc b/chromeos/services/device_sync/remote_device_provider.cc
similarity index 78%
rename from components/cryptauth/remote_device_provider.cc
rename to chromeos/services/device_sync/remote_device_provider.cc
index e9c7034..468e15e 100644
--- a/components/cryptauth/remote_device_provider.cc
+++ b/chromeos/services/device_sync/remote_device_provider.cc
@@ -2,9 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/cryptauth/remote_device_provider.h"
+#include "chromeos/services/device_sync/remote_device_provider.h"
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
RemoteDeviceProvider::RemoteDeviceProvider() {}
@@ -23,4 +25,6 @@
observer.OnSyncDeviceListChanged();
}
-} // namespace cryptauth
+} // namespace device_sync
+
+} // namespace chromeos
diff --git a/components/cryptauth/remote_device_provider.h b/chromeos/services/device_sync/remote_device_provider.h
similarity index 77%
rename from components/cryptauth/remote_device_provider.h
rename to chromeos/services/device_sync/remote_device_provider.h
index b0d8655..76ef1b3 100644
--- a/components/cryptauth/remote_device_provider.h
+++ b/chromeos/services/device_sync/remote_device_provider.h
@@ -2,13 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef COMPONENTS_CRYPTAUTH_REMOTE_DEVICE_PROVIDER_H_
-#define COMPONENTS_CRYPTAUTH_REMOTE_DEVICE_PROVIDER_H_
+#ifndef CHROMEOS_SERVICES_DEVICE_SYNC_REMOTE_DEVICE_PROVIDER_H_
+#define CHROMEOS_SERVICES_DEVICE_SYNC_REMOTE_DEVICE_PROVIDER_H_
#include "base/observer_list.h"
#include "chromeos/components/multidevice/remote_device.h"
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
// This class generates and caches chromeos::multidevice::RemoteDevice objects
// when associated metadata has been synced, and updates this cache when a new
@@ -41,6 +43,8 @@
base::ObserverList<Observer>::Unchecked observers_;
};
-} // namespace cryptauth
+} // namespace device_sync
-#endif // COMPONENTS_CRYPTAUTH_REMOTE_DEVICE_PROVIDER_H_
+} // namespace chromeos
+
+#endif // CHROMEOS_SERVICES_DEVICE_SYNC_REMOTE_DEVICE_PROVIDER_H_
diff --git a/components/cryptauth/remote_device_provider_impl.cc b/chromeos/services/device_sync/remote_device_provider_impl.cc
similarity index 93%
rename from components/cryptauth/remote_device_provider_impl.cc
rename to chromeos/services/device_sync/remote_device_provider_impl.cc
index ac98eea..dd8fe8a66 100644
--- a/components/cryptauth/remote_device_provider_impl.cc
+++ b/chromeos/services/device_sync/remote_device_provider_impl.cc
@@ -2,14 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/cryptauth/remote_device_provider_impl.h"
+#include "chromeos/services/device_sync/remote_device_provider_impl.h"
#include "base/bind.h"
#include "base/memory/ptr_util.h"
-#include "components/cryptauth/remote_device_loader.h"
+#include "chromeos/services/device_sync/remote_device_loader.h"
#include "components/cryptauth/secure_message_delegate_impl.h"
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
// static
RemoteDeviceProviderImpl::Factory*
@@ -98,4 +100,6 @@
return synced_remote_devices_;
}
-} // namespace cryptauth
+} // namespace device_sync
+
+} // namespace chromeos
diff --git a/components/cryptauth/remote_device_provider_impl.h b/chromeos/services/device_sync/remote_device_provider_impl.h
similarity index 81%
rename from components/cryptauth/remote_device_provider_impl.h
rename to chromeos/services/device_sync/remote_device_provider_impl.h
index 7fffb038..42abd13 100644
--- a/components/cryptauth/remote_device_provider_impl.h
+++ b/chromeos/services/device_sync/remote_device_provider_impl.h
@@ -2,13 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef COMPONENTS_CRYPTAUTH_REMOTE_DEVICE_PROVIDER_IMPL_H_
-#define COMPONENTS_CRYPTAUTH_REMOTE_DEVICE_PROVIDER_IMPL_H_
+#ifndef CHROMEOS_SERVICES_DEVICE_SYNC_REMOTE_DEVICE_PROVIDER_IMPL_H_
+#define CHROMEOS_SERVICES_DEVICE_SYNC_REMOTE_DEVICE_PROVIDER_IMPL_H_
-#include "components/cryptauth/cryptauth_device_manager.h"
-#include "components/cryptauth/remote_device_provider.h"
+#include "chromeos/services/device_sync/cryptauth_device_manager.h"
+#include "chromeos/services/device_sync/remote_device_provider.h"
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
class RemoteDeviceLoader;
@@ -56,7 +58,7 @@
void OnRemoteDevicesLoaded(
const chromeos::multidevice::RemoteDeviceList& synced_remote_devices);
- // To get ExternalDeviceInfo needed to retrieve
+ // To get cryptauth::ExternalDeviceInfo needed to retrieve
// chromeos::multidevice::RemoteDevices.
CryptAuthDeviceManager* device_manager_;
@@ -73,6 +75,8 @@
DISALLOW_COPY_AND_ASSIGN(RemoteDeviceProviderImpl);
};
-} // namespace cryptauth
+} // namespace device_sync
-#endif // COMPONENTS_CRYPTAUTH_REMOTE_DEVICE_PROVIDER_IMPL_H_
+} // namespace chromeos
+
+#endif // CHROMEOS_SERVICES_DEVICE_SYNC_REMOTE_DEVICE_PROVIDER_IMPL_H_
diff --git a/components/cryptauth/remote_device_provider_impl_unittest.cc b/chromeos/services/device_sync/remote_device_provider_impl_unittest.cc
similarity index 91%
rename from components/cryptauth/remote_device_provider_impl_unittest.cc
rename to chromeos/services/device_sync/remote_device_provider_impl_unittest.cc
index 16ce82a1..2ae490f 100644
--- a/components/cryptauth/remote_device_provider_impl_unittest.cc
+++ b/chromeos/services/device_sync/remote_device_provider_impl_unittest.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/cryptauth/remote_device_provider_impl.h"
+#include "chromeos/services/device_sync/remote_device_provider_impl.h"
#include <memory>
#include <vector>
@@ -11,11 +11,11 @@
#include "base/memory/ptr_util.h"
#include "base/run_loop.h"
#include "chromeos/components/multidevice/remote_device_test_util.h"
+#include "chromeos/services/device_sync/cryptauth_device_manager.h"
+#include "chromeos/services/device_sync/fake_cryptauth_device_manager.h"
#include "chromeos/services/device_sync/proto/cryptauth_api.pb.h"
-#include "components/cryptauth/cryptauth_device_manager.h"
-#include "components/cryptauth/fake_cryptauth_device_manager.h"
+#include "chromeos/services/device_sync/remote_device_loader.h"
#include "components/cryptauth/fake_secure_message_delegate.h"
-#include "components/cryptauth/remote_device_loader.h"
#include "components/cryptauth/secure_message_delegate_impl.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -25,7 +25,9 @@
using testing::NiceMock;
using testing::Return;
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
namespace {
@@ -52,7 +54,7 @@
const chromeos::multidevice::RemoteDeviceList remote_devices) {
std::vector<cryptauth::ExternalDeviceInfo> device_infos;
for (const auto& remote_device : remote_devices) {
- // Add an ExternalDeviceInfo with the same public key as the
+ // Add an cryptauth::ExternalDeviceInfo with the same public key as the
// chromeos::multidevice::RemoteDevice.
cryptauth::ExternalDeviceInfo info;
info.set_public_key(remote_device.public_key);
@@ -82,7 +84,7 @@
class TestRemoteDeviceLoaderFactory final
: public RemoteDeviceLoader::Factory {
public:
- explicit TestRemoteDeviceLoaderFactory()
+ TestRemoteDeviceLoaderFactory()
: test_devices_(
chromeos::multidevice::CreateRemoteDeviceListForTest(5)),
test_device_infos_(
@@ -149,9 +151,9 @@
}
};
-class RemoteDeviceProviderImplTest : public testing::Test {
+class DeviceSyncRemoteDeviceProviderImplTest : public testing::Test {
public:
- RemoteDeviceProviderImplTest() {}
+ DeviceSyncRemoteDeviceProviderImplTest() {}
void SetUp() override {
fake_device_manager_ = std::make_unique<FakeCryptAuthDeviceManager>();
@@ -201,7 +203,7 @@
return test_device_loader_factory_->test_devices_;
}
- ExternalDeviceInfo test_device_infos_(int val) {
+ cryptauth::ExternalDeviceInfo test_device_infos_(int val) {
return test_device_loader_factory_->test_device_infos_[val];
}
@@ -218,10 +220,10 @@
std::unique_ptr<TestObserver> test_observer_;
private:
- DISALLOW_COPY_AND_ASSIGN(RemoteDeviceProviderImplTest);
+ DISALLOW_COPY_AND_ASSIGN(DeviceSyncRemoteDeviceProviderImplTest);
};
-TEST_F(RemoteDeviceProviderImplTest, TestMultipleSyncs) {
+TEST_F(DeviceSyncRemoteDeviceProviderImplTest, TestMultipleSyncs) {
// Initialize with devices 0 and 1.
fake_device_manager_->synced_devices().push_back(test_device_infos_(0));
fake_device_manager_->synced_devices().push_back(test_device_infos_(1));
@@ -251,7 +253,7 @@
EXPECT_EQ(3, test_observer_->num_times_device_list_changed());
}
-TEST_F(RemoteDeviceProviderImplTest,
+TEST_F(DeviceSyncRemoteDeviceProviderImplTest,
TestNotifySyncFinishedParameterCombinations) {
fake_device_manager_->synced_devices().push_back(test_device_infos_(0));
CreateRemoteDeviceProvider();
@@ -287,7 +289,8 @@
EXPECT_EQ(2, test_observer_->num_times_device_list_changed());
}
-TEST_F(RemoteDeviceProviderImplTest, TestNewSyncDuringDeviceRegeneration) {
+TEST_F(DeviceSyncRemoteDeviceProviderImplTest,
+ TestNewSyncDuringDeviceRegeneration) {
fake_device_manager_->synced_devices().push_back(test_device_infos_(0));
CreateRemoteDeviceProvider();
VerifySyncedDevicesMatchExpectation(1u /* expected_size */);
@@ -312,7 +315,7 @@
EXPECT_EQ(2, test_observer_->num_times_device_list_changed());
}
-TEST_F(RemoteDeviceProviderImplTest, TestZeroSyncedDevices) {
+TEST_F(DeviceSyncRemoteDeviceProviderImplTest, TestZeroSyncedDevices) {
CreateRemoteDeviceProvider();
VerifySyncedDevicesMatchExpectation(0 /* expected_size */);
EXPECT_EQ(1, test_observer_->num_times_device_list_changed());
@@ -324,4 +327,6 @@
EXPECT_EQ(1, test_observer_->num_times_device_list_changed());
}
-} // namespace cryptauth
+} // namespace device_sync
+
+} // namespace chromeos
diff --git a/components/cryptauth/software_feature_manager.h b/chromeos/services/device_sync/software_feature_manager.h
similarity index 73%
rename from components/cryptauth/software_feature_manager.h
rename to chromeos/services/device_sync/software_feature_manager.h
index 28301b2..d89e802 100644
--- a/components/cryptauth/software_feature_manager.h
+++ b/chromeos/services/device_sync/software_feature_manager.h
@@ -2,14 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef COMPONENTS_CRYPTAUTH_SOFTWARE_FEATURE_MANAGER_H_
-#define COMPONENTS_CRYPTAUTH_SOFTWARE_FEATURE_MANAGER_H_
+#ifndef CHROMEOS_SERVICES_DEVICE_SYNC_SOFTWARE_FEATURE_MANAGER_H_
+#define CHROMEOS_SERVICES_DEVICE_SYNC_SOFTWARE_FEATURE_MANAGER_H_
#include "base/callback.h"
#include "chromeos/components/multidevice/software_feature.h"
-#include "components/cryptauth/network_request_error.h"
+#include "chromeos/services/device_sync/network_request_error.h"
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
// Queries for eligible MultiDevice hosts and sets/changes/unsets the current
// MultiDevice host for the logged-in account.
@@ -37,12 +39,14 @@
// |software_feature|.
virtual void FindEligibleDevices(
chromeos::multidevice::SoftwareFeature software_feature,
- const base::Callback<void(const std::vector<ExternalDeviceInfo>&,
- const std::vector<IneligibleDevice>&)>&
- success_callback,
+ const base::Callback<void(
+ const std::vector<cryptauth::ExternalDeviceInfo>&,
+ const std::vector<cryptauth::IneligibleDevice>&)>& success_callback,
const base::Callback<void(NetworkRequestError)>& error_callback) = 0;
};
-} // namespace cryptauth
+} // namespace device_sync
-#endif // COMPONENTS_CRYPTAUTH_SOFTWARE_FEATURE_MANAGER_H_
+} // namespace chromeos
+
+#endif // CHROMEOS_SERVICES_DEVICE_SYNC_SOFTWARE_FEATURE_MANAGER_H_
diff --git a/components/cryptauth/software_feature_manager_impl.cc b/chromeos/services/device_sync/software_feature_manager_impl.cc
similarity index 82%
rename from components/cryptauth/software_feature_manager_impl.cc
rename to chromeos/services/device_sync/software_feature_manager_impl.cc
index fd07733..50028c9 100644
--- a/components/cryptauth/software_feature_manager_impl.cc
+++ b/chromeos/services/device_sync/software_feature_manager_impl.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/cryptauth/software_feature_manager_impl.h"
+#include "chromeos/services/device_sync/software_feature_manager_impl.h"
#include <memory>
@@ -12,7 +12,9 @@
#include "chromeos/services/device_sync/proto/cryptauth_api.pb.h"
#include "chromeos/services/device_sync/proto/enum_util.h"
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
// static
SoftwareFeatureManagerImpl::Factory*
@@ -44,7 +46,7 @@
}
SoftwareFeatureManagerImpl::Request::Request(
- std::unique_ptr<ToggleEasyUnlockRequest> toggle_request,
+ std::unique_ptr<cryptauth::ToggleEasyUnlockRequest> toggle_request,
const base::Closure& set_software_success_callback,
const base::Callback<void(NetworkRequestError)> error_callback)
: error_callback(error_callback),
@@ -52,9 +54,9 @@
set_software_success_callback(set_software_success_callback) {}
SoftwareFeatureManagerImpl::Request::Request(
- std::unique_ptr<FindEligibleUnlockDevicesRequest> find_request,
- const base::Callback<void(const std::vector<ExternalDeviceInfo>&,
- const std::vector<IneligibleDevice>&)>
+ std::unique_ptr<cryptauth::FindEligibleUnlockDevicesRequest> find_request,
+ const base::Callback<void(const std::vector<cryptauth::ExternalDeviceInfo>&,
+ const std::vector<cryptauth::IneligibleDevice>&)>
find_hosts_success_callback,
const base::Callback<void(NetworkRequestError)> error_callback)
: error_callback(error_callback),
@@ -79,8 +81,8 @@
bool is_exclusive) {
// Note: For legacy reasons, this proto message mentions "ToggleEasyUnlock"
// instead of "SetSoftwareFeature" in its name.
- auto request = std::make_unique<ToggleEasyUnlockRequest>();
- request->set_feature(cryptauth::SoftwareFeatureEnumToString(
+ auto request = std::make_unique<cryptauth::ToggleEasyUnlockRequest>();
+ request->set_feature(SoftwareFeatureEnumToString(
chromeos::multidevice::ToCryptAuthFeature(software_feature)));
request->set_enable(enabled);
request->set_is_exclusive(enabled && is_exclusive);
@@ -101,14 +103,15 @@
void SoftwareFeatureManagerImpl::FindEligibleDevices(
chromeos::multidevice::SoftwareFeature software_feature,
- const base::Callback<void(const std::vector<ExternalDeviceInfo>&,
- const std::vector<IneligibleDevice>&)>&
+ const base::Callback<void(const std::vector<cryptauth::ExternalDeviceInfo>&,
+ const std::vector<cryptauth::IneligibleDevice>&)>&
success_callback,
const base::Callback<void(NetworkRequestError)>& error_callback) {
// Note: For legacy reasons, this proto message mentions "UnlockDevices"
// instead of "MultiDeviceHosts" in its name.
- auto request = std::make_unique<FindEligibleUnlockDevicesRequest>();
- request->set_feature(cryptauth::SoftwareFeatureEnumToString(
+ auto request =
+ std::make_unique<cryptauth::FindEligibleUnlockDevicesRequest>();
+ request->set_feature(SoftwareFeatureEnumToString(
chromeos::multidevice::ToCryptAuthFeature(software_feature)));
// For historical reasons, the Bluetooth address is abused to mark a which
@@ -161,7 +164,7 @@
}
void SoftwareFeatureManagerImpl::OnToggleEasyUnlockResponse(
- const ToggleEasyUnlockResponse& response) {
+ const cryptauth::ToggleEasyUnlockResponse& response) {
current_cryptauth_client_.reset();
current_request_->set_software_success_callback.Run();
current_request_.reset();
@@ -169,13 +172,15 @@
}
void SoftwareFeatureManagerImpl::OnFindEligibleUnlockDevicesResponse(
- const FindEligibleUnlockDevicesResponse& response) {
+ const cryptauth::FindEligibleUnlockDevicesResponse& response) {
current_cryptauth_client_.reset();
current_request_->find_hosts_success_callback.Run(
- std::vector<ExternalDeviceInfo>(response.eligible_devices().begin(),
- response.eligible_devices().end()),
- std::vector<IneligibleDevice>(response.ineligible_devices().begin(),
- response.ineligible_devices().end()));
+ std::vector<cryptauth::ExternalDeviceInfo>(
+ response.eligible_devices().begin(),
+ response.eligible_devices().end()),
+ std::vector<cryptauth::IneligibleDevice>(
+ response.ineligible_devices().begin(),
+ response.ineligible_devices().end()));
current_request_.reset();
ProcessRequestQueue();
}
@@ -187,4 +192,6 @@
ProcessRequestQueue();
}
-} // namespace cryptauth
+} // namespace device_sync
+
+} // namespace chromeos
diff --git a/components/cryptauth/software_feature_manager_impl.h b/chromeos/services/device_sync/software_feature_manager_impl.h
similarity index 65%
rename from components/cryptauth/software_feature_manager_impl.h
rename to chromeos/services/device_sync/software_feature_manager_impl.h
index 82c4cffa..99f2e8e5 100644
--- a/components/cryptauth/software_feature_manager_impl.h
+++ b/chromeos/services/device_sync/software_feature_manager_impl.h
@@ -2,18 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef COMPONENTS_CRYPTAUTH_SOFTWARE_FEATURE_MANAGER_IMPL_H_
-#define COMPONENTS_CRYPTAUTH_SOFTWARE_FEATURE_MANAGER_IMPL_H_
+#ifndef CHROMEOS_SERVICES_DEVICE_SYNC_SOFTWARE_FEATURE_MANAGER_IMPL_H_
+#define CHROMEOS_SERVICES_DEVICE_SYNC_SOFTWARE_FEATURE_MANAGER_IMPL_H_
#include "base/bind.h"
#include "base/callback_forward.h"
#include "base/containers/queue.h"
#include "base/memory/weak_ptr.h"
+#include "chromeos/services/device_sync/cryptauth_client.h"
#include "chromeos/services/device_sync/proto/cryptauth_api.pb.h"
-#include "components/cryptauth/cryptauth_client.h"
-#include "components/cryptauth/software_feature_manager.h"
+#include "chromeos/services/device_sync/software_feature_manager.h"
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
// Concrete SoftwareFeatureManager implementation. To query and/or set
// MultiDevice hosts, this class makes network requests to the CryptAuth
@@ -48,9 +50,9 @@
bool is_exclusive = false) override;
void FindEligibleDevices(
chromeos::multidevice::SoftwareFeature software_feature,
- const base::Callback<void(const std::vector<ExternalDeviceInfo>&,
- const std::vector<IneligibleDevice>&)>&
- success_callback,
+ const base::Callback<void(
+ const std::vector<cryptauth::ExternalDeviceInfo>&,
+ const std::vector<cryptauth::IneligibleDevice>&)>& success_callback,
const base::Callback<void(NetworkRequestError)>& error_callback) override;
private:
@@ -61,14 +63,16 @@
struct Request {
// Used for SET_SOFTWARE_FEATURE Requests.
- Request(std::unique_ptr<ToggleEasyUnlockRequest> toggle_request,
+ Request(std::unique_ptr<cryptauth::ToggleEasyUnlockRequest> toggle_request,
const base::Closure& set_software_success_callback,
const base::Callback<void(NetworkRequestError)> error_callback);
// Used for FIND_ELIGIBLE_MULTIDEVICE_HOSTS Requests.
- Request(std::unique_ptr<FindEligibleUnlockDevicesRequest> find_request,
- const base::Callback<void(const std::vector<ExternalDeviceInfo>&,
- const std::vector<IneligibleDevice>&)>
+ Request(std::unique_ptr<cryptauth::FindEligibleUnlockDevicesRequest>
+ find_request,
+ const base::Callback<
+ void(const std::vector<cryptauth::ExternalDeviceInfo>&,
+ const std::vector<cryptauth::IneligibleDevice>&)>
find_hosts_success_callback,
const base::Callback<void(NetworkRequestError)> error_callback);
@@ -77,25 +81,27 @@
const base::Callback<void(NetworkRequestError)> error_callback;
// Set for SET_SOFTWARE_FEATURE; unset otherwise.
- std::unique_ptr<ToggleEasyUnlockRequest> toggle_request;
+ std::unique_ptr<cryptauth::ToggleEasyUnlockRequest> toggle_request;
const base::Closure set_software_success_callback;
// Set for FIND_ELIGIBLE_MULTIDEVICE_HOSTS; unset otherwise.
- std::unique_ptr<FindEligibleUnlockDevicesRequest> find_request;
- const base::Callback<void(const std::vector<ExternalDeviceInfo>&,
- const std::vector<IneligibleDevice>&)>
+ std::unique_ptr<cryptauth::FindEligibleUnlockDevicesRequest> find_request;
+ const base::Callback<void(const std::vector<cryptauth::ExternalDeviceInfo>&,
+ const std::vector<cryptauth::IneligibleDevice>&)>
find_hosts_success_callback;
};
- SoftwareFeatureManagerImpl(CryptAuthClientFactory* cryptauth_client_factory);
+ explicit SoftwareFeatureManagerImpl(
+ CryptAuthClientFactory* cryptauth_client_factory);
void ProcessRequestQueue();
void ProcessSetSoftwareFeatureStateRequest();
void ProcessFindEligibleDevicesRequest();
- void OnToggleEasyUnlockResponse(const ToggleEasyUnlockResponse& response);
+ void OnToggleEasyUnlockResponse(
+ const cryptauth::ToggleEasyUnlockResponse& response);
void OnFindEligibleUnlockDevicesResponse(
- const FindEligibleUnlockDevicesResponse& response);
+ const cryptauth::FindEligibleUnlockDevicesResponse& response);
void OnErrorResponse(NetworkRequestError response);
CryptAuthClientFactory* crypt_auth_client_factory_;
@@ -106,6 +112,9 @@
base::WeakPtrFactory<SoftwareFeatureManagerImpl> weak_ptr_factory_;
};
-} // namespace cryptauth
-#endif // COMPONENTS_CRYPTAUTH_SOFTWARE_FEATURE_MANAGER_IMPL_H_
+} // namespace device_sync
+
+} // namespace chromeos
+
+#endif // CHROMEOS_SERVICES_DEVICE_SYNC_SOFTWARE_FEATURE_MANAGER_IMPL_H_
diff --git a/components/cryptauth/software_feature_manager_impl_unittest.cc b/chromeos/services/device_sync/software_feature_manager_impl_unittest.cc
similarity index 76%
rename from components/cryptauth/software_feature_manager_impl_unittest.cc
rename to chromeos/services/device_sync/software_feature_manager_impl_unittest.cc
index 8561464..475b5ad 100644
--- a/components/cryptauth/software_feature_manager_impl_unittest.cc
+++ b/chromeos/services/device_sync/software_feature_manager_impl_unittest.cc
@@ -2,22 +2,24 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/cryptauth/software_feature_manager_impl.h"
+#include "chromeos/services/device_sync/software_feature_manager_impl.h"
#include "base/bind.h"
#include "base/macros.h"
#include "chromeos/components/multidevice/remote_device_ref.h"
#include "chromeos/components/multidevice/remote_device_test_util.h"
#include "chromeos/components/multidevice/software_feature.h"
+#include "chromeos/services/device_sync/mock_cryptauth_client.h"
#include "chromeos/services/device_sync/proto/enum_util.h"
-#include "components/cryptauth/mock_cryptauth_client.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using testing::_;
using testing::Invoke;
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
namespace {
@@ -39,7 +41,7 @@
const chromeos::multidevice::RemoteDeviceRefList remote_devices) {
std::vector<cryptauth::ExternalDeviceInfo> device_infos;
for (const auto& remote_device : remote_devices) {
- // Add an ExternalDeviceInfo with the same public key as the
+ // Add an cryptauth::ExternalDeviceInfo with the same public key as the
// chromeos::multidevice::RemoteDevice.
cryptauth::ExternalDeviceInfo info;
info.set_public_key(remote_device.public_key());
@@ -50,11 +52,11 @@
} // namespace
-class CryptAuthSoftwareFeatureManagerImplTest
+class DeviceSyncSoftwareFeatureManagerImplTest
: public testing::Test,
public MockCryptAuthClientFactory::Observer {
public:
- CryptAuthSoftwareFeatureManagerImplTest()
+ DeviceSyncSoftwareFeatureManagerImplTest()
: all_test_external_device_infos_(
CreateExternalDeviceInfosForRemoteDevices(
chromeos::multidevice::CreateRemoteDeviceRefListForTest(5))),
@@ -84,15 +86,15 @@
ON_CALL(*client, ToggleEasyUnlock(_, _, _))
.WillByDefault(Invoke(
this,
- &CryptAuthSoftwareFeatureManagerImplTest::MockToggleEasyUnlock));
+ &DeviceSyncSoftwareFeatureManagerImplTest::MockToggleEasyUnlock));
ON_CALL(*client, FindEligibleUnlockDevices(_, _, _))
- .WillByDefault(Invoke(this, &CryptAuthSoftwareFeatureManagerImplTest::
+ .WillByDefault(Invoke(this, &DeviceSyncSoftwareFeatureManagerImplTest::
MockFindEligibleUnlockDevices));
}
// Mock CryptAuthClient::ToggleEasyUnlock() implementation.
void MockToggleEasyUnlock(
- const ToggleEasyUnlockRequest& request,
+ const cryptauth::ToggleEasyUnlockRequest& request,
const CryptAuthClient::ToggleEasyUnlockCallback& callback,
const CryptAuthClient::ErrorCallback& error_callback) {
last_toggle_request_ = request;
@@ -103,7 +105,7 @@
// Mock CryptAuthClient::FindEligibleUnlockDevices() implementation.
void MockFindEligibleUnlockDevices(
- const FindEligibleUnlockDevicesRequest& request,
+ const cryptauth::FindEligibleUnlockDevicesRequest& request,
const CryptAuthClient::FindEligibleUnlockDevicesCallback& callback,
const CryptAuthClient::ErrorCallback& error_callback) {
last_find_request_ = request;
@@ -112,8 +114,10 @@
error_code_ = kErrorFindingEligibleNetworkRequestError;
}
- FindEligibleUnlockDevicesResponse CreateFindEligibleUnlockDevicesResponse() {
- FindEligibleUnlockDevicesResponse find_eligible_unlock_devices_response;
+ cryptauth::FindEligibleUnlockDevicesResponse
+ CreateFindEligibleUnlockDevicesResponse() {
+ cryptauth::FindEligibleUnlockDevicesResponse
+ find_eligible_unlock_devices_response;
for (const auto& device_info : test_eligible_external_devices_infos_) {
find_eligible_unlock_devices_response.add_eligible_devices()->CopyFrom(
device_info);
@@ -155,15 +159,15 @@
}
void SetSoftwareFeatureState(chromeos::multidevice::SoftwareFeature feature,
- const ExternalDeviceInfo& device_info,
+ const cryptauth::ExternalDeviceInfo& device_info,
bool enabled,
bool is_exclusive = false) {
software_feature_manager_->SetSoftwareFeatureState(
device_info.public_key(), feature, enabled,
- base::Bind(
- &CryptAuthSoftwareFeatureManagerImplTest::OnSoftwareFeatureStateSet,
- base::Unretained(this)),
- base::Bind(&CryptAuthSoftwareFeatureManagerImplTest::OnError,
+ base::Bind(&DeviceSyncSoftwareFeatureManagerImplTest::
+ OnSoftwareFeatureStateSet,
+ base::Unretained(this)),
+ base::Bind(&DeviceSyncSoftwareFeatureManagerImplTest::OnError,
base::Unretained(this)),
is_exclusive);
}
@@ -172,17 +176,17 @@
software_feature_manager_->FindEligibleDevices(
feature,
base::Bind(
- &CryptAuthSoftwareFeatureManagerImplTest::OnEligibleDevicesFound,
+ &DeviceSyncSoftwareFeatureManagerImplTest::OnEligibleDevicesFound,
base::Unretained(this)),
- base::Bind(&CryptAuthSoftwareFeatureManagerImplTest::OnError,
+ base::Bind(&DeviceSyncSoftwareFeatureManagerImplTest::OnError,
base::Unretained(this)));
}
void OnSoftwareFeatureStateSet() { result_ = Result::kSuccess; }
void OnEligibleDevicesFound(
- const std::vector<ExternalDeviceInfo>& eligible_devices,
- const std::vector<IneligibleDevice>& ineligible_devices) {
+ const std::vector<cryptauth::ExternalDeviceInfo>& eligible_devices,
+ const std::vector<cryptauth::IneligibleDevice>& ineligible_devices) {
result_ = Result::kSuccess;
result_eligible_devices_ = eligible_devices;
result_ineligible_devices_ = ineligible_devices;
@@ -202,11 +206,12 @@
toggle_easy_unlock_callback_;
ASSERT_TRUE(!success_callback.is_null());
toggle_easy_unlock_callback_.Reset();
- success_callback.Run(ToggleEasyUnlockResponse());
+ success_callback.Run(cryptauth::ToggleEasyUnlockResponse());
}
void InvokeFindEligibleDevicesCallback(
- const FindEligibleUnlockDevicesResponse& retrieved_devices_response) {
+ const cryptauth::FindEligibleUnlockDevicesResponse&
+ retrieved_devices_response) {
CryptAuthClient::FindEligibleUnlockDevicesCallback success_callback =
find_eligible_unlock_devices_callback_;
ASSERT_TRUE(!success_callback.is_null());
@@ -230,11 +235,13 @@
const std::vector<cryptauth::ExternalDeviceInfo>
all_test_external_device_infos_;
- const std::vector<ExternalDeviceInfo> test_eligible_external_devices_infos_;
- const std::vector<ExternalDeviceInfo> test_ineligible_external_devices_infos_;
+ const std::vector<cryptauth::ExternalDeviceInfo>
+ test_eligible_external_devices_infos_;
+ const std::vector<cryptauth::ExternalDeviceInfo>
+ test_ineligible_external_devices_infos_;
std::unique_ptr<MockCryptAuthClientFactory> mock_cryptauth_client_factory_;
- std::unique_ptr<cryptauth::SoftwareFeatureManager> software_feature_manager_;
+ std::unique_ptr<SoftwareFeatureManager> software_feature_manager_;
CryptAuthClient::ErrorCallback error_callback_;
@@ -247,21 +254,22 @@
base::Optional<NetworkRequestError> error_code_;
// For SetSoftwareFeatureState() tests.
- ToggleEasyUnlockRequest last_toggle_request_;
+ cryptauth::ToggleEasyUnlockRequest last_toggle_request_;
CryptAuthClient::ToggleEasyUnlockCallback toggle_easy_unlock_callback_;
// For FindEligibleDevices() tests.
- FindEligibleUnlockDevicesRequest last_find_request_;
+ cryptauth::FindEligibleUnlockDevicesRequest last_find_request_;
CryptAuthClient::FindEligibleUnlockDevicesCallback
find_eligible_unlock_devices_callback_;
- std::vector<ExternalDeviceInfo> result_eligible_devices_;
- std::vector<IneligibleDevice> result_ineligible_devices_;
+ std::vector<cryptauth::ExternalDeviceInfo> result_eligible_devices_;
+ std::vector<cryptauth::IneligibleDevice> result_ineligible_devices_;
private:
- DISALLOW_COPY_AND_ASSIGN(CryptAuthSoftwareFeatureManagerImplTest);
+ DISALLOW_COPY_AND_ASSIGN(DeviceSyncSoftwareFeatureManagerImplTest);
};
-TEST_F(CryptAuthSoftwareFeatureManagerImplTest, TestOrderUponMultipleRequests) {
+TEST_F(DeviceSyncSoftwareFeatureManagerImplTest,
+ TestOrderUponMultipleRequests) {
SetSoftwareFeatureState(
chromeos::multidevice::SoftwareFeature::kBetterTogetherHost,
test_eligible_external_devices_infos_[0], true /* enable */);
@@ -273,14 +281,16 @@
FindEligibleDevices(
chromeos::multidevice::SoftwareFeature::kBetterTogetherClient);
- EXPECT_EQ(SoftwareFeatureEnumToString(SoftwareFeature::BETTER_TOGETHER_HOST),
+ EXPECT_EQ(SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::BETTER_TOGETHER_HOST),
last_toggle_request_.feature());
EXPECT_EQ(true, last_toggle_request_.enable());
EXPECT_EQ(false, last_toggle_request_.is_exclusive());
InvokeSetSoftwareFeatureCallback();
EXPECT_EQ(Result::kSuccess, GetResultAndReset());
- EXPECT_EQ(SoftwareFeatureEnumToString(SoftwareFeature::BETTER_TOGETHER_HOST),
+ EXPECT_EQ(SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::BETTER_TOGETHER_HOST),
last_find_request_.feature());
EXPECT_EQ(kBetterTogetherHostCallbackBluetoothAddress,
last_find_request_.callback_bluetooth_address());
@@ -288,17 +298,17 @@
EXPECT_EQ(Result::kSuccess, GetResultAndReset());
VerifyDeviceEligibility();
- EXPECT_EQ(
- SoftwareFeatureEnumToString(SoftwareFeature::BETTER_TOGETHER_CLIENT),
- last_toggle_request_.feature());
+ EXPECT_EQ(SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::BETTER_TOGETHER_CLIENT),
+ last_toggle_request_.feature());
EXPECT_EQ(false, last_toggle_request_.enable());
EXPECT_EQ(false, last_toggle_request_.is_exclusive());
InvokeSetSoftwareFeatureCallback();
EXPECT_EQ(Result::kSuccess, GetResultAndReset());
- EXPECT_EQ(
- SoftwareFeatureEnumToString(SoftwareFeature::BETTER_TOGETHER_CLIENT),
- last_find_request_.feature());
+ EXPECT_EQ(SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::BETTER_TOGETHER_CLIENT),
+ last_find_request_.feature());
EXPECT_EQ(kBetterTogetherClientCallbackBluetoothAddress,
last_find_request_.callback_bluetooth_address());
InvokeFindEligibleDevicesCallback(CreateFindEligibleUnlockDevicesResponse());
@@ -306,7 +316,7 @@
VerifyDeviceEligibility();
}
-TEST_F(CryptAuthSoftwareFeatureManagerImplTest,
+TEST_F(DeviceSyncSoftwareFeatureManagerImplTest,
TestMultipleSetUnlocksRequests) {
SetSoftwareFeatureState(
chromeos::multidevice::SoftwareFeature::kBetterTogetherHost,
@@ -318,22 +328,24 @@
chromeos::multidevice::SoftwareFeature::kBetterTogetherHost,
test_eligible_external_devices_infos_[2], true /* enable */);
- EXPECT_EQ(SoftwareFeatureEnumToString(SoftwareFeature::BETTER_TOGETHER_HOST),
+ EXPECT_EQ(SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::BETTER_TOGETHER_HOST),
last_toggle_request_.feature());
EXPECT_EQ(true, last_toggle_request_.enable());
EXPECT_EQ(false, last_toggle_request_.is_exclusive());
InvokeErrorCallback();
EXPECT_EQ(Result::kErrorSettingFeature, GetResultAndReset());
- EXPECT_EQ(
- SoftwareFeatureEnumToString(SoftwareFeature::BETTER_TOGETHER_CLIENT),
- last_toggle_request_.feature());
+ EXPECT_EQ(SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::BETTER_TOGETHER_CLIENT),
+ last_toggle_request_.feature());
EXPECT_EQ(false, last_toggle_request_.enable());
EXPECT_EQ(false, last_toggle_request_.is_exclusive());
InvokeSetSoftwareFeatureCallback();
EXPECT_EQ(Result::kSuccess, GetResultAndReset());
- EXPECT_EQ(SoftwareFeatureEnumToString(SoftwareFeature::BETTER_TOGETHER_HOST),
+ EXPECT_EQ(SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::BETTER_TOGETHER_HOST),
last_toggle_request_.feature());
EXPECT_EQ(true, last_toggle_request_.enable());
EXPECT_EQ(false, last_toggle_request_.is_exclusive());
@@ -341,7 +353,7 @@
EXPECT_EQ(Result::kSuccess, GetResultAndReset());
}
-TEST_F(CryptAuthSoftwareFeatureManagerImplTest,
+TEST_F(DeviceSyncSoftwareFeatureManagerImplTest,
TestMultipleFindEligibleForUnlockDevicesRequests) {
FindEligibleDevices(
chromeos::multidevice::SoftwareFeature::kBetterTogetherHost);
@@ -350,7 +362,8 @@
FindEligibleDevices(
chromeos::multidevice::SoftwareFeature::kBetterTogetherHost);
- EXPECT_EQ(SoftwareFeatureEnumToString(SoftwareFeature::BETTER_TOGETHER_HOST),
+ EXPECT_EQ(SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::BETTER_TOGETHER_HOST),
last_find_request_.feature());
EXPECT_EQ(kBetterTogetherHostCallbackBluetoothAddress,
last_find_request_.callback_bluetooth_address());
@@ -358,15 +371,16 @@
EXPECT_EQ(Result::kSuccess, GetResultAndReset());
VerifyDeviceEligibility();
- EXPECT_EQ(
- SoftwareFeatureEnumToString(SoftwareFeature::BETTER_TOGETHER_CLIENT),
- last_find_request_.feature());
+ EXPECT_EQ(SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::BETTER_TOGETHER_CLIENT),
+ last_find_request_.feature());
EXPECT_EQ(kBetterTogetherClientCallbackBluetoothAddress,
last_find_request_.callback_bluetooth_address());
InvokeErrorCallback();
EXPECT_EQ(Result::kErrorFindingEligible, GetResultAndReset());
- EXPECT_EQ(SoftwareFeatureEnumToString(SoftwareFeature::BETTER_TOGETHER_HOST),
+ EXPECT_EQ(SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::BETTER_TOGETHER_HOST),
last_find_request_.feature());
EXPECT_EQ(kBetterTogetherHostCallbackBluetoothAddress,
last_find_request_.callback_bluetooth_address());
@@ -375,19 +389,21 @@
VerifyDeviceEligibility();
}
-TEST_F(CryptAuthSoftwareFeatureManagerImplTest, TestOrderViaMultipleErrors) {
+TEST_F(DeviceSyncSoftwareFeatureManagerImplTest, TestOrderViaMultipleErrors) {
SetSoftwareFeatureState(
chromeos::multidevice::SoftwareFeature::kBetterTogetherHost,
test_eligible_external_devices_infos_[0], true /* enable */);
FindEligibleDevices(
chromeos::multidevice::SoftwareFeature::kBetterTogetherHost);
- EXPECT_EQ(SoftwareFeatureEnumToString(SoftwareFeature::BETTER_TOGETHER_HOST),
+ EXPECT_EQ(SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::BETTER_TOGETHER_HOST),
last_toggle_request_.feature());
InvokeErrorCallback();
EXPECT_EQ(Result::kErrorSettingFeature, GetResultAndReset());
- EXPECT_EQ(SoftwareFeatureEnumToString(SoftwareFeature::BETTER_TOGETHER_HOST),
+ EXPECT_EQ(SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::BETTER_TOGETHER_HOST),
last_find_request_.feature());
EXPECT_EQ(kBetterTogetherHostCallbackBluetoothAddress,
last_find_request_.callback_bluetooth_address());
@@ -395,13 +411,14 @@
EXPECT_EQ(Result::kErrorFindingEligible, GetResultAndReset());
}
-TEST_F(CryptAuthSoftwareFeatureManagerImplTest, TestIsExclusive) {
+TEST_F(DeviceSyncSoftwareFeatureManagerImplTest, TestIsExclusive) {
SetSoftwareFeatureState(
chromeos::multidevice::SoftwareFeature::kBetterTogetherHost,
test_eligible_external_devices_infos_[0], true /* enable */,
true /* is_exclusive */);
- EXPECT_EQ(SoftwareFeatureEnumToString(SoftwareFeature::BETTER_TOGETHER_HOST),
+ EXPECT_EQ(SoftwareFeatureEnumToString(
+ cryptauth::SoftwareFeature::BETTER_TOGETHER_HOST),
last_toggle_request_.feature());
EXPECT_EQ(true, last_toggle_request_.enable());
EXPECT_EQ(true, last_toggle_request_.is_exclusive());
@@ -409,13 +426,14 @@
EXPECT_EQ(Result::kErrorSettingFeature, GetResultAndReset());
}
-TEST_F(CryptAuthSoftwareFeatureManagerImplTest, TestEasyUnlockSpecialCase) {
+TEST_F(DeviceSyncSoftwareFeatureManagerImplTest, TestEasyUnlockSpecialCase) {
SetSoftwareFeatureState(
chromeos::multidevice::SoftwareFeature::kSmartLockHost,
test_eligible_external_devices_infos_[0], false /* enable */);
- EXPECT_EQ(SoftwareFeatureEnumToString(SoftwareFeature::EASY_UNLOCK_HOST),
- last_toggle_request_.feature());
+ EXPECT_EQ(
+ SoftwareFeatureEnumToString(cryptauth::SoftwareFeature::EASY_UNLOCK_HOST),
+ last_toggle_request_.feature());
EXPECT_EQ(false, last_toggle_request_.enable());
// apply_to_all() should be false when disabling EasyUnlock host capabilities.
EXPECT_EQ(true, last_toggle_request_.apply_to_all());
@@ -424,4 +442,6 @@
EXPECT_EQ(Result::kErrorSettingFeature, GetResultAndReset());
}
-} // namespace cryptauth
+} // namespace device_sync
+
+} // namespace chromeos
diff --git a/components/cryptauth/switches.cc b/chromeos/services/device_sync/switches.cc
similarity index 70%
rename from components/cryptauth/switches.cc
rename to chromeos/services/device_sync/switches.cc
index d5aec05d..b57b0ee 100644
--- a/components/cryptauth/switches.cc
+++ b/chromeos/services/device_sync/switches.cc
@@ -2,9 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/cryptauth/switches.h"
+#include "chromeos/services/device_sync//switches.h"
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
+
namespace switches {
// Overrides the default URL for Google APIs (https://www.googleapis.com) used
@@ -12,4 +15,7 @@
const char kCryptAuthHTTPHost[] = "cryptauth-http-host";
} // namespace switches
-} // namespace cryptauth
+
+} // namespace device_sync
+
+} // namespace chromeos
diff --git a/components/cryptauth/switches.h b/chromeos/services/device_sync/switches.h
similarity index 60%
rename from components/cryptauth/switches.h
rename to chromeos/services/device_sync/switches.h
index 51fecb6..74fe0e7 100644
--- a/components/cryptauth/switches.h
+++ b/chromeos/services/device_sync/switches.h
@@ -2,10 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef COMPONENTS_CRYPTAUTH_SWITCHES_H_
-#define COMPONENTS_CRYPTAUTH_SWITCHES_H_
+#ifndef CHROMEOS_SERVICES_DEVICE_SYNC_SWITCHES_H_
+#define CHROMEOS_SERVICES_DEVICE_SYNC_SWITCHES_H_
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
+
namespace switches {
// All switches in alphabetical order. The switches should be documented
@@ -13,6 +16,9 @@
extern const char kCryptAuthHTTPHost[];
} // namespace switches
-} // namespace cryptauth
-#endif // COMPONENTS_CRYPTAUTH_SWITCHES_H_
+} // namespace device_sync
+
+} // namespace chromeos
+
+#endif // CHROMEOS_SERVICES_DEVICE_SYNC_SWITCHES_H_
diff --git a/components/cryptauth/sync_scheduler.cc b/chromeos/services/device_sync/sync_scheduler.cc
similarity index 79%
rename from components/cryptauth/sync_scheduler.cc
rename to chromeos/services/device_sync/sync_scheduler.cc
index f75efb52..35810bd 100644
--- a/components/cryptauth/sync_scheduler.cc
+++ b/chromeos/services/device_sync/sync_scheduler.cc
@@ -2,16 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/cryptauth/sync_scheduler.h"
+#include "chromeos/services/device_sync/sync_scheduler.h"
#include "chromeos/components/proximity_auth/logging/logging.h"
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
SyncScheduler::SyncRequest::SyncRequest(
base::WeakPtr<SyncScheduler> sync_scheduler)
- : sync_scheduler_(sync_scheduler), completed_(false) {
-}
+ : sync_scheduler_(sync_scheduler), completed_(false) {}
SyncScheduler::SyncRequest::~SyncRequest() {
if (!completed_)
@@ -33,4 +34,6 @@
completed_ = true;
}
-} // namespace cryptauth
+} // namespace device_sync
+
+} // namespace chromeos
diff --git a/components/cryptauth/sync_scheduler.h b/chromeos/services/device_sync/sync_scheduler.h
similarity index 92%
rename from components/cryptauth/sync_scheduler.h
rename to chromeos/services/device_sync/sync_scheduler.h
index 9741764..69b8aa94 100644
--- a/components/cryptauth/sync_scheduler.h
+++ b/chromeos/services/device_sync/sync_scheduler.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef COMPONENTS_CRYPTAUTH_SYNC_SCHEDULER_H_
-#define COMPONENTS_CRYPTAUTH_SYNC_SCHEDULER_H_
+#ifndef CHROMEOS_SERVICES_DEVICE_SYNC_SYNC_SCHEDULER_H_
+#define CHROMEOS_SERVICES_DEVICE_SYNC_SYNC_SCHEDULER_H_
#include <memory>
@@ -11,7 +11,9 @@
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
// Interface for scheduling the next CryptAuth sync (e.g. enrollment or device
// sync). The scheduler has two different strategies affecting when to perform
@@ -94,6 +96,8 @@
virtual void OnSyncCompleted(bool success) = 0;
};
-} // namespace cryptauth
+} // namespace device_sync
-#endif // COMPONENTS_CRYPTAUTH_SYNC_SCHEDULER_H_
+} // namespace chromeos
+
+#endif // CHROMEOS_SERVICES_DEVICE_SYNC_SYNC_SCHEDULER_H_
diff --git a/components/cryptauth/sync_scheduler_impl.cc b/chromeos/services/device_sync/sync_scheduler_impl.cc
similarity index 96%
rename from components/cryptauth/sync_scheduler_impl.cc
rename to chromeos/services/device_sync/sync_scheduler_impl.cc
index 443b6a3..f03f9c73 100644
--- a/components/cryptauth/sync_scheduler_impl.cc
+++ b/chromeos/services/device_sync/sync_scheduler_impl.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/cryptauth/sync_scheduler_impl.h"
+#include "chromeos/services/device_sync/sync_scheduler_impl.h"
#include <algorithm>
#include <cmath>
@@ -15,7 +15,9 @@
#include "base/strings/stringprintf.h"
#include "chromeos/components/proximity_auth/logging/logging.h"
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
namespace {
@@ -49,11 +51,9 @@
strategy_(Strategy::PERIODIC_REFRESH),
sync_state_(SyncState::NOT_STARTED),
failure_count_(0),
- weak_ptr_factory_(this) {
-}
+ weak_ptr_factory_(this) {}
-SyncSchedulerImpl::~SyncSchedulerImpl() {
-}
+SyncSchedulerImpl::~SyncSchedulerImpl() {}
void SyncSchedulerImpl::Start(
const base::TimeDelta& elapsed_time_since_last_sync,
@@ -192,4 +192,6 @@
return base::TimeDelta();
}
-} // namespace cryptauth
+} // namespace device_sync
+
+} // namespace chromeos
diff --git a/components/cryptauth/sync_scheduler_impl.h b/chromeos/services/device_sync/sync_scheduler_impl.h
similarity index 90%
rename from components/cryptauth/sync_scheduler_impl.h
rename to chromeos/services/device_sync/sync_scheduler_impl.h
index 77ffcd8d..b8e86e5 100644
--- a/components/cryptauth/sync_scheduler_impl.h
+++ b/chromeos/services/device_sync/sync_scheduler_impl.h
@@ -2,16 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef COMPONENTS_CRYPTAUTH_SYNC_SCHEDULER_IMPL_H_
-#define COMPONENTS_CRYPTAUTH_SYNC_SCHEDULER_IMPL_H_
+#ifndef CHROMEOS_SERVICES_DEVICE_SYNC_SYNC_SCHEDULER_IMPL_H_
+#define CHROMEOS_SERVICES_DEVICE_SYNC_SYNC_SCHEDULER_IMPL_H_
#include <stddef.h>
#include "base/macros.h"
#include "base/timer/timer.h"
-#include "components/cryptauth/sync_scheduler.h"
+#include "chromeos/services/device_sync/sync_scheduler.h"
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
// Implementation of SyncScheduler.
class SyncSchedulerImpl : public SyncScheduler {
@@ -99,6 +101,8 @@
DISALLOW_COPY_AND_ASSIGN(SyncSchedulerImpl);
};
-} // namespace cryptauth
+} // namespace device_sync
-#endif // COMPONENTS_CRYPTAUTH_SYNC_SCHEDULER_IMPL_H_
+} // namespace chromeos
+
+#endif // CHROMEOS_SERVICES_DEVICE_SYNC_SYNC_SCHEDULER_IMPL_H_
diff --git a/components/cryptauth/sync_scheduler_impl_unittest.cc b/chromeos/services/device_sync/sync_scheduler_impl_unittest.cc
similarity index 86%
rename from components/cryptauth/sync_scheduler_impl_unittest.cc
rename to chromeos/services/device_sync/sync_scheduler_impl_unittest.cc
index cc3ae12..066f62c 100644
--- a/components/cryptauth/sync_scheduler_impl_unittest.cc
+++ b/chromeos/services/device_sync/sync_scheduler_impl_unittest.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/cryptauth/sync_scheduler_impl.h"
+#include "chromeos/services/device_sync/sync_scheduler_impl.h"
#include <utility>
@@ -11,7 +11,9 @@
#include "base/timer/mock_timer.h"
#include "testing/gtest/include/gtest/gtest.h"
-namespace cryptauth {
+namespace chromeos {
+
+namespace device_sync {
using Strategy = SyncScheduler::Strategy;
using SyncState = SyncScheduler::SyncState;
@@ -71,10 +73,10 @@
} // namespace
-class CryptAuthSyncSchedulerImplTest : public testing::Test,
- public SyncSchedulerImpl::Delegate {
+class DeviceSyncSyncSchedulerImplTest : public testing::Test,
+ public SyncSchedulerImpl::Delegate {
protected:
- CryptAuthSyncSchedulerImplTest()
+ DeviceSyncSyncSchedulerImplTest()
: refresh_period_(base::TimeDelta::FromDays(kRefreshPeriodDays)),
base_recovery_period_(
base::TimeDelta::FromSeconds(kRecoveryPeriodSeconds)),
@@ -84,7 +86,7 @@
base_recovery_period_,
0)) {}
- ~CryptAuthSyncSchedulerImplTest() override {}
+ ~DeviceSyncSyncSchedulerImplTest() override {}
void OnSyncRequested(
std::unique_ptr<SyncScheduler::SyncRequest> sync_request) override {
@@ -103,10 +105,10 @@
std::unique_ptr<SyncScheduler::SyncRequest> sync_request_;
- DISALLOW_COPY_AND_ASSIGN(CryptAuthSyncSchedulerImplTest);
+ DISALLOW_COPY_AND_ASSIGN(DeviceSyncSyncSchedulerImplTest);
};
-TEST_F(CryptAuthSyncSchedulerImplTest, ForceSyncSuccess) {
+TEST_F(DeviceSyncSyncSchedulerImplTest, ForceSyncSuccess) {
scheduler_->Start(zero_elapsed_time_, Strategy::PERIODIC_REFRESH);
EXPECT_EQ(Strategy::PERIODIC_REFRESH, scheduler_->GetStrategy());
EXPECT_EQ(SyncState::WAITING_FOR_REFRESH, scheduler_->GetSyncState());
@@ -119,7 +121,7 @@
EXPECT_EQ(SyncState::WAITING_FOR_REFRESH, scheduler_->GetSyncState());
}
-TEST_F(CryptAuthSyncSchedulerImplTest, ForceSyncFailure) {
+TEST_F(DeviceSyncSyncSchedulerImplTest, ForceSyncFailure) {
scheduler_->Start(zero_elapsed_time_, Strategy::PERIODIC_REFRESH);
EXPECT_EQ(Strategy::PERIODIC_REFRESH, scheduler_->GetStrategy());
@@ -129,7 +131,7 @@
EXPECT_EQ(Strategy::AGGRESSIVE_RECOVERY, scheduler_->GetStrategy());
}
-TEST_F(CryptAuthSyncSchedulerImplTest, PeriodicRefreshSuccess) {
+TEST_F(DeviceSyncSyncSchedulerImplTest, PeriodicRefreshSuccess) {
EXPECT_EQ(SyncState::NOT_STARTED, scheduler_->GetSyncState());
scheduler_->Start(zero_elapsed_time_, Strategy::PERIODIC_REFRESH);
EXPECT_EQ(Strategy::PERIODIC_REFRESH, scheduler_->GetStrategy());
@@ -144,7 +146,7 @@
EXPECT_EQ(Strategy::PERIODIC_REFRESH, scheduler_->GetStrategy());
}
-TEST_F(CryptAuthSyncSchedulerImplTest, PeriodicRefreshFailure) {
+TEST_F(DeviceSyncSyncSchedulerImplTest, PeriodicRefreshFailure) {
scheduler_->Start(zero_elapsed_time_, Strategy::PERIODIC_REFRESH);
EXPECT_EQ(Strategy::PERIODIC_REFRESH, scheduler_->GetStrategy());
timer()->Fire();
@@ -152,7 +154,7 @@
EXPECT_EQ(Strategy::AGGRESSIVE_RECOVERY, scheduler_->GetStrategy());
}
-TEST_F(CryptAuthSyncSchedulerImplTest, AggressiveRecoverySuccess) {
+TEST_F(DeviceSyncSyncSchedulerImplTest, AggressiveRecoverySuccess) {
scheduler_->Start(zero_elapsed_time_, Strategy::AGGRESSIVE_RECOVERY);
EXPECT_EQ(Strategy::AGGRESSIVE_RECOVERY, scheduler_->GetStrategy());
@@ -166,7 +168,7 @@
EXPECT_EQ(Strategy::PERIODIC_REFRESH, scheduler_->GetStrategy());
}
-TEST_F(CryptAuthSyncSchedulerImplTest, AggressiveRecoveryFailure) {
+TEST_F(DeviceSyncSyncSchedulerImplTest, AggressiveRecoveryFailure) {
scheduler_->Start(zero_elapsed_time_, Strategy::AGGRESSIVE_RECOVERY);
timer()->Fire();
@@ -174,7 +176,7 @@
EXPECT_EQ(Strategy::AGGRESSIVE_RECOVERY, scheduler_->GetStrategy());
}
-TEST_F(CryptAuthSyncSchedulerImplTest, AggressiveRecoveryBackOff) {
+TEST_F(DeviceSyncSyncSchedulerImplTest, AggressiveRecoveryBackOff) {
scheduler_->Start(zero_elapsed_time_, Strategy::AGGRESSIVE_RECOVERY);
base::TimeDelta last_recovery_period = base::TimeDelta::FromSeconds(0);
@@ -194,7 +196,7 @@
EXPECT_EQ(refresh_period_, last_recovery_period);
}
-TEST_F(CryptAuthSyncSchedulerImplTest, RefreshFailureRecoverySuccess) {
+TEST_F(DeviceSyncSyncSchedulerImplTest, RefreshFailureRecoverySuccess) {
scheduler_->Start(zero_elapsed_time_, Strategy::PERIODIC_REFRESH);
EXPECT_EQ(Strategy::PERIODIC_REFRESH, scheduler_->GetStrategy());
@@ -207,7 +209,7 @@
EXPECT_EQ(Strategy::PERIODIC_REFRESH, scheduler_->GetStrategy());
}
-TEST_F(CryptAuthSyncSchedulerImplTest, SyncImmediatelyForPeriodicRefresh) {
+TEST_F(DeviceSyncSyncSchedulerImplTest, SyncImmediatelyForPeriodicRefresh) {
scheduler_->Start(base::TimeDelta::FromDays(kElapsedTimeDays),
Strategy::PERIODIC_REFRESH);
EXPECT_TRUE(scheduler_->GetTimeToNextSync().is_zero());
@@ -218,8 +220,7 @@
EXPECT_EQ(Strategy::PERIODIC_REFRESH, scheduler_->GetStrategy());
}
-TEST_F(CryptAuthSyncSchedulerImplTest,
- SyncImmediatelyForAggressiveRecovery) {
+TEST_F(DeviceSyncSyncSchedulerImplTest, SyncImmediatelyForAggressiveRecovery) {
scheduler_->Start(base::TimeDelta::FromDays(kElapsedTimeDays),
Strategy::AGGRESSIVE_RECOVERY);
EXPECT_TRUE(scheduler_->GetTimeToNextSync().is_zero());
@@ -230,7 +231,7 @@
EXPECT_EQ(Strategy::AGGRESSIVE_RECOVERY, scheduler_->GetStrategy());
}
-TEST_F(CryptAuthSyncSchedulerImplTest, InitialSyncShorterByElapsedTime) {
+TEST_F(DeviceSyncSyncSchedulerImplTest, InitialSyncShorterByElapsedTime) {
base::TimeDelta elapsed_time = base::TimeDelta::FromDays(2);
scheduler_->Start(elapsed_time, Strategy::PERIODIC_REFRESH);
EXPECT_EQ(refresh_period_ - elapsed_time, scheduler_->GetTimeToNextSync());
@@ -238,7 +239,7 @@
EXPECT_TRUE(sync_request_);
}
-TEST_F(CryptAuthSyncSchedulerImplTest, PeriodicRefreshJitter) {
+TEST_F(DeviceSyncSyncSchedulerImplTest, PeriodicRefreshJitter) {
scheduler_.reset(new TestSyncSchedulerImpl(
this, refresh_period_, base_recovery_period_, kMaxJitterPercentage));
@@ -260,7 +261,7 @@
EXPECT_FALSE(cumulative_jitter.is_zero());
}
-TEST_F(CryptAuthSyncSchedulerImplTest, JitteredTimeDeltaIsNonNegative) {
+TEST_F(DeviceSyncSyncSchedulerImplTest, JitteredTimeDeltaIsNonNegative) {
base::TimeDelta zero_delta = base::TimeDelta::FromSeconds(0);
double max_jitter_ratio = 1;
scheduler_.reset(new TestSyncSchedulerImpl(this, zero_delta, zero_delta,
@@ -277,7 +278,7 @@
}
}
-TEST_F(CryptAuthSyncSchedulerImplTest, StartWithNegativeElapsedTime) {
+TEST_F(DeviceSyncSyncSchedulerImplTest, StartWithNegativeElapsedTime) {
// This could happen in rare cases where the system clock changes.
scheduler_->Start(base::TimeDelta::FromDays(-1000),
Strategy::PERIODIC_REFRESH);
@@ -287,4 +288,6 @@
EXPECT_EQ(zero_delta, timer()->GetCurrentDelay());
}
-} // namespace cryptauth
+} // namespace device_sync
+
+} // namespace chromeos
diff --git a/chromeos/services/multidevice_setup/device_reenroller.cc b/chromeos/services/multidevice_setup/device_reenroller.cc
index 014f309f..306588b 100644
--- a/chromeos/services/multidevice_setup/device_reenroller.cc
+++ b/chromeos/services/multidevice_setup/device_reenroller.cc
@@ -8,7 +8,7 @@
#include "base/no_destructor.h"
#include "chromeos/components/proximity_auth/logging/logging.h"
#include "chromeos/services/device_sync/proto/enum_util.h"
-#include "components/cryptauth/gcm_device_info_provider.h"
+#include "chromeos/services/device_sync/public/cpp/gcm_device_info_provider.h"
namespace chromeos {
@@ -84,7 +84,7 @@
std::unique_ptr<DeviceReenroller> DeviceReenroller::Factory::BuildInstance(
device_sync::DeviceSyncClient* device_sync_client,
- const cryptauth::GcmDeviceInfoProvider* gcm_device_info_provider,
+ const device_sync::GcmDeviceInfoProvider* gcm_device_info_provider,
std::unique_ptr<base::OneShotTimer> timer) {
return base::WrapUnique(new DeviceReenroller(
device_sync_client, gcm_device_info_provider, std::move(timer)));
@@ -96,7 +96,7 @@
DeviceReenroller::DeviceReenroller(
device_sync::DeviceSyncClient* device_sync_client,
- const cryptauth::GcmDeviceInfoProvider* gcm_device_info_provider,
+ const device_sync::GcmDeviceInfoProvider* gcm_device_info_provider,
std::unique_ptr<base::OneShotTimer> timer)
: device_sync_client_(device_sync_client),
gcm_supported_software_features_(GetSupportedFeaturesFromGcmDeviceInfo(
diff --git a/chromeos/services/multidevice_setup/device_reenroller.h b/chromeos/services/multidevice_setup/device_reenroller.h
index f669f36..e6b2f70 100644
--- a/chromeos/services/multidevice_setup/device_reenroller.h
+++ b/chromeos/services/multidevice_setup/device_reenroller.h
@@ -15,12 +15,13 @@
class OneShotTimer;
} // namespace base
-namespace cryptauth {
-class GcmDeviceInfoProvider;
-} // namespace cryptauth
namespace chromeos {
+namespace device_sync {
+class GcmDeviceInfoProvider;
+} // namespace device_sync
+
namespace multidevice_setup {
// This class re-enrolls the device if the set of supported SoftwareFeatures in
@@ -60,7 +61,7 @@
virtual ~Factory();
virtual std::unique_ptr<DeviceReenroller> BuildInstance(
device_sync::DeviceSyncClient* device_sync_client,
- const cryptauth::GcmDeviceInfoProvider* gcm_device_info_provider,
+ const device_sync::GcmDeviceInfoProvider* gcm_device_info_provider,
std::unique_ptr<base::OneShotTimer> timer =
std::make_unique<base::OneShotTimer>());
@@ -73,7 +74,7 @@
private:
DeviceReenroller(
device_sync::DeviceSyncClient* device_sync_client,
- const cryptauth::GcmDeviceInfoProvider* gcm_device_info_provider,
+ const device_sync::GcmDeviceInfoProvider* gcm_device_info_provider,
std::unique_ptr<base::OneShotTimer> timer);
void AttemptReenrollmentIfNecessary();
diff --git a/chromeos/services/multidevice_setup/device_reenroller_unittest.cc b/chromeos/services/multidevice_setup/device_reenroller_unittest.cc
index cc17c9e..4e5e3f35 100644
--- a/chromeos/services/multidevice_setup/device_reenroller_unittest.cc
+++ b/chromeos/services/multidevice_setup/device_reenroller_unittest.cc
@@ -10,7 +10,7 @@
#include "chromeos/components/multidevice/software_feature.h"
#include "chromeos/components/multidevice/software_feature_state.h"
#include "chromeos/services/device_sync/public/cpp/fake_device_sync_client.h"
-#include "components/cryptauth/fake_gcm_device_info_provider.h"
+#include "chromeos/services/device_sync/public/cpp/fake_gcm_device_info_provider.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace chromeos {
@@ -30,7 +30,7 @@
fake_device_sync_client_->NotifyReady();
fake_gcm_device_info_provider_ =
- std::make_unique<cryptauth::FakeGcmDeviceInfoProvider>(
+ std::make_unique<device_sync::FakeGcmDeviceInfoProvider>(
cryptauth::GcmDeviceInfo());
}
@@ -51,7 +51,8 @@
gcm_device_info.add_supported_software_features(feature);
}
fake_gcm_device_info_provider_ =
- std::make_unique<cryptauth::FakeGcmDeviceInfoProvider>(gcm_device_info);
+ std::make_unique<device_sync::FakeGcmDeviceInfoProvider>(
+ gcm_device_info);
}
device_sync::FakeDeviceSyncClient* fake_device_sync_client() {
@@ -86,7 +87,7 @@
multidevice::RemoteDeviceRef test_local_device_;
std::unique_ptr<device_sync::FakeDeviceSyncClient> fake_device_sync_client_;
- std::unique_ptr<cryptauth::FakeGcmDeviceInfoProvider>
+ std::unique_ptr<device_sync::FakeGcmDeviceInfoProvider>
fake_gcm_device_info_provider_;
base::MockOneShotTimer* mock_timer_;
diff --git a/chromeos/services/multidevice_setup/multidevice_setup_impl.cc b/chromeos/services/multidevice_setup/multidevice_setup_impl.cc
index 3c0acf4..aa90845 100644
--- a/chromeos/services/multidevice_setup/multidevice_setup_impl.cc
+++ b/chromeos/services/multidevice_setup/multidevice_setup_impl.cc
@@ -82,7 +82,7 @@
android_sms_app_helper_delegate,
std::unique_ptr<AndroidSmsPairingStateTracker>
android_sms_pairing_state_tracker,
- const cryptauth::GcmDeviceInfoProvider* gcm_device_info_provider) {
+ const device_sync::GcmDeviceInfoProvider* gcm_device_info_provider) {
return base::WrapUnique(new MultiDeviceSetupImpl(
pref_service, device_sync_client, auth_token_validator,
oobe_completion_tracker, std::move(android_sms_app_helper_delegate),
@@ -98,7 +98,7 @@
android_sms_app_helper_delegate,
std::unique_ptr<AndroidSmsPairingStateTracker>
android_sms_pairing_state_tracker,
- const cryptauth::GcmDeviceInfoProvider* gcm_device_info_provider)
+ const device_sync::GcmDeviceInfoProvider* gcm_device_info_provider)
: eligible_host_devices_provider_(
EligibleHostDevicesProviderImpl::Factory::Get()->BuildInstance(
device_sync_client)),
diff --git a/chromeos/services/multidevice_setup/multidevice_setup_impl.h b/chromeos/services/multidevice_setup/multidevice_setup_impl.h
index 1da78e1..5576566 100644
--- a/chromeos/services/multidevice_setup/multidevice_setup_impl.h
+++ b/chromeos/services/multidevice_setup/multidevice_setup_impl.h
@@ -18,14 +18,11 @@
class PrefService;
-namespace cryptauth {
-class GcmDeviceInfoProvider;
-} // namespace cryptauth
-
namespace chromeos {
namespace device_sync {
class DeviceSyncClient;
+class GcmDeviceInfoProvider;
} // namespace device_sync
namespace multidevice_setup {
@@ -63,7 +60,7 @@
android_sms_app_helper_delegate,
std::unique_ptr<AndroidSmsPairingStateTracker>
android_sms_pairing_state_tracker,
- const cryptauth::GcmDeviceInfoProvider* gcm_device_info_provider);
+ const device_sync::GcmDeviceInfoProvider* gcm_device_info_provider);
private:
static Factory* test_factory_;
@@ -83,7 +80,7 @@
android_sms_app_helper_delegate,
std::unique_ptr<AndroidSmsPairingStateTracker>
android_sms_pairing_state_tracker,
- const cryptauth::GcmDeviceInfoProvider* gcm_device_info_provider);
+ const device_sync::GcmDeviceInfoProvider* gcm_device_info_provider);
// mojom::MultiDeviceSetup:
void SetAccountStatusChangeDelegate(
diff --git a/chromeos/services/multidevice_setup/multidevice_setup_impl_unittest.cc b/chromeos/services/multidevice_setup/multidevice_setup_impl_unittest.cc
index e9276f4..164ec6f 100644
--- a/chromeos/services/multidevice_setup/multidevice_setup_impl_unittest.cc
+++ b/chromeos/services/multidevice_setup/multidevice_setup_impl_unittest.cc
@@ -10,6 +10,7 @@
#include "base/test/scoped_task_environment.h"
#include "chromeos/components/multidevice/remote_device_test_util.h"
#include "chromeos/services/device_sync/public/cpp/fake_device_sync_client.h"
+#include "chromeos/services/device_sync/public/cpp/fake_gcm_device_info_provider.h"
#include "chromeos/services/multidevice_setup/account_status_change_delegate_notifier_impl.h"
#include "chromeos/services/multidevice_setup/android_sms_app_installing_status_observer.h"
#include "chromeos/services/multidevice_setup/device_reenroller.h"
@@ -36,7 +37,6 @@
#include "chromeos/services/multidevice_setup/public/cpp/fake_auth_token_validator.h"
#include "chromeos/services/multidevice_setup/public/cpp/oobe_completion_tracker.h"
#include "chromeos/services/multidevice_setup/public/mojom/multidevice_setup.mojom.h"
-#include "components/cryptauth/fake_gcm_device_info_provider.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -417,7 +417,7 @@
public:
FakeDeviceReenrollerFactory(
device_sync::FakeDeviceSyncClient* expected_device_sync_client,
- const cryptauth::FakeGcmDeviceInfoProvider*
+ const device_sync::FakeGcmDeviceInfoProvider*
expected_gcm_device_info_provider)
: expected_device_sync_client_(expected_device_sync_client),
expected_gcm_device_info_provider_(expected_gcm_device_info_provider) {}
@@ -428,7 +428,7 @@
// DeviceReenroller::Factory:
std::unique_ptr<DeviceReenroller> BuildInstance(
device_sync::DeviceSyncClient* device_sync_client,
- const cryptauth::GcmDeviceInfoProvider* gcm_device_info_provider,
+ const device_sync::GcmDeviceInfoProvider* gcm_device_info_provider,
std::unique_ptr<base::OneShotTimer> timer) override {
EXPECT_EQ(expected_device_sync_client_, device_sync_client);
EXPECT_EQ(expected_gcm_device_info_provider_, gcm_device_info_provider);
@@ -438,7 +438,7 @@
}
device_sync::FakeDeviceSyncClient* expected_device_sync_client_;
- const cryptauth::GcmDeviceInfoProvider* expected_gcm_device_info_provider_;
+ const device_sync::GcmDeviceInfoProvider* expected_gcm_device_info_provider_;
DISALLOW_COPY_AND_ASSIGN(FakeDeviceReenrollerFactory);
};
@@ -511,7 +511,7 @@
fake_android_sms_pairing_state_tracker.get();
fake_gcm_device_info_provider_ =
- std::make_unique<cryptauth::FakeGcmDeviceInfoProvider>(
+ std::make_unique<device_sync::FakeGcmDeviceInfoProvider>(
cryptauth::GcmDeviceInfo());
fake_eligible_host_devices_provider_factory_ =
@@ -869,7 +869,7 @@
std::unique_ptr<device_sync::FakeDeviceSyncClient> fake_device_sync_client_;
std::unique_ptr<FakeAuthTokenValidator> fake_auth_token_validator_;
std::unique_ptr<OobeCompletionTracker> fake_oobe_completion_tracker_;
- std::unique_ptr<cryptauth::FakeGcmDeviceInfoProvider>
+ std::unique_ptr<device_sync::FakeGcmDeviceInfoProvider>
fake_gcm_device_info_provider_;
std::unique_ptr<FakeEligibleHostDevicesProviderFactory>
diff --git a/chromeos/services/multidevice_setup/multidevice_setup_initializer.cc b/chromeos/services/multidevice_setup/multidevice_setup_initializer.cc
index 56b4d97..0690a41 100644
--- a/chromeos/services/multidevice_setup/multidevice_setup_initializer.cc
+++ b/chromeos/services/multidevice_setup/multidevice_setup_initializer.cc
@@ -48,7 +48,7 @@
android_sms_app_helper_delegate,
std::unique_ptr<AndroidSmsPairingStateTracker>
android_sms_pairing_state_tracker,
- const cryptauth::GcmDeviceInfoProvider* gcm_device_info_provider) {
+ const device_sync::GcmDeviceInfoProvider* gcm_device_info_provider) {
return base::WrapUnique(new MultiDeviceSetupInitializer(
pref_service, device_sync_client, auth_token_validator,
oobe_completion_tracker, std::move(android_sms_app_helper_delegate),
@@ -79,7 +79,7 @@
android_sms_app_helper_delegate,
std::unique_ptr<AndroidSmsPairingStateTracker>
android_sms_pairing_state_tracker,
- const cryptauth::GcmDeviceInfoProvider* gcm_device_info_provider)
+ const device_sync::GcmDeviceInfoProvider* gcm_device_info_provider)
: pref_service_(pref_service),
device_sync_client_(device_sync_client),
auth_token_validator_(auth_token_validator),
diff --git a/chromeos/services/multidevice_setup/multidevice_setup_initializer.h b/chromeos/services/multidevice_setup/multidevice_setup_initializer.h
index 20a55a1..a0fd550 100644
--- a/chromeos/services/multidevice_setup/multidevice_setup_initializer.h
+++ b/chromeos/services/multidevice_setup/multidevice_setup_initializer.h
@@ -16,12 +16,12 @@
class PrefService;
-namespace cryptauth {
-class GcmDeviceInfoProvider;
-} // namespace cryptauth
-
namespace chromeos {
+namespace device_sync {
+class GcmDeviceInfoProvider;
+} // namespace device_sync
+
namespace multidevice_setup {
class AndroidSmsAppHelperDelegate;
@@ -50,7 +50,7 @@
android_sms_app_helper_delegate,
std::unique_ptr<AndroidSmsPairingStateTracker>
android_sms_pairing_state_tracker,
- const cryptauth::GcmDeviceInfoProvider* gcm_device_info_provider);
+ const device_sync::GcmDeviceInfoProvider* gcm_device_info_provider);
private:
static Factory* test_factory_;
@@ -88,7 +88,7 @@
android_sms_app_helper_delegate,
std::unique_ptr<AndroidSmsPairingStateTracker>
android_sms_pairing_state_tracker,
- const cryptauth::GcmDeviceInfoProvider* gcm_device_info_provider);
+ const device_sync::GcmDeviceInfoProvider* gcm_device_info_provider);
// mojom::MultiDeviceSetup:
void SetAccountStatusChangeDelegate(
@@ -130,7 +130,7 @@
std::unique_ptr<AndroidSmsAppHelperDelegate> android_sms_app_helper_delegate_;
std::unique_ptr<AndroidSmsPairingStateTracker>
android_sms_pairing_state_tracker_;
- const cryptauth::GcmDeviceInfoProvider* gcm_device_info_provider_;
+ const device_sync::GcmDeviceInfoProvider* gcm_device_info_provider_;
std::unique_ptr<MultiDeviceSetupBase> multidevice_setup_impl_;
diff --git a/chromeos/services/multidevice_setup/multidevice_setup_service.cc b/chromeos/services/multidevice_setup/multidevice_setup_service.cc
index 65c940ab..ef13c86 100644
--- a/chromeos/services/multidevice_setup/multidevice_setup_service.cc
+++ b/chromeos/services/multidevice_setup/multidevice_setup_service.cc
@@ -43,7 +43,7 @@
android_sms_app_helper_delegate,
std::unique_ptr<AndroidSmsPairingStateTracker>
android_sms_pairing_state_tracker,
- const cryptauth::GcmDeviceInfoProvider* gcm_device_info_provider)
+ const device_sync::GcmDeviceInfoProvider* gcm_device_info_provider)
: service_binding_(this, std::move(request)),
multidevice_setup_(
MultiDeviceSetupInitializer::Factory::Get()->BuildInstance(
diff --git a/chromeos/services/multidevice_setup/multidevice_setup_service.h b/chromeos/services/multidevice_setup/multidevice_setup_service.h
index 265553f3..06f6749 100644
--- a/chromeos/services/multidevice_setup/multidevice_setup_service.h
+++ b/chromeos/services/multidevice_setup/multidevice_setup_service.h
@@ -16,14 +16,11 @@
class PrefService;
class PrefRegistrySimple;
-namespace cryptauth {
-class GcmDeviceInfoProvider;
-} // namespace cryptauth
-
namespace chromeos {
namespace device_sync {
class DeviceSyncClient;
+class GcmDeviceInfoProvider;
} // namespace device_sync
namespace multidevice_setup {
@@ -50,7 +47,7 @@
android_sms_app_helper_delegate,
std::unique_ptr<AndroidSmsPairingStateTracker>
android_sms_pairing_state_tracker,
- const cryptauth::GcmDeviceInfoProvider* gcm_device_info_provider);
+ const device_sync::GcmDeviceInfoProvider* gcm_device_info_provider);
~MultiDeviceSetupService() override;
static void RegisterProfilePrefs(PrefRegistrySimple* registry);
diff --git a/chromeos/services/multidevice_setup/multidevice_setup_service_unittest.cc b/chromeos/services/multidevice_setup/multidevice_setup_service_unittest.cc
index 832ad7b..37d7c79 100644
--- a/chromeos/services/multidevice_setup/multidevice_setup_service_unittest.cc
+++ b/chromeos/services/multidevice_setup/multidevice_setup_service_unittest.cc
@@ -8,6 +8,7 @@
#include "base/test/scoped_task_environment.h"
#include "chromeos/components/multidevice/remote_device_test_util.h"
#include "chromeos/services/device_sync/public/cpp/fake_device_sync_client.h"
+#include "chromeos/services/device_sync/public/cpp/fake_gcm_device_info_provider.h"
#include "chromeos/services/multidevice_setup/fake_account_status_change_delegate.h"
#include "chromeos/services/multidevice_setup/fake_feature_state_observer.h"
#include "chromeos/services/multidevice_setup/fake_host_status_observer.h"
@@ -20,7 +21,6 @@
#include "chromeos/services/multidevice_setup/public/cpp/oobe_completion_tracker.h"
#include "chromeos/services/multidevice_setup/public/mojom/constants.mojom.h"
#include "chromeos/services/multidevice_setup/public/mojom/multidevice_setup.mojom.h"
-#include "components/cryptauth/fake_gcm_device_info_provider.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "services/service_manager/public/cpp/test/test_connector_factory.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -44,7 +44,7 @@
FakeAndroidSmsAppHelperDelegate* expected_android_sms_app_helper_delegate,
FakeAndroidSmsPairingStateTracker*
expected_android_sms_pairing_state_tracker,
- const cryptauth::FakeGcmDeviceInfoProvider*
+ const device_sync::FakeGcmDeviceInfoProvider*
expected_gcm_device_info_provider)
: expected_testing_pref_service_(expected_testing_pref_service),
expected_device_sync_client_(expected_device_sync_client),
@@ -70,7 +70,7 @@
android_sms_app_helper_delegate,
std::unique_ptr<AndroidSmsPairingStateTracker>
android_sms_pairing_state_tracker,
- const cryptauth::GcmDeviceInfoProvider* gcm_device_info_provider)
+ const device_sync::GcmDeviceInfoProvider* gcm_device_info_provider)
override {
EXPECT_FALSE(instance_);
EXPECT_EQ(expected_testing_pref_service_, pref_service);
@@ -95,7 +95,7 @@
FakeAndroidSmsAppHelperDelegate* expected_android_sms_app_helper_delegate_;
FakeAndroidSmsPairingStateTracker*
expected_android_sms_pairing_state_tracker_;
- const cryptauth::FakeGcmDeviceInfoProvider*
+ const device_sync::FakeGcmDeviceInfoProvider*
expected_gcm_device_info_provider_;
FakeMultiDeviceSetup* instance_ = nullptr;
@@ -129,7 +129,7 @@
fake_android_sms_pairing_state_tracker_ =
fake_android_sms_pairing_state_tracker.get();
fake_gcm_device_info_provider_ =
- std::make_unique<cryptauth::FakeGcmDeviceInfoProvider>(
+ std::make_unique<device_sync::FakeGcmDeviceInfoProvider>(
cryptauth::GcmDeviceInfo());
fake_multidevice_setup_factory_ =
@@ -215,7 +215,7 @@
std::unique_ptr<OobeCompletionTracker> fake_oobe_completion_tracker_;
FakeAndroidSmsAppHelperDelegate* fake_android_sms_app_helper_delegate_;
FakeAndroidSmsPairingStateTracker* fake_android_sms_pairing_state_tracker_;
- std::unique_ptr<cryptauth::FakeGcmDeviceInfoProvider>
+ std::unique_ptr<device_sync::FakeGcmDeviceInfoProvider>
fake_gcm_device_info_provider_;
std::unique_ptr<FakeMultiDeviceSetupFactory> fake_multidevice_setup_factory_;
diff --git a/chromeos/services/multidevice_setup/public/cpp/multidevice_setup_client_impl_unittest.cc b/chromeos/services/multidevice_setup/public/cpp/multidevice_setup_client_impl_unittest.cc
index c21b8ab..e403cc9c 100644
--- a/chromeos/services/multidevice_setup/public/cpp/multidevice_setup_client_impl_unittest.cc
+++ b/chromeos/services/multidevice_setup/public/cpp/multidevice_setup_client_impl_unittest.cc
@@ -51,7 +51,7 @@
android_sms_app_helper_delegate,
std::unique_ptr<AndroidSmsPairingStateTracker>
android_sms_pairing_state_tracker,
- const cryptauth::GcmDeviceInfoProvider* gcm_device_info_provider)
+ const device_sync::GcmDeviceInfoProvider* gcm_device_info_provider)
override {
EXPECT_TRUE(fake_multidevice_setup_);
return std::move(fake_multidevice_setup_);
diff --git a/components/cryptauth/BUILD.gn b/components/cryptauth/BUILD.gn
index 3287cb27..83410e9 100644
--- a/components/cryptauth/BUILD.gn
+++ b/components/cryptauth/BUILD.gn
@@ -16,34 +16,10 @@
"background_eid_generator.h",
"connection.cc",
"connection.h",
- "cryptauth_api_call_flow.cc",
- "cryptauth_api_call_flow.h",
- "cryptauth_client.h",
- "cryptauth_client_impl.cc",
- "cryptauth_client_impl.h",
- "cryptauth_device_manager.cc",
- "cryptauth_device_manager.h",
- "cryptauth_device_manager_impl.cc",
- "cryptauth_device_manager_impl.h",
- "cryptauth_enroller.h",
- "cryptauth_enroller_impl.cc",
- "cryptauth_enroller_impl.h",
- "cryptauth_enrollment_manager.cc",
- "cryptauth_enrollment_manager.h",
- "cryptauth_enrollment_manager_impl.cc",
- "cryptauth_enrollment_manager_impl.h",
- "cryptauth_enrollment_utils.cc",
- "cryptauth_enrollment_utils.h",
- "cryptauth_gcm_manager.cc",
- "cryptauth_gcm_manager.h",
- "cryptauth_gcm_manager_impl.cc",
- "cryptauth_gcm_manager_impl.h",
"cryptauth_service.cc",
"cryptauth_service.h",
"data_with_timestamp.cc",
"data_with_timestamp.h",
- "device_classifier_util.cc",
- "device_classifier_util.h",
"device_to_device_authenticator.cc",
"device_to_device_authenticator.h",
"device_to_device_initiator_helper.cc",
@@ -52,47 +28,25 @@
"device_to_device_secure_context.h",
"foreground_eid_generator.cc",
"foreground_eid_generator.h",
- "gcm_device_info_provider.h",
- "network_request_error.cc",
- "network_request_error.h",
- "pref_names.cc",
- "pref_names.h",
"raw_eid_generator.h",
"raw_eid_generator_impl.cc",
"raw_eid_generator_impl.h",
- "remote_device_loader.cc",
- "remote_device_loader.h",
- "remote_device_provider.cc",
- "remote_device_provider.h",
- "remote_device_provider_impl.cc",
- "remote_device_provider_impl.h",
"secure_channel.cc",
"secure_channel.h",
"secure_context.h",
- "secure_message_delegate.cc",
- "secure_message_delegate.h",
- "secure_message_delegate_impl.cc",
- "secure_message_delegate_impl.h",
"session_keys.cc",
"session_keys.h",
- "software_feature_manager.h",
- "software_feature_manager_impl.cc",
- "software_feature_manager_impl.h",
- "switches.cc",
- "switches.h",
- "sync_scheduler.cc",
- "sync_scheduler.h",
- "sync_scheduler_impl.cc",
- "sync_scheduler_impl.h",
"wire_message.cc",
"wire_message.h",
]
deps = [
+ ":secure_message",
"//base",
"//chromeos",
"//chromeos/components/multidevice",
"//chromeos/components/proximity_auth/logging",
+ "//chromeos/services/device_sync",
"//chromeos/services/device_sync/proto:util",
"//components/cryptauth/ble",
"//components/gcm_driver",
@@ -113,6 +67,37 @@
allow_circular_includes_from = [ "//components/cryptauth/ble" ]
}
+static_library("secure_message") {
+ sources = [
+ "secure_message_delegate.cc",
+ "secure_message_delegate.h",
+ "secure_message_delegate_impl.cc",
+ "secure_message_delegate_impl.h",
+ ]
+
+ deps = [
+ "//base",
+ "//chromeos",
+ "//chromeos/components/proximity_auth/logging",
+ ]
+
+ public_deps = [
+ "//chromeos/services/device_sync/proto",
+ ]
+}
+
+static_library("secure_message_test_support") {
+ sources = [
+ "fake_secure_message_delegate.cc",
+ "fake_secure_message_delegate.h",
+ ]
+
+ deps = [
+ ":secure_message",
+ "//base",
+ ]
+}
+
static_library("test_support") {
testonly = true
@@ -125,32 +110,14 @@
"fake_background_eid_generator.h",
"fake_connection.cc",
"fake_connection.h",
- "fake_cryptauth_device_manager.cc",
- "fake_cryptauth_device_manager.h",
- "fake_cryptauth_enrollment_manager.cc",
- "fake_cryptauth_enrollment_manager.h",
- "fake_cryptauth_gcm_manager.cc",
- "fake_cryptauth_gcm_manager.h",
"fake_cryptauth_service.cc",
"fake_cryptauth_service.h",
- "fake_gcm_device_info_provider.cc",
- "fake_gcm_device_info_provider.h",
- "fake_remote_device_provider.cc",
- "fake_remote_device_provider.h",
"fake_secure_channel.cc",
"fake_secure_channel.h",
"fake_secure_context.cc",
"fake_secure_context.h",
- "fake_secure_message_delegate.cc",
- "fake_secure_message_delegate.h",
- "fake_software_feature_manager.cc",
- "fake_software_feature_manager.h",
- "mock_cryptauth_client.cc",
- "mock_cryptauth_client.h",
"mock_foreground_eid_generator.cc",
"mock_foreground_eid_generator.h",
- "mock_sync_scheduler.cc",
- "mock_sync_scheduler.h",
]
public_deps = [
@@ -160,8 +127,10 @@
]
deps = [
+ ":secure_message",
"//base",
"//chromeos/components/proximity_auth/logging",
+ "//chromeos/services/device_sync:test_support",
"//testing/gmock",
]
}
@@ -171,29 +140,21 @@
sources = [
"background_eid_generator_unittest.cc",
"connection_unittest.cc",
- "cryptauth_api_call_flow_unittest.cc",
- "cryptauth_client_impl_unittest.cc",
- "cryptauth_device_manager_impl_unittest.cc",
- "cryptauth_enroller_impl_unittest.cc",
- "cryptauth_enrollment_manager_impl_unittest.cc",
- "cryptauth_gcm_manager_impl_unittest.cc",
"device_to_device_authenticator_unittest.cc",
"device_to_device_operations_unittest.cc",
"device_to_device_secure_context_unittest.cc",
"fake_secure_message_delegate_unittest.cc",
"foreground_eid_generator_unittest.cc",
"raw_eid_generator_impl_unittest.cc",
- "remote_device_loader_unittest.cc",
- "remote_device_provider_impl_unittest.cc",
"secure_channel_unittest.cc",
"session_keys_unittest.cc",
- "software_feature_manager_impl_unittest.cc",
- "sync_scheduler_impl_unittest.cc",
"wire_message_unittest.cc",
]
deps = [
":cryptauth",
+ ":secure_message",
+ ":secure_message_test_support",
":test_support",
"//base/test:test_support",
"//chromeos/components/multidevice",
diff --git a/components/cryptauth/cryptauth_device_id_provider.h b/components/cryptauth/cryptauth_device_id_provider.h
deleted file mode 100644
index 5d825571..0000000
--- a/components/cryptauth/cryptauth_device_id_provider.h
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright 2018 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef COMPONENTS_CRYPTAUTH_CRYPTAUTH_DEVICE_ID_PROVIDER_H_
-#define COMPONENTS_CRYPTAUTH_CRYPTAUTH_DEVICE_ID_PROVIDER_H_
-
-#include <string>
-
-#include "base/macros.h"
-
-namespace cryptauth {
-
-// Provides the ID of the current device. In this context, "device ID" refers to
-// the |long_device_id| field of the GcmDeviceInfo proto which is sent to the
-// CryptAuth back-end during device enrollment.
-class CryptAuthDeviceIdProvider {
- public:
- CryptAuthDeviceIdProvider() = default;
- virtual ~CryptAuthDeviceIdProvider() = default;
-
- virtual std::string GetDeviceId() const = 0;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(CryptAuthDeviceIdProvider);
-};
-
-} // namespace cryptauth
-
-#endif // COMPONENTS_CRYPTAUTH_CRYPTAUTH_DEVICE_ID_PROVIDER_H_
diff --git a/components/cryptauth/cryptauth_enrollment_utils.cc b/components/cryptauth/cryptauth_enrollment_utils.cc
deleted file mode 100644
index dabcec1..0000000
--- a/components/cryptauth/cryptauth_enrollment_utils.cc
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "components/cryptauth/cryptauth_enrollment_utils.h"
-
-#include <stddef.h>
-
-#include "base/md5.h"
-
-namespace cryptauth {
-
-int64_t HashStringToInt64(const std::string& string) {
- base::MD5Context context;
- base::MD5Init(&context);
- base::MD5Update(&context, string);
-
- base::MD5Digest digest;
- base::MD5Final(&digest, &context);
-
- // Fold the digest into an int64_t value. |digest.a| is a 16-byte array, so we
- // sum the two 8-byte halves of the digest to create the hash.
- int64_t hash = 0;
- for (size_t i = 0; i < sizeof(digest.a); ++i) {
- uint8_t byte = digest.a[i];
- hash += static_cast<int64_t>(byte) << (i % sizeof(int64_t));
- }
-
- return hash;
-}
-
-} // namespace cryptauth
diff --git a/components/cryptauth/cryptauth_enrollment_utils.h b/components/cryptauth/cryptauth_enrollment_utils.h
deleted file mode 100644
index 99c83fa..0000000
--- a/components/cryptauth/cryptauth_enrollment_utils.h
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef COMPONENTS_CRYPTAUTH_CRYPTAUTH_ENROLLMENT_UTILS_H
-#define COMPONENTS_CRYPTAUTH_CRYPTAUTH_ENROLLMENT_UTILS_H
-
-#include <stdint.h>
-#include <string>
-
-namespace cryptauth {
-
-// Hashes |string| to an int64_t value. These int64_t hashes are used to fill
-// the GcmDeviceInfo proto to upload to CryptAuth.
-int64_t HashStringToInt64(const std::string& string);
-
-} // namespace cryptauth
-
-#endif // COMPONENTS_CRYPTAUTH_CRYPTAUTH_ENROLLMENT_UTILS_H
diff --git a/components/cryptauth/cryptauth_gcm_manager.cc b/components/cryptauth/cryptauth_gcm_manager.cc
deleted file mode 100644
index d289300..0000000
--- a/components/cryptauth/cryptauth_gcm_manager.cc
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "components/cryptauth/cryptauth_gcm_manager.h"
-
-#include "components/cryptauth/pref_names.h"
-#include "components/prefs/pref_registry_simple.h"
-
-namespace cryptauth {
-
-CryptAuthGCMManager::Observer::~Observer() {
-}
-
-void CryptAuthGCMManager::Observer::OnGCMRegistrationResult(bool success) {
-}
-
-void CryptAuthGCMManager::Observer::OnReenrollMessage() {
-}
-
-void CryptAuthGCMManager::Observer::OnResyncMessage() {
-}
-
-// static.
-void CryptAuthGCMManager::RegisterPrefs(PrefRegistrySimple* registry) {
- registry->RegisterStringPref(prefs::kCryptAuthGCMRegistrationId,
- std::string());
-}
-
-} // namespace cryptauth
diff --git a/components/cryptauth/cryptauth_service.cc b/components/cryptauth/cryptauth_service.cc
index 806516b..79facc24 100644
--- a/components/cryptauth/cryptauth_service.cc
+++ b/components/cryptauth/cryptauth_service.cc
@@ -4,17 +4,17 @@
#include "components/cryptauth/cryptauth_service.h"
-#include "components/cryptauth/cryptauth_device_manager.h"
-#include "components/cryptauth/cryptauth_enrollment_manager.h"
-#include "components/cryptauth/cryptauth_gcm_manager.h"
+#include "chromeos/services/device_sync/cryptauth_device_manager.h"
+#include "chromeos/services/device_sync/cryptauth_enrollment_manager.h"
+#include "chromeos/services/device_sync/cryptauth_gcm_manager.h"
namespace cryptauth {
// static
void CryptAuthService::RegisterProfilePrefs(PrefRegistrySimple* registry) {
- CryptAuthGCMManager::RegisterPrefs(registry);
- CryptAuthDeviceManager::RegisterPrefs(registry);
- CryptAuthEnrollmentManager::RegisterPrefs(registry);
+ chromeos::device_sync::CryptAuthGCMManager::RegisterPrefs(registry);
+ chromeos::device_sync::CryptAuthDeviceManager::RegisterPrefs(registry);
+ chromeos::device_sync::CryptAuthEnrollmentManager::RegisterPrefs(registry);
}
} // namespace cryptauth
diff --git a/components/cryptauth/cryptauth_service.h b/components/cryptauth/cryptauth_service.h
index 27546cd..113945d 100644
--- a/components/cryptauth/cryptauth_service.h
+++ b/components/cryptauth/cryptauth_service.h
@@ -11,22 +11,28 @@
#include "chromeos/services/device_sync/proto/cryptauth_api.pb.h"
#include "components/prefs/pref_registry_simple.h"
-namespace cryptauth {
-
+namespace chromeos {
+namespace device_sync {
class CryptAuthClientFactory;
class CryptAuthDeviceManager;
class CryptAuthEnrollmentManager;
+} // namespace device_sync
+} // namespace chromeos
+
+namespace cryptauth {
// Service which provides access to various CryptAuth singletons.
class CryptAuthService {
public:
static void RegisterProfilePrefs(PrefRegistrySimple* registry);
- virtual CryptAuthDeviceManager* GetCryptAuthDeviceManager() = 0;
- virtual CryptAuthEnrollmentManager* GetCryptAuthEnrollmentManager() = 0;
+ virtual chromeos::device_sync::CryptAuthDeviceManager*
+ GetCryptAuthDeviceManager() = 0;
+ virtual chromeos::device_sync::CryptAuthEnrollmentManager*
+ GetCryptAuthEnrollmentManager() = 0;
virtual DeviceClassifier GetDeviceClassifier() = 0;
virtual std::string GetAccountId() = 0;
- virtual std::unique_ptr<CryptAuthClientFactory>
+ virtual std::unique_ptr<chromeos::device_sync::CryptAuthClientFactory>
CreateCryptAuthClientFactory() = 0;
protected:
diff --git a/components/cryptauth/device_classifier_util.h b/components/cryptauth/device_classifier_util.h
deleted file mode 100644
index 0c2bb6ee..0000000
--- a/components/cryptauth/device_classifier_util.h
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2018 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef COMPONENTS_CRYPTAUTH_DEVICE_CLASSIFIER_UTIL_H_
-#define COMPONENTS_CRYPTAUTH_DEVICE_CLASSIFIER_UTIL_H_
-
-#include "chromeos/services/device_sync/proto/cryptauth_api.pb.h"
-
-namespace cryptauth {
-
-namespace device_classifier_util {
-
-const cryptauth::DeviceClassifier& GetDeviceClassifier();
-
-} // namespace device_classifier_util
-
-} // namespace cryptauth
-
-#endif // COMPONENTS_CRYPTAUTH_DEVICE_CLASSIFIER_UTIL_H_
diff --git a/components/cryptauth/fake_cryptauth_device_manager.h b/components/cryptauth/fake_cryptauth_device_manager.h
deleted file mode 100644
index 8d5bf3e..0000000
--- a/components/cryptauth/fake_cryptauth_device_manager.h
+++ /dev/null
@@ -1,118 +0,0 @@
-// Copyright 2018 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef COMPONENTS_CRYPTAUTH_FAKE_CRYPTAUTH_DEVICE_MANAGER_H_
-#define COMPONENTS_CRYPTAUTH_FAKE_CRYPTAUTH_DEVICE_MANAGER_H_
-
-#include <memory>
-
-#include "base/macros.h"
-#include "chromeos/services/device_sync/proto/cryptauth_api.pb.h"
-#include "components/cryptauth/cryptauth_device_manager.h"
-
-namespace cryptauth {
-
-// Test double for CryptAuthDeviceManager.
-class FakeCryptAuthDeviceManager : public CryptAuthDeviceManager {
- public:
- FakeCryptAuthDeviceManager();
- ~FakeCryptAuthDeviceManager() override;
-
- bool has_started() { return has_started_; }
-
- void set_last_sync_time(base::Time last_sync_time) {
- last_sync_time_ = last_sync_time;
- }
-
- void set_time_to_next_attempt(base::TimeDelta time_to_next_attempt) {
- time_to_next_attempt_ = time_to_next_attempt;
- }
-
- std::vector<ExternalDeviceInfo>& synced_devices() { return synced_devices_; }
-
- void set_synced_devices(std::vector<ExternalDeviceInfo> synced_devices) {
- synced_devices_ = synced_devices;
- }
-
- std::vector<ExternalDeviceInfo>& unlock_keys() { return unlock_keys_; }
-
- void set_unlock_keys(const std::vector<ExternalDeviceInfo>& unlock_keys) {
- unlock_keys_ = unlock_keys;
- }
-
- std::vector<ExternalDeviceInfo>& pixel_unlock_keys() {
- return pixel_unlock_keys_;
- }
-
- void set_pixel_unlock_keys(
- const std::vector<ExternalDeviceInfo>& pixel_unlock_keys) {
- pixel_unlock_keys_ = pixel_unlock_keys;
- }
-
- std::vector<ExternalDeviceInfo>& tether_hosts() { return tether_hosts_; }
-
- void set_tether_hosts(const std::vector<ExternalDeviceInfo>& tether_hosts) {
- tether_hosts_ = tether_hosts;
- }
-
- std::vector<ExternalDeviceInfo>& pixel_tether_hosts() {
- return pixel_tether_hosts_;
- }
-
- void set_pixel_tether_hosts(
- const std::vector<ExternalDeviceInfo>& pixel_tether_hosts) {
- pixel_tether_hosts_ = pixel_tether_hosts;
- }
-
- void set_is_recovering_from_failure(bool is_recovering_from_failure) {
- is_recovering_from_failure_ = is_recovering_from_failure;
- }
-
- void set_is_sync_in_progress(bool is_sync_in_progress) {
- is_sync_in_progress_ = is_sync_in_progress;
- }
-
- // Finishes the active sync; should only be called if a sync is in progress
- // due to a previous call to ForceSyncNow(). If |sync_result| is SUCCESS,
- // |sync_finish_time| will be stored as the last sync time and will be
- // returned by future calls to GetLastSyncTime().
- void FinishActiveSync(SyncResult sync_result,
- DeviceChangeResult device_change_result,
- base::Time sync_finish_time = base::Time());
-
- // Make these functions public for testing.
- using CryptAuthDeviceManager::NotifySyncStarted;
- using CryptAuthDeviceManager::NotifySyncFinished;
-
- // CryptAuthDeviceManager:
- void Start() override;
- void ForceSyncNow(InvocationReason invocation_reason) override;
- base::Time GetLastSyncTime() const override;
- base::TimeDelta GetTimeToNextAttempt() const override;
- bool IsSyncInProgress() const override;
- bool IsRecoveringFromFailure() const override;
- std::vector<ExternalDeviceInfo> GetSyncedDevices() const override;
- std::vector<ExternalDeviceInfo> GetUnlockKeys() const override;
- std::vector<ExternalDeviceInfo> GetPixelUnlockKeys() const override;
- std::vector<ExternalDeviceInfo> GetTetherHosts() const override;
- std::vector<ExternalDeviceInfo> GetPixelTetherHosts() const override;
-
- private:
- bool has_started_ = false;
- bool is_sync_in_progress_ = false;
- bool is_recovering_from_failure_ = false;
- base::Time last_sync_time_;
- base::TimeDelta time_to_next_attempt_;
- std::vector<ExternalDeviceInfo> synced_devices_;
- std::vector<ExternalDeviceInfo> unlock_keys_;
- std::vector<ExternalDeviceInfo> pixel_unlock_keys_;
- std::vector<ExternalDeviceInfo> tether_hosts_;
- std::vector<ExternalDeviceInfo> pixel_tether_hosts_;
-
- DISALLOW_COPY_AND_ASSIGN(FakeCryptAuthDeviceManager);
-};
-
-} // namespace cryptauth
-
-#endif // COMPONENTS_CRYPTAUTH_FAKE_CRYPTAUTH_DEVICE_MANAGER_H_
diff --git a/components/cryptauth/fake_cryptauth_service.cc b/components/cryptauth/fake_cryptauth_service.cc
index 38a5c76..a147cce 100644
--- a/components/cryptauth/fake_cryptauth_service.cc
+++ b/components/cryptauth/fake_cryptauth_service.cc
@@ -7,7 +7,7 @@
#include <memory>
#include "base/callback.h"
-#include "components/cryptauth/mock_cryptauth_client.h"
+#include "chromeos/services/device_sync/mock_cryptauth_client.h"
namespace cryptauth {
@@ -15,11 +15,12 @@
FakeCryptAuthService::~FakeCryptAuthService() {}
-CryptAuthDeviceManager* FakeCryptAuthService::GetCryptAuthDeviceManager() {
+chromeos::device_sync::CryptAuthDeviceManager*
+FakeCryptAuthService::GetCryptAuthDeviceManager() {
return cryptauth_device_manager_;
}
-CryptAuthEnrollmentManager*
+chromeos::device_sync::CryptAuthEnrollmentManager*
FakeCryptAuthService::GetCryptAuthEnrollmentManager() {
return cryptauth_enrollment_manager_;
}
@@ -32,10 +33,11 @@
return account_id_;
}
-std::unique_ptr<CryptAuthClientFactory>
+std::unique_ptr<chromeos::device_sync::CryptAuthClientFactory>
FakeCryptAuthService::CreateCryptAuthClientFactory() {
- return std::make_unique<MockCryptAuthClientFactory>(
- MockCryptAuthClientFactory::MockType::MAKE_NICE_MOCKS);
+ return std::make_unique<chromeos::device_sync::MockCryptAuthClientFactory>(
+ chromeos::device_sync::MockCryptAuthClientFactory::MockType::
+ MAKE_NICE_MOCKS);
}
} // namespace cryptauth
diff --git a/components/cryptauth/fake_cryptauth_service.h b/components/cryptauth/fake_cryptauth_service.h
index 9b4d651..6780175 100644
--- a/components/cryptauth/fake_cryptauth_service.h
+++ b/components/cryptauth/fake_cryptauth_service.h
@@ -11,11 +11,15 @@
#include "chromeos/services/device_sync/proto/cryptauth_api.pb.h"
#include "components/cryptauth/cryptauth_service.h"
-namespace cryptauth {
-
+namespace chromeos {
+namespace device_sync {
class CryptAuthClientFactory;
class CryptAuthDeviceManager;
class CryptAuthEnrollmentManager;
+} // namespace device_sync
+} // namespace chromeos
+
+namespace cryptauth {
// Service which provides access to various CryptAuth singletons.
class FakeCryptAuthService : public CryptAuthService {
@@ -24,12 +28,13 @@
~FakeCryptAuthService() override;
void set_cryptauth_device_manager(
- CryptAuthDeviceManager* cryptauth_device_manager) {
+ chromeos::device_sync::CryptAuthDeviceManager* cryptauth_device_manager) {
cryptauth_device_manager_ = cryptauth_device_manager;
}
void set_cryptauth_enrollment_manager(
- CryptAuthEnrollmentManager* cryptauth_enrollment_manager) {
+ chromeos::device_sync::CryptAuthEnrollmentManager*
+ cryptauth_enrollment_manager) {
cryptauth_enrollment_manager_ = cryptauth_enrollment_manager;
}
@@ -42,16 +47,19 @@
}
// CryptAuthService:
- CryptAuthDeviceManager* GetCryptAuthDeviceManager() override;
- CryptAuthEnrollmentManager* GetCryptAuthEnrollmentManager() override;
+ chromeos::device_sync::CryptAuthDeviceManager* GetCryptAuthDeviceManager()
+ override;
+ chromeos::device_sync::CryptAuthEnrollmentManager*
+ GetCryptAuthEnrollmentManager() override;
DeviceClassifier GetDeviceClassifier() override;
std::string GetAccountId() override;
- std::unique_ptr<CryptAuthClientFactory> CreateCryptAuthClientFactory()
- override;
+ std::unique_ptr<chromeos::device_sync::CryptAuthClientFactory>
+ CreateCryptAuthClientFactory() override;
private:
- CryptAuthDeviceManager* cryptauth_device_manager_;
- CryptAuthEnrollmentManager* cryptauth_enrollment_manager_;
+ chromeos::device_sync::CryptAuthDeviceManager* cryptauth_device_manager_;
+ chromeos::device_sync::CryptAuthEnrollmentManager*
+ cryptauth_enrollment_manager_;
DeviceClassifier device_classifier_;
std::string account_id_;
diff --git a/components/cryptauth/fake_gcm_device_info_provider.cc b/components/cryptauth/fake_gcm_device_info_provider.cc
deleted file mode 100644
index 63fcc2d..0000000
--- a/components/cryptauth/fake_gcm_device_info_provider.cc
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright 2018 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "components/cryptauth/fake_gcm_device_info_provider.h"
-
-namespace cryptauth {
-
-FakeGcmDeviceInfoProvider::FakeGcmDeviceInfoProvider(
- const GcmDeviceInfo& gcm_device_info)
- : gcm_device_info_(gcm_device_info) {}
-
-FakeGcmDeviceInfoProvider::~FakeGcmDeviceInfoProvider() = default;
-
-const GcmDeviceInfo& FakeGcmDeviceInfoProvider::GetGcmDeviceInfo() const {
- return gcm_device_info_;
-}
-
-} // namespace cryptauth
diff --git a/components/cryptauth/fake_gcm_device_info_provider.h b/components/cryptauth/fake_gcm_device_info_provider.h
deleted file mode 100644
index e3084f0..0000000
--- a/components/cryptauth/fake_gcm_device_info_provider.h
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright 2018 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef COMPONENTS_CRYPTAUTH_FAKE_GCM_DEVICE_INFO_PROVIDER_H_
-#define COMPONENTS_CRYPTAUTH_FAKE_GCM_DEVICE_INFO_PROVIDER_H_
-
-#include "base/macros.h"
-#include "chromeos/services/device_sync/proto/cryptauth_api.pb.h"
-#include "components/cryptauth/gcm_device_info_provider.h"
-
-namespace cryptauth {
-
-// Test GcmDeviceInfoProvider implementation.
-class FakeGcmDeviceInfoProvider : public GcmDeviceInfoProvider {
- public:
- FakeGcmDeviceInfoProvider(const GcmDeviceInfo& gcm_device_info);
- ~FakeGcmDeviceInfoProvider() override;
-
- // GcmDeviceInfoProvider:
- const GcmDeviceInfo& GetGcmDeviceInfo() const override;
-
- private:
- const GcmDeviceInfo gcm_device_info_;
-
- DISALLOW_COPY_AND_ASSIGN(FakeGcmDeviceInfoProvider);
-};
-
-} // namespace cryptauth
-
-#endif // COMPONENTS_CRYPTAUTH_FAKE_GCM_DEVICE_INFO_PROVIDER_H_
diff --git a/components/cryptauth/gcm_device_info_provider.h b/components/cryptauth/gcm_device_info_provider.h
deleted file mode 100644
index dd4070f..0000000
--- a/components/cryptauth/gcm_device_info_provider.h
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright 2018 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef COMPONENTS_CRYPTAUTH_GCM_DEVICE_INFO_PROVIDER_H_
-#define COMPONENTS_CRYPTAUTH_GCM_DEVICE_INFO_PROVIDER_H_
-
-#include "base/macros.h"
-#include "chromeos/services/device_sync/proto/cryptauth_api.pb.h"
-
-namespace cryptauth {
-
-// Provides the GcmDeviceInfo object associated with the current device.
-// GcmDeviceInfo describes properties of this Chromebook and is not expected to
-// change except when the OS version is updated.
-class GcmDeviceInfoProvider {
- public:
- GcmDeviceInfoProvider() = default;
- virtual ~GcmDeviceInfoProvider() = default;
-
- virtual const GcmDeviceInfo& GetGcmDeviceInfo() const = 0;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(GcmDeviceInfoProvider);
-};
-
-} // namespace cryptauth
-
-#endif // COMPONENTS_CRYPTAUTH_GCM_DEVICE_INFO_PROVIDER_H_
diff --git a/components/cryptauth/mock_sync_scheduler.cc b/components/cryptauth/mock_sync_scheduler.cc
deleted file mode 100644
index 11f5dd8..0000000
--- a/components/cryptauth/mock_sync_scheduler.cc
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "components/cryptauth/mock_sync_scheduler.h"
-
-namespace cryptauth {
-
-MockSyncScheduler::MockSyncScheduler() {
-}
-
-MockSyncScheduler::~MockSyncScheduler() {
-}
-
-} // namespace cryptauth