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

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

Issue 6310012: Allow policy refresh rate to be configured through policy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unit test. Created 9 years, 11 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
« no previous file with comments | « chrome/browser/policy/profile_policy_context.h ('k') | chrome/browser/prefs/browser_prefs.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "chrome/browser/policy/configuration_policy_pref_store.h" 6 #include "chrome/browser/policy/configuration_policy_pref_store.h"
7 #include "chrome/browser/policy/device_management_policy_provider.h" 7 #include "chrome/browser/policy/device_management_policy_provider.h"
8 #include "chrome/browser/policy/device_management_service.h" 8 #include "chrome/browser/policy/device_management_service.h"
9 #include "chrome/browser/policy/profile_policy_context.h" 9 #include "chrome/browser/policy/profile_policy_context.h"
10 #include "chrome/browser/prefs/pref_service.h"
10 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/common/chrome_switches.h" 12 #include "chrome/common/chrome_switches.h"
13 #include "chrome/common/notification_details.h"
14 #include "chrome/common/notification_source.h"
15 #include "chrome/common/pref_names.h"
16
17 namespace {
18
19 // Refresh rate sanity interval bounds.
20 const int64 kPolicyRefreshRateMinMs = 30 * 60 * 1000; // 30 minutes
21 const int64 kPolicyRefreshRateMaxMs = 24 * 60 * 60 * 1000; // 1 day
22
23 }
12 24
13 namespace policy { 25 namespace policy {
14 26
15 ProfilePolicyContext::ProfilePolicyContext(Profile* profile) 27 ProfilePolicyContext::ProfilePolicyContext(Profile* profile)
16 : profile_(profile) { 28 : profile_(profile) {
17 CommandLine* command_line = CommandLine::ForCurrentProcess(); 29 CommandLine* command_line = CommandLine::ForCurrentProcess();
18 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) { 30 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) {
19 device_management_service_.reset(new DeviceManagementService( 31 device_management_service_.reset(new DeviceManagementService(
20 command_line->GetSwitchValueASCII(switches::kDeviceManagementUrl))); 32 command_line->GetSwitchValueASCII(switches::kDeviceManagementUrl)));
21 device_management_policy_provider_.reset( 33 device_management_policy_provider_.reset(
22 new policy::DeviceManagementPolicyProvider( 34 new policy::DeviceManagementPolicyProvider(
23 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), 35 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(),
24 device_management_service_->CreateBackend(), 36 device_management_service_->CreateBackend(),
25 profile_)); 37 profile_));
26 } 38 }
27 } 39 }
28 40
29 ProfilePolicyContext::~ProfilePolicyContext() { 41 ProfilePolicyContext::~ProfilePolicyContext() {
30 device_management_policy_provider_.reset(); 42 device_management_policy_provider_.reset();
31 device_management_service_.reset(); 43 device_management_service_.reset();
32 } 44 }
33 45
34 void ProfilePolicyContext::Initialize() { 46 void ProfilePolicyContext::Initialize() {
35 if (device_management_service_.get()) 47 if (device_management_service_.get())
36 device_management_service_->Initialize(profile_->GetRequestContext()); 48 device_management_service_->Initialize(profile_->GetRequestContext());
49
50 policy_refresh_rate_.Init(prefs::kPolicyRefreshRate, profile_->GetPrefs(),
51 this);
52 UpdatePolicyRefreshRate();
37 } 53 }
38 54
39 void ProfilePolicyContext::Shutdown() { 55 void ProfilePolicyContext::Shutdown() {
40 if (device_management_service_.get()) 56 if (device_management_service_.get())
41 device_management_service_->Shutdown(); 57 device_management_service_->Shutdown();
42 } 58 }
43 59
44 DeviceManagementPolicyProvider* 60 DeviceManagementPolicyProvider*
45 ProfilePolicyContext::GetDeviceManagementPolicyProvider() { 61 ProfilePolicyContext::GetDeviceManagementPolicyProvider() {
46 return device_management_policy_provider_.get(); 62 return device_management_policy_provider_.get();
47 } 63 }
48 64
65 // static
66 void ProfilePolicyContext::RegisterUserPrefs(PrefService* user_prefs) {
67 user_prefs->RegisterIntegerPref(prefs::kPolicyRefreshRate,
68 kDefaultPolicyRefreshRateInMilliseconds);
69 }
70
71 void ProfilePolicyContext::UpdatePolicyRefreshRate() {
72 if (device_management_policy_provider_.get()) {
73 // Clamp to sane values.
74 int64 refresh_rate = policy_refresh_rate_.GetValue();
75 refresh_rate = std::max(kPolicyRefreshRateMinMs, refresh_rate);
76 refresh_rate = std::min(kPolicyRefreshRateMaxMs, refresh_rate);
77 device_management_policy_provider_->SetRefreshRate(refresh_rate);
78 }
79 }
80
81 void ProfilePolicyContext::Observe(NotificationType type,
82 const NotificationSource& source,
83 const NotificationDetails& details) {
84 if (type == NotificationType::PREF_CHANGED &&
85 prefs::kPolicyRefreshRate == *(Details<std::string>(details).ptr()) &&
86 profile_->GetPrefs() == Source<PrefService>(source).ptr()) {
87 UpdatePolicyRefreshRate();
88 } else {
89 NOTREACHED();
90 }
91 }
92
49 } // namespace policy 93 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/profile_policy_context.h ('k') | chrome/browser/prefs/browser_prefs.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698