Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: chrome/browser/policy/cloud_policy_controller.cc

Issue 7941008: Cosmetic cleanups in chrome/browser/policy/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Upload was broken? Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 9
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
12 #include "base/rand_util.h" 13 #include "base/rand_util.h"
13 #include "base/string_util.h" 14 #include "base/string_util.h"
15 #include "base/time.h"
14 #include "chrome/browser/policy/cloud_policy_cache_base.h" 16 #include "chrome/browser/policy/cloud_policy_cache_base.h"
15 #include "chrome/browser/policy/cloud_policy_subsystem.h" 17 #include "chrome/browser/policy/cloud_policy_subsystem.h"
18 #include "chrome/browser/policy/delayed_work_scheduler.h"
16 #include "chrome/browser/policy/device_management_service.h" 19 #include "chrome/browser/policy/device_management_service.h"
20 #include "chrome/browser/policy/device_token_fetcher.h"
17 #include "chrome/browser/policy/enterprise_metrics.h" 21 #include "chrome/browser/policy/enterprise_metrics.h"
22 #include "chrome/browser/policy/policy_notifier.h"
18 #include "chrome/browser/policy/proto/device_management_constants.h" 23 #include "chrome/browser/policy/proto/device_management_constants.h"
19 #include "chrome/common/guid.h" 24 #include "chrome/common/guid.h"
20 25
21 namespace { 26 namespace {
22 27
28 // The maximum ratio in percent of the policy refresh rate we use for adjusting
29 // the policy refresh time instant. The rationale is to avoid load spikes from
30 // many devices that were set up in sync for some reason.
31 const int kPolicyRefreshDeviationFactorPercent = 10;
32 // Maximum deviation we are willing to accept.
33 const int64 kPolicyRefreshDeviationMaxInMilliseconds = 30 * 60 * 1000;
34
35 // These are the base values for delays before retrying after an error. They
36 // will be doubled each time they are used.
37 const int64 kPolicyRefreshErrorDelayInMilliseconds =
38 5 * 60 * 1000; // 5 minutes.
39
40 // Default value for the policy refresh rate.
41 const int kPolicyRefreshRateInMilliseconds = 3 * 60 * 60 * 1000; // 3 hours.
42
23 // Domain names that are known not to be managed. 43 // Domain names that are known not to be managed.
24 // We don't register the device when such a user logs in. 44 // We don't register the device when such a user logs in.
25 const char* kNonManagedDomains[] = { 45 const char* kNonManagedDomains[] = {
26 "@googlemail.com", 46 "@googlemail.com",
27 "@gmail.com" 47 "@gmail.com"
28 }; 48 };
29 49
30 // Checks the domain part of the given username against the list of known 50 // Checks the domain part of the given username against the list of known
31 // non-managed domain names. Returns false if |username| is empty or 51 // non-managed domain names. Returns false if |username| is empty or
32 // in a domain known not to be managed. 52 // in a domain known not to be managed.
33 bool CanBeInManagedDomain(const std::string& username) { 53 bool CanBeInManagedDomain(const std::string& username) {
34 if (username.empty()) { 54 if (username.empty()) {
35 // This means incognito user in case of ChromiumOS and 55 // This means incognito user in case of ChromiumOS and
36 // no logged-in user in case of Chromium (SigninService). 56 // no logged-in user in case of Chromium (SigninService).
37 return false; 57 return false;
38 } 58 }
39 for (size_t i = 0; i < arraysize(kNonManagedDomains); i++) { 59 for (size_t i = 0; i < arraysize(kNonManagedDomains); i++) {
40 if (EndsWith(username, kNonManagedDomains[i], true)) { 60 if (EndsWith(username, kNonManagedDomains[i], true)) {
41 return false; 61 return false;
42 } 62 }
43 } 63 }
44 return true; 64 return true;
45 } 65 }
46 66
47 } 67 } // namespace
48 68
49 namespace policy { 69 namespace policy {
50 70
51 namespace em = enterprise_management; 71 namespace em = enterprise_management;
52 72
53 // The maximum ratio in percent of the policy refresh rate we use for adjusting
54 // the policy refresh time instant. The rationale is to avoid load spikes from
55 // many devices that were set up in sync for some reason.
56 static const int kPolicyRefreshDeviationFactorPercent = 10;
57 // Maximum deviation we are willing to accept.
58 static const int64 kPolicyRefreshDeviationMaxInMilliseconds = 30 * 60 * 1000;
59
60 // These are the base values for delays before retrying after an error. They
61 // will be doubled each time they are used.
62 static const int64 kPolicyRefreshErrorDelayInMilliseconds =
63 5 * 60 * 1000; // 5 minutes
64
65 // Default value for the policy refresh rate.
66 static const int kPolicyRefreshRateInMilliseconds =
67 3 * 60 * 60 * 1000; // 3 hours.
68
69 CloudPolicyController::CloudPolicyController( 73 CloudPolicyController::CloudPolicyController(
70 DeviceManagementService* service, 74 DeviceManagementService* service,
71 CloudPolicyCacheBase* cache, 75 CloudPolicyCacheBase* cache,
72 DeviceTokenFetcher* token_fetcher, 76 DeviceTokenFetcher* token_fetcher,
73 CloudPolicyDataStore* data_store, 77 CloudPolicyDataStore* data_store,
74 PolicyNotifier* notifier) { 78 PolicyNotifier* notifier) {
75 Initialize(service, 79 Initialize(service,
76 cache, 80 cache,
77 token_fetcher, 81 token_fetcher,
78 data_store, 82 data_store,
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 } 372 }
369 373
370 int64 CloudPolicyController::GetRefreshDelay() { 374 int64 CloudPolicyController::GetRefreshDelay() {
371 int64 deviation = (kPolicyRefreshDeviationFactorPercent * 375 int64 deviation = (kPolicyRefreshDeviationFactorPercent *
372 policy_refresh_rate_ms_) / 100; 376 policy_refresh_rate_ms_) / 100;
373 deviation = std::min(deviation, kPolicyRefreshDeviationMaxInMilliseconds); 377 deviation = std::min(deviation, kPolicyRefreshDeviationMaxInMilliseconds);
374 return policy_refresh_rate_ms_ - base::RandGenerator(deviation + 1); 378 return policy_refresh_rate_ms_ - base::RandGenerator(deviation + 1);
375 } 379 }
376 380
377 } // namespace policy 381 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/cloud_policy_controller.h ('k') | chrome/browser/policy/cloud_policy_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698