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

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

Issue 6979011: Move user cloud policy to BrowserProcess. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments by mnissler. 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/browser_policy_connector.h" 5 #include "chrome/browser/policy/browser_policy_connector.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/net/gaia/token_service.h"
11 #include "chrome/browser/policy/cloud_policy_provider.h"
10 #include "chrome/browser/policy/cloud_policy_subsystem.h" 12 #include "chrome/browser/policy/cloud_policy_subsystem.h"
11 #include "chrome/browser/policy/configuration_policy_pref_store.h" 13 #include "chrome/browser/policy/configuration_policy_pref_store.h"
12 #include "chrome/browser/policy/configuration_policy_provider.h" 14 #include "chrome/browser/policy/configuration_policy_provider.h"
13 #include "chrome/browser/policy/dummy_configuration_policy_provider.h" 15 #include "chrome/browser/policy/dummy_configuration_policy_provider.h"
16 #include "chrome/browser/policy/user_policy_cache.h"
17 #include "chrome/browser/policy/user_policy_identity_strategy.h"
14 #include "chrome/common/chrome_paths.h" 18 #include "chrome/common/chrome_paths.h"
15 #include "chrome/common/chrome_switches.h" 19 #include "chrome/common/chrome_switches.h"
20 #include "chrome/common/net/gaia/gaia_constants.h"
16 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
22 #include "content/common/notification_details.h"
23 #include "content/common/notification_source.h"
17 24
18 #if defined(OS_WIN) 25 #if defined(OS_WIN)
19 #include "chrome/browser/policy/configuration_policy_provider_win.h" 26 #include "chrome/browser/policy/configuration_policy_provider_win.h"
20 #elif defined(OS_MACOSX) 27 #elif defined(OS_MACOSX)
21 #include "chrome/browser/policy/configuration_policy_provider_mac.h" 28 #include "chrome/browser/policy/configuration_policy_provider_mac.h"
22 #elif defined(OS_POSIX) 29 #elif defined(OS_POSIX)
23 #include "chrome/browser/policy/config_dir_policy_provider.h" 30 #include "chrome/browser/policy/config_dir_policy_provider.h"
24 #endif 31 #endif
25 32
26 #if defined(OS_CHROMEOS) 33 #if defined(OS_CHROMEOS)
27 #include "chrome/browser/chromeos/cros/cros_library.h" 34 #include "chrome/browser/chromeos/cros/cros_library.h"
28 #include "chrome/browser/policy/device_policy_cache.h" 35 #include "chrome/browser/policy/device_policy_cache.h"
29 #include "chrome/browser/policy/device_policy_identity_strategy.h" 36 #include "chrome/browser/policy/device_policy_identity_strategy.h"
30 #include "chrome/browser/policy/enterprise_install_attributes.h" 37 #include "chrome/browser/policy/enterprise_install_attributes.h"
38 #include "content/common/notification_service.h"
31 #endif 39 #endif
32 40
33 namespace policy { 41 namespace policy {
34 42
35 namespace { 43 namespace {
36 44
45 // The directory suffixes for user cloud policy.
46 const FilePath::CharType kPolicyDir[] = FILE_PATH_LITERAL("Device Management");
47 const FilePath::CharType kTokenCacheFile[] = FILE_PATH_LITERAL("Token");
48 const FilePath::CharType kPolicyCacheFile[] = FILE_PATH_LITERAL("Policy");
49
37 // The following constants define delays applied before the initial policy fetch 50 // The following constants define delays applied before the initial policy fetch
38 // on startup. (So that displaying Chrome's GUI does not get delayed.) 51 // on startup. (So that displaying Chrome's GUI does not get delayed.)
39 // Delay in milliseconds from startup. 52 // Delay in milliseconds from startup.
40 const int64 kServiceInitializationStartupDelay = 5000; 53 const int64 kServiceInitializationStartupDelay = 5000;
41 54
42 } // namespace 55 } // namespace
43 56
44 // static 57 // static
45 BrowserPolicyConnector* BrowserPolicyConnector::Create() { 58 BrowserPolicyConnector* BrowserPolicyConnector::Create() {
46 return new BrowserPolicyConnector(); 59 return new BrowserPolicyConnector();
47 } 60 }
48 61
49 // static 62 // static
50 BrowserPolicyConnector* BrowserPolicyConnector::CreateForTests() { 63 BrowserPolicyConnector* BrowserPolicyConnector::CreateForTests() {
51 const ConfigurationPolicyProvider::PolicyDefinitionList* 64 const ConfigurationPolicyProvider::PolicyDefinitionList*
52 policy_list = ConfigurationPolicyPrefStore:: 65 policy_list = ConfigurationPolicyPrefStore::
53 GetChromePolicyDefinitionList(); 66 GetChromePolicyDefinitionList();
54 return new BrowserPolicyConnector( 67 return new BrowserPolicyConnector(
55 new DummyConfigurationPolicyProvider(policy_list), 68 new policy::DummyConfigurationPolicyProvider(policy_list),
56 new DummyConfigurationPolicyProvider(policy_list)); 69 new policy::DummyConfigurationPolicyProvider(policy_list),
70 new CloudPolicyProvider(
71 policy_list,
72 CloudPolicyCacheBase::POLICY_LEVEL_MANDATORY),
73 new CloudPolicyProvider(
74 policy_list,
75 CloudPolicyCacheBase::POLICY_LEVEL_RECOMMENDED));
57 } 76 }
58 77
59 BrowserPolicyConnector::BrowserPolicyConnector() 78 BrowserPolicyConnector::BrowserPolicyConnector()
60 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { 79 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
61 managed_platform_provider_.reset(CreateManagedPlatformProvider()); 80 managed_platform_provider_.reset(CreateManagedPlatformProvider());
62 recommended_platform_provider_.reset(CreateRecommendedPlatformProvider()); 81 recommended_platform_provider_.reset(CreateRecommendedPlatformProvider());
63 82
83 managed_cloud_provider_.reset(new CloudPolicyProvider(
84 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(),
85 CloudPolicyCacheBase::POLICY_LEVEL_MANDATORY));
86 recommended_cloud_provider_.reset(new CloudPolicyProvider(
87 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(),
88 CloudPolicyCacheBase::POLICY_LEVEL_RECOMMENDED));
89
64 #if defined(OS_CHROMEOS) 90 #if defined(OS_CHROMEOS)
65 CommandLine* command_line = CommandLine::ForCurrentProcess(); 91 InitializeDevicePolicy();
66 if (command_line->HasSwitch(switches::kEnableDevicePolicy)) {
67 identity_strategy_.reset(new DevicePolicyIdentityStrategy());
68 install_attributes_.reset(new EnterpriseInstallAttributes(
69 chromeos::CrosLibrary::Get()->GetCryptohomeLibrary()));
70 cloud_policy_subsystem_.reset(new CloudPolicySubsystem(
71 identity_strategy_.get(),
72 new DevicePolicyCache(identity_strategy_.get(),
73 install_attributes_.get())));
74
75 // Initialize the subsystem once the message loops are spinning.
76 MessageLoop::current()->PostTask(
77 FROM_HERE,
78 method_factory_.NewRunnableMethod(&BrowserPolicyConnector::Initialize));
79 }
80 #endif 92 #endif
81 } 93 }
82 94
83 BrowserPolicyConnector::BrowserPolicyConnector( 95 BrowserPolicyConnector::BrowserPolicyConnector(
84 ConfigurationPolicyProvider* managed_platform_provider, 96 ConfigurationPolicyProvider* managed_platform_provider,
85 ConfigurationPolicyProvider* recommended_platform_provider) 97 ConfigurationPolicyProvider* recommended_platform_provider,
98 CloudPolicyProvider* managed_cloud_provider,
99 CloudPolicyProvider* recommended_cloud_provider)
86 : managed_platform_provider_(managed_platform_provider), 100 : managed_platform_provider_(managed_platform_provider),
87 recommended_platform_provider_(recommended_platform_provider), 101 recommended_platform_provider_(recommended_platform_provider),
102 managed_cloud_provider_(managed_cloud_provider),
103 recommended_cloud_provider_(recommended_cloud_provider),
88 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {} 104 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {}
89 105
90 BrowserPolicyConnector::~BrowserPolicyConnector() { 106 BrowserPolicyConnector::~BrowserPolicyConnector() {
91 if (cloud_policy_subsystem_.get()) 107 // Shutdown device cloud policy.
92 cloud_policy_subsystem_->Shutdown();
93 cloud_policy_subsystem_.reset();
94 #if defined(OS_CHROMEOS) 108 #if defined(OS_CHROMEOS)
95 identity_strategy_.reset(); 109 if (device_cloud_policy_subsystem_.get())
110 device_cloud_policy_subsystem_->Shutdown();
111 device_cloud_policy_subsystem_.reset();
112 device_identity_strategy_.reset();
96 #endif 113 #endif
114
115 // Shutdown user cloud policy.
116 if (user_cloud_policy_subsystem_.get())
117 user_cloud_policy_subsystem_->Shutdown();
118 user_cloud_policy_subsystem_.reset();
119 user_identity_strategy_.reset();
97 } 120 }
98 121
99 ConfigurationPolicyProvider* 122 ConfigurationPolicyProvider*
100 BrowserPolicyConnector::GetManagedPlatformProvider() const { 123 BrowserPolicyConnector::GetManagedPlatformProvider() const {
101 return managed_platform_provider_.get(); 124 return managed_platform_provider_.get();
102 } 125 }
103 126
104 ConfigurationPolicyProvider* 127 ConfigurationPolicyProvider*
105 BrowserPolicyConnector::GetManagedCloudProvider() const { 128 BrowserPolicyConnector::GetManagedCloudProvider() const {
106 if (cloud_policy_subsystem_.get()) 129 return managed_cloud_provider_.get();
107 return cloud_policy_subsystem_->GetManagedPolicyProvider();
108
109 return NULL;
110 } 130 }
111 131
112 ConfigurationPolicyProvider* 132 ConfigurationPolicyProvider*
113 BrowserPolicyConnector::GetRecommendedPlatformProvider() const { 133 BrowserPolicyConnector::GetRecommendedPlatformProvider() const {
114 return recommended_platform_provider_.get(); 134 return recommended_platform_provider_.get();
115 } 135 }
116 136
117 ConfigurationPolicyProvider* 137 ConfigurationPolicyProvider*
118 BrowserPolicyConnector::GetRecommendedCloudProvider() const { 138 BrowserPolicyConnector::GetRecommendedCloudProvider() const {
119 if (cloud_policy_subsystem_.get()) 139 return recommended_cloud_provider_.get();
120 return cloud_policy_subsystem_->GetRecommendedPolicyProvider();
121
122 return NULL;
123 } 140 }
124 141
125 ConfigurationPolicyProvider* 142 ConfigurationPolicyProvider*
126 BrowserPolicyConnector::CreateManagedPlatformProvider() { 143 BrowserPolicyConnector::CreateManagedPlatformProvider() {
127 const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list = 144 const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list =
128 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(); 145 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList();
129 #if defined(OS_WIN) 146 #if defined(OS_WIN)
130 return new ConfigurationPolicyProviderWin(policy_list); 147 return new ConfigurationPolicyProviderWin(policy_list);
131 #elif defined(OS_MACOSX) 148 #elif defined(OS_MACOSX)
132 return new ConfigurationPolicyProviderMac(policy_list); 149 return new ConfigurationPolicyProviderMac(policy_list);
(...skipping 22 matching lines...) Expand all
155 policy_list, 172 policy_list,
156 config_dir_path.Append(FILE_PATH_LITERAL("recommended"))); 173 config_dir_path.Append(FILE_PATH_LITERAL("recommended")));
157 } else { 174 } else {
158 return new DummyConfigurationPolicyProvider(policy_list); 175 return new DummyConfigurationPolicyProvider(policy_list);
159 } 176 }
160 #else 177 #else
161 return new DummyConfigurationPolicyProvider(policy_list); 178 return new DummyConfigurationPolicyProvider(policy_list);
162 #endif 179 #endif
163 } 180 }
164 181
165 void BrowserPolicyConnector::SetCredentials(const std::string& owner_email, 182 void BrowserPolicyConnector::SetDeviceCredentials(
166 const std::string& gaia_token) { 183 const std::string& owner_email,
184 const std::string& gaia_token) {
167 #if defined(OS_CHROMEOS) 185 #if defined(OS_CHROMEOS)
168 if (identity_strategy_.get()) 186 if (device_identity_strategy_.get())
169 identity_strategy_->SetAuthCredentials(owner_email, gaia_token); 187 device_identity_strategy_->SetAuthCredentials(owner_email, gaia_token);
170 #endif 188 #endif
171 } 189 }
172 190
173 bool BrowserPolicyConnector::IsEnterpriseManaged() { 191 bool BrowserPolicyConnector::IsEnterpriseManaged() {
174 #if defined(OS_CHROMEOS) 192 #if defined(OS_CHROMEOS)
175 return install_attributes_.get() && install_attributes_->IsEnterpriseDevice(); 193 return install_attributes_.get() && install_attributes_->IsEnterpriseDevice();
176 #else 194 #else
177 return false; 195 return false;
178 #endif 196 #endif
179 } 197 }
(...skipping 10 matching lines...) Expand all
190 208
191 std::string BrowserPolicyConnector::GetEnterpriseDomain() { 209 std::string BrowserPolicyConnector::GetEnterpriseDomain() {
192 #if defined(OS_CHROMEOS) 210 #if defined(OS_CHROMEOS)
193 if (install_attributes_.get()) 211 if (install_attributes_.get())
194 return install_attributes_->GetDomain(); 212 return install_attributes_->GetDomain();
195 #endif 213 #endif
196 214
197 return std::string(); 215 return std::string();
198 } 216 }
199 217
200 void BrowserPolicyConnector::StopAutoRetry() { 218 void BrowserPolicyConnector::DeviceStopAutoRetry() {
201 if (cloud_policy_subsystem_.get())
202 cloud_policy_subsystem_->StopAutoRetry();
203 }
204
205 void BrowserPolicyConnector::FetchPolicy() {
206 #if defined(OS_CHROMEOS) 219 #if defined(OS_CHROMEOS)
207 if (identity_strategy_.get()) 220 if (device_cloud_policy_subsystem_.get())
208 return identity_strategy_->FetchPolicy(); 221 device_cloud_policy_subsystem_->StopAutoRetry();
209 #endif 222 #endif
210 } 223 }
211 224
212 void BrowserPolicyConnector::Initialize() { 225 void BrowserPolicyConnector::FetchDevicePolicy() {
213 if (cloud_policy_subsystem_.get()) { 226 #if defined(OS_CHROMEOS)
214 cloud_policy_subsystem_->Initialize( 227 if (device_identity_strategy_.get())
215 prefs::kDevicePolicyRefreshRate, 228 return device_identity_strategy_->FetchPolicy();
229 #endif
230 }
231
232 void BrowserPolicyConnector::InitializeUserPolicy(std::string& user_name,
233 const FilePath& policy_dir,
234 TokenService* token_service) {
235 // Throw away the old backend.
236 user_cloud_policy_subsystem_.reset();
237 user_identity_strategy_.reset();
238 registrar_.RemoveAll();
239
240 CommandLine* command_line = CommandLine::ForCurrentProcess();
241 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) {
242 token_service_ = token_service;
243 if (token_service_) {
244 registrar_.Add(this,
245 NotificationType::TOKEN_AVAILABLE,
246 Source<TokenService>(token_service_));
247 }
248
249 FilePath policy_cache_dir = policy_dir.Append(kPolicyDir);
250 UserPolicyCache* user_policy_cache =
251 new UserPolicyCache(policy_cache_dir.Append(kPolicyCacheFile));
252
253 // Prepending user caches meaning they will take precedence of device policy
254 // caches.
255 managed_cloud_provider_->PrependCache(user_policy_cache);
256 recommended_cloud_provider_->PrependCache(user_policy_cache);
257 user_identity_strategy_.reset(
258 new UserPolicyIdentityStrategy(
259 user_name,
260 policy_cache_dir.Append(kTokenCacheFile)));
261 user_cloud_policy_subsystem_.reset(new CloudPolicySubsystem(
262 user_identity_strategy_.get(),
263 user_policy_cache));
264
265 // Initiate the DM-Token load.
266 user_identity_strategy_->LoadTokenCache();
267
268 // In case the token of |token_service_| is already available we set it
269 // directly, since there will be no notification for it.
270 if (token_service_) {
271 if (token_service_->HasTokenForService(
272 GaiaConstants::kDeviceManagementService)) {
273 user_identity_strategy_->SetAuthToken(
274 token_service_->GetTokenForService(
275 GaiaConstants::kDeviceManagementService));
276 }
277 }
278
279 user_cloud_policy_subsystem_->Initialize(
280 prefs::kUserPolicyRefreshRate,
216 kServiceInitializationStartupDelay); 281 kServiceInitializationStartupDelay);
217 } 282 }
218 } 283 }
219 284
220 void BrowserPolicyConnector::ScheduleServiceInitialization( 285 void BrowserPolicyConnector::ScheduleServiceInitialization(
221 int64 delay_milliseconds) { 286 int64 delay_milliseconds) {
222 if (cloud_policy_subsystem_.get()) 287 if (user_cloud_policy_subsystem_.get()) {
223 cloud_policy_subsystem_->ScheduleServiceInitialization(delay_milliseconds); 288 user_cloud_policy_subsystem_->
289 ScheduleServiceInitialization(delay_milliseconds);
290 }
291 #if defined(OS_CHROMEOS)
292 if (device_cloud_policy_subsystem_.get()) {
293 device_cloud_policy_subsystem_->
294 ScheduleServiceInitialization(delay_milliseconds);
295 }
296 #endif
297 }
298
299 void BrowserPolicyConnector::InitializeDevicePolicy() {
300 #if defined(OS_CHROMEOS)
301 // Throw away the old backend.
302 device_cloud_policy_subsystem_.reset();
303 device_identity_strategy_.reset();
304
305 CommandLine* command_line = CommandLine::ForCurrentProcess();
306 if (command_line->HasSwitch(switches::kEnableDevicePolicy)) {
307 device_cloud_policy_subsystem_.reset();
308 device_identity_strategy_.reset();
309
310 device_identity_strategy_.reset(new DevicePolicyIdentityStrategy());
311 install_attributes_.reset(new EnterpriseInstallAttributes(
312 chromeos::CrosLibrary::Get()->GetCryptohomeLibrary()));
313 DevicePolicyCache* device_policy_cache =
314 new DevicePolicyCache(device_identity_strategy_.get(),
315 install_attributes_.get());
316
317 managed_cloud_provider_->AppendCache(device_policy_cache);
318 recommended_cloud_provider_->AppendCache(device_policy_cache);
319
320 device_cloud_policy_subsystem_.reset(new CloudPolicySubsystem(
321 device_identity_strategy_.get(),
322 device_policy_cache));
323
324 // Initialize the subsystem once the message loops are spinning.
325 MessageLoop::current()->PostTask(
326 FROM_HERE,
327 method_factory_.NewRunnableMethod(
328 &BrowserPolicyConnector::InitializeDevicePolicySubsystem));
329 }
330 #endif
331 }
332
333 void BrowserPolicyConnector::InitializeDevicePolicySubsystem() {
334 #if defined(OS_CHROMEOS)
335 if (device_cloud_policy_subsystem_.get()) {
336 device_cloud_policy_subsystem_->Initialize(
337 prefs::kDevicePolicyRefreshRate,
338 kServiceInitializationStartupDelay);
339 }
340 #endif
341 }
342
343 void BrowserPolicyConnector::Observe(NotificationType type,
344 const NotificationSource& source,
345 const NotificationDetails& details) {
346 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
347 if (type == NotificationType::TOKEN_AVAILABLE) {
348 const TokenService* token_source =
349 Source<const TokenService>(source).ptr();
350 DCHECK_EQ(token_service_, token_source);
351 const TokenService::TokenAvailableDetails* token_details =
352 Details<const TokenService::TokenAvailableDetails>(details).ptr();
353 if (token_details->service() == GaiaConstants::kDeviceManagementService) {
354 if (user_identity_strategy_.get()) {
355 user_identity_strategy_->SetAuthToken(token_details->token());
356 }
357 }
358 } else {
359 NOTREACHED();
360 }
224 } 361 }
225 362
226 } // namespace 363 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/policy/browser_policy_connector.h ('k') | chrome/browser/policy/cloud_policy_cache_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698