| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/policy/cloud_policy_provider.h" | 13 #include "chrome/browser/policy/cloud_policy_provider.h" |
| 14 #include "chrome/browser/policy/cloud_policy_provider_impl.h" | |
| 15 #include "chrome/browser/policy/cloud_policy_subsystem.h" | 14 #include "chrome/browser/policy/cloud_policy_subsystem.h" |
| 16 #include "chrome/browser/policy/configuration_policy_provider.h" | 15 #include "chrome/browser/policy/configuration_policy_provider.h" |
| 17 #include "chrome/browser/policy/policy_service_impl.h" | 16 #include "chrome/browser/policy/policy_service_impl.h" |
| 18 #include "chrome/browser/policy/user_policy_cache.h" | 17 #include "chrome/browser/policy/user_policy_cache.h" |
| 19 #include "chrome/browser/policy/user_policy_token_cache.h" | 18 #include "chrome/browser/policy/user_policy_token_cache.h" |
| 20 #include "chrome/browser/signin/token_service.h" | 19 #include "chrome/browser/signin/token_service.h" |
| 21 #include "chrome/common/chrome_notification_types.h" | 20 #include "chrome/common/chrome_notification_types.h" |
| 22 #include "chrome/common/chrome_paths.h" | 21 #include "chrome/common/chrome_paths.h" |
| 23 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
| 24 #include "chrome/common/net/gaia/gaia_constants.h" | 23 #include "chrome/common/net/gaia/gaia_constants.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 user_cloud_policy_subsystem_->Shutdown(); | 103 user_cloud_policy_subsystem_->Shutdown(); |
| 105 user_cloud_policy_subsystem_.reset(); | 104 user_cloud_policy_subsystem_.reset(); |
| 106 user_policy_token_cache_.reset(); | 105 user_policy_token_cache_.reset(); |
| 107 user_data_store_.reset(); | 106 user_data_store_.reset(); |
| 108 } | 107 } |
| 109 | 108 |
| 110 void BrowserPolicyConnector::Init() { | 109 void BrowserPolicyConnector::Init() { |
| 111 managed_platform_provider_.reset(CreateManagedPlatformProvider()); | 110 managed_platform_provider_.reset(CreateManagedPlatformProvider()); |
| 112 recommended_platform_provider_.reset(CreateRecommendedPlatformProvider()); | 111 recommended_platform_provider_.reset(CreateRecommendedPlatformProvider()); |
| 113 | 112 |
| 114 managed_cloud_provider_.reset(new CloudPolicyProviderImpl( | 113 #if defined(OS_CHROMEOS) |
| 115 this, | 114 // The CloudPolicyProvider blocks asynchronous Profile creation until a login |
| 116 GetChromePolicyDefinitionList(), | 115 // is performed. This is used to ensure that the Profile's PrefService sees |
| 117 POLICY_LEVEL_MANDATORY)); | 116 // managed preferences on managed Chrome OS devices. However, this also |
| 118 recommended_cloud_provider_.reset(new CloudPolicyProviderImpl( | 117 // prevents creation of new Profiles in Desktop Chrome. The implementation of |
| 119 this, | 118 // cloud policy on the Desktop requires a refactoring of the cloud provider, |
| 120 GetChromePolicyDefinitionList(), | 119 // but for now it just isn't created. |
| 121 POLICY_LEVEL_RECOMMENDED)); | 120 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 121 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) { |
| 122 managed_cloud_provider_.reset(new CloudPolicyProvider( |
| 123 this, |
| 124 GetChromePolicyDefinitionList(), |
| 125 POLICY_LEVEL_MANDATORY)); |
| 126 recommended_cloud_provider_.reset(new CloudPolicyProvider( |
| 127 this, |
| 128 GetChromePolicyDefinitionList(), |
| 129 POLICY_LEVEL_RECOMMENDED)); |
| 130 } |
| 131 #endif |
| 122 | 132 |
| 123 // |providers| in decreasing order of priority. | 133 // |providers| in decreasing order of priority. |
| 124 PolicyServiceImpl::Providers providers; | 134 PolicyServiceImpl::Providers providers; |
| 125 providers.push_back(managed_platform_provider_.get()); | 135 if (managed_platform_provider_.get()) |
| 126 providers.push_back(managed_cloud_provider_.get()); | 136 providers.push_back(managed_platform_provider_.get()); |
| 127 providers.push_back(recommended_platform_provider_.get()); | 137 if (managed_cloud_provider_.get()) |
| 128 providers.push_back(recommended_cloud_provider_.get()); | 138 providers.push_back(managed_cloud_provider_.get()); |
| 139 if (recommended_platform_provider_.get()) |
| 140 providers.push_back(recommended_platform_provider_.get()); |
| 141 if (recommended_cloud_provider_.get()) |
| 142 providers.push_back(recommended_cloud_provider_.get()); |
| 129 policy_service_.reset(new PolicyServiceImpl(providers)); | 143 policy_service_.reset(new PolicyServiceImpl(providers)); |
| 130 | 144 |
| 131 #if defined(OS_CHROMEOS) | 145 #if defined(OS_CHROMEOS) |
| 132 InitializeDevicePolicy(); | 146 InitializeDevicePolicy(); |
| 133 | 147 |
| 134 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableONCPolicy)) { | 148 if (command_line->HasSwitch(switches::kEnableONCPolicy)) { |
| 135 network_configuration_updater_.reset( | 149 network_configuration_updater_.reset( |
| 136 new NetworkConfigurationUpdater( | 150 new NetworkConfigurationUpdater( |
| 137 managed_cloud_provider_.get(), | 151 managed_cloud_provider_.get(), |
| 138 chromeos::CrosLibrary::Get()->GetNetworkLibrary())); | 152 chromeos::CrosLibrary::Get()->GetNetworkLibrary())); |
| 139 } | 153 } |
| 140 | 154 |
| 141 // Create the AppPackUpdater to start updating the cache. It requires the | 155 // Create the AppPackUpdater to start updating the cache. It requires the |
| 142 // system request context, which isn't available yet; therefore it is | 156 // system request context, which isn't available yet; therefore it is |
| 143 // created only once the loops are running. | 157 // created only once the loops are running. |
| 144 MessageLoop::current()->PostTask( | 158 MessageLoop::current()->PostTask( |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 FilePath policy_cache_dir = policy_dir.Append(kPolicyDir); | 325 FilePath policy_cache_dir = policy_dir.Append(kPolicyDir); |
| 312 | 326 |
| 313 UserPolicyCache* user_policy_cache = | 327 UserPolicyCache* user_policy_cache = |
| 314 new UserPolicyCache(policy_cache_dir.Append(kPolicyCacheFile), | 328 new UserPolicyCache(policy_cache_dir.Append(kPolicyCacheFile), |
| 315 wait_for_policy_fetch); | 329 wait_for_policy_fetch); |
| 316 user_data_store_.reset(CloudPolicyDataStore::CreateForUserPolicies()); | 330 user_data_store_.reset(CloudPolicyDataStore::CreateForUserPolicies()); |
| 317 user_policy_token_cache_.reset( | 331 user_policy_token_cache_.reset( |
| 318 new UserPolicyTokenCache(user_data_store_.get(), | 332 new UserPolicyTokenCache(user_data_store_.get(), |
| 319 policy_cache_dir.Append(kTokenCacheFile))); | 333 policy_cache_dir.Append(kTokenCacheFile))); |
| 320 | 334 |
| 321 // Prepending user caches meaning they will take precedence of device policy | 335 managed_cloud_provider_->SetUserPolicyCache(user_policy_cache); |
| 322 // caches. | 336 recommended_cloud_provider_->SetUserPolicyCache(user_policy_cache); |
| 323 managed_cloud_provider_->PrependCache(user_policy_cache); | |
| 324 recommended_cloud_provider_->PrependCache(user_policy_cache); | |
| 325 user_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( | 337 user_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( |
| 326 user_data_store_.get(), | 338 user_data_store_.get(), |
| 327 user_policy_cache)); | 339 user_policy_cache)); |
| 328 | 340 |
| 329 // Initiate the DM-Token load. | 341 // Initiate the DM-Token load. |
| 330 user_policy_token_cache_->Load(); | 342 user_policy_token_cache_->Load(); |
| 331 | 343 |
| 332 user_data_store_->set_user_name(user_name); | 344 user_data_store_->set_user_name(user_name); |
| 333 user_data_store_->set_user_affiliation(GetUserAffiliation(user_name)); | 345 user_data_store_->set_user_affiliation(GetUserAffiliation(user_name)); |
| 334 | 346 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 460 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 449 if (command_line->HasSwitch(switches::kEnableDevicePolicy)) { | 461 if (command_line->HasSwitch(switches::kEnableDevicePolicy)) { |
| 450 device_data_store_.reset(CloudPolicyDataStore::CreateForDevicePolicies()); | 462 device_data_store_.reset(CloudPolicyDataStore::CreateForDevicePolicies()); |
| 451 chromeos::CryptohomeLibrary* cryptohome = | 463 chromeos::CryptohomeLibrary* cryptohome = |
| 452 chromeos::CrosLibrary::Get()->GetCryptohomeLibrary(); | 464 chromeos::CrosLibrary::Get()->GetCryptohomeLibrary(); |
| 453 install_attributes_.reset(new EnterpriseInstallAttributes(cryptohome)); | 465 install_attributes_.reset(new EnterpriseInstallAttributes(cryptohome)); |
| 454 DevicePolicyCache* device_policy_cache = | 466 DevicePolicyCache* device_policy_cache = |
| 455 new DevicePolicyCache(device_data_store_.get(), | 467 new DevicePolicyCache(device_data_store_.get(), |
| 456 install_attributes_.get()); | 468 install_attributes_.get()); |
| 457 | 469 |
| 458 managed_cloud_provider_->AppendCache(device_policy_cache); | 470 managed_cloud_provider_->SetDevicePolicyCache(device_policy_cache); |
| 459 recommended_cloud_provider_->AppendCache(device_policy_cache); | 471 recommended_cloud_provider_->SetDevicePolicyCache(device_policy_cache); |
| 460 | 472 |
| 461 device_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( | 473 device_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( |
| 462 device_data_store_.get(), | 474 device_data_store_.get(), |
| 463 device_policy_cache)); | 475 device_policy_cache)); |
| 464 | 476 |
| 465 // Initialize the subsystem once the message loops are spinning. | 477 // Initialize the subsystem once the message loops are spinning. |
| 466 MessageLoop::current()->PostTask( | 478 MessageLoop::current()->PostTask( |
| 467 FROM_HERE, | 479 FROM_HERE, |
| 468 base::Bind(&BrowserPolicyConnector::CompleteInitialization, | 480 base::Bind(&BrowserPolicyConnector::CompleteInitialization, |
| 469 weak_ptr_factory_.GetWeakPtr())); | 481 weak_ptr_factory_.GetWeakPtr())); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 config_dir_path.Append(FILE_PATH_LITERAL("recommended"))); | 567 config_dir_path.Append(FILE_PATH_LITERAL("recommended"))); |
| 556 } else { | 568 } else { |
| 557 return NULL; | 569 return NULL; |
| 558 } | 570 } |
| 559 #else | 571 #else |
| 560 return NULL; | 572 return NULL; |
| 561 #endif | 573 #endif |
| 562 } | 574 } |
| 563 | 575 |
| 564 } // namespace policy | 576 } // namespace policy |
| OLD | NEW |