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

Side by Side 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, 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
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 oem_manifest_loaded_ = true; 591 oem_manifest_loaded_ = true;
571 VLOG(1) << "Loaded OEM Manifest statistics from " << file.value(); 592 VLOG(1) << "Loaded OEM Manifest statistics from " << file.value();
572 } 593 }
573 594
574 StatisticsProviderImpl* StatisticsProviderImpl::GetInstance() { 595 StatisticsProviderImpl* StatisticsProviderImpl::GetInstance() {
575 return base::Singleton< 596 return base::Singleton<
576 StatisticsProviderImpl, 597 StatisticsProviderImpl,
577 base::DefaultSingletonTraits<StatisticsProviderImpl>>::get(); 598 base::DefaultSingletonTraits<StatisticsProviderImpl>>::get();
578 } 599 }
579 600
580 bool StatisticsProvider::HasMachineStatistic(const std::string& name) { 601 std::string StatisticsProvider::GetEnterpriseMachineID() {
581 return GetMachineStatistic(name, nullptr); 602 std::string machine_id;
603 for (const char* key : kMachineInfoSerialNumberKeys) {
604 if (GetMachineStatistic(key, &machine_id) && !machine_id.empty()) {
605 break;
606 }
607 }
608 return machine_id;
582 } 609 }
583 610
584 static StatisticsProvider* g_test_statistics_provider = NULL; 611 static StatisticsProvider* g_test_statistics_provider = NULL;
585 612
586 // static 613 // static
587 StatisticsProvider* StatisticsProvider::GetInstance() { 614 StatisticsProvider* StatisticsProvider::GetInstance() {
588 if (g_test_statistics_provider) 615 if (g_test_statistics_provider)
589 return g_test_statistics_provider; 616 return g_test_statistics_provider;
590 return StatisticsProviderImpl::GetInstance(); 617 return StatisticsProviderImpl::GetInstance();
591 } 618 }
592 619
593 // static 620 // static
594 void StatisticsProvider::SetTestProvider(StatisticsProvider* test_provider) { 621 void StatisticsProvider::SetTestProvider(StatisticsProvider* test_provider) {
595 g_test_statistics_provider = test_provider; 622 g_test_statistics_provider = test_provider;
596 } 623 }
597 624
598 } // namespace system 625 } // namespace system
599 } // namespace chromeos 626 } // 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