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/browser_policy_connector.h" | 5 #include "chrome/browser/policy/browser_policy_connector.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
225 ScheduleServiceInitialization(delay_milliseconds); | 225 ScheduleServiceInitialization(delay_milliseconds); |
226 } | 226 } |
227 #if defined(OS_CHROMEOS) | 227 #if defined(OS_CHROMEOS) |
228 if (device_cloud_policy_subsystem_.get()) { | 228 if (device_cloud_policy_subsystem_.get()) { |
229 device_cloud_policy_subsystem_-> | 229 device_cloud_policy_subsystem_-> |
230 ScheduleServiceInitialization(delay_milliseconds); | 230 ScheduleServiceInitialization(delay_milliseconds); |
231 } | 231 } |
232 #endif | 232 #endif |
233 } | 233 } |
234 void BrowserPolicyConnector::InitializeUserPolicy( | 234 void BrowserPolicyConnector::InitializeUserPolicy( |
235 const std::string& user_name) { | 235 const std::string& user_name, |
236 bool wait_for_policy_fetch) { | |
236 // Throw away the old backend. | 237 // Throw away the old backend. |
237 user_cloud_policy_subsystem_.reset(); | 238 user_cloud_policy_subsystem_.reset(); |
238 user_policy_token_cache_.reset(); | 239 user_policy_token_cache_.reset(); |
239 user_data_store_.reset(); | 240 user_data_store_.reset(); |
240 token_service_ = NULL; | 241 token_service_ = NULL; |
241 registrar_.RemoveAll(); | 242 registrar_.RemoveAll(); |
242 | 243 |
243 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 244 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
244 | 245 |
245 FilePath policy_dir; | 246 FilePath policy_dir; |
246 PathService::Get(chrome::DIR_USER_DATA, &policy_dir); | 247 PathService::Get(chrome::DIR_USER_DATA, &policy_dir); |
247 #if defined(OS_CHROMEOS) | 248 #if defined(OS_CHROMEOS) |
248 policy_dir = policy_dir.Append( | 249 policy_dir = policy_dir.Append( |
249 command_line->GetSwitchValuePath(switches::kLoginProfile)); | 250 command_line->GetSwitchValuePath(switches::kLoginProfile)); |
250 #endif | 251 #endif |
251 | 252 |
252 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) { | 253 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) { |
253 FilePath policy_cache_dir = policy_dir.Append(kPolicyDir); | 254 FilePath policy_cache_dir = policy_dir.Append(kPolicyDir); |
255 | |
254 UserPolicyCache* user_policy_cache = | 256 UserPolicyCache* user_policy_cache = |
255 new UserPolicyCache(policy_cache_dir.Append(kPolicyCacheFile)); | 257 new UserPolicyCache(policy_cache_dir.Append(kPolicyCacheFile), |
258 wait_for_policy_fetch); | |
256 user_data_store_.reset(CloudPolicyDataStore::CreateForUserPolicies()); | 259 user_data_store_.reset(CloudPolicyDataStore::CreateForUserPolicies()); |
257 user_policy_token_cache_.reset( | 260 user_policy_token_cache_.reset( |
258 new UserPolicyTokenCache(user_data_store_.get(), | 261 new UserPolicyTokenCache(user_data_store_.get(), |
259 policy_cache_dir.Append(kTokenCacheFile))); | 262 policy_cache_dir.Append(kTokenCacheFile))); |
260 | 263 |
261 // Prepending user caches meaning they will take precedence of device policy | 264 // Prepending user caches meaning they will take precedence of device policy |
262 // caches. | 265 // caches. |
263 managed_cloud_provider_->PrependCache(user_policy_cache); | 266 managed_cloud_provider_->PrependCache(user_policy_cache); |
264 recommended_cloud_provider_->PrependCache(user_policy_cache); | 267 recommended_cloud_provider_->PrependCache(user_policy_cache); |
265 user_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( | 268 user_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( |
266 user_data_store_.get(), | 269 user_data_store_.get(), |
267 user_policy_cache)); | 270 user_policy_cache)); |
268 | 271 |
269 // Initiate the DM-Token load. | 272 // Initiate the DM-Token load. |
270 user_policy_token_cache_->Load(); | 273 user_policy_token_cache_->Load(); |
271 | 274 |
272 user_data_store_->set_user_name(user_name); | 275 user_data_store_->set_user_name(user_name); |
273 user_data_store_->set_user_affiliation(GetUserAffiliation(user_name)); | 276 user_data_store_->set_user_affiliation(GetUserAffiliation(user_name)); |
274 | 277 |
278 int64 delay = wait_for_policy_fetch ? 0 | |
279 : kServiceInitializationStartupDelay; | |
Mattias Nissler (ping if slow)
2011/11/11 14:38:50
never seen this style :) I must say I tend to like
Joao da Silva
2011/11/14 15:59:48
I like it too :-) Using a line break after = now.
| |
275 user_cloud_policy_subsystem_->CompleteInitialization( | 280 user_cloud_policy_subsystem_->CompleteInitialization( |
276 prefs::kUserPolicyRefreshRate, | 281 prefs::kUserPolicyRefreshRate, |
277 kServiceInitializationStartupDelay); | 282 delay); |
278 } | 283 } |
279 } | 284 } |
280 | 285 |
281 void BrowserPolicyConnector::SetUserPolicyTokenService( | 286 void BrowserPolicyConnector::SetUserPolicyTokenService( |
282 TokenService* token_service) { | 287 TokenService* token_service) { |
283 token_service_ = token_service; | 288 token_service_ = token_service; |
284 registrar_.Add(this, | 289 registrar_.Add(this, |
285 chrome::NOTIFICATION_TOKEN_AVAILABLE, | 290 chrome::NOTIFICATION_TOKEN_AVAILABLE, |
286 content::Source<TokenService>(token_service_)); | 291 content::Source<TokenService>(token_service_)); |
287 | 292 |
288 if (token_service_->HasTokenForService( | 293 if (token_service_->HasTokenForService( |
289 GaiaConstants::kDeviceManagementService)) { | 294 GaiaConstants::kDeviceManagementService)) { |
290 user_data_store_->SetGaiaToken(token_service_->GetTokenForService( | 295 user_data_store_->SetGaiaToken(token_service_->GetTokenForService( |
291 GaiaConstants::kDeviceManagementService)); | 296 GaiaConstants::kDeviceManagementService)); |
292 } | 297 } |
293 } | 298 } |
294 | 299 |
295 void BrowserPolicyConnector::RegisterForUserPolicy( | 300 void BrowserPolicyConnector::RegisterForUserPolicy( |
296 const std::string& oauth_token) { | 301 const std::string& oauth_token) { |
297 if (user_data_store_.get()) | 302 if (oauth_token.empty()) { |
298 user_data_store_->SetOAuthToken(oauth_token); | 303 // An attempt to fetch the dm service oauth token has failed. Notify |
304 // the user policy cache of this, so that a potential blocked login | |
305 // proceeds without waiting for user policy. | |
306 if (user_cloud_policy_subsystem_.get()) { | |
307 user_cloud_policy_subsystem_->GetCloudPolicyCacheBase()-> | |
308 SetFetchingDone(); | |
309 } | |
310 } else { | |
311 if (user_data_store_.get()) | |
312 user_data_store_->SetOAuthToken(oauth_token); | |
313 } | |
299 } | 314 } |
300 | 315 |
301 const CloudPolicyDataStore* | 316 const CloudPolicyDataStore* |
302 BrowserPolicyConnector::GetDeviceCloudPolicyDataStore() const { | 317 BrowserPolicyConnector::GetDeviceCloudPolicyDataStore() const { |
303 #if defined(OS_CHROMEOS) | 318 #if defined(OS_CHROMEOS) |
304 return device_data_store_.get(); | 319 return device_data_store_.get(); |
305 #else | 320 #else |
306 return NULL; | 321 return NULL; |
307 #endif | 322 #endif |
308 } | 323 } |
309 | 324 |
310 const CloudPolicyDataStore* | 325 const CloudPolicyDataStore* |
311 BrowserPolicyConnector::GetUserCloudPolicyDataStore() const { | 326 BrowserPolicyConnector::GetUserCloudPolicyDataStore() const { |
312 return user_data_store_.get(); | 327 return user_data_store_.get(); |
313 } | 328 } |
314 | 329 |
315 const ConfigurationPolicyHandlerList* | 330 const ConfigurationPolicyHandlerList* |
316 BrowserPolicyConnector::GetHandlerList() const { | 331 BrowserPolicyConnector::GetHandlerList() const { |
317 return &handler_list_; | 332 return &handler_list_; |
318 } | 333 } |
319 | 334 |
335 CloudPolicyDataStore::UserAffiliation | |
336 BrowserPolicyConnector::GetUserAffiliation(const std::string& user_name) { | |
337 #if defined(OS_CHROMEOS) | |
338 if (install_attributes_.get()) { | |
339 size_t pos = user_name.find('@'); | |
340 if (pos != std::string::npos && | |
341 user_name.substr(pos + 1) == install_attributes_->GetDomain()) { | |
342 return CloudPolicyDataStore::USER_AFFILIATION_MANAGED; | |
343 } | |
344 } | |
345 #endif | |
346 | |
347 return CloudPolicyDataStore::USER_AFFILIATION_NONE; | |
348 } | |
349 | |
320 BrowserPolicyConnector::BrowserPolicyConnector() | 350 BrowserPolicyConnector::BrowserPolicyConnector() |
321 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 351 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
322 managed_platform_provider_.reset(CreateManagedPlatformProvider()); | 352 managed_platform_provider_.reset(CreateManagedPlatformProvider()); |
323 recommended_platform_provider_.reset(CreateRecommendedPlatformProvider()); | 353 recommended_platform_provider_.reset(CreateRecommendedPlatformProvider()); |
324 | 354 |
325 managed_cloud_provider_.reset(new CloudPolicyProviderImpl( | 355 managed_cloud_provider_.reset(new CloudPolicyProviderImpl( |
326 GetChromePolicyDefinitionList(), | 356 GetChromePolicyDefinitionList(), |
327 CloudPolicyCacheBase::POLICY_LEVEL_MANDATORY)); | 357 CloudPolicyCacheBase::POLICY_LEVEL_MANDATORY)); |
328 recommended_cloud_provider_.reset(new CloudPolicyProviderImpl( | 358 recommended_cloud_provider_.reset(new CloudPolicyProviderImpl( |
329 GetChromePolicyDefinitionList(), | 359 GetChromePolicyDefinitionList(), |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
409 void BrowserPolicyConnector::InitializeDevicePolicySubsystem() { | 439 void BrowserPolicyConnector::InitializeDevicePolicySubsystem() { |
410 #if defined(OS_CHROMEOS) | 440 #if defined(OS_CHROMEOS) |
411 if (device_cloud_policy_subsystem_.get()) { | 441 if (device_cloud_policy_subsystem_.get()) { |
412 device_cloud_policy_subsystem_->CompleteInitialization( | 442 device_cloud_policy_subsystem_->CompleteInitialization( |
413 prefs::kDevicePolicyRefreshRate, | 443 prefs::kDevicePolicyRefreshRate, |
414 kServiceInitializationStartupDelay); | 444 kServiceInitializationStartupDelay); |
415 } | 445 } |
416 #endif | 446 #endif |
417 } | 447 } |
418 | 448 |
419 CloudPolicyDataStore::UserAffiliation | |
420 BrowserPolicyConnector::GetUserAffiliation(const std::string& user_name) { | |
421 #if defined(OS_CHROMEOS) | |
422 if (install_attributes_.get()) { | |
423 size_t pos = user_name.find('@'); | |
424 if (pos != std::string::npos && | |
425 user_name.substr(pos + 1) == install_attributes_->GetDomain()) { | |
426 return CloudPolicyDataStore::USER_AFFILIATION_MANAGED; | |
427 } | |
428 } | |
429 #endif | |
430 | |
431 return CloudPolicyDataStore::USER_AFFILIATION_NONE; | |
432 } | |
433 | |
434 // static | 449 // static |
435 BrowserPolicyConnector* BrowserPolicyConnector::CreateForTests() { | 450 BrowserPolicyConnector* BrowserPolicyConnector::CreateForTests() { |
436 return new BrowserPolicyConnector(NULL, NULL, NULL, NULL); | 451 return new BrowserPolicyConnector(NULL, NULL, NULL, NULL); |
437 } | 452 } |
438 | 453 |
439 // static | 454 // static |
440 ConfigurationPolicyProvider* | 455 ConfigurationPolicyProvider* |
441 BrowserPolicyConnector::CreateManagedPlatformProvider() { | 456 BrowserPolicyConnector::CreateManagedPlatformProvider() { |
442 const PolicyDefinitionList* policy_list = GetChromePolicyDefinitionList(); | 457 const PolicyDefinitionList* policy_list = GetChromePolicyDefinitionList(); |
443 #if defined(OS_WIN) | 458 #if defined(OS_WIN) |
(...skipping 26 matching lines...) Expand all Loading... | |
470 config_dir_path.Append(FILE_PATH_LITERAL("recommended"))); | 485 config_dir_path.Append(FILE_PATH_LITERAL("recommended"))); |
471 } else { | 486 } else { |
472 return NULL; | 487 return NULL; |
473 } | 488 } |
474 #else | 489 #else |
475 return NULL; | 490 return NULL; |
476 #endif | 491 #endif |
477 } | 492 } |
478 | 493 |
479 } // namespace policy | 494 } // namespace policy |
OLD | NEW |