Commit d83f8c5a authored by Kyle Horimoto's avatar Kyle Horimoto Committed by Commit Bot

[CrOS MultiDevice] Refactor GcmDeviceInfo generation.

When a device registers to use the CryptAuth back-end, it sends a
GcmDeviceInfo proto message. Before this CL, this was done from within
ChromeCryptAuthService, which resides in //chrome.

In order to share this code with the in-progress DeviceSync service,
this CL refactors this code and moves it to a new location where it can
be shared between both clients. Implementation is split between a
pure-virtual GcmDeviceInfoProvider class living in
//components/cryptauth and an implementation which has //chrome
dependencies in //chrome/browser/chromeos/cryptauth. This separation is
necessary so that the DeviceSync services, which resides in //chromeos,
can utilize this class behind an interface.

Bug: 824568, 752273
Change-Id: I0b5a4401809185cf3beef7e95cc1a68c369eaa79
Reviewed-on: https://chromium-review.googlesource.com/991234Reviewed-by: default avatarJames Hawkins <jhawkins@chromium.org>
Commit-Queue: Kyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#547895}
parent ea3d1c58
......@@ -509,6 +509,8 @@ source_set("chromeos") {
"cryptauth/chrome_cryptauth_service_factory.h",
"cryptauth/cryptauth_device_id_provider_impl.cc",
"cryptauth/cryptauth_device_id_provider_impl.h",
"cryptauth/gcm_device_info_provider_impl.cc",
"cryptauth/gcm_device_info_provider_impl.h",
"customization/customization_document.cc",
"customization/customization_document.h",
"customization/customization_wallpaper_downloader.cc",
......
......@@ -13,6 +13,7 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_content_browser_client.h"
#include "chrome/browser/chromeos/cryptauth/cryptauth_device_id_provider_impl.h"
#include "chrome/browser/chromeos/cryptauth/gcm_device_info_provider_impl.h"
#include "chrome/browser/chromeos/login/easy_unlock/secure_message_delegate_chromeos.h"
#include "chrome/browser/gcm/gcm_profile_service_factory.h"
#include "chrome/browser/profiles/profile.h"
......@@ -45,29 +46,6 @@ namespace chromeos {
namespace {
cryptauth::GcmDeviceInfo GetGcmDeviceInfo() {
cryptauth::GcmDeviceInfo device_info;
device_info.set_long_device_id(
cryptauth::CryptAuthDeviceIdProviderImpl::GetInstance()->GetDeviceId());
device_info.set_device_type(cryptauth::CHROME);
device_info.set_device_software_version(version_info::GetVersionNumber());
google::protobuf::int64 software_version_code =
cryptauth::HashStringToInt64(version_info::GetLastChange());
device_info.set_device_software_version_code(software_version_code);
ChromeContentBrowserClient chrome_content_browser_client;
device_info.set_locale(chrome_content_browser_client.GetApplicationLocale());
device_info.set_device_model(base::SysInfo::GetLsbReleaseBoard());
device_info.set_device_os_version(base::GetLinuxDistro());
// The Chrome OS version tracks the Chrome version, so fill in the same value
// as |device_software_version_code|.
device_info.set_device_os_version_code(software_version_code);
// |device_display_diagonal_mils| is unused because it only applies to
// phones/tablets, but it must be set due to server API verification.
device_info.set_device_display_diagonal_mils(0);
return device_info;
}
std::unique_ptr<cryptauth::CryptAuthClientFactory>
CreateCryptAuthClientFactoryImpl(Profile* profile) {
return std::make_unique<cryptauth::CryptAuthClientFactoryImpl>(
......@@ -117,7 +95,8 @@ std::unique_ptr<ChromeCryptAuthService> ChromeCryptAuthService::Create(
cryptauth::CryptAuthEnrollmentManagerImpl::Factory::NewInstance(
base::DefaultClock::GetInstance(),
std::make_unique<CryptAuthEnrollerFactoryImpl>(profile),
CreateSecureMessageDelegateImpl(), GetGcmDeviceInfo(),
CreateSecureMessageDelegateImpl(),
GcmDeviceInfoProviderImpl::GetInstance()->GetGcmDeviceInfo(),
gcm_manager.get(), profile->GetPrefs());
// Note: ChromeCryptAuthServiceFactory DependsOn(OAuth2TokenServiceFactory),
......
// 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 "chrome/browser/chromeos/cryptauth/gcm_device_info_provider_impl.h"
#include "base/linux_util.h"
#include "base/no_destructor.h"
#include "base/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 "components/cryptauth/cryptauth_enrollment_utils.h"
#include "components/version_info/version_info.h"
namespace chromeos {
// static
const GcmDeviceInfoProviderImpl* GcmDeviceInfoProviderImpl::GetInstance() {
static const base::NoDestructor<GcmDeviceInfoProviderImpl> provider;
return provider.get();
}
const cryptauth::GcmDeviceInfo& GcmDeviceInfoProviderImpl::GetGcmDeviceInfo()
const {
static const base::NoDestructor<cryptauth::GcmDeviceInfo> gcm_device_info([] {
static const google::protobuf::int64 kSoftwareVersionCode =
cryptauth::HashStringToInt64(version_info::GetLastChange());
cryptauth::GcmDeviceInfo gcm_device_info;
gcm_device_info.set_long_device_id(
cryptauth::CryptAuthDeviceIdProviderImpl::GetInstance()->GetDeviceId());
gcm_device_info.set_device_type(cryptauth::CHROME);
gcm_device_info.set_device_software_version(
version_info::GetVersionNumber());
gcm_device_info.set_device_software_version_code(kSoftwareVersionCode);
gcm_device_info.set_locale(
ChromeContentBrowserClient().GetApplicationLocale());
gcm_device_info.set_device_model(base::SysInfo::GetLsbReleaseBoard());
gcm_device_info.set_device_os_version(base::GetLinuxDistro());
// The Chrome OS version tracks the Chrome version, so fill in the same
// value as |device_kSoftwareVersionCode|.
gcm_device_info.set_device_os_version_code(kSoftwareVersionCode);
// |device_display_diagonal_mils| is unused because it only applies to
// phones/tablets, but it must be set due to server API verification.
gcm_device_info.set_device_display_diagonal_mils(0);
return gcm_device_info;
}());
return *gcm_device_info;
}
GcmDeviceInfoProviderImpl::GcmDeviceInfoProviderImpl() = default;
} // namespace chromeos
// 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 CHROME_BROWSER_CHROMEOS_CRYPTAUTH_GCM_DEVICE_INFO_PROVIDER_IMPL_H_
#define CHROME_BROWSER_CHROMEOS_CRYPTAUTH_GCM_DEVICE_INFO_PROVIDER_IMPL_H_
#include "base/macros.h"
#include "base/no_destructor.h"
#include "components/cryptauth/gcm_device_info_provider.h"
#include "components/cryptauth/proto/cryptauth_api.pb.h"
namespace chromeos {
// Concrete GcmDeviceInfoProvider implementation.
class GcmDeviceInfoProviderImpl : public cryptauth::GcmDeviceInfoProvider {
public:
static const GcmDeviceInfoProviderImpl* GetInstance();
// cryptauth::GcmDeviceInfoProvider:
const cryptauth::GcmDeviceInfo& GetGcmDeviceInfo() const override;
private:
friend class base::NoDestructor<GcmDeviceInfoProviderImpl>;
GcmDeviceInfoProviderImpl();
DISALLOW_COPY_AND_ASSIGN(GcmDeviceInfoProviderImpl);
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_CRYPTAUTH_GCM_DEVICE_INFO_PROVIDER_IMPL_H_
......@@ -58,6 +58,7 @@ static_library("cryptauth") {
"device_to_device_secure_context.h",
"foreground_eid_generator.cc",
"foreground_eid_generator.h",
"gcm_device_info_provider.h",
"local_device_data_provider.cc",
"local_device_data_provider.h",
"pref_names.cc",
......@@ -139,6 +140,8 @@ static_library("test_support") {
"fake_cryptauth_service.h",
"fake_device_capability_manager.cc",
"fake_device_capability_manager.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",
......
// 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
// 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 "components/cryptauth/gcm_device_info_provider.h"
#include "components/cryptauth/proto/cryptauth_api.pb.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_
// 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 "components/cryptauth/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_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment