Commit d22640a5 authored by Georges Khalil's avatar Georges Khalil Committed by Commit Bot

Add serial number to cloud reports.

This CL adds the serial number to cloud reporting, as a step to
transition to using that as the client ID.

Bug: 910594
Change-Id: I7b336da99f2f7304b3e03b7a3a25aa07715749d2
Reviewed-on: https://chromium-review.googlesource.com/c/1354342
Commit-Queue: Georges Khalil <georgesak@chromium.org>
Reviewed-by: default avatarOwen Min <zmin@chromium.org>
Reviewed-by: default avatarJulian Pastarmov <pastarmovj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612696}
parent af37afb4
......@@ -11,8 +11,10 @@
#include "base/path_service.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/api/enterprise_reporting_private/prefs.h"
#include "chrome/browser/policy/browser_dm_token_storage.h"
#include "chrome/browser/policy/chrome_browser_policy_connector.h"
#include "chrome/browser/policy/machine_level_user_cloud_policy_controller.h"
#include "chrome/browser/policy/policy_conversions.h"
......@@ -80,6 +82,11 @@ void AppendAdditionalBrowserInformation(em::ChromeDesktopReportRequest* request,
Profile* profile) {
const PrefService* prefs = profile->GetPrefs();
#if defined(OS_WIN)
request->mutable_browser_report()->set_serial_number(
policy::BrowserDMTokenStorage::Get()->RetrieveSerialNumber());
#endif
// Set Chrome version number
request->mutable_browser_report()->set_browser_version(
version_info::GetVersionNumber());
......
......@@ -7,6 +7,7 @@
#include "base/json/json_reader.h"
#include "base/json/string_escape.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/extensions/api/enterprise_reporting_private/prefs.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_profile.h"
......@@ -243,4 +244,16 @@ TEST_F(ChromeDesktopReportRequestGeneratorTest, DontReportSafeBrowsingData) {
.has_safe_browsing_warnings_click_through());
}
TEST_F(ChromeDesktopReportRequestGeneratorTest, SerialNumberNotEmpty) {
std::unique_ptr<em::ChromeDesktopReportRequest> request;
request =
GenerateChromeDesktopReportRequest(base::DictionaryValue(), &profile_);
ASSERT_TRUE(request);
#if defined(OS_WIN)
EXPECT_NE(request->browser_report().serial_number(), std::string());
#else
EXPECT_TRUE(request->browser_report().serial_number().empty());
#endif
}
} // namespace extensions
......@@ -14,8 +14,10 @@
#include "base/callback.h"
#include "base/logging.h"
#include "base/no_destructor.h"
#include "base/run_loop.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "base/system/sys_info.h"
#include "base/task/post_task.h"
#include "base/task_runner_util.h"
#include "base/threading/sequenced_task_runner_handle.h"
......@@ -25,6 +27,15 @@
namespace policy {
namespace {
void OnHardwarePlatformInfo(base::OnceClosure quit_closure,
std::string* out,
base::SysInfo::HardwareInfo info) {
*out = info.serial_number;
std::move(quit_closure).Run();
}
} // namespace
// static
BrowserDMTokenStorage* BrowserDMTokenStorage::storage_for_testing_ = nullptr;
......@@ -47,6 +58,17 @@ std::string BrowserDMTokenStorage::RetrieveClientId() {
return client_id_;
}
std::string BrowserDMTokenStorage::RetrieveSerialNumber() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!serial_number_) {
serial_number_ = InitSerialNumber();
DVLOG(1) << "Serial number= " << serial_number_.value();
}
return serial_number_.value();
}
std::string BrowserDMTokenStorage::RetrieveEnrollmentToken() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
......@@ -124,6 +146,22 @@ void BrowserDMTokenStorage::InitIfNeeded() {
should_display_error_message_on_failure_ = InitEnrollmentErrorOption();
}
std::string BrowserDMTokenStorage::InitSerialNumber() {
// GetHardwareInfo is asynchronous, but we need this synchronously. This call
// will only happens once, as we cache the value. This will eventually be
// moved earlier in Chrome's startup as it will be needed by the registration
// as well.
// TODO(907518): Move this earlier and make it async.
base::RunLoop run_loop;
std::string serial_number;
base::SysInfo::GetHardwareInfo(base::BindOnce(
&OnHardwarePlatformInfo, run_loop.QuitClosure(), &serial_number));
run_loop.Run();
return serial_number;
}
void BrowserDMTokenStorage::DeletePolicyDirectory() {}
} // namespace policy
......@@ -13,8 +13,11 @@
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "base/no_destructor.h"
#include "base/optional.h"
#include "base/run_loop.h"
#include "base/sequence_checker.h"
#include "base/single_thread_task_runner.h"
#include "base/system/sys_info.h"
namespace policy {
......@@ -34,6 +37,8 @@ class BrowserDMTokenStorage {
static BrowserDMTokenStorage* Get();
// Returns a client ID unique to the machine. Virtual for tests.
virtual std::string RetrieveClientId();
// Returns the serial number of the machine.
std::string RetrieveSerialNumber();
// Returns the enrollment token, or an empty string if there is none. Virtual
// for tests.
virtual std::string RetrieveEnrollmentToken();
......@@ -77,14 +82,17 @@ class BrowserDMTokenStorage {
// is called the first time the BrowserDMTokenStorage is interacted with.
void InitIfNeeded();
// Gets the client ID and stores it in |client_id_|. This implementation is
// platform dependant.
// Gets the client ID and returns it. This implementation is platform
// dependant.
virtual std::string InitClientId() = 0;
// Gets the enrollment token and stores it in |enrollment_token_|. This
// implementation is platform dependant.
// Gets the client ID and returns it. This implementation is shared by all
// platforms.
std::string InitSerialNumber();
// Gets the enrollment token and returns it. This implementation is platform
// dependant.
virtual std::string InitEnrollmentToken() = 0;
// Gets the DM token and stores it in |dm_token_|. This implementation is
// platform dependant.
// Gets the DM token and returns it. This implementation is platform
// dependant.
virtual std::string InitDMToken() = 0;
// Gets the boolean value that determines if error message will be displayed
// when enrollment fails.
......@@ -101,6 +109,7 @@ class BrowserDMTokenStorage {
bool is_initialized_;
std::string client_id_;
base::Optional<std::string> serial_number_;
std::string enrollment_token_;
std::string dm_token_;
bool should_display_error_message_on_failure_;
......
......@@ -60,6 +60,7 @@ class MockBrowserDMTokenStorage : public BrowserDMTokenStorage {
private:
std::string test_client_id_;
std::string test_serial_number_;
std::string test_enrollment_token_;
std::string test_dm_token_;
bool test_error_option_;
......
......@@ -951,6 +951,10 @@ message BrowserReport {
// Profile specific reports, one per profile.
repeated ChromeUserProfileReport chrome_user_profile_reports = 4;
// The device serial number (this might differ with the client ID, depending
// on the platform)
optional string serial_number = 5;
}
// Report the status of a Chrome installation on non-Chrome OS platform.
......
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