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

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: Undo testserver changes. Remove unnecessary DCHECK. 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) :
Mattias Nissler (ping if slow) 2011/06/06 15:19:30 colon goes on next line.
54 : prefs_(NULL), 55 identity_strategy_(identity_strategy) {
55 identity_strategy_(identity_strategy) {
56 net::NetworkChangeNotifier::AddIPAddressObserver(this); 56 net::NetworkChangeNotifier::AddIPAddressObserver(this);
57 notifier_.reset(new PolicyNotifier()); 57 notifier_.reset(new PolicyNotifier());
58 CommandLine* command_line = CommandLine::ForCurrentProcess(); 58 CommandLine* command_line = CommandLine::ForCurrentProcess();
59 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) { 59 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) {
60 device_management_service_.reset(new DeviceManagementService( 60 device_management_service_.reset(new DeviceManagementService(
61 command_line->GetSwitchValueASCII(switches::kDeviceManagementUrl))); 61 command_line->GetSwitchValueASCII(switches::kDeviceManagementUrl)));
62 cloud_policy_cache_.reset(policy_cache); 62 cloud_policy_cache_.reset(policy_cache);
63 cloud_policy_cache_->set_policy_notifier(notifier_.get()); 63 cloud_policy_cache_->set_policy_notifier(notifier_.get());
64 cloud_policy_cache_->Load(); 64 cloud_policy_cache_->Load();
65 65
66 device_token_fetcher_.reset( 66 device_token_fetcher_.reset(
67 new DeviceTokenFetcher(device_management_service_.get(), 67 new DeviceTokenFetcher(device_management_service_.get(),
68 cloud_policy_cache_.get(), 68 cloud_policy_cache_.get(),
69 notifier_.get())); 69 notifier_.get()));
70 } 70 }
71 } 71 }
72 72
73 CloudPolicySubsystem::~CloudPolicySubsystem() { 73 CloudPolicySubsystem::~CloudPolicySubsystem() {
74 DCHECK(!prefs_);
75 cloud_policy_controller_.reset(); 74 cloud_policy_controller_.reset();
76 device_token_fetcher_.reset(); 75 device_token_fetcher_.reset();
77 cloud_policy_cache_.reset(); 76 cloud_policy_cache_.reset();
78 device_management_service_.reset(); 77 device_management_service_.reset();
79 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); 78 net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
80 } 79 }
81 80
82 void CloudPolicySubsystem::OnIPAddressChanged() { 81 void CloudPolicySubsystem::OnIPAddressChanged() {
83 if (state() == CloudPolicySubsystem::NETWORK_ERROR && 82 if (state() == CloudPolicySubsystem::NETWORK_ERROR &&
84 cloud_policy_controller_.get()) { 83 cloud_policy_controller_.get()) {
85 cloud_policy_controller_->Retry(); 84 cloud_policy_controller_->Retry();
86 } 85 }
87 } 86 }
88 87
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) {
Mattias Nissler (ping if slow) 2011/06/06 15:19:30 nit: parameters should fit after opening ( on line
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 // Temporarily also consider the profile preference service as a valid
180 // source, since we cannot yet push user cloud policy to |local_state|.
181 UpdatePolicyRefreshRate(pref_service->GetInteger(refresh_pref_name_));
175 } else { 182 } else {
176 NOTREACHED(); 183 NOTREACHED();
177 } 184 }
178 } 185 }
179 186
180 void CloudPolicySubsystem::ScheduleServiceInitialization( 187 void CloudPolicySubsystem::ScheduleServiceInitialization(
181 int64 delay_milliseconds) { 188 int64 delay_milliseconds) {
182 if (device_management_service_.get()) 189 if (device_management_service_.get())
183 device_management_service_->ScheduleInitialization(delay_milliseconds); 190 device_management_service_->ScheduleInitialization(delay_milliseconds);
184 } 191 }
185 192
186 } // namespace policy 193 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/cloud_policy_subsystem.h ('k') | chrome/browser/policy/config_dir_policy_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698