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

Side by Side Diff: chrome/browser/chromeos/policy/device_cloud_policy_initializer.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_initializer.h" 5 #include "chrome/browser/chromeos/policy/device_cloud_policy_initializer.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 21 matching lines...) Expand all
32 #include "chromeos/cryptohome/cryptohome_parameters.h" 32 #include "chromeos/cryptohome/cryptohome_parameters.h"
33 #include "chromeos/dbus/dbus_thread_manager.h" 33 #include "chromeos/dbus/dbus_thread_manager.h"
34 #include "chromeos/system/statistics_provider.h" 34 #include "chromeos/system/statistics_provider.h"
35 #include "components/policy/core/common/cloud/cloud_policy_core.h" 35 #include "components/policy/core/common/cloud/cloud_policy_core.h"
36 #include "components/policy/core/common/cloud/device_management_service.h" 36 #include "components/policy/core/common/cloud/device_management_service.h"
37 #include "components/prefs/pref_service.h" 37 #include "components/prefs/pref_service.h"
38 #include "net/url_request/url_request_context_getter.h" 38 #include "net/url_request/url_request_context_getter.h"
39 39
40 namespace policy { 40 namespace policy {
41 41
42 namespace {
43
44 // Gets a machine flag from StatisticsProvider, returning the given
45 // |default_value| if not present.
46 bool GetMachineFlag(const std::string& key, bool default_value) {
47 bool value = default_value;
48 chromeos::system::StatisticsProvider* provider =
49 chromeos::system::StatisticsProvider::GetInstance();
50 if (!provider->GetMachineFlag(key, &value))
51 return default_value;
52
53 return value;
54 }
55
56 } // namespace
57
58 DeviceCloudPolicyInitializer::DeviceCloudPolicyInitializer( 42 DeviceCloudPolicyInitializer::DeviceCloudPolicyInitializer(
59 PrefService* local_state, 43 PrefService* local_state,
60 DeviceManagementService* enterprise_service, 44 DeviceManagementService* enterprise_service,
61 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner, 45 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner,
62 chromeos::InstallAttributes* install_attributes, 46 chromeos::InstallAttributes* install_attributes,
63 ServerBackedStateKeysBroker* state_keys_broker, 47 ServerBackedStateKeysBroker* state_keys_broker,
64 DeviceCloudPolicyStoreChromeOS* device_store, 48 DeviceCloudPolicyStoreChromeOS* device_store,
65 DeviceCloudPolicyManagerChromeOS* manager, 49 DeviceCloudPolicyManagerChromeOS* manager,
66 cryptohome::AsyncMethodCaller* async_method_caller, 50 cryptohome::AsyncMethodCaller* async_method_caller,
67 std::unique_ptr<chromeos::attestation::AttestationFlow> attestation_flow) 51 std::unique_ptr<chromeos::attestation::AttestationFlow> attestation_flow,
52 chromeos::system::StatisticsProvider* statistics_provider)
68 : local_state_(local_state), 53 : local_state_(local_state),
69 enterprise_service_(enterprise_service), 54 enterprise_service_(enterprise_service),
70 background_task_runner_(background_task_runner), 55 background_task_runner_(background_task_runner),
71 install_attributes_(install_attributes), 56 install_attributes_(install_attributes),
72 state_keys_broker_(state_keys_broker), 57 state_keys_broker_(state_keys_broker),
73 device_store_(device_store), 58 device_store_(device_store),
74 manager_(manager), 59 manager_(manager),
75 attestation_flow_(std::move(attestation_flow)), 60 attestation_flow_(std::move(attestation_flow)),
61 statistics_provider_(statistics_provider),
76 signing_service_(base::MakeUnique<TpmEnrollmentKeySigningService>( 62 signing_service_(base::MakeUnique<TpmEnrollmentKeySigningService>(
77 async_method_caller)) {} 63 async_method_caller)) {}
78 64
79 void DeviceCloudPolicyInitializer::SetSigningServiceForTesting( 65 void DeviceCloudPolicyInitializer::SetSigningServiceForTesting(
80 std::unique_ptr<policy::SigningService> signing_service) { 66 std::unique_ptr<policy::SigningService> signing_service) {
81 signing_service_ = std::move(signing_service); 67 signing_service_ = std::move(signing_service);
82 } 68 }
83 69
84 DeviceCloudPolicyInitializer::~DeviceCloudPolicyInitializer() { 70 DeviceCloudPolicyInitializer::~DeviceCloudPolicyInitializer() {
85 DCHECK(!is_initialized_); 71 DCHECK(!is_initialized_);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 // If OOBE is done and we are enrolled, check for need to recover enrollment. 144 // If OOBE is done and we are enrolled, check for need to recover enrollment.
159 if (oobe_complete && install_attributes_->IsEnterpriseDevice()) { 145 if (oobe_complete && install_attributes_->IsEnterpriseDevice()) {
160 // Regardless what mode is applicable, the enrollment domain is fixed. 146 // Regardless what mode is applicable, the enrollment domain is fixed.
161 config.management_domain = install_attributes_->GetDomain(); 147 config.management_domain = install_attributes_->GetDomain();
162 148
163 // Enrollment has completed previously and installation-time attributes 149 // Enrollment has completed previously and installation-time attributes
164 // are in place. Enrollment recovery is required when the server 150 // are in place. Enrollment recovery is required when the server
165 // registration gets lost. 151 // registration gets lost.
166 if (local_state_->GetBoolean(prefs::kEnrollmentRecoveryRequired)) { 152 if (local_state_->GetBoolean(prefs::kEnrollmentRecoveryRequired)) {
167 LOG(WARNING) << "Enrollment recovery required according to pref."; 153 LOG(WARNING) << "Enrollment recovery required according to pref.";
168 if (DeviceCloudPolicyManagerChromeOS::GetMachineID().empty()) 154 if (statistics_provider_->GetEnterpriseMachineID().empty())
169 LOG(WARNING) << "Postponing recovery because machine id is missing."; 155 LOG(WARNING) << "Postponing recovery because machine id is missing.";
170 else 156 else
171 config.mode = EnrollmentConfig::MODE_RECOVERY; 157 config.mode = EnrollmentConfig::MODE_RECOVERY;
172 } 158 }
173 159
174 return config; 160 return config;
175 } 161 }
176 162
177 // OOBE is still running, or it is complete but the device hasn't been 163 // OOBE is still running, or it is complete but the device hasn't been
178 // enrolled yet. In either case, enrollment should take place if there's a 164 // enrolled yet. In either case, enrollment should take place if there's a
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 // was in progress. We give it a try again. 242 // was in progress. We give it a try again.
257 TryToCreateClient(); 243 TryToCreateClient();
258 } 244 }
259 245
260 if (!enrollment_callback.is_null()) 246 if (!enrollment_callback.is_null())
261 enrollment_callback.Run(status); 247 enrollment_callback.Run(status);
262 } 248 }
263 249
264 std::unique_ptr<CloudPolicyClient> DeviceCloudPolicyInitializer::CreateClient( 250 std::unique_ptr<CloudPolicyClient> DeviceCloudPolicyInitializer::CreateClient(
265 DeviceManagementService* device_management_service) { 251 DeviceManagementService* device_management_service) {
252 std::string machine_model;
253 statistics_provider_->GetMachineStatistic(chromeos::system::kHardwareClassKey,
254 &machine_model);
266 return base::MakeUnique<CloudPolicyClient>( 255 return base::MakeUnique<CloudPolicyClient>(
267 DeviceCloudPolicyManagerChromeOS::GetMachineID(), 256 statistics_provider_->GetEnterpriseMachineID(), machine_model,
268 DeviceCloudPolicyManagerChromeOS::GetMachineModel(),
269 kPolicyVerificationKeyHash, device_management_service, 257 kPolicyVerificationKeyHash, device_management_service,
270 g_browser_process->system_request_context(), signing_service_.get()); 258 g_browser_process->system_request_context(), signing_service_.get());
271 } 259 }
272 260
273 void DeviceCloudPolicyInitializer::TryToCreateClient() { 261 void DeviceCloudPolicyInitializer::TryToCreateClient() {
274 if (!device_store_->is_initialized() || 262 if (!device_store_->is_initialized() ||
275 !device_store_->has_policy() || 263 !device_store_->has_policy() ||
276 state_keys_broker_->pending() || 264 state_keys_broker_->pending() ||
277 enrollment_handler_) { 265 enrollment_handler_) {
278 return; 266 return;
279 } 267 }
280 StartConnection(CreateClient(enterprise_service_)); 268 StartConnection(CreateClient(enterprise_service_));
281 } 269 }
282 270
283 void DeviceCloudPolicyInitializer::StartConnection( 271 void DeviceCloudPolicyInitializer::StartConnection(
284 std::unique_ptr<CloudPolicyClient> client) { 272 std::unique_ptr<CloudPolicyClient> client) {
285 if (!manager_->core()->service()) 273 if (!manager_->core()->service())
286 manager_->StartConnection(std::move(client), install_attributes_); 274 manager_->StartConnection(std::move(client), install_attributes_);
287 } 275 }
288 276
277 bool DeviceCloudPolicyInitializer::GetMachineFlag(const std::string& key,
278 bool default_value) const {
279 bool value = default_value;
280 if (!statistics_provider_->GetMachineFlag(key, &value))
281 return default_value;
282
283 return value;
284 }
285
289 DeviceCloudPolicyInitializer::TpmEnrollmentKeySigningService:: 286 DeviceCloudPolicyInitializer::TpmEnrollmentKeySigningService::
290 TpmEnrollmentKeySigningService( 287 TpmEnrollmentKeySigningService(
291 cryptohome::AsyncMethodCaller* async_method_caller) 288 cryptohome::AsyncMethodCaller* async_method_caller)
292 : async_method_caller_(async_method_caller), weak_ptr_factory_(this) {} 289 : async_method_caller_(async_method_caller), weak_ptr_factory_(this) {}
293 290
294 DeviceCloudPolicyInitializer::TpmEnrollmentKeySigningService:: 291 DeviceCloudPolicyInitializer::TpmEnrollmentKeySigningService::
295 ~TpmEnrollmentKeySigningService() {} 292 ~TpmEnrollmentKeySigningService() {}
296 293
297 void DeviceCloudPolicyInitializer::TpmEnrollmentKeySigningService::SignData( 294 void DeviceCloudPolicyInitializer::TpmEnrollmentKeySigningService::SignData(
298 const std::string& data, 295 const std::string& data,
(...skipping 22 matching lines...) Expand all
321 if (success && (success = att_signed_data.ParseFromString(signed_data))) { 318 if (success && (success = att_signed_data.ParseFromString(signed_data))) {
322 em_signed_data.set_data(att_signed_data.data()); 319 em_signed_data.set_data(att_signed_data.data());
323 em_signed_data.set_signature(att_signed_data.signature()); 320 em_signed_data.set_signature(att_signed_data.signature());
324 em_signed_data.set_extra_data_bytes(att_signed_data.data().size() - 321 em_signed_data.set_extra_data_bytes(att_signed_data.data().size() -
325 data.size()); 322 data.size());
326 } 323 }
327 callback.Run(success, em_signed_data); 324 callback.Run(success, em_signed_data);
328 } 325 }
329 326
330 } // namespace policy 327 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698