| 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 11 matching lines...) Expand all Loading... |
| 22 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 23 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
| 24 #include "content/public/browser/notification_source.h" | 24 #include "content/public/browser/notification_source.h" |
| 25 #include "crypto/rsa_private_key.h" | 25 #include "crypto/rsa_private_key.h" |
| 26 | 26 |
| 27 namespace em = enterprise_management; | 27 namespace em = enterprise_management; |
| 28 | 28 |
| 29 using ownership::OwnerKeyUtil; | 29 using ownership::OwnerKeyUtil; |
| 30 using ownership::PublicKey; | 30 using ownership::PublicKey; |
| 31 | 31 |
| 32 namespace { | |
| 33 | |
| 34 // Delay between load retries when there was a validation error. | |
| 35 // NOTE: This code is here to mitigate clock loss on some devices where policy | |
| 36 // loads will fail with a validation error caused by RTC clock being reset when | |
| 37 // the battery is drained. | |
| 38 int kLoadRetryDelayMs = 1000 * 5; | |
| 39 // Maximal number of retries before we give up. Calculated to allow for 10 min | |
| 40 // of retry time. | |
| 41 int kMaxLoadRetries = (1000 * 60 * 10) / kLoadRetryDelayMs; | |
| 42 | |
| 43 } // namespace | |
| 44 | |
| 45 namespace chromeos { | 32 namespace chromeos { |
| 46 | 33 |
| 47 DeviceSettingsService::Observer::~Observer() {} | 34 DeviceSettingsService::Observer::~Observer() {} |
| 48 | 35 |
| 49 void DeviceSettingsService::Observer::OwnershipStatusChanged() {} | 36 void DeviceSettingsService::Observer::OwnershipStatusChanged() {} |
| 50 | 37 |
| 51 void DeviceSettingsService::Observer::DeviceSettingsUpdated() {} | 38 void DeviceSettingsService::Observer::DeviceSettingsUpdated() {} |
| 52 | 39 |
| 53 void DeviceSettingsService::Observer::OnDeviceSettingsServiceShutdown() {} | 40 void DeviceSettingsService::Observer::OnDeviceSettingsServiceShutdown() {} |
| 54 | 41 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 71 delete g_device_settings_service; | 58 delete g_device_settings_service; |
| 72 g_device_settings_service = NULL; | 59 g_device_settings_service = NULL; |
| 73 } | 60 } |
| 74 | 61 |
| 75 // static | 62 // static |
| 76 DeviceSettingsService* DeviceSettingsService::Get() { | 63 DeviceSettingsService* DeviceSettingsService::Get() { |
| 77 CHECK(g_device_settings_service); | 64 CHECK(g_device_settings_service); |
| 78 return g_device_settings_service; | 65 return g_device_settings_service; |
| 79 } | 66 } |
| 80 | 67 |
| 81 DeviceSettingsService::DeviceSettingsService() | 68 DeviceSettingsService::DeviceSettingsService() {} |
| 82 : load_retries_left_(kMaxLoadRetries), weak_factory_(this) {} | |
| 83 | 69 |
| 84 DeviceSettingsService::~DeviceSettingsService() { | 70 DeviceSettingsService::~DeviceSettingsService() { |
| 85 DCHECK(pending_operations_.empty()); | 71 DCHECK(pending_operations_.empty()); |
| 86 for (auto& observer : observers_) | 72 for (auto& observer : observers_) |
| 87 observer.OnDeviceSettingsServiceShutdown(); | 73 observer.OnDeviceSettingsServiceShutdown(); |
| 88 } | 74 } |
| 89 | 75 |
| 90 void DeviceSettingsService::SetSessionManager( | 76 void DeviceSettingsService::SetSessionManager( |
| 91 SessionManagerClient* session_manager_client, | 77 SessionManagerClient* session_manager_client, |
| 92 scoped_refptr<OwnerKeyUtil> owner_key_util) { | 78 scoped_refptr<OwnerKeyUtil> owner_key_util) { |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 } | 282 } |
| 297 | 283 |
| 298 void DeviceSettingsService::HandleCompletedOperation( | 284 void DeviceSettingsService::HandleCompletedOperation( |
| 299 const base::Closure& callback, | 285 const base::Closure& callback, |
| 300 SessionManagerOperation* operation, | 286 SessionManagerOperation* operation, |
| 301 Status status) { | 287 Status status) { |
| 302 store_status_ = status; | 288 store_status_ = status; |
| 303 if (status == STORE_SUCCESS) { | 289 if (status == STORE_SUCCESS) { |
| 304 policy_data_ = std::move(operation->policy_data()); | 290 policy_data_ = std::move(operation->policy_data()); |
| 305 device_settings_ = std::move(operation->device_settings()); | 291 device_settings_ = std::move(operation->device_settings()); |
| 306 load_retries_left_ = kMaxLoadRetries; | |
| 307 } else if (status != STORE_KEY_UNAVAILABLE) { | 292 } else if (status != STORE_KEY_UNAVAILABLE) { |
| 308 LOG(ERROR) << "Session manager operation failed: " << status; | 293 LOG(ERROR) << "Session manager operation failed: " << status; |
| 309 // Validation errors can be temporary if the rtc has gone on holiday for a | |
| 310 // short while. So we will retry such loads for up to 10 minutes. | |
| 311 if (status == STORE_TEMP_VALIDATION_ERROR) { | |
| 312 if (load_retries_left_ > 0) { | |
| 313 load_retries_left_--; | |
| 314 LOG(ERROR) << "A re-load has been scheduled due to a validation error."; | |
| 315 content::BrowserThread::PostDelayedTask( | |
| 316 content::BrowserThread::UI, | |
| 317 FROM_HERE, | |
| 318 base::Bind(&DeviceSettingsService::Load, base::Unretained(this)), | |
| 319 base::TimeDelta::FromMilliseconds(kLoadRetryDelayMs)); | |
| 320 } else { | |
| 321 // Once we've given up retrying, the validation error is not temporary | |
| 322 // anymore. | |
| 323 store_status_ = STORE_VALIDATION_ERROR; | |
| 324 } | |
| 325 } | |
| 326 } | 294 } |
| 327 | 295 |
| 328 public_key_ = scoped_refptr<PublicKey>(operation->public_key()); | 296 public_key_ = scoped_refptr<PublicKey>(operation->public_key()); |
| 329 if (GetOwnershipStatus() != previous_ownership_status_) { | 297 if (GetOwnershipStatus() != previous_ownership_status_) { |
| 330 previous_ownership_status_ = GetOwnershipStatus(); | 298 previous_ownership_status_ = GetOwnershipStatus(); |
| 331 NotifyOwnershipStatusChanged(); | 299 NotifyOwnershipStatusChanged(); |
| 332 } | 300 } |
| 333 NotifyDeviceSettingsUpdated(); | 301 NotifyDeviceSettingsUpdated(); |
| 334 RunPendingOwnershipStatusCallbacks(); | 302 RunPendingOwnershipStatusCallbacks(); |
| 335 | 303 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 DeviceSettingsService::Initialize(); | 346 DeviceSettingsService::Initialize(); |
| 379 } | 347 } |
| 380 | 348 |
| 381 ScopedTestDeviceSettingsService::~ScopedTestDeviceSettingsService() { | 349 ScopedTestDeviceSettingsService::~ScopedTestDeviceSettingsService() { |
| 382 // Clean pending operations. | 350 // Clean pending operations. |
| 383 DeviceSettingsService::Get()->UnsetSessionManager(); | 351 DeviceSettingsService::Get()->UnsetSessionManager(); |
| 384 DeviceSettingsService::Shutdown(); | 352 DeviceSettingsService::Shutdown(); |
| 385 } | 353 } |
| 386 | 354 |
| 387 } // namespace chromeos | 355 } // namespace chromeos |
| OLD | NEW |