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

Side by Side Diff: chromeos/system/statistics_provider.cc

Issue 2371213002: Refactor: Inject StatisticsProvider as a dependency of DeviceCloudPolicyInitializer. (Closed)
Patch Set: Rebase. Created 4 years, 2 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 unified diff | Download patch
OLDNEW
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
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
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
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::GetEnterpriseMachineID() {
emaxx 2016/09/30 16:17:59 nit: Move the method definition down just before o
Thiemo Nagel 2016/09/30 16:57:59 Done.
207 std::string machine_id;
208 for (size_t i = 0; i < arraysize(kMachineInfoSerialNumberKeys); i++) {
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
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
OLDNEW
« 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