OLD | NEW |
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/browser_process.h" |
12 #include "chrome/browser/policy/cloud_policy_cache_base.h" | 12 #include "chrome/browser/policy/cloud_policy_cache_base.h" |
13 #include "chrome/browser/policy/cloud_policy_controller.h" | 13 #include "chrome/browser/policy/cloud_policy_controller.h" |
14 #include "chrome/browser/policy/cloud_policy_identity_strategy.h" | 14 #include "chrome/browser/policy/cloud_policy_identity_strategy.h" |
15 #include "chrome/browser/policy/configuration_policy_provider.h" | |
16 #include "chrome/browser/policy/device_management_service.h" | 15 #include "chrome/browser/policy/device_management_service.h" |
17 #include "chrome/browser/policy/device_token_fetcher.h" | 16 #include "chrome/browser/policy/device_token_fetcher.h" |
18 #include "chrome/browser/policy/policy_notifier.h" | 17 #include "chrome/browser/policy/policy_notifier.h" |
19 #include "chrome/browser/prefs/pref_service.h" | 18 #include "chrome/browser/prefs/pref_service.h" |
20 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
21 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
22 #include "content/common/notification_details.h" | 21 #include "content/common/notification_details.h" |
23 #include "content/common/notification_source.h" | 22 #include "content/common/notification_source.h" |
24 #include "content/common/notification_type.h" | 23 #include "content/common/notification_type.h" |
25 | 24 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 | 128 |
130 CloudPolicySubsystem::ErrorDetails CloudPolicySubsystem::error_details() { | 129 CloudPolicySubsystem::ErrorDetails CloudPolicySubsystem::error_details() { |
131 return notifier_->error_details(); | 130 return notifier_->error_details(); |
132 } | 131 } |
133 | 132 |
134 void CloudPolicySubsystem::StopAutoRetry() { | 133 void CloudPolicySubsystem::StopAutoRetry() { |
135 cloud_policy_controller_->StopAutoRetry(); | 134 cloud_policy_controller_->StopAutoRetry(); |
136 device_token_fetcher_->StopAutoRetry(); | 135 device_token_fetcher_->StopAutoRetry(); |
137 } | 136 } |
138 | 137 |
139 ConfigurationPolicyProvider* CloudPolicySubsystem::GetManagedPolicyProvider() { | |
140 if (cloud_policy_cache_.get()) | |
141 return cloud_policy_cache_->GetManagedPolicyProvider(); | |
142 | |
143 return NULL; | |
144 } | |
145 | |
146 ConfigurationPolicyProvider* | |
147 CloudPolicySubsystem::GetRecommendedPolicyProvider() { | |
148 if (cloud_policy_cache_.get()) | |
149 return cloud_policy_cache_->GetRecommendedPolicyProvider(); | |
150 | |
151 return NULL; | |
152 } | |
153 | |
154 // static | 138 // static |
155 void CloudPolicySubsystem::RegisterPrefs(PrefService* pref_service) { | 139 void CloudPolicySubsystem::RegisterPrefs(PrefService* pref_service) { |
156 pref_service->RegisterIntegerPref(prefs::kDevicePolicyRefreshRate, | 140 pref_service->RegisterIntegerPref(prefs::kDevicePolicyRefreshRate, |
157 kDefaultPolicyRefreshRateMs, | 141 kDefaultPolicyRefreshRateMs, |
158 PrefService::UNSYNCABLE_PREF); | 142 PrefService::UNSYNCABLE_PREF); |
159 pref_service->RegisterIntegerPref(prefs::kUserPolicyRefreshRate, | 143 pref_service->RegisterIntegerPref(prefs::kUserPolicyRefreshRate, |
160 kDefaultPolicyRefreshRateMs, | 144 kDefaultPolicyRefreshRateMs, |
161 PrefService::UNSYNCABLE_PREF); | 145 PrefService::UNSYNCABLE_PREF); |
162 } | 146 } |
163 | 147 |
164 void CloudPolicySubsystem::UpdatePolicyRefreshRate(int64 refresh_rate) { | 148 void CloudPolicySubsystem::UpdatePolicyRefreshRate(int64 refresh_rate) { |
165 if (cloud_policy_controller_.get()) { | 149 if (cloud_policy_controller_.get()) { |
166 // Clamp to sane values. | 150 // Clamp to sane values. |
167 refresh_rate = std::max(kPolicyRefreshRateMinMs, refresh_rate); | 151 refresh_rate = std::max(kPolicyRefreshRateMinMs, refresh_rate); |
168 refresh_rate = std::min(kPolicyRefreshRateMaxMs, refresh_rate); | 152 refresh_rate = std::min(kPolicyRefreshRateMaxMs, refresh_rate); |
169 cloud_policy_controller_->SetRefreshRate(refresh_rate); | 153 cloud_policy_controller_->SetRefreshRate(refresh_rate); |
170 } | 154 } |
171 } | 155 } |
172 | 156 |
173 void CloudPolicySubsystem::Observe(NotificationType type, | 157 void CloudPolicySubsystem::Observe(NotificationType type, |
174 const NotificationSource& source, | 158 const NotificationSource& source, |
175 const NotificationDetails& details) { | 159 const NotificationDetails& details) { |
176 if (type == NotificationType::PREF_CHANGED) { | 160 if (type == NotificationType::PREF_CHANGED) { |
177 DCHECK_EQ(*(Details<std::string>(details).ptr()), | 161 DCHECK_EQ(*(Details<std::string>(details).ptr()), |
178 std::string(refresh_pref_name_)); | 162 std::string(refresh_pref_name_)); |
179 PrefService* pref_service = Source<PrefService>(source).ptr(); | 163 PrefService* local_state = g_browser_process->local_state(); |
180 // Temporarily also consider the profile preference service as a valid | 164 DCHECK_EQ(Source<PrefService>(source).ptr(), local_state); |
181 // source, since we cannot yet push user cloud policy to |local_state|. | 165 UpdatePolicyRefreshRate(local_state->GetInteger(refresh_pref_name_)); |
182 UpdatePolicyRefreshRate(pref_service->GetInteger(refresh_pref_name_)); | |
183 } else { | 166 } else { |
184 NOTREACHED(); | 167 NOTREACHED(); |
185 } | 168 } |
186 } | 169 } |
187 | 170 |
188 void CloudPolicySubsystem::ScheduleServiceInitialization( | 171 void CloudPolicySubsystem::ScheduleServiceInitialization( |
189 int64 delay_milliseconds) { | 172 int64 delay_milliseconds) { |
190 if (device_management_service_.get()) | 173 if (device_management_service_.get()) |
191 device_management_service_->ScheduleInitialization(delay_milliseconds); | 174 device_management_service_->ScheduleInitialization(delay_milliseconds); |
192 } | 175 } |
(...skipping 15 matching lines...) Expand all Loading... |
208 identity_strategy_, | 191 identity_strategy_, |
209 notifier_.get())); | 192 notifier_.get())); |
210 } | 193 } |
211 | 194 |
212 CloudPolicySubsystem::CloudPolicySubsystem() | 195 CloudPolicySubsystem::CloudPolicySubsystem() |
213 : refresh_pref_name_(NULL), | 196 : refresh_pref_name_(NULL), |
214 identity_strategy_(NULL) { | 197 identity_strategy_(NULL) { |
215 } | 198 } |
216 | 199 |
217 } // namespace policy | 200 } // namespace policy |
OLD | NEW |