| OLD | NEW |
| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 return default_value; | 45 return default_value; |
| 46 | 46 |
| 47 return value; | 47 return value; |
| 48 } | 48 } |
| 49 | 49 |
| 50 } // namespace | 50 } // namespace |
| 51 | 51 |
| 52 DeviceCloudPolicyInitializer::DeviceCloudPolicyInitializer( | 52 DeviceCloudPolicyInitializer::DeviceCloudPolicyInitializer( |
| 53 PrefService* local_state, | 53 PrefService* local_state, |
| 54 DeviceManagementService* enterprise_service, | 54 DeviceManagementService* enterprise_service, |
| 55 DeviceManagementService* consumer_service, | |
| 56 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner, | 55 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner, |
| 57 EnterpriseInstallAttributes* install_attributes, | 56 EnterpriseInstallAttributes* install_attributes, |
| 58 ServerBackedStateKeysBroker* state_keys_broker, | 57 ServerBackedStateKeysBroker* state_keys_broker, |
| 59 DeviceCloudPolicyStoreChromeOS* device_store, | 58 DeviceCloudPolicyStoreChromeOS* device_store, |
| 60 DeviceCloudPolicyManagerChromeOS* manager) | 59 DeviceCloudPolicyManagerChromeOS* manager) |
| 61 : local_state_(local_state), | 60 : local_state_(local_state), |
| 62 enterprise_service_(enterprise_service), | 61 enterprise_service_(enterprise_service), |
| 63 consumer_service_(consumer_service), | |
| 64 background_task_runner_(background_task_runner), | 62 background_task_runner_(background_task_runner), |
| 65 install_attributes_(install_attributes), | 63 install_attributes_(install_attributes), |
| 66 state_keys_broker_(state_keys_broker), | 64 state_keys_broker_(state_keys_broker), |
| 67 device_store_(device_store), | 65 device_store_(device_store), |
| 68 manager_(manager), | 66 manager_(manager), |
| 69 is_initialized_(false) { | 67 is_initialized_(false) { |
| 70 } | 68 } |
| 71 | 69 |
| 72 DeviceCloudPolicyInitializer::~DeviceCloudPolicyInitializer() { | 70 DeviceCloudPolicyInitializer::~DeviceCloudPolicyInitializer() { |
| 73 DCHECK(!is_initialized_); | 71 DCHECK(!is_initialized_); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 88 void DeviceCloudPolicyInitializer::Shutdown() { | 86 void DeviceCloudPolicyInitializer::Shutdown() { |
| 89 DCHECK(is_initialized_); | 87 DCHECK(is_initialized_); |
| 90 | 88 |
| 91 device_store_->RemoveObserver(this); | 89 device_store_->RemoveObserver(this); |
| 92 enrollment_handler_.reset(); | 90 enrollment_handler_.reset(); |
| 93 state_keys_update_subscription_.reset(); | 91 state_keys_update_subscription_.reset(); |
| 94 is_initialized_ = false; | 92 is_initialized_ = false; |
| 95 } | 93 } |
| 96 | 94 |
| 97 void DeviceCloudPolicyInitializer::StartEnrollment( | 95 void DeviceCloudPolicyInitializer::StartEnrollment( |
| 98 ManagementMode management_mode, | |
| 99 DeviceManagementService* device_management_service, | 96 DeviceManagementService* device_management_service, |
| 100 chromeos::OwnerSettingsServiceChromeOS* owner_settings_service, | |
| 101 const EnrollmentConfig& enrollment_config, | 97 const EnrollmentConfig& enrollment_config, |
| 102 const std::string& auth_token, | 98 const std::string& auth_token, |
| 103 const AllowedDeviceModes& allowed_device_modes, | 99 const AllowedDeviceModes& allowed_device_modes, |
| 104 const EnrollmentCallback& enrollment_callback) { | 100 const EnrollmentCallback& enrollment_callback) { |
| 105 DCHECK(is_initialized_); | 101 DCHECK(is_initialized_); |
| 106 DCHECK(!enrollment_handler_); | 102 DCHECK(!enrollment_handler_); |
| 107 | 103 |
| 108 manager_->core()->Disconnect(); | 104 manager_->core()->Disconnect(); |
| 109 enrollment_handler_.reset(new EnrollmentHandlerChromeOS( | 105 enrollment_handler_.reset(new EnrollmentHandlerChromeOS( |
| 110 device_store_, install_attributes_, state_keys_broker_, | 106 device_store_, install_attributes_, state_keys_broker_, |
| 111 owner_settings_service, CreateClient(device_management_service), | 107 CreateClient(device_management_service), background_task_runner_, |
| 112 background_task_runner_, enrollment_config, auth_token, | 108 enrollment_config, auth_token, install_attributes_->GetDeviceId(), |
| 113 install_attributes_->GetDeviceId(), manager_->GetDeviceRequisition(), | 109 manager_->GetDeviceRequisition(), allowed_device_modes, |
| 114 allowed_device_modes, management_mode, | |
| 115 base::Bind(&DeviceCloudPolicyInitializer::EnrollmentCompleted, | 110 base::Bind(&DeviceCloudPolicyInitializer::EnrollmentCompleted, |
| 116 base::Unretained(this), enrollment_callback))); | 111 base::Unretained(this), enrollment_callback))); |
| 117 enrollment_handler_->StartEnrollment(); | 112 enrollment_handler_->StartEnrollment(); |
| 118 } | 113 } |
| 119 | 114 |
| 120 EnrollmentConfig DeviceCloudPolicyInitializer::GetPrescribedEnrollmentConfig() | 115 EnrollmentConfig DeviceCloudPolicyInitializer::GetPrescribedEnrollmentConfig() |
| 121 const { | 116 const { |
| 122 EnrollmentConfig config; | 117 EnrollmentConfig config; |
| 123 | 118 |
| 124 // Authentication through the attestation mechanism is controlled by a | 119 // Authentication through the attestation mechanism is controlled by a |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 g_browser_process->system_request_context())); | 251 g_browser_process->system_request_context())); |
| 257 } | 252 } |
| 258 | 253 |
| 259 void DeviceCloudPolicyInitializer::TryToCreateClient() { | 254 void DeviceCloudPolicyInitializer::TryToCreateClient() { |
| 260 if (!device_store_->is_initialized() || | 255 if (!device_store_->is_initialized() || |
| 261 !device_store_->has_policy() || | 256 !device_store_->has_policy() || |
| 262 state_keys_broker_->pending() || | 257 state_keys_broker_->pending() || |
| 263 enrollment_handler_) { | 258 enrollment_handler_) { |
| 264 return; | 259 return; |
| 265 } | 260 } |
| 266 | 261 StartConnection(CreateClient(enterprise_service_)); |
| 267 DeviceManagementService* service = nullptr; | |
| 268 if (GetManagementMode(*device_store_->policy()) == | |
| 269 MANAGEMENT_MODE_CONSUMER_MANAGED) { | |
| 270 service = consumer_service_; | |
| 271 } else if (GetManagementMode(*device_store_->policy()) == | |
| 272 MANAGEMENT_MODE_ENTERPRISE_MANAGED) { | |
| 273 service = enterprise_service_; | |
| 274 } | |
| 275 | |
| 276 if (service) | |
| 277 StartConnection(CreateClient(service)); | |
| 278 } | 262 } |
| 279 | 263 |
| 280 void DeviceCloudPolicyInitializer::StartConnection( | 264 void DeviceCloudPolicyInitializer::StartConnection( |
| 281 std::unique_ptr<CloudPolicyClient> client) { | 265 std::unique_ptr<CloudPolicyClient> client) { |
| 282 if (!manager_->core()->service()) | 266 if (!manager_->core()->service()) |
| 283 manager_->StartConnection(std::move(client), install_attributes_); | 267 manager_->StartConnection(std::move(client), install_attributes_); |
| 284 } | 268 } |
| 285 | 269 |
| 286 } // namespace policy | 270 } // namespace policy |
| OLD | NEW |