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/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" |
| 11 #include "base/guid.h" |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
12 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
13 #include "base/rand_util.h" | 14 #include "base/rand_util.h" |
14 #include "base/string_util.h" | 15 #include "base/string_util.h" |
15 #include "chrome/browser/policy/cloud_policy_cache_base.h" | 16 #include "chrome/browser/policy/cloud_policy_cache_base.h" |
16 #include "chrome/browser/policy/cloud_policy_constants.h" | 17 #include "chrome/browser/policy/cloud_policy_constants.h" |
17 #include "chrome/browser/policy/cloud_policy_subsystem.h" | 18 #include "chrome/browser/policy/cloud_policy_subsystem.h" |
18 #include "chrome/browser/policy/delayed_work_scheduler.h" | 19 #include "chrome/browser/policy/delayed_work_scheduler.h" |
19 #include "chrome/browser/policy/device_management_service.h" | 20 #include "chrome/browser/policy/device_management_service.h" |
20 #include "chrome/browser/policy/device_token_fetcher.h" | 21 #include "chrome/browser/policy/device_token_fetcher.h" |
21 #include "chrome/browser/policy/enterprise_metrics.h" | 22 #include "chrome/browser/policy/enterprise_metrics.h" |
22 #include "chrome/browser/policy/policy_notifier.h" | 23 #include "chrome/browser/policy/policy_notifier.h" |
23 #include "chrome/common/guid.h" | |
24 | 24 |
25 namespace policy { | 25 namespace policy { |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
29 // The maximum ratio in percent of the policy refresh rate we use for adjusting | 29 // The maximum ratio in percent of the policy refresh rate we use for adjusting |
30 // the policy refresh time instant. The rationale is to avoid load spikes from | 30 // the policy refresh time instant. The rationale is to avoid load spikes from |
31 // many devices that were set up in sync for some reason. | 31 // many devices that were set up in sync for some reason. |
32 const int kPolicyRefreshDeviationFactorPercent = 10; | 32 const int kPolicyRefreshDeviationFactorPercent = 10; |
33 // Maximum deviation we are willing to accept. | 33 // Maximum deviation we are willing to accept. |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 return data_store_->token_cache_loaded() && | 312 return data_store_->token_cache_loaded() && |
313 !data_store_->user_name().empty() && | 313 !data_store_->user_name().empty() && |
314 data_store_->has_auth_token(); | 314 data_store_->has_auth_token(); |
315 } | 315 } |
316 | 316 |
317 void CloudPolicyController::FetchToken() { | 317 void CloudPolicyController::FetchToken() { |
318 if (ReadyToFetchToken()) { | 318 if (ReadyToFetchToken()) { |
319 if (CanBeInManagedDomain(data_store_->user_name())) { | 319 if (CanBeInManagedDomain(data_store_->user_name())) { |
320 // Generate a new random device id. (It'll only be kept if registration | 320 // Generate a new random device id. (It'll only be kept if registration |
321 // succeeds.) | 321 // succeeds.) |
322 data_store_->set_device_id(guid::GenerateGUID()); | 322 data_store_->set_device_id(base::GenerateGUID()); |
323 token_fetcher_->FetchToken(); | 323 token_fetcher_->FetchToken(); |
324 } else { | 324 } else { |
325 SetState(STATE_TOKEN_UNMANAGED); | 325 SetState(STATE_TOKEN_UNMANAGED); |
326 } | 326 } |
327 } else { | 327 } else { |
328 VLOG(1) << "Not ready to fetch DMToken yet, will try again later."; | 328 VLOG(1) << "Not ready to fetch DMToken yet, will try again later."; |
329 } | 329 } |
330 } | 330 } |
331 | 331 |
332 void CloudPolicyController::SendPolicyRequest() { | 332 void CloudPolicyController::SendPolicyRequest() { |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 | 485 |
486 base::Time CloudPolicyController::GetLastRefreshTime(const base::Time& now) { | 486 base::Time CloudPolicyController::GetLastRefreshTime(const base::Time& now) { |
487 base::Time last_refresh(cache_->last_policy_refresh_time()); | 487 base::Time last_refresh(cache_->last_policy_refresh_time()); |
488 if (last_refresh.is_null()) | 488 if (last_refresh.is_null()) |
489 last_refresh = now; | 489 last_refresh = now; |
490 | 490 |
491 return last_refresh; | 491 return last_refresh; |
492 } | 492 } |
493 | 493 |
494 } // namespace policy | 494 } // namespace policy |
OLD | NEW |