| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 void DeviceCloudPolicyInitializer::StartEnrollment( | 93 void DeviceCloudPolicyInitializer::StartEnrollment( |
| 94 DeviceManagementService* device_management_service, | 94 DeviceManagementService* device_management_service, |
| 95 const std::string& auth_token, | 95 const std::string& auth_token, |
| 96 bool is_auto_enrollment, | 96 bool is_auto_enrollment, |
| 97 const AllowedDeviceModes& allowed_device_modes, | 97 const AllowedDeviceModes& allowed_device_modes, |
| 98 const EnrollmentCallback& enrollment_callback) { | 98 const EnrollmentCallback& enrollment_callback) { |
| 99 CHECK(!enrollment_handler_); | 99 CHECK(!enrollment_handler_); |
| 100 | 100 |
| 101 manager_->core()->Disconnect(); | 101 manager_->core()->Disconnect(); |
| 102 enrollment_handler_.reset(new EnrollmentHandlerChromeOS( | 102 enrollment_handler_.reset(new EnrollmentHandlerChromeOS( |
| 103 local_state_, |
| 103 device_store_, | 104 device_store_, |
| 104 install_attributes_, | 105 install_attributes_, |
| 105 state_keys_broker_, | 106 state_keys_broker_, |
| 106 CreateClient(device_management_service), | 107 CreateClient(device_management_service), |
| 107 background_task_runner_, | 108 background_task_runner_, |
| 108 auth_token, | 109 auth_token, |
| 109 install_attributes_->GetDeviceId(), | 110 install_attributes_->GetDeviceId(), |
| 110 is_auto_enrollment, | 111 is_auto_enrollment, |
| 111 manager_->GetDeviceRequisition(), | |
| 112 allowed_device_modes, | 112 allowed_device_modes, |
| 113 base::Bind(&DeviceCloudPolicyInitializer::EnrollmentCompleted, | 113 base::Bind(&DeviceCloudPolicyInitializer::EnrollmentCompleted, |
| 114 base::Unretained(this), | 114 base::Unretained(this), |
| 115 enrollment_callback))); | 115 enrollment_callback))); |
| 116 enrollment_handler_->StartEnrollment(); | 116 enrollment_handler_->StartEnrollment(); |
| 117 } | 117 } |
| 118 | 118 |
| 119 bool DeviceCloudPolicyInitializer::ShouldAutoStartEnrollment() const { | 119 bool DeviceCloudPolicyInitializer::ShouldAutoStartEnrollment() const { |
| 120 std::string restore_mode = GetRestoreMode(); | 120 std::string restore_mode = GetRestoreMode(); |
| 121 if (restore_mode == kDeviceStateRestoreModeReEnrollmentRequested || | 121 if (restore_mode == kDeviceStateRestoreModeReEnrollmentRequested || |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 } else { | 220 } else { |
| 221 service = enterprise_service_; | 221 service = enterprise_service_; |
| 222 } | 222 } |
| 223 StartConnection(CreateClient(service)); | 223 StartConnection(CreateClient(service)); |
| 224 } | 224 } |
| 225 } | 225 } |
| 226 | 226 |
| 227 void DeviceCloudPolicyInitializer::StartConnection( | 227 void DeviceCloudPolicyInitializer::StartConnection( |
| 228 scoped_ptr<CloudPolicyClient> client) { | 228 scoped_ptr<CloudPolicyClient> client) { |
| 229 if (!manager_->core()->service()) | 229 if (!manager_->core()->service()) |
| 230 manager_->StartConnection(client.Pass(), device_status_provider_.Pass()); | 230 manager_->StartConnection(client.Pass(), |
| 231 device_status_provider_.Pass(), |
| 232 local_state_); |
| 231 | 233 |
| 232 if (!on_connected_callback_.is_null()) { | 234 if (!on_connected_callback_.is_null()) { |
| 233 on_connected_callback_.Run(); | 235 on_connected_callback_.Run(); |
| 234 on_connected_callback_.Reset(); | 236 on_connected_callback_.Reset(); |
| 235 } | 237 } |
| 236 } | 238 } |
| 237 | 239 |
| 238 std::string DeviceCloudPolicyInitializer::GetRestoreMode() const { | 240 std::string DeviceCloudPolicyInitializer::GetRestoreMode() const { |
| 239 const base::DictionaryValue* device_state_dict = | 241 const base::DictionaryValue* device_state_dict = |
| 240 local_state_->GetDictionary(prefs::kServerBackedDeviceState); | 242 local_state_->GetDictionary(prefs::kServerBackedDeviceState); |
| 241 std::string restore_mode; | 243 std::string restore_mode; |
| 242 device_state_dict->GetString(kDeviceStateRestoreMode, &restore_mode); | 244 device_state_dict->GetString(kDeviceStateRestoreMode, &restore_mode); |
| 243 return restore_mode; | 245 return restore_mode; |
| 244 } | 246 } |
| 245 | 247 |
| 246 } // namespace policy | 248 } // namespace policy |
| OLD | NEW |