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 | 8 |
| 9 #include "base/logging.h" |
9 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
10 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
11 #include "base/string_util.h" | 12 #include "base/string_util.h" |
12 #include "chrome/browser/policy/cloud_policy_cache.h" | 13 #include "chrome/browser/policy/cloud_policy_cache_base.h" |
13 #include "chrome/browser/policy/cloud_policy_subsystem.h" | 14 #include "chrome/browser/policy/cloud_policy_subsystem.h" |
14 #include "chrome/browser/policy/device_management_backend.h" | 15 #include "chrome/browser/policy/device_management_backend.h" |
15 #include "chrome/browser/policy/proto/device_management_constants.h" | 16 #include "chrome/browser/policy/proto/device_management_constants.h" |
16 | 17 |
17 // Domain names that are known not to be managed. | 18 // Domain names that are known not to be managed. |
18 // We don't register the device when such a user logs in. | 19 // We don't register the device when such a user logs in. |
19 static const char* kNonManagedDomains[] = { | 20 static const char* kNonManagedDomains[] = { |
20 "@googlemail.com", | 21 "@googlemail.com", |
21 "@gmail.com" | 22 "@gmail.com" |
22 }; | 23 }; |
(...skipping 29 matching lines...) Expand all Loading... |
52 // These are the base values for delays before retrying after an error. They | 53 // These are the base values for delays before retrying after an error. They |
53 // will be doubled each time they are used. | 54 // will be doubled each time they are used. |
54 static const int64 kPolicyRefreshErrorDelayInMilliseconds = | 55 static const int64 kPolicyRefreshErrorDelayInMilliseconds = |
55 5 * 60 * 1000; // 5 minutes | 56 5 * 60 * 1000; // 5 minutes |
56 | 57 |
57 // Default value for the policy refresh rate. | 58 // Default value for the policy refresh rate. |
58 static const int kPolicyRefreshRateInMilliseconds = | 59 static const int kPolicyRefreshRateInMilliseconds = |
59 3 * 60 * 60 * 1000; // 3 hours. | 60 3 * 60 * 60 * 1000; // 3 hours. |
60 | 61 |
61 CloudPolicyController::CloudPolicyController( | 62 CloudPolicyController::CloudPolicyController( |
62 CloudPolicyCache* cache, | 63 CloudPolicyCacheBase* cache, |
63 DeviceManagementBackend* backend, | 64 DeviceManagementBackend* backend, |
64 DeviceTokenFetcher* token_fetcher, | 65 DeviceTokenFetcher* token_fetcher, |
65 CloudPolicyIdentityStrategy* identity_strategy) | 66 CloudPolicyIdentityStrategy* identity_strategy) |
66 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { | 67 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |
67 Initialize(cache, | 68 Initialize(cache, |
68 backend, | 69 backend, |
69 token_fetcher, | 70 token_fetcher, |
70 identity_strategy, | 71 identity_strategy, |
71 kPolicyRefreshRateInMilliseconds, | 72 kPolicyRefreshRateInMilliseconds, |
72 kPolicyRefreshDeviationFactorPercent, | 73 kPolicyRefreshDeviationFactorPercent, |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 else | 170 else |
170 SetState(STATE_TOKEN_VALID); | 171 SetState(STATE_TOKEN_VALID); |
171 } | 172 } |
172 | 173 |
173 void CloudPolicyController::OnCredentialsChanged() { | 174 void CloudPolicyController::OnCredentialsChanged() { |
174 effective_policy_refresh_error_delay_ms_ = policy_refresh_error_delay_ms_; | 175 effective_policy_refresh_error_delay_ms_ = policy_refresh_error_delay_ms_; |
175 SetState(STATE_TOKEN_UNAVAILABLE); | 176 SetState(STATE_TOKEN_UNAVAILABLE); |
176 } | 177 } |
177 | 178 |
178 CloudPolicyController::CloudPolicyController( | 179 CloudPolicyController::CloudPolicyController( |
179 CloudPolicyCache* cache, | 180 CloudPolicyCacheBase* cache, |
180 DeviceManagementBackend* backend, | 181 DeviceManagementBackend* backend, |
181 DeviceTokenFetcher* token_fetcher, | 182 DeviceTokenFetcher* token_fetcher, |
182 CloudPolicyIdentityStrategy* identity_strategy, | 183 CloudPolicyIdentityStrategy* identity_strategy, |
183 int64 policy_refresh_rate_ms, | 184 int64 policy_refresh_rate_ms, |
184 int policy_refresh_deviation_factor_percent, | 185 int policy_refresh_deviation_factor_percent, |
185 int64 policy_refresh_deviation_max_ms, | 186 int64 policy_refresh_deviation_max_ms, |
186 int64 policy_refresh_error_delay_ms) | 187 int64 policy_refresh_error_delay_ms) |
187 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { | 188 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |
188 Initialize(cache, | 189 Initialize(cache, |
189 backend, | 190 backend, |
190 token_fetcher, | 191 token_fetcher, |
191 identity_strategy, | 192 identity_strategy, |
192 policy_refresh_rate_ms, | 193 policy_refresh_rate_ms, |
193 policy_refresh_deviation_factor_percent, | 194 policy_refresh_deviation_factor_percent, |
194 policy_refresh_deviation_max_ms, | 195 policy_refresh_deviation_max_ms, |
195 policy_refresh_error_delay_ms); | 196 policy_refresh_error_delay_ms); |
196 } | 197 } |
197 | 198 |
198 void CloudPolicyController::Initialize( | 199 void CloudPolicyController::Initialize( |
199 CloudPolicyCache* cache, | 200 CloudPolicyCacheBase* cache, |
200 DeviceManagementBackend* backend, | 201 DeviceManagementBackend* backend, |
201 DeviceTokenFetcher* token_fetcher, | 202 DeviceTokenFetcher* token_fetcher, |
202 CloudPolicyIdentityStrategy* identity_strategy, | 203 CloudPolicyIdentityStrategy* identity_strategy, |
203 int64 policy_refresh_rate_ms, | 204 int64 policy_refresh_rate_ms, |
204 int policy_refresh_deviation_factor_percent, | 205 int policy_refresh_deviation_factor_percent, |
205 int64 policy_refresh_deviation_max_ms, | 206 int64 policy_refresh_deviation_max_ms, |
206 int64 policy_refresh_error_delay_ms) { | 207 int64 policy_refresh_error_delay_ms) { |
207 DCHECK(cache); | 208 DCHECK(cache); |
208 | 209 |
209 cache_ = cache; | 210 cache_ = cache; |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 } | 345 } |
345 | 346 |
346 int64 CloudPolicyController::GetRefreshDelay() { | 347 int64 CloudPolicyController::GetRefreshDelay() { |
347 int64 deviation = (policy_refresh_deviation_factor_percent_ * | 348 int64 deviation = (policy_refresh_deviation_factor_percent_ * |
348 policy_refresh_rate_ms_) / 100; | 349 policy_refresh_rate_ms_) / 100; |
349 deviation = std::min(deviation, policy_refresh_deviation_max_ms_); | 350 deviation = std::min(deviation, policy_refresh_deviation_max_ms_); |
350 return policy_refresh_rate_ms_ - base::RandGenerator(deviation + 1); | 351 return policy_refresh_rate_ms_ - base::RandGenerator(deviation + 1); |
351 } | 352 } |
352 | 353 |
353 } // namespace policy | 354 } // namespace policy |
OLD | NEW |