Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chromeos/system/statistics_provider.h" | 5 #include "chromeos/system/statistics_provider.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 | 74 |
| 75 // The location of OEM manifest file used to trigger OOBE flow for kiosk mode. | 75 // The location of OEM manifest file used to trigger OOBE flow for kiosk mode. |
| 76 const base::CommandLine::CharType kOemManifestFilePath[] = | 76 const base::CommandLine::CharType kOemManifestFilePath[] = |
| 77 FILE_PATH_LITERAL("/usr/share/oem/oobe/manifest.json"); | 77 FILE_PATH_LITERAL("/usr/share/oem/oobe/manifest.json"); |
| 78 | 78 |
| 79 // Items in region dictionary. | 79 // Items in region dictionary. |
| 80 const char kKeyboardsPath[] = "keyboards"; | 80 const char kKeyboardsPath[] = "keyboards"; |
| 81 const char kLocalesPath[] = "locales"; | 81 const char kLocalesPath[] = "locales"; |
| 82 const char kTimeZonesPath[] = "time_zones"; | 82 const char kTimeZonesPath[] = "time_zones"; |
| 83 | 83 |
| 84 // These are the machine serial number keys that we check in order until we | |
| 85 // find a non-empty serial number. The VPD spec says the serial number should be | |
| 86 // in the "serial_number" key for v2+ VPDs. However, legacy devices used a | |
| 87 // different key to report their serial number, which we fall back to if | |
| 88 // "serial_number" is not present. | |
| 89 // | |
| 90 // Product_S/N is still special-cased due to inconsistencies with serial | |
| 91 // numbers on Lumpy devices: On these devices, serial_number is identical to | |
| 92 // Product_S/N with an appended checksum. Unfortunately, the sticker on the | |
| 93 // packaging doesn't include that checksum either (the sticker on the device | |
| 94 // does though!). The former sticker is the source of the serial number used by | |
| 95 // device management service, so we prefer Product_S/N over serial number to | |
| 96 // match the server. | |
| 97 const char* const kMachineInfoSerialNumberKeys[] = { | |
| 98 "Product_S/N", // Lumpy/Alex devices | |
|
Mattias Nissler (ping if slow)
2016/09/30 12:01:55
Note that the Product_S/N preference is a kludge t
Thiemo Nagel
2016/09/30 13:03:00
Actually I pulled it out of policy because its bei
Mattias Nissler (ping if slow)
2016/09/30 13:16:44
VersionInfoUpdater is specifically for enterprise
Thiemo Nagel
2016/09/30 13:22:10
It looks like I'm missing something here. My read
Mattias Nissler (ping if slow)
2016/09/30 13:30:25
The "correct" implementation of this would be to k
Thiemo Nagel
2016/09/30 16:13:11
Thanks a lot. I had to read your review comment a
| |
| 99 kSerialNumberKey, // VPD v2+ devices | |
| 100 "Product_SN", // Mario | |
| 101 "sn", // old ZGB devices (more recent ones use serial_number) | |
| 102 }; | |
| 103 | |
| 84 // Gets ListValue from given |dictionary| by given |key| and (unless |result| is | 104 // Gets ListValue from given |dictionary| by given |key| and (unless |result| is |
| 85 // nullptr) sets |result| to a string with all list values joined by ','. | 105 // nullptr) sets |result| to a string with all list values joined by ','. |
| 86 // Returns true on success. | 106 // Returns true on success. |
| 87 bool JoinListValuesToString(const base::DictionaryValue* dictionary, | 107 bool JoinListValuesToString(const base::DictionaryValue* dictionary, |
| 88 const std::string key, | 108 const std::string key, |
| 89 std::string* result) { | 109 std::string* result) { |
| 90 const base::ListValue* list = nullptr; | 110 const base::ListValue* list = nullptr; |
| 91 if (!dictionary->GetListWithoutPathExpansion(key, &list)) | 111 if (!dictionary->GetListWithoutPathExpansion(key, &list)) |
| 92 return false; | 112 return false; |
| 93 | 113 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 const char kIsVmKey[] = "is_vm"; | 181 const char kIsVmKey[] = "is_vm"; |
| 162 const char kIsVmValueTrue[] = "1"; | 182 const char kIsVmValueTrue[] = "1"; |
| 163 const char kIsVmValueFalse[] = "0"; | 183 const char kIsVmValueFalse[] = "0"; |
| 164 const char kOffersCouponCodeKey[] = "ubind_attribute"; | 184 const char kOffersCouponCodeKey[] = "ubind_attribute"; |
| 165 const char kOffersGroupCodeKey[] = "gbind_attribute"; | 185 const char kOffersGroupCodeKey[] = "gbind_attribute"; |
| 166 const char kRlzBrandCodeKey[] = "rlz_brand_code"; | 186 const char kRlzBrandCodeKey[] = "rlz_brand_code"; |
| 167 const char kWriteProtectSwitchBootKey[] = "wpsw_boot"; | 187 const char kWriteProtectSwitchBootKey[] = "wpsw_boot"; |
| 168 const char kWriteProtectSwitchBootValueOff[] = "0"; | 188 const char kWriteProtectSwitchBootValueOff[] = "0"; |
| 169 const char kWriteProtectSwitchBootValueOn[] = "1"; | 189 const char kWriteProtectSwitchBootValueOn[] = "1"; |
| 170 const char kRegionKey[] = "region"; | 190 const char kRegionKey[] = "region"; |
| 191 const char kSerialNumberKey[] = "serial_number"; | |
| 171 const char kInitialLocaleKey[] = "initial_locale"; | 192 const char kInitialLocaleKey[] = "initial_locale"; |
| 172 const char kInitialTimezoneKey[] = "initial_timezone"; | 193 const char kInitialTimezoneKey[] = "initial_timezone"; |
| 173 const char kKeyboardLayoutKey[] = "keyboard_layout"; | 194 const char kKeyboardLayoutKey[] = "keyboard_layout"; |
| 174 | 195 |
| 175 // OEM specific statistics. Must be prefixed with "oem_". | 196 // OEM specific statistics. Must be prefixed with "oem_". |
| 176 const char kOemCanExitEnterpriseEnrollmentKey[] = "oem_can_exit_enrollment"; | 197 const char kOemCanExitEnterpriseEnrollmentKey[] = "oem_can_exit_enrollment"; |
| 177 const char kOemDeviceRequisitionKey[] = "oem_device_requisition"; | 198 const char kOemDeviceRequisitionKey[] = "oem_device_requisition"; |
| 178 const char kOemIsEnterpriseManagedKey[] = "oem_enterprise_managed"; | 199 const char kOemIsEnterpriseManagedKey[] = "oem_enterprise_managed"; |
| 179 const char kOemKeyboardDrivenOobeKey[] = "oem_keyboard_driven_oobe"; | 200 const char kOemKeyboardDrivenOobeKey[] = "oem_keyboard_driven_oobe"; |
| 180 | 201 |
| 181 bool HasOemPrefix(const std::string& name) { | 202 bool HasOemPrefix(const std::string& name) { |
| 182 return name.substr(0, 4) == "oem_"; | 203 return name.substr(0, 4) == "oem_"; |
| 183 } | 204 } |
| 184 | 205 |
| 206 std::string StatisticsProvider::GetMachineID() { | |
| 207 std::string machine_id; | |
| 208 for (size_t i = 0; i < arraysize(kMachineInfoSerialNumberKeys); i++) { | |
|
emaxx
2016/09/30 16:17:59
nit: Use range-based for loop?
Thiemo Nagel
2016/09/30 16:57:58
Great idea! I never knew that was even possible..
| |
| 209 if (GetMachineStatistic(kMachineInfoSerialNumberKeys[i], &machine_id) && | |
| 210 !machine_id.empty()) { | |
| 211 break; | |
| 212 } | |
| 213 } | |
| 214 return machine_id; | |
| 215 } | |
| 216 | |
| 185 // The StatisticsProvider implementation used in production. | 217 // The StatisticsProvider implementation used in production. |
| 186 class StatisticsProviderImpl : public StatisticsProvider { | 218 class StatisticsProviderImpl : public StatisticsProvider { |
| 187 public: | 219 public: |
| 188 // StatisticsProvider implementation: | 220 // StatisticsProvider implementation: |
| 189 void StartLoadingMachineStatistics( | 221 void StartLoadingMachineStatistics( |
| 190 const scoped_refptr<base::TaskRunner>& file_task_runner, | 222 const scoped_refptr<base::TaskRunner>& file_task_runner, |
| 191 bool load_oem_manifest) override; | 223 bool load_oem_manifest) override; |
| 192 bool GetMachineStatistic(const std::string& name, | 224 bool GetMachineStatistic(const std::string& name, |
| 193 std::string* result) override; | 225 std::string* result) override; |
| 194 bool GetMachineFlag(const std::string& name, bool* result) override; | 226 bool GetMachineFlag(const std::string& name, bool* result) override; |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 570 oem_manifest_loaded_ = true; | 602 oem_manifest_loaded_ = true; |
| 571 VLOG(1) << "Loaded OEM Manifest statistics from " << file.value(); | 603 VLOG(1) << "Loaded OEM Manifest statistics from " << file.value(); |
| 572 } | 604 } |
| 573 | 605 |
| 574 StatisticsProviderImpl* StatisticsProviderImpl::GetInstance() { | 606 StatisticsProviderImpl* StatisticsProviderImpl::GetInstance() { |
| 575 return base::Singleton< | 607 return base::Singleton< |
| 576 StatisticsProviderImpl, | 608 StatisticsProviderImpl, |
| 577 base::DefaultSingletonTraits<StatisticsProviderImpl>>::get(); | 609 base::DefaultSingletonTraits<StatisticsProviderImpl>>::get(); |
| 578 } | 610 } |
| 579 | 611 |
| 580 bool StatisticsProvider::HasMachineStatistic(const std::string& name) { | |
| 581 return GetMachineStatistic(name, nullptr); | |
| 582 } | |
| 583 | |
| 584 static StatisticsProvider* g_test_statistics_provider = NULL; | 612 static StatisticsProvider* g_test_statistics_provider = NULL; |
| 585 | 613 |
| 586 // static | 614 // static |
| 587 StatisticsProvider* StatisticsProvider::GetInstance() { | 615 StatisticsProvider* StatisticsProvider::GetInstance() { |
| 588 if (g_test_statistics_provider) | 616 if (g_test_statistics_provider) |
| 589 return g_test_statistics_provider; | 617 return g_test_statistics_provider; |
| 590 return StatisticsProviderImpl::GetInstance(); | 618 return StatisticsProviderImpl::GetInstance(); |
| 591 } | 619 } |
| 592 | 620 |
| 593 // static | 621 // static |
| 594 void StatisticsProvider::SetTestProvider(StatisticsProvider* test_provider) { | 622 void StatisticsProvider::SetTestProvider(StatisticsProvider* test_provider) { |
| 595 g_test_statistics_provider = test_provider; | 623 g_test_statistics_provider = test_provider; |
| 596 } | 624 } |
| 597 | 625 |
| 598 } // namespace system | 626 } // namespace system |
| 599 } // namespace chromeos | 627 } // namespace chromeos |
| OLD | NEW |