Chromium Code Reviews| Index: chrome/browser/policy/browser_policy_connector.cc |
| diff --git a/chrome/browser/policy/browser_policy_connector.cc b/chrome/browser/policy/browser_policy_connector.cc |
| index 4c1967b390c738dbc5bfff9b2850052d0443567e..044ddb3ff85ab007237b419ebc905296f0c23eea 100644 |
| --- a/chrome/browser/policy/browser_policy_connector.cc |
| +++ b/chrome/browser/policy/browser_policy_connector.cc |
| @@ -10,10 +10,14 @@ |
| #include "base/file_path.h" |
| #include "base/path_service.h" |
| #include "chrome/browser/browser_process.h" |
| +#include "chrome/browser/policy/cloud_policy_client.h" |
| #include "chrome/browser/policy/cloud_policy_provider.h" |
| +#include "chrome/browser/policy/cloud_policy_service.h" |
| #include "chrome/browser/policy/cloud_policy_subsystem.h" |
| #include "chrome/browser/policy/configuration_policy_provider.h" |
| +#include "chrome/browser/policy/device_management_service.h" |
| #include "chrome/browser/policy/policy_service_impl.h" |
| +#include "chrome/browser/policy/user_cloud_policy_manager.h" |
| #include "chrome/browser/policy/user_policy_cache.h" |
| #include "chrome/browser/policy/user_policy_token_cache.h" |
| #include "chrome/browser/signin/token_service.h" |
| @@ -106,6 +110,12 @@ BrowserPolicyConnector::~BrowserPolicyConnector() { |
| user_policy_token_cache_.reset(); |
| user_data_store_.reset(); |
| + if (user_cloud_policy_manager_.get()) |
| + user_cloud_policy_manager_->Shutdown(); |
| + user_cloud_policy_manager_.reset(); |
| + |
| + device_management_service_.reset(); |
| + |
| // Delete the providers while the |handler_list_| is still valid, since |
| // OnProviderGoingAway() can trigger refreshes at the |
| // ConfigurationPolicyPrefStore. |
| @@ -128,14 +138,19 @@ void BrowserPolicyConnector::Init() { |
| // but for now it just isn't created. |
| CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| if (command_line->HasSwitch(switches::kDeviceManagementUrl)) { |
| - managed_cloud_provider_.reset(new CloudPolicyProvider( |
| - this, |
| - GetChromePolicyDefinitionList(), |
| - POLICY_LEVEL_MANDATORY)); |
| - recommended_cloud_provider_.reset(new CloudPolicyProvider( |
| - this, |
| - GetChromePolicyDefinitionList(), |
| - POLICY_LEVEL_RECOMMENDED)); |
| + device_management_service_.reset( |
| + new DeviceManagementService( |
| + command_line->GetSwitchValueASCII(switches::kDeviceManagementUrl))); |
| + if (!command_line->HasSwitch(switches::kEnableCloudPolicyService)) { |
| + managed_cloud_provider_.reset(new CloudPolicyProvider( |
| + this, |
| + GetChromePolicyDefinitionList(), |
| + POLICY_LEVEL_MANDATORY)); |
| + recommended_cloud_provider_.reset(new CloudPolicyProvider( |
| + this, |
| + GetChromePolicyDefinitionList(), |
| + POLICY_LEVEL_RECOMMENDED)); |
| + } |
| } |
| InitializeDevicePolicy(); |
| @@ -151,7 +166,7 @@ void BrowserPolicyConnector::Init() { |
| } |
| PolicyService* BrowserPolicyConnector::CreatePolicyService( |
| - Profile* profile) const { |
| + Profile* profile) { |
| // |providers| in decreasing order of priority. |
| PolicyServiceImpl::Providers providers; |
| if (managed_platform_provider_.get()) |
| @@ -162,6 +177,9 @@ PolicyService* BrowserPolicyConnector::CreatePolicyService( |
| providers.push_back(recommended_platform_provider_.get()); |
| if (recommended_cloud_provider_.get()) |
| providers.push_back(recommended_cloud_provider_.get()); |
| + if (user_cloud_policy_manager_.get()) |
| + providers.push_back(user_cloud_policy_manager_.get()); |
|
Joao da Silva
2012/06/05 07:21:46
I think this should be removed now that the proxy
Mattias Nissler (ping if slow)
2012/06/05 10:27:21
Yes, for wait_for_policy_fetch to work correctly.
|
| + providers.push_back(&user_cloud_policy_provider_); |
| return new PolicyServiceImpl(providers); |
| } |
| @@ -260,6 +278,8 @@ void BrowserPolicyConnector::FetchCloudPolicy() { |
| void BrowserPolicyConnector::ScheduleServiceInitialization( |
| int64 delay_milliseconds) { |
| + if (device_management_service_.get()) |
| + device_management_service_->ScheduleInitialization(delay_milliseconds); |
| if (user_cloud_policy_subsystem_.get()) { |
| user_cloud_policy_subsystem_-> |
| ScheduleServiceInitialization(delay_milliseconds); |
| @@ -275,6 +295,8 @@ void BrowserPolicyConnector::InitializeUserPolicy( |
| const std::string& user_name, |
| bool wait_for_policy_fetch) { |
| // Throw away the old backend. |
| + user_cloud_policy_manager_.reset(); |
| + |
| user_cloud_policy_subsystem_.reset(); |
| user_policy_token_cache_.reset(); |
| user_data_store_.reset(); |
| @@ -284,51 +306,65 @@ void BrowserPolicyConnector::InitializeUserPolicy( |
| CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| if (command_line->HasSwitch(switches::kDeviceManagementUrl)) { |
| - user_data_store_.reset(CloudPolicyDataStore::CreateForUserPolicies()); |
| + int64 startup_delay = |
| + wait_for_policy_fetch ? 0 : kServiceInitializationStartupDelay; |
| - FilePath profile_dir; |
| - PathService::Get(chrome::DIR_USER_DATA, &profile_dir); |
| + if (command_line->HasSwitch(switches::kEnableCloudPolicyService)) { |
| +#if defined(OS_CHROMEOS) |
| + user_cloud_policy_manager_ = |
| + UserCloudPolicyManager::Create(wait_for_policy_fetch); |
| + user_cloud_policy_manager_->Initialize(g_browser_process->local_state(), |
| + device_management_service_.get(), |
| + GetUserAffiliation(user_name)); |
| + user_cloud_policy_provider_.SetDelegate(user_cloud_policy_manager_.get()); |
| + |
| + device_management_service_->ScheduleInitialization(startup_delay); |
| +#endif |
| + } else { |
| + FilePath profile_dir; |
| + PathService::Get(chrome::DIR_USER_DATA, &profile_dir); |
| #if defined(OS_CHROMEOS) |
| - profile_dir = profile_dir.Append( |
| - command_line->GetSwitchValuePath(switches::kLoginProfile)); |
| + profile_dir = profile_dir.Append( |
| + command_line->GetSwitchValuePath(switches::kLoginProfile)); |
| #endif |
| - const FilePath policy_dir = profile_dir.Append(kPolicyDir); |
| - const FilePath policy_cache_file = policy_dir.Append(kPolicyCacheFile); |
| - const FilePath token_cache_file = policy_dir.Append(kTokenCacheFile); |
| - CloudPolicyCacheBase* user_policy_cache = NULL; |
| + const FilePath policy_dir = profile_dir.Append(kPolicyDir); |
| + const FilePath policy_cache_file = policy_dir.Append(kPolicyCacheFile); |
| + const FilePath token_cache_file = policy_dir.Append(kTokenCacheFile); |
| + CloudPolicyCacheBase* user_policy_cache = NULL; |
| + user_data_store_.reset(CloudPolicyDataStore::CreateForUserPolicies()); |
| #if defined(OS_CHROMEOS) |
| - user_policy_cache = |
| - new CrosUserPolicyCache( |
| - chromeos::DBusThreadManager::Get()->GetSessionManagerClient(), |
| - user_data_store_.get(), |
| - wait_for_policy_fetch, |
| - token_cache_file, |
| - policy_cache_file); |
| + user_policy_cache = |
| + new CrosUserPolicyCache( |
| + chromeos::DBusThreadManager::Get()->GetSessionManagerClient(), |
| + user_data_store_.get(), |
| + wait_for_policy_fetch, |
| + token_cache_file, |
| + policy_cache_file); |
| #else |
| - user_policy_cache = new UserPolicyCache(policy_cache_file, |
| - wait_for_policy_fetch); |
| - user_policy_token_cache_.reset( |
| - new UserPolicyTokenCache(user_data_store_.get(), token_cache_file)); |
| + user_policy_cache = new UserPolicyCache(policy_cache_file, |
| + wait_for_policy_fetch); |
| + user_policy_token_cache_.reset( |
| + new UserPolicyTokenCache(user_data_store_.get(), token_cache_file)); |
| - // Initiate the DM-Token load. |
| - user_policy_token_cache_->Load(); |
| + // Initiate the DM-Token load. |
| + user_policy_token_cache_->Load(); |
| #endif |
| - managed_cloud_provider_->SetUserPolicyCache(user_policy_cache); |
| - recommended_cloud_provider_->SetUserPolicyCache(user_policy_cache); |
| - user_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( |
| - user_data_store_.get(), |
| - user_policy_cache)); |
| + user_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( |
| + user_data_store_.get(), |
| + user_policy_cache)); |
| - user_data_store_->set_user_name(user_name); |
| - user_data_store_->set_user_affiliation(GetUserAffiliation(user_name)); |
| + user_data_store_->set_user_name(user_name); |
| + user_data_store_->set_user_affiliation(GetUserAffiliation(user_name)); |
| - int64 delay = |
| - wait_for_policy_fetch ? 0 : kServiceInitializationStartupDelay; |
| - user_cloud_policy_subsystem_->CompleteInitialization( |
| - prefs::kUserPolicyRefreshRate, |
| - delay); |
| + user_cloud_policy_subsystem_->CompleteInitialization( |
| + prefs::kUserPolicyRefreshRate, |
| + startup_delay); |
| + |
| + managed_cloud_provider_->SetUserPolicyCache(user_policy_cache); |
| + recommended_cloud_provider_->SetUserPolicyCache(user_policy_cache); |
| + } |
| } |
| } |
| @@ -360,6 +396,17 @@ void BrowserPolicyConnector::RegisterForUserPolicy( |
| if (user_data_store_.get()) |
| user_data_store_->SetOAuthToken(oauth_token); |
| } |
| + if (user_cloud_policy_manager_.get()) { |
| + CloudPolicyService* service = |
| + user_cloud_policy_manager_->cloud_policy_service(); |
| + if (service->client() && |
| + !service->client()->is_registered() && |
| + !oauth_token.empty()) { |
| + service->client()->Register(oauth_token); |
| + } else { |
| + user_cloud_policy_manager_->CancelWaitForPolicyFetch(); |
| + } |
| + } |
| } |
| CloudPolicyDataStore* BrowserPolicyConnector::GetDeviceCloudPolicyDataStore() { |
| @@ -439,26 +486,31 @@ void BrowserPolicyConnector::InitializeDevicePolicy() { |
| CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| if (command_line->HasSwitch(switches::kEnableDevicePolicy)) { |
| - device_data_store_.reset(CloudPolicyDataStore::CreateForDevicePolicies()); |
| - chromeos::CryptohomeLibrary* cryptohome = |
| - chromeos::CrosLibrary::Get()->GetCryptohomeLibrary(); |
| - install_attributes_.reset(new EnterpriseInstallAttributes(cryptohome)); |
| - DevicePolicyCache* device_policy_cache = |
| - new DevicePolicyCache(device_data_store_.get(), |
| - install_attributes_.get()); |
| - |
| - managed_cloud_provider_->SetDevicePolicyCache(device_policy_cache); |
| - recommended_cloud_provider_->SetDevicePolicyCache(device_policy_cache); |
| - |
| - device_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( |
| - device_data_store_.get(), |
| - device_policy_cache)); |
| - |
| - // Initialize the subsystem once the message loops are spinning. |
| - MessageLoop::current()->PostTask( |
| - FROM_HERE, |
| - base::Bind(&BrowserPolicyConnector::CompleteInitialization, |
| - weak_ptr_factory_.GetWeakPtr())); |
| + if (command_line->HasSwitch(switches::kEnableCloudPolicyService)) { |
| + // TODO(mnissler): Initialize new-style device policy here once it's |
| + // implemented. |
| + } else { |
| + device_data_store_.reset(CloudPolicyDataStore::CreateForDevicePolicies()); |
| + chromeos::CryptohomeLibrary* cryptohome = |
| + chromeos::CrosLibrary::Get()->GetCryptohomeLibrary(); |
| + install_attributes_.reset(new EnterpriseInstallAttributes(cryptohome)); |
| + DevicePolicyCache* device_policy_cache = |
| + new DevicePolicyCache(device_data_store_.get(), |
| + install_attributes_.get()); |
| + |
| + managed_cloud_provider_->SetDevicePolicyCache(device_policy_cache); |
| + recommended_cloud_provider_->SetDevicePolicyCache(device_policy_cache); |
| + |
| + device_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( |
| + device_data_store_.get(), |
| + device_policy_cache)); |
| + |
| + // Initialize the subsystem once the message loops are spinning. |
| + MessageLoop::current()->PostTask( |
| + FROM_HERE, |
| + base::Bind(&BrowserPolicyConnector::CompleteInitialization, |
| + weak_ptr_factory_.GetWeakPtr())); |
| + } |
| } |
| #endif |
| } |