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

Side by Side Diff: chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" 5 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 54
55 // Well-known requisition types. 55 // Well-known requisition types.
56 const char kNoRequisition[] = "none"; 56 const char kNoRequisition[] = "none";
57 const char kRemoraRequisition[] = "remora"; 57 const char kRemoraRequisition[] = "remora";
58 const char kSharkRequisition[] = "shark"; 58 const char kSharkRequisition[] = "shark";
59 const char kRialtoRequisition[] = "rialto"; 59 const char kRialtoRequisition[] = "rialto";
60 60
61 // Zero-touch enrollment flag values. 61 // Zero-touch enrollment flag values.
62 const char kZeroTouchEnrollmentForced[] = "forced"; 62 const char kZeroTouchEnrollmentForced[] = "forced";
63 63
64 // These are the machine serial number keys that we check in order until we
65 // find a non-empty serial number. The VPD spec says the serial number should be
66 // in the "serial_number" key for v2+ VPDs. However, legacy devices used a
67 // different key to report their serial number, which we fall back to if
68 // "serial_number" is not present.
69 //
70 // Product_S/N is still special-cased due to inconsistencies with serial
71 // numbers on Lumpy devices: On these devices, serial_number is identical to
72 // Product_S/N with an appended checksum. Unfortunately, the sticker on the
73 // packaging doesn't include that checksum either (the sticker on the device
74 // does though!). The former sticker is the source of the serial number used by
75 // device management service, so we prefer Product_S/N over serial number to
76 // match the server.
77 const char* const kMachineInfoSerialNumberKeys[] = {
78 "Product_S/N", // Lumpy/Alex devices
79 "serial_number", // VPD v2+ devices
80 "Product_SN", // Mario
81 "sn", // old ZGB devices (more recent ones use serial_number)
82 };
83
84 // Fetches a machine statistic value from StatisticsProvider, returns an empty 64 // Fetches a machine statistic value from StatisticsProvider, returns an empty
85 // string on failure. 65 // string on failure.
86 std::string GetMachineStatistic(const std::string& key) { 66 std::string GetMachineStatistic(const std::string& key) {
87 std::string value; 67 std::string value;
88 chromeos::system::StatisticsProvider* provider = 68 chromeos::system::StatisticsProvider* provider =
89 chromeos::system::StatisticsProvider::GetInstance(); 69 chromeos::system::StatisticsProvider::GetInstance();
90 if (!provider->GetMachineStatistic(key, &value)) 70 if (!provider->GetMachineStatistic(key, &value))
91 return std::string(); 71 return std::string();
92 72
93 return value; 73 return value;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 void DeviceCloudPolicyManagerChromeOS::RegisterPrefs( 193 void DeviceCloudPolicyManagerChromeOS::RegisterPrefs(
214 PrefRegistrySimple* registry) { 194 PrefRegistrySimple* registry) {
215 registry->RegisterStringPref(prefs::kDeviceEnrollmentRequisition, 195 registry->RegisterStringPref(prefs::kDeviceEnrollmentRequisition,
216 std::string()); 196 std::string());
217 registry->RegisterBooleanPref(prefs::kDeviceEnrollmentAutoStart, false); 197 registry->RegisterBooleanPref(prefs::kDeviceEnrollmentAutoStart, false);
218 registry->RegisterBooleanPref(prefs::kDeviceEnrollmentCanExit, true); 198 registry->RegisterBooleanPref(prefs::kDeviceEnrollmentCanExit, true);
219 registry->RegisterDictionaryPref(prefs::kServerBackedDeviceState); 199 registry->RegisterDictionaryPref(prefs::kServerBackedDeviceState);
220 } 200 }
221 201
222 // static 202 // static
223 std::string DeviceCloudPolicyManagerChromeOS::GetMachineID() {
224 std::string machine_id;
225 chromeos::system::StatisticsProvider* provider =
226 chromeos::system::StatisticsProvider::GetInstance();
227 for (size_t i = 0; i < arraysize(kMachineInfoSerialNumberKeys); i++) {
228 if (provider->HasMachineStatistic(kMachineInfoSerialNumberKeys[i]) &&
229 provider->GetMachineStatistic(kMachineInfoSerialNumberKeys[i],
230 &machine_id) &&
231 !machine_id.empty()) {
232 break;
233 }
234 }
235
236 if (machine_id.empty()) {
237 LOG(WARNING) << "Failed to get machine id. This is only an error if the "
238 "device has not yet been enrolled or claimed by a local "
239 "user.";
240 }
241
242 return machine_id;
243 }
244
245 // static
246 std::string DeviceCloudPolicyManagerChromeOS::GetMachineModel() {
247 return GetMachineStatistic(chromeos::system::kHardwareClassKey);
248 }
249
250 // static
251 ZeroTouchEnrollmentMode 203 ZeroTouchEnrollmentMode
252 DeviceCloudPolicyManagerChromeOS::GetZeroTouchEnrollmentMode() { 204 DeviceCloudPolicyManagerChromeOS::GetZeroTouchEnrollmentMode() {
253 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 205 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
254 if (!command_line->HasSwitch( 206 if (!command_line->HasSwitch(
255 chromeos::switches::kEnterpriseEnableZeroTouchEnrollment)) { 207 chromeos::switches::kEnterpriseEnableZeroTouchEnrollment)) {
256 return ZeroTouchEnrollmentMode::DISABLED; 208 return ZeroTouchEnrollmentMode::DISABLED;
257 } 209 }
258 210
259 std::string value = command_line->GetSwitchValueASCII( 211 std::string value = command_line->GetSwitchValueASCII(
260 chromeos::switches::kEnterpriseEnableZeroTouchEnrollment); 212 chromeos::switches::kEnterpriseEnableZeroTouchEnrollment);
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 client(), 330 client(),
379 base::MakeUnique<DeviceStatusCollector>( 331 base::MakeUnique<DeviceStatusCollector>(
380 local_state_, chromeos::system::StatisticsProvider::GetInstance(), 332 local_state_, chromeos::system::StatisticsProvider::GetInstance(),
381 DeviceStatusCollector::VolumeInfoFetcher(), 333 DeviceStatusCollector::VolumeInfoFetcher(),
382 DeviceStatusCollector::CPUStatisticsFetcher(), 334 DeviceStatusCollector::CPUStatisticsFetcher(),
383 DeviceStatusCollector::CPUTempFetcher()), 335 DeviceStatusCollector::CPUTempFetcher()),
384 task_runner_)); 336 task_runner_));
385 } 337 }
386 338
387 } // namespace policy 339 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698