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

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

Issue 7014036: Split the policy refresh rate preference into user- and device-policy refresh rate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Temporarily added user policy refresh rate to both local_state and profile prefs. Rebased. Created 9 years, 6 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_subsystem.h" 5 #include "chrome/browser/policy/cloud_policy_subsystem.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/policy/cloud_policy_cache_base.h" 12 #include "chrome/browser/policy/cloud_policy_cache_base.h"
12 #include "chrome/browser/policy/cloud_policy_controller.h" 13 #include "chrome/browser/policy/cloud_policy_controller.h"
13 #include "chrome/browser/policy/cloud_policy_identity_strategy.h" 14 #include "chrome/browser/policy/cloud_policy_identity_strategy.h"
14 #include "chrome/browser/policy/configuration_policy_provider.h" 15 #include "chrome/browser/policy/configuration_policy_provider.h"
15 #include "chrome/browser/policy/device_management_service.h" 16 #include "chrome/browser/policy/device_management_service.h"
16 #include "chrome/browser/policy/device_token_fetcher.h" 17 #include "chrome/browser/policy/device_token_fetcher.h"
17 #include "chrome/browser/policy/policy_notifier.h" 18 #include "chrome/browser/policy/policy_notifier.h"
18 #include "chrome/browser/prefs/pref_service.h" 19 #include "chrome/browser/prefs/pref_service.h"
19 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
20 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
(...skipping 22 matching lines...) Expand all
43 policy_notifier_->AddObserver(observer); 44 policy_notifier_->AddObserver(observer);
44 } 45 }
45 46
46 CloudPolicySubsystem::ObserverRegistrar::~ObserverRegistrar() { 47 CloudPolicySubsystem::ObserverRegistrar::~ObserverRegistrar() {
47 if (policy_notifier_) 48 if (policy_notifier_)
48 policy_notifier_->RemoveObserver(observer_); 49 policy_notifier_->RemoveObserver(observer_);
49 } 50 }
50 51
51 CloudPolicySubsystem::CloudPolicySubsystem( 52 CloudPolicySubsystem::CloudPolicySubsystem(
52 CloudPolicyIdentityStrategy* identity_strategy, 53 CloudPolicyIdentityStrategy* identity_strategy,
53 CloudPolicyCacheBase* policy_cache) 54 CloudPolicyCacheBase* policy_cache) :
54 : prefs_(NULL), 55 identity_strategy_(identity_strategy) {
55 identity_strategy_(identity_strategy) { 56
Mattias Nissler (ping if slow) 2011/05/31 12:35:53 excess whitespace.
sfeuz 2011/05/31 12:52:18 Done.
56 net::NetworkChangeNotifier::AddIPAddressObserver(this); 57 net::NetworkChangeNotifier::AddIPAddressObserver(this);
57 notifier_.reset(new PolicyNotifier()); 58 notifier_.reset(new PolicyNotifier());
58 CommandLine* command_line = CommandLine::ForCurrentProcess(); 59 CommandLine* command_line = CommandLine::ForCurrentProcess();
59 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) { 60 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) {
60 device_management_service_.reset(new DeviceManagementService( 61 device_management_service_.reset(new DeviceManagementService(
61 command_line->GetSwitchValueASCII(switches::kDeviceManagementUrl))); 62 command_line->GetSwitchValueASCII(switches::kDeviceManagementUrl)));
62 cloud_policy_cache_.reset(policy_cache); 63 cloud_policy_cache_.reset(policy_cache);
63 cloud_policy_cache_->set_policy_notifier(notifier_.get()); 64 cloud_policy_cache_->set_policy_notifier(notifier_.get());
64 cloud_policy_cache_->Load(); 65 cloud_policy_cache_->Load();
65 66
66 device_token_fetcher_.reset( 67 device_token_fetcher_.reset(
67 new DeviceTokenFetcher(device_management_service_.get(), 68 new DeviceTokenFetcher(device_management_service_.get(),
68 cloud_policy_cache_.get(), 69 cloud_policy_cache_.get(),
69 notifier_.get())); 70 notifier_.get()));
70 } 71 }
71 } 72 }
72 73
73 CloudPolicySubsystem::~CloudPolicySubsystem() { 74 CloudPolicySubsystem::~CloudPolicySubsystem() {
74 DCHECK(!prefs_);
75 cloud_policy_controller_.reset(); 75 cloud_policy_controller_.reset();
76 device_token_fetcher_.reset(); 76 device_token_fetcher_.reset();
77 cloud_policy_cache_.reset(); 77 cloud_policy_cache_.reset();
78 device_management_service_.reset(); 78 device_management_service_.reset();
79 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); 79 net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
80 } 80 }
81 81
82 void CloudPolicySubsystem::OnIPAddressChanged() { 82 void CloudPolicySubsystem::OnIPAddressChanged() {
83 if (state() == CloudPolicySubsystem::NETWORK_ERROR && 83 if (state() == CloudPolicySubsystem::NETWORK_ERROR &&
84 cloud_policy_controller_.get()) { 84 cloud_policy_controller_.get()) {
85 cloud_policy_controller_->Retry(); 85 cloud_policy_controller_->Retry();
86 } 86 }
87 } 87 }
88
Mattias Nissler (ping if slow) 2011/05/31 12:35:53 Please don't delete this whitespace.
sfeuz 2011/05/31 12:52:18 Done.
89 void CloudPolicySubsystem::Initialize( 88 void CloudPolicySubsystem::Initialize(
90 PrefService* prefs, 89 const char* refresh_pref_name,
91 int64 delay_milliseconds) { 90 int delay_milliseconds) {
92 DCHECK(!prefs_);
93 prefs_ = prefs;
94
95 CommandLine* command_line = CommandLine::ForCurrentProcess(); 91 CommandLine* command_line = CommandLine::ForCurrentProcess();
96 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) { 92 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) {
93 DCHECK(device_management_service_.get());
94 DCHECK(cloud_policy_cache_.get());
95 DCHECK(device_token_fetcher_.get());
96 DCHECK(identity_strategy_);
97
98 refresh_pref_name_ = refresh_pref_name;
97 DCHECK(!cloud_policy_controller_.get()); 99 DCHECK(!cloud_policy_controller_.get());
98 cloud_policy_controller_.reset( 100 cloud_policy_controller_.reset(
99 new CloudPolicyController(device_management_service_.get(), 101 new CloudPolicyController(device_management_service_.get(),
100 cloud_policy_cache_.get(), 102 cloud_policy_cache_.get(),
101 device_token_fetcher_.get(), 103 device_token_fetcher_.get(),
102 identity_strategy_, 104 identity_strategy_,
103 notifier_.get())); 105 notifier_.get()));
104 }
105 106
106 if (device_management_service_.get())
107 device_management_service_->ScheduleInitialization(delay_milliseconds); 107 device_management_service_->ScheduleInitialization(delay_milliseconds);
108 108
109 policy_refresh_rate_.Init(prefs::kPolicyRefreshRate, prefs_, this); 109 PrefService* local_state = g_browser_process->local_state();
110 UpdatePolicyRefreshRate(); 110 DCHECK(pref_change_registrar_.IsEmpty());
111 pref_change_registrar_.Init(local_state);
112 pref_change_registrar_.Add(refresh_pref_name_, this);
113 UpdatePolicyRefreshRate(local_state->GetInteger(refresh_pref_name_));
114 }
111 } 115 }
112 116
113 void CloudPolicySubsystem::Shutdown() { 117 void CloudPolicySubsystem::Shutdown() {
114 if (device_management_service_.get()) 118 if (device_management_service_.get())
115 device_management_service_->Shutdown(); 119 device_management_service_->Shutdown();
116 cloud_policy_controller_.reset(); 120 cloud_policy_controller_.reset();
117 cloud_policy_cache_.reset(); 121 cloud_policy_cache_.reset();
118 policy_refresh_rate_.Destroy(); 122 pref_change_registrar_.RemoveAll();
119 prefs_ = NULL;
120 } 123 }
121 124
122 CloudPolicySubsystem::PolicySubsystemState CloudPolicySubsystem::state() { 125 CloudPolicySubsystem::PolicySubsystemState CloudPolicySubsystem::state() {
123 return notifier_->state(); 126 return notifier_->state();
124 } 127 }
125 128
126 CloudPolicySubsystem::ErrorDetails CloudPolicySubsystem::error_details() { 129 CloudPolicySubsystem::ErrorDetails CloudPolicySubsystem::error_details() {
127 return notifier_->error_details(); 130 return notifier_->error_details();
128 } 131 }
129 132
(...skipping 12 matching lines...) Expand all
142 ConfigurationPolicyProvider* 145 ConfigurationPolicyProvider*
143 CloudPolicySubsystem::GetRecommendedPolicyProvider() { 146 CloudPolicySubsystem::GetRecommendedPolicyProvider() {
144 if (cloud_policy_cache_.get()) 147 if (cloud_policy_cache_.get())
145 return cloud_policy_cache_->GetRecommendedPolicyProvider(); 148 return cloud_policy_cache_->GetRecommendedPolicyProvider();
146 149
147 return NULL; 150 return NULL;
148 } 151 }
149 152
150 // static 153 // static
151 void CloudPolicySubsystem::RegisterPrefs(PrefService* pref_service) { 154 void CloudPolicySubsystem::RegisterPrefs(PrefService* pref_service) {
152 pref_service->RegisterIntegerPref(prefs::kPolicyRefreshRate, 155 pref_service->RegisterIntegerPref(prefs::kDevicePolicyRefreshRate,
156 kDefaultPolicyRefreshRateMs,
157 PrefService::UNSYNCABLE_PREF);
158 pref_service->RegisterIntegerPref(prefs::kUserPolicyRefreshRate,
153 kDefaultPolicyRefreshRateMs, 159 kDefaultPolicyRefreshRateMs,
154 PrefService::UNSYNCABLE_PREF); 160 PrefService::UNSYNCABLE_PREF);
155 } 161 }
156 162
157 void CloudPolicySubsystem::UpdatePolicyRefreshRate() { 163 void CloudPolicySubsystem::UpdatePolicyRefreshRate(int64 refresh_rate) {
158 if (cloud_policy_controller_.get()) { 164 if (cloud_policy_controller_.get()) {
159 // Clamp to sane values. 165 // Clamp to sane values.
160 int64 refresh_rate = policy_refresh_rate_.GetValue();
161 refresh_rate = std::max(kPolicyRefreshRateMinMs, refresh_rate); 166 refresh_rate = std::max(kPolicyRefreshRateMinMs, refresh_rate);
162 refresh_rate = std::min(kPolicyRefreshRateMaxMs, refresh_rate); 167 refresh_rate = std::min(kPolicyRefreshRateMaxMs, refresh_rate);
163 cloud_policy_controller_->SetRefreshRate(refresh_rate); 168 cloud_policy_controller_->SetRefreshRate(refresh_rate);
164 } 169 }
165 } 170 }
166 171
167 void CloudPolicySubsystem::Observe(NotificationType type, 172 void CloudPolicySubsystem::Observe(NotificationType type,
168 const NotificationSource& source, 173 const NotificationSource& source,
169 const NotificationDetails& details) { 174 const NotificationDetails& details) {
170 if (type == NotificationType::PREF_CHANGED && 175 if (type == NotificationType::PREF_CHANGED) {
171 policy_refresh_rate_.GetPrefName() == 176 DCHECK_EQ(*(Details<std::string>(details).ptr()),
172 *(Details<std::string>(details).ptr()) && 177 std::string(refresh_pref_name_));
173 prefs_ == Source<PrefService>(source).ptr()) { 178 PrefService* pref_service = Source<PrefService>(source).ptr();
174 UpdatePolicyRefreshRate(); 179 DCHECK(pref_service);
Mattias Nissler (ping if slow) 2011/05/31 12:35:53 Don't need the DCHECK, since we'll be crashing bel
sfeuz 2011/05/31 12:52:18 Is that really a reason to remove this DCHECK?
Mattias Nissler (ping if slow) 2011/05/31 13:01:05 Yes. The reasoning is that the DCHECK doesn't give
180 // Temporarily also consider the profile preference service as a valid
181 // source, since we cannot yet push user cloud policy to |local_state|.
182 UpdatePolicyRefreshRate(pref_service->GetInteger(refresh_pref_name_));
175 } else { 183 } else {
176 NOTREACHED(); 184 NOTREACHED();
177 } 185 }
178 } 186 }
179 187
180 void CloudPolicySubsystem::ScheduleServiceInitialization( 188 void CloudPolicySubsystem::ScheduleServiceInitialization(
181 int64 delay_milliseconds) { 189 int64 delay_milliseconds) {
182 if (device_management_service_.get()) 190 if (device_management_service_.get())
183 device_management_service_->ScheduleInitialization(delay_milliseconds); 191 device_management_service_->ScheduleInitialization(delay_milliseconds);
184 } 192 }
185 193
186 } // namespace policy 194 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698