Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(187)

Unified Diff: chromeos/system/statistics_provider.cc

Issue 2371213002: Refactor: Inject StatisticsProvider as a dependency of DeviceCloudPolicyInitializer. (Closed)
Patch Set: Address Maksim's comments. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chromeos/system/statistics_provider.h ('k') | components/policy/core/common/cloud/cloud_policy_client.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/system/statistics_provider.cc
diff --git a/chromeos/system/statistics_provider.cc b/chromeos/system/statistics_provider.cc
index 15db2c36874de0a1acd8689f6e20312174aead28..c2352e6b23f26a22b210580aa0d1edc73ce5102c 100644
--- a/chromeos/system/statistics_provider.cc
+++ b/chromeos/system/statistics_provider.cc
@@ -81,6 +81,26 @@ const char kKeyboardsPath[] = "keyboards";
const char kLocalesPath[] = "locales";
const char kTimeZonesPath[] = "time_zones";
+// These are the machine serial number keys that we check in order until we
+// find a non-empty serial number. The VPD spec says the serial number should be
+// in the "serial_number" key for v2+ VPDs. However, legacy devices used a
+// different key to report their serial number, which we fall back to if
+// "serial_number" is not present.
+//
+// Product_S/N is still special-cased due to inconsistencies with serial
+// numbers on Lumpy devices: On these devices, serial_number is identical to
+// Product_S/N with an appended checksum. Unfortunately, the sticker on the
+// packaging doesn't include that checksum either (the sticker on the device
+// does though!). The former sticker is the source of the serial number used by
+// device management service, so we prefer Product_S/N over serial number to
+// match the server.
+const char* const kMachineInfoSerialNumberKeys[] = {
+ "Product_S/N", // Lumpy/Alex devices
+ kSerialNumberKey, // VPD v2+ devices
+ "Product_SN", // Mario
+ "sn", // old ZGB devices (more recent ones use serial_number)
+};
+
// Gets ListValue from given |dictionary| by given |key| and (unless |result| is
// nullptr) sets |result| to a string with all list values joined by ','.
// Returns true on success.
@@ -168,6 +188,7 @@ const char kWriteProtectSwitchBootKey[] = "wpsw_boot";
const char kWriteProtectSwitchBootValueOff[] = "0";
const char kWriteProtectSwitchBootValueOn[] = "1";
const char kRegionKey[] = "region";
+const char kSerialNumberKey[] = "serial_number";
const char kInitialLocaleKey[] = "initial_locale";
const char kInitialTimezoneKey[] = "initial_timezone";
const char kKeyboardLayoutKey[] = "keyboard_layout";
@@ -577,8 +598,14 @@ StatisticsProviderImpl* StatisticsProviderImpl::GetInstance() {
base::DefaultSingletonTraits<StatisticsProviderImpl>>::get();
}
-bool StatisticsProvider::HasMachineStatistic(const std::string& name) {
- return GetMachineStatistic(name, nullptr);
+std::string StatisticsProvider::GetEnterpriseMachineID() {
+ std::string machine_id;
+ for (const char* key : kMachineInfoSerialNumberKeys) {
+ if (GetMachineStatistic(key, &machine_id) && !machine_id.empty()) {
+ break;
+ }
+ }
+ return machine_id;
}
static StatisticsProvider* g_test_statistics_provider = NULL;
« no previous file with comments | « chromeos/system/statistics_provider.h ('k') | components/policy/core/common/cloud/cloud_policy_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698