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

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: Created 9 years, 7 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 net::NetworkChangeNotifier::AddIPAddressObserver(this); 55 net::NetworkChangeNotifier::AddIPAddressObserver(this);
56 notifier_.reset(new PolicyNotifier()); 56 notifier_.reset(new PolicyNotifier());
57 CommandLine* command_line = CommandLine::ForCurrentProcess(); 57 CommandLine* command_line = CommandLine::ForCurrentProcess();
58 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) { 58 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) {
59 device_management_service_.reset(new DeviceManagementService( 59 device_management_service_.reset(new DeviceManagementService(
60 command_line->GetSwitchValueASCII(switches::kDeviceManagementUrl))); 60 command_line->GetSwitchValueASCII(switches::kDeviceManagementUrl)));
61 cloud_policy_cache_.reset(policy_cache); 61 cloud_policy_cache_.reset(policy_cache);
62 cloud_policy_cache_->set_policy_notifier(notifier_.get()); 62 cloud_policy_cache_->set_policy_notifier(notifier_.get());
63 cloud_policy_cache_->Load(); 63 cloud_policy_cache_->Load();
64 64
65 device_token_fetcher_.reset( 65 device_token_fetcher_.reset(
66 new DeviceTokenFetcher(device_management_service_.get(), 66 new DeviceTokenFetcher(device_management_service_.get(),
67 cloud_policy_cache_.get(), 67 cloud_policy_cache_.get(),
68 notifier_.get())); 68 notifier_.get()));
69 69
70 cloud_policy_controller_.reset( 70 cloud_policy_controller_.reset(
71 new CloudPolicyController(device_management_service_.get(), 71 new CloudPolicyController(device_management_service_.get(),
72 cloud_policy_cache_.get(), 72 cloud_policy_cache_.get(),
73 device_token_fetcher_.get(), 73 device_token_fetcher_.get(),
74 identity_strategy, 74 identity_strategy,
75 notifier_.get())); 75 notifier_.get()));
76 } 76 }
77 } 77 }
78 78
79 CloudPolicySubsystem::~CloudPolicySubsystem() { 79 CloudPolicySubsystem::~CloudPolicySubsystem() {
80 DCHECK(!prefs_);
81 cloud_policy_controller_.reset(); 80 cloud_policy_controller_.reset();
82 device_token_fetcher_.reset(); 81 device_token_fetcher_.reset();
83 cloud_policy_cache_.reset(); 82 cloud_policy_cache_.reset();
84 device_management_service_.reset(); 83 device_management_service_.reset();
85 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); 84 net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
86 } 85 }
87 86
88 void CloudPolicySubsystem::OnIPAddressChanged() { 87 void CloudPolicySubsystem::OnIPAddressChanged() {
89 if (state() == CloudPolicySubsystem::NETWORK_ERROR && 88 if (state() == CloudPolicySubsystem::NETWORK_ERROR &&
90 cloud_policy_controller_.get()) { 89 cloud_policy_controller_.get()) {
91 cloud_policy_controller_->Retry(); 90 cloud_policy_controller_->Retry();
92 } 91 }
93 } 92 }
94 93
95 void CloudPolicySubsystem::Initialize( 94 void CloudPolicySubsystem::Initialize(const char* policy_refresh_name,
Mattias Nissler (ping if slow) 2011/05/13 09:45:03 Indentation
sfeuz 2011/05/17 14:27:42 Done.
96 PrefService* prefs,
97 net::URLRequestContextGetter* request_context) { 95 net::URLRequestContextGetter* request_context) {
98 DCHECK(!prefs_);
99 prefs_ = prefs;
100
101 if (device_management_service_.get()) 96 if (device_management_service_.get())
102 device_management_service_->Initialize(request_context); 97 device_management_service_->Initialize(request_context);
103 98
104 policy_refresh_rate_.Init(prefs::kPolicyRefreshRate, prefs_, this); 99 DCHECK(std::string(policy_refresh_name) ==
100 std::string(prefs::kUserPolicyRefreshRate) ||
101 std::string(policy_refresh_name) ==
102 std::string(prefs::kDevicePolicyRefreshRate));
Mattias Nissler (ping if slow) 2011/05/13 09:45:03 Why this DCHECK? The subsystem doesn't care what p
sfeuz 2011/05/17 14:27:42 Done.
103 policy_refresh_rate_.Init(policy_refresh_name,
104 g_browser_process->local_state(),
105 this);
106
105 UpdatePolicyRefreshRate(); 107 UpdatePolicyRefreshRate();
106 } 108 }
107 109
108 void CloudPolicySubsystem::Shutdown() { 110 void CloudPolicySubsystem::Shutdown() {
109 if (device_management_service_.get()) 111 if (device_management_service_.get())
110 device_management_service_->Shutdown(); 112 device_management_service_->Shutdown();
111 cloud_policy_controller_.reset(); 113 cloud_policy_controller_.reset();
112 cloud_policy_cache_.reset(); 114 cloud_policy_cache_.reset();
113 policy_refresh_rate_.Destroy(); 115 policy_refresh_rate_.Destroy();
114 prefs_ = NULL;
115 } 116 }
116 117
117 CloudPolicySubsystem::PolicySubsystemState CloudPolicySubsystem::state() { 118 CloudPolicySubsystem::PolicySubsystemState CloudPolicySubsystem::state() {
118 return notifier_->state(); 119 return notifier_->state();
119 } 120 }
120 121
121 CloudPolicySubsystem::ErrorDetails CloudPolicySubsystem::error_details() { 122 CloudPolicySubsystem::ErrorDetails CloudPolicySubsystem::error_details() {
122 return notifier_->error_details(); 123 return notifier_->error_details();
123 } 124 }
124 125
(...skipping 12 matching lines...) Expand all
137 ConfigurationPolicyProvider* 138 ConfigurationPolicyProvider*
138 CloudPolicySubsystem::GetRecommendedPolicyProvider() { 139 CloudPolicySubsystem::GetRecommendedPolicyProvider() {
139 if (cloud_policy_cache_.get()) 140 if (cloud_policy_cache_.get())
140 return cloud_policy_cache_->GetRecommendedPolicyProvider(); 141 return cloud_policy_cache_->GetRecommendedPolicyProvider();
141 142
142 return NULL; 143 return NULL;
143 } 144 }
144 145
145 // static 146 // static
146 void CloudPolicySubsystem::RegisterPrefs(PrefService* pref_service) { 147 void CloudPolicySubsystem::RegisterPrefs(PrefService* pref_service) {
147 pref_service->RegisterIntegerPref(prefs::kPolicyRefreshRate, 148 pref_service->RegisterIntegerPref(prefs::kDevicePolicyRefreshRate,
149 kDefaultPolicyRefreshRateMs,
150 PrefService::UNSYNCABLE_PREF);
151 pref_service->RegisterIntegerPref(prefs::kUserPolicyRefreshRate,
148 kDefaultPolicyRefreshRateMs, 152 kDefaultPolicyRefreshRateMs,
149 PrefService::UNSYNCABLE_PREF); 153 PrefService::UNSYNCABLE_PREF);
150 } 154 }
151 155
152 void CloudPolicySubsystem::UpdatePolicyRefreshRate() { 156 void CloudPolicySubsystem::UpdatePolicyRefreshRate() {
153 if (cloud_policy_controller_.get()) { 157 if (cloud_policy_controller_.get()) {
154 // Clamp to sane values. 158 // Clamp to sane values.
155 int64 refresh_rate = policy_refresh_rate_.GetValue(); 159 int64 refresh_rate = policy_refresh_rate_.GetValue();
156 refresh_rate = std::max(kPolicyRefreshRateMinMs, refresh_rate); 160 refresh_rate = std::max(kPolicyRefreshRateMinMs, refresh_rate);
157 refresh_rate = std::min(kPolicyRefreshRateMaxMs, refresh_rate); 161 refresh_rate = std::min(kPolicyRefreshRateMaxMs, refresh_rate);
158 cloud_policy_controller_->SetRefreshRate(refresh_rate); 162 cloud_policy_controller_->SetRefreshRate(refresh_rate);
159 } 163 }
160 } 164 }
161 165
162 void CloudPolicySubsystem::Observe(NotificationType type, 166 void CloudPolicySubsystem::Observe(NotificationType type,
163 const NotificationSource& source, 167 const NotificationSource& source,
164 const NotificationDetails& details) { 168 const NotificationDetails& details) {
165 if (type == NotificationType::PREF_CHANGED && 169 if (type == NotificationType::PREF_CHANGED &&
166 policy_refresh_rate_.GetPrefName() == 170 policy_refresh_rate_.GetPrefName() ==
167 *(Details<std::string>(details).ptr()) && 171 *(Details<std::string>(details).ptr())) {
168 prefs_ == Source<PrefService>(source).ptr()) { 172 DCHECK(Source<PrefService>(source).ptr() ==
Mattias Nissler (ping if slow) 2011/05/13 09:45:03 Why not use DCHECK_EQ?
sfeuz 2011/05/17 14:27:42 Done.
173 g_browser_process->local_state());
169 UpdatePolicyRefreshRate(); 174 UpdatePolicyRefreshRate();
170 } else { 175 } else {
171 NOTREACHED(); 176 NOTREACHED();
172 } 177 }
173 } 178 }
174 179
175 } // namespace policy 180 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698