OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/policy/cloud_policy_controller.h" | 5 #include "chrome/browser/policy/cloud_policy_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 cache_->SetPolicy(response.response(0)); | 119 cache_->SetPolicy(response.response(0)); |
120 SetState(STATE_POLICY_VALID); | 120 SetState(STATE_POLICY_VALID); |
121 } else { | 121 } else { |
122 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchBadResponse, | 122 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchBadResponse, |
123 kMetricPolicySize); | 123 kMetricPolicySize); |
124 SetState(STATE_POLICY_UNAVAILABLE); | 124 SetState(STATE_POLICY_UNAVAILABLE); |
125 } | 125 } |
126 } else { | 126 } else { |
127 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchBadResponse, | 127 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchBadResponse, |
128 kMetricPolicySize); | 128 kMetricPolicySize); |
| 129 SetState(STATE_POLICY_UNAVAILABLE); |
129 } | 130 } |
130 } | 131 } |
131 | 132 |
132 void CloudPolicyController::OnError(DeviceManagementBackend::ErrorCode code) { | 133 void CloudPolicyController::OnError(DeviceManagementBackend::ErrorCode code) { |
133 switch (code) { | 134 switch (code) { |
134 case DeviceManagementBackend::kErrorServiceDeviceNotFound: | 135 case DeviceManagementBackend::kErrorServiceDeviceNotFound: |
135 case DeviceManagementBackend::kErrorServiceDeviceIdConflict: | 136 case DeviceManagementBackend::kErrorServiceDeviceIdConflict: |
136 case DeviceManagementBackend::kErrorServiceManagementTokenInvalid: { | 137 case DeviceManagementBackend::kErrorServiceManagementTokenInvalid: { |
137 LOG(WARNING) << "The device token was either invalid or unknown to the " | 138 LOG(WARNING) << "The device token was either invalid or unknown to the " |
138 << "device manager, re-registering device."; | 139 << "device manager, re-registering device."; |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 } | 363 } |
363 | 364 |
364 // Update the delayed work task. | 365 // Update the delayed work task. |
365 scheduler_->CancelDelayedWork(); | 366 scheduler_->CancelDelayedWork(); |
366 if (!refresh_at.is_null()) { | 367 if (!refresh_at.is_null()) { |
367 int64 delay = std::max<int64>((refresh_at - now).InMilliseconds(), 0); | 368 int64 delay = std::max<int64>((refresh_at - now).InMilliseconds(), 0); |
368 scheduler_->PostDelayedWork( | 369 scheduler_->PostDelayedWork( |
369 base::Bind(&CloudPolicyController::DoWork, base::Unretained(this)), | 370 base::Bind(&CloudPolicyController::DoWork, base::Unretained(this)), |
370 delay); | 371 delay); |
371 } | 372 } |
| 373 |
| 374 // Inform the cache if a fetch attempt has completed. This happens if policy |
| 375 // has been succesfully fetched, or if token or policy fetching failed. |
| 376 if (state_ != STATE_TOKEN_UNAVAILABLE && state_ != STATE_TOKEN_VALID) |
| 377 cache_->SetFetchingDone(); |
372 } | 378 } |
373 | 379 |
374 int64 CloudPolicyController::GetRefreshDelay() { | 380 int64 CloudPolicyController::GetRefreshDelay() { |
375 int64 deviation = (kPolicyRefreshDeviationFactorPercent * | 381 int64 deviation = (kPolicyRefreshDeviationFactorPercent * |
376 policy_refresh_rate_ms_) / 100; | 382 policy_refresh_rate_ms_) / 100; |
377 deviation = std::min(deviation, kPolicyRefreshDeviationMaxInMilliseconds); | 383 deviation = std::min(deviation, kPolicyRefreshDeviationMaxInMilliseconds); |
378 return policy_refresh_rate_ms_ - base::RandGenerator(deviation + 1); | 384 return policy_refresh_rate_ms_ - base::RandGenerator(deviation + 1); |
379 } | 385 } |
380 | 386 |
381 } // namespace policy | 387 } // namespace policy |
OLD | NEW |