OLD | NEW |
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/settings/device_settings_service.h" | 5 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 } | 122 } |
123 | 123 |
124 scoped_refptr<PublicKey> DeviceSettingsService::GetPublicKey() { | 124 scoped_refptr<PublicKey> DeviceSettingsService::GetPublicKey() { |
125 return public_key_; | 125 return public_key_; |
126 } | 126 } |
127 | 127 |
128 void DeviceSettingsService::Load() { | 128 void DeviceSettingsService::Load() { |
129 EnqueueLoad(false); | 129 EnqueueLoad(false); |
130 } | 130 } |
131 | 131 |
| 132 void DeviceSettingsService::LoadImmediately() { |
| 133 bool request_key_load = true; |
| 134 bool cloud_validations = true; |
| 135 if (device_mode_ == policy::DEVICE_MODE_ENTERPRISE_AD) { |
| 136 request_key_load = false; |
| 137 cloud_validations = false; |
| 138 } |
| 139 std::unique_ptr<SessionManagerOperation> operation(new LoadSettingsOperation( |
| 140 request_key_load, cloud_validations, true /*force_immediate_load*/, |
| 141 base::Bind(&DeviceSettingsService::HandleCompletedOperation, |
| 142 weak_factory_.GetWeakPtr(), base::Closure()))); |
| 143 operation->Start(session_manager_client_, owner_key_util_, public_key_); |
| 144 } |
| 145 |
132 void DeviceSettingsService::Store( | 146 void DeviceSettingsService::Store( |
133 std::unique_ptr<em::PolicyFetchResponse> policy, | 147 std::unique_ptr<em::PolicyFetchResponse> policy, |
134 const base::Closure& callback) { | 148 const base::Closure& callback) { |
135 // On Active Directory managed devices policy is written only by authpolicyd. | 149 // On Active Directory managed devices policy is written only by authpolicyd. |
136 CHECK(device_mode_ != policy::DEVICE_MODE_ENTERPRISE_AD); | 150 CHECK(device_mode_ != policy::DEVICE_MODE_ENTERPRISE_AD); |
137 Enqueue(linked_ptr<SessionManagerOperation>(new StoreSettingsOperation( | 151 Enqueue(linked_ptr<SessionManagerOperation>(new StoreSettingsOperation( |
138 base::Bind(&DeviceSettingsService::HandleCompletedOperation, | 152 base::Bind(&DeviceSettingsService::HandleCompletedAsyncOperation, |
139 weak_factory_.GetWeakPtr(), callback), | 153 weak_factory_.GetWeakPtr(), callback), |
140 std::move(policy)))); | 154 std::move(policy)))); |
141 } | 155 } |
142 | 156 |
143 DeviceSettingsService::OwnershipStatus | 157 DeviceSettingsService::OwnershipStatus |
144 DeviceSettingsService::GetOwnershipStatus() { | 158 DeviceSettingsService::GetOwnershipStatus() { |
145 if (public_key_.get()) | 159 if (public_key_.get()) |
146 return public_key_->is_loaded() ? OWNERSHIP_TAKEN : OWNERSHIP_NONE; | 160 return public_key_->is_loaded() ? OWNERSHIP_TAKEN : OWNERSHIP_NONE; |
147 if (device_mode_ == policy::DEVICE_MODE_ENTERPRISE_AD) | 161 if (device_mode_ == policy::DEVICE_MODE_ENTERPRISE_AD) |
148 return OWNERSHIP_TAKEN; | 162 return OWNERSHIP_TAKEN; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 StartNextOperation(); | 240 StartNextOperation(); |
227 } | 241 } |
228 | 242 |
229 void DeviceSettingsService::EnqueueLoad(bool request_key_load) { | 243 void DeviceSettingsService::EnqueueLoad(bool request_key_load) { |
230 bool cloud_validations = true; | 244 bool cloud_validations = true; |
231 if (device_mode_ == policy::DEVICE_MODE_ENTERPRISE_AD) { | 245 if (device_mode_ == policy::DEVICE_MODE_ENTERPRISE_AD) { |
232 request_key_load = false; | 246 request_key_load = false; |
233 cloud_validations = false; | 247 cloud_validations = false; |
234 } | 248 } |
235 linked_ptr<SessionManagerOperation> operation(new LoadSettingsOperation( | 249 linked_ptr<SessionManagerOperation> operation(new LoadSettingsOperation( |
236 request_key_load, cloud_validations, | 250 request_key_load, cloud_validations, false /*force_immediate_load*/, |
237 base::Bind(&DeviceSettingsService::HandleCompletedOperation, | 251 base::Bind(&DeviceSettingsService::HandleCompletedAsyncOperation, |
238 weak_factory_.GetWeakPtr(), base::Closure()))); | 252 weak_factory_.GetWeakPtr(), base::Closure()))); |
239 Enqueue(operation); | 253 Enqueue(operation); |
240 } | 254 } |
241 | 255 |
242 void DeviceSettingsService::EnsureReload(bool request_key_load) { | 256 void DeviceSettingsService::EnsureReload(bool request_key_load) { |
243 if (!pending_operations_.empty()) | 257 if (!pending_operations_.empty()) |
244 pending_operations_.front()->RestartLoad(request_key_load); | 258 pending_operations_.front()->RestartLoad(request_key_load); |
245 else | 259 else |
246 EnqueueLoad(request_key_load); | 260 EnqueueLoad(request_key_load); |
247 } | 261 } |
248 | 262 |
249 void DeviceSettingsService::StartNextOperation() { | 263 void DeviceSettingsService::StartNextOperation() { |
250 if (!pending_operations_.empty() && session_manager_client_ && | 264 if (!pending_operations_.empty() && session_manager_client_ && |
251 owner_key_util_.get()) { | 265 owner_key_util_.get()) { |
252 pending_operations_.front()->Start( | 266 pending_operations_.front()->Start( |
253 session_manager_client_, owner_key_util_, public_key_); | 267 session_manager_client_, owner_key_util_, public_key_); |
254 } | 268 } |
255 } | 269 } |
256 | 270 |
| 271 void DeviceSettingsService::HandleCompletedAsyncOperation( |
| 272 const base::Closure& callback, |
| 273 SessionManagerOperation* operation, |
| 274 Status status) { |
| 275 DCHECK_EQ(operation, pending_operations_.front().get()); |
| 276 HandleCompletedOperation(callback, operation, status); |
| 277 // Only remove the pending operation here, so new operations triggered by |
| 278 // any of the callbacks above are queued up properly. |
| 279 pending_operations_.pop_front(); |
| 280 |
| 281 StartNextOperation(); |
| 282 } |
| 283 |
257 void DeviceSettingsService::HandleCompletedOperation( | 284 void DeviceSettingsService::HandleCompletedOperation( |
258 const base::Closure& callback, | 285 const base::Closure& callback, |
259 SessionManagerOperation* operation, | 286 SessionManagerOperation* operation, |
260 Status status) { | 287 Status status) { |
261 DCHECK_EQ(operation, pending_operations_.front().get()); | |
262 | |
263 store_status_ = status; | 288 store_status_ = status; |
264 if (status == STORE_SUCCESS) { | 289 if (status == STORE_SUCCESS) { |
265 policy_data_ = std::move(operation->policy_data()); | 290 policy_data_ = std::move(operation->policy_data()); |
266 device_settings_ = std::move(operation->device_settings()); | 291 device_settings_ = std::move(operation->device_settings()); |
267 load_retries_left_ = kMaxLoadRetries; | 292 load_retries_left_ = kMaxLoadRetries; |
268 } else if (status != STORE_KEY_UNAVAILABLE) { | 293 } else if (status != STORE_KEY_UNAVAILABLE) { |
269 LOG(ERROR) << "Session manager operation failed: " << status; | 294 LOG(ERROR) << "Session manager operation failed: " << status; |
270 // Validation errors can be temporary if the rtc has gone on holiday for a | 295 // Validation errors can be temporary if the rtc has gone on holiday for a |
271 // short while. So we will retry such loads for up to 10 minutes. | 296 // short while. So we will retry such loads for up to 10 minutes. |
272 if (status == STORE_TEMP_VALIDATION_ERROR) { | 297 if (status == STORE_TEMP_VALIDATION_ERROR) { |
(...skipping 18 matching lines...) Expand all Loading... |
291 previous_ownership_status_ = GetOwnershipStatus(); | 316 previous_ownership_status_ = GetOwnershipStatus(); |
292 NotifyOwnershipStatusChanged(); | 317 NotifyOwnershipStatusChanged(); |
293 } | 318 } |
294 NotifyDeviceSettingsUpdated(); | 319 NotifyDeviceSettingsUpdated(); |
295 RunPendingOwnershipStatusCallbacks(); | 320 RunPendingOwnershipStatusCallbacks(); |
296 | 321 |
297 // The completion callback happens after the notification so clients can | 322 // The completion callback happens after the notification so clients can |
298 // filter self-triggered updates. | 323 // filter self-triggered updates. |
299 if (!callback.is_null()) | 324 if (!callback.is_null()) |
300 callback.Run(); | 325 callback.Run(); |
301 | |
302 // Only remove the pending operation here, so new operations triggered by any | |
303 // of the callbacks above are queued up properly. | |
304 pending_operations_.pop_front(); | |
305 | |
306 StartNextOperation(); | |
307 } | 326 } |
308 | 327 |
309 void DeviceSettingsService::HandleError(Status status, | 328 void DeviceSettingsService::HandleError(Status status, |
310 const base::Closure& callback) { | 329 const base::Closure& callback) { |
311 store_status_ = status; | 330 store_status_ = status; |
312 LOG(ERROR) << "Session manager operation failed: " << status; | 331 LOG(ERROR) << "Session manager operation failed: " << status; |
313 NotifyDeviceSettingsUpdated(); | 332 NotifyDeviceSettingsUpdated(); |
314 | 333 |
315 // The completion callback happens after the notification so clients can | 334 // The completion callback happens after the notification so clients can |
316 // filter self-triggered updates. | 335 // filter self-triggered updates. |
(...skipping 28 matching lines...) Expand all Loading... |
345 DeviceSettingsService::Initialize(); | 364 DeviceSettingsService::Initialize(); |
346 } | 365 } |
347 | 366 |
348 ScopedTestDeviceSettingsService::~ScopedTestDeviceSettingsService() { | 367 ScopedTestDeviceSettingsService::~ScopedTestDeviceSettingsService() { |
349 // Clean pending operations. | 368 // Clean pending operations. |
350 DeviceSettingsService::Get()->UnsetSessionManager(); | 369 DeviceSettingsService::Get()->UnsetSessionManager(); |
351 DeviceSettingsService::Shutdown(); | 370 DeviceSettingsService::Shutdown(); |
352 } | 371 } |
353 | 372 |
354 } // namespace chromeos | 373 } // namespace chromeos |
OLD | NEW |