| 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 | 74 |
| 75 DeviceSettingsService::DeviceSettingsService() | 75 DeviceSettingsService::DeviceSettingsService() |
| 76 : session_manager_client_(NULL), | 76 : session_manager_client_(NULL), |
| 77 store_status_(STORE_SUCCESS), | 77 store_status_(STORE_SUCCESS), |
| 78 load_retries_left_(kMaxLoadRetries), | 78 load_retries_left_(kMaxLoadRetries), |
| 79 weak_factory_(this) { | 79 weak_factory_(this) { |
| 80 } | 80 } |
| 81 | 81 |
| 82 DeviceSettingsService::~DeviceSettingsService() { | 82 DeviceSettingsService::~DeviceSettingsService() { |
| 83 DCHECK(pending_operations_.empty()); | 83 DCHECK(pending_operations_.empty()); |
| 84 FOR_EACH_OBSERVER(Observer, observers_, OnDeviceSettingsServiceShutdown()); | 84 for (auto& observer : observers_) |
| 85 observer.OnDeviceSettingsServiceShutdown(); |
| 85 } | 86 } |
| 86 | 87 |
| 87 void DeviceSettingsService::SetSessionManager( | 88 void DeviceSettingsService::SetSessionManager( |
| 88 SessionManagerClient* session_manager_client, | 89 SessionManagerClient* session_manager_client, |
| 89 scoped_refptr<OwnerKeyUtil> owner_key_util) { | 90 scoped_refptr<OwnerKeyUtil> owner_key_util) { |
| 90 DCHECK(session_manager_client); | 91 DCHECK(session_manager_client); |
| 91 DCHECK(owner_key_util.get()); | 92 DCHECK(owner_key_util.get()); |
| 92 DCHECK(!session_manager_client_); | 93 DCHECK(!session_manager_client_); |
| 93 DCHECK(!owner_key_util_.get()); | 94 DCHECK(!owner_key_util_.get()); |
| 94 | 95 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 base::TimeDelta::FromMilliseconds(kLoadRetryDelayMs)); | 275 base::TimeDelta::FromMilliseconds(kLoadRetryDelayMs)); |
| 275 } else { | 276 } else { |
| 276 // Once we've given up retrying, the validation error is not temporary | 277 // Once we've given up retrying, the validation error is not temporary |
| 277 // anymore. | 278 // anymore. |
| 278 store_status_ = STORE_VALIDATION_ERROR; | 279 store_status_ = STORE_VALIDATION_ERROR; |
| 279 } | 280 } |
| 280 } | 281 } |
| 281 } | 282 } |
| 282 | 283 |
| 283 if (new_owner_key) { | 284 if (new_owner_key) { |
| 284 FOR_EACH_OBSERVER(Observer, observers_, OwnershipStatusChanged()); | 285 for (auto& observer : observers_) |
| 286 observer.OwnershipStatusChanged(); |
| 285 content::NotificationService::current()->Notify( | 287 content::NotificationService::current()->Notify( |
| 286 chrome::NOTIFICATION_OWNERSHIP_STATUS_CHANGED, | 288 chrome::NOTIFICATION_OWNERSHIP_STATUS_CHANGED, |
| 287 content::Source<DeviceSettingsService>(this), | 289 content::Source<DeviceSettingsService>(this), |
| 288 content::NotificationService::NoDetails()); | 290 content::NotificationService::NoDetails()); |
| 289 } | 291 } |
| 290 | 292 |
| 291 FOR_EACH_OBSERVER(Observer, observers_, DeviceSettingsUpdated()); | 293 for (auto& observer : observers_) |
| 294 observer.DeviceSettingsUpdated(); |
| 292 | 295 |
| 293 std::vector<OwnershipStatusCallback> callbacks; | 296 std::vector<OwnershipStatusCallback> callbacks; |
| 294 callbacks.swap(pending_ownership_status_callbacks_); | 297 callbacks.swap(pending_ownership_status_callbacks_); |
| 295 for (std::vector<OwnershipStatusCallback>::iterator iter(callbacks.begin()); | 298 for (std::vector<OwnershipStatusCallback>::iterator iter(callbacks.begin()); |
| 296 iter != callbacks.end(); ++iter) { | 299 iter != callbacks.end(); ++iter) { |
| 297 iter->Run(ownership_status); | 300 iter->Run(ownership_status); |
| 298 } | 301 } |
| 299 | 302 |
| 300 // The completion callback happens after the notification so clients can | 303 // The completion callback happens after the notification so clients can |
| 301 // filter self-triggered updates. | 304 // filter self-triggered updates. |
| 302 if (!callback.is_null()) | 305 if (!callback.is_null()) |
| 303 callback.Run(); | 306 callback.Run(); |
| 304 | 307 |
| 305 // Only remove the pending operation here, so new operations triggered by any | 308 // Only remove the pending operation here, so new operations triggered by any |
| 306 // of the callbacks above are queued up properly. | 309 // of the callbacks above are queued up properly. |
| 307 pending_operations_.pop_front(); | 310 pending_operations_.pop_front(); |
| 308 | 311 |
| 309 StartNextOperation(); | 312 StartNextOperation(); |
| 310 } | 313 } |
| 311 | 314 |
| 312 void DeviceSettingsService::HandleError(Status status, | 315 void DeviceSettingsService::HandleError(Status status, |
| 313 const base::Closure& callback) { | 316 const base::Closure& callback) { |
| 314 store_status_ = status; | 317 store_status_ = status; |
| 315 | 318 |
| 316 LOG(ERROR) << "Session manager operation failed: " << status; | 319 LOG(ERROR) << "Session manager operation failed: " << status; |
| 317 | 320 |
| 318 FOR_EACH_OBSERVER(Observer, observers_, DeviceSettingsUpdated()); | 321 for (auto& observer : observers_) |
| 322 observer.DeviceSettingsUpdated(); |
| 319 | 323 |
| 320 // The completion callback happens after the notification so clients can | 324 // The completion callback happens after the notification so clients can |
| 321 // filter self-triggered updates. | 325 // filter self-triggered updates. |
| 322 if (!callback.is_null()) | 326 if (!callback.is_null()) |
| 323 callback.Run(); | 327 callback.Run(); |
| 324 } | 328 } |
| 325 | 329 |
| 326 ScopedTestDeviceSettingsService::ScopedTestDeviceSettingsService() { | 330 ScopedTestDeviceSettingsService::ScopedTestDeviceSettingsService() { |
| 327 DeviceSettingsService::Initialize(); | 331 DeviceSettingsService::Initialize(); |
| 328 } | 332 } |
| 329 | 333 |
| 330 ScopedTestDeviceSettingsService::~ScopedTestDeviceSettingsService() { | 334 ScopedTestDeviceSettingsService::~ScopedTestDeviceSettingsService() { |
| 331 // Clean pending operations. | 335 // Clean pending operations. |
| 332 DeviceSettingsService::Get()->UnsetSessionManager(); | 336 DeviceSettingsService::Get()->UnsetSessionManager(); |
| 333 DeviceSettingsService::Shutdown(); | 337 DeviceSettingsService::Shutdown(); |
| 334 } | 338 } |
| 335 | 339 |
| 336 } // namespace chromeos | 340 } // namespace chromeos |
| OLD | NEW |