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 1ea5041bf4f6c576cba90c6312999fa5c25b93b6..a54203f552e2cdc8813635cd09ec51b7afb8ac0d 100644 |
| --- a/chrome/browser/policy/browser_policy_connector.cc |
| +++ b/chrome/browser/policy/browser_policy_connector.cc |
| @@ -61,6 +61,8 @@ |
| #include "chrome/browser/policy/device_cloud_policy_store_chromeos.h" |
| #include "chrome/browser/policy/device_policy_cache.h" |
| #include "chrome/browser/policy/network_configuration_updater.h" |
| +#include "chrome/browser/policy/user_cloud_policy_manager_chromeos.h" |
| +#include "chrome/browser/policy/user_cloud_policy_store_chromeos.h" |
| #include "chromeos/dbus/dbus_thread_manager.h" |
| #endif |
| @@ -157,7 +159,6 @@ void BrowserPolicyConnector::Shutdown() { |
| // policy subsystems, which own the caches that |cloud_provider_| uses. |
| if (cloud_provider_) |
| cloud_provider_->Shutdown(); |
| - user_cloud_policy_provider_.Shutdown(); |
| #if defined(OS_CHROMEOS) |
| // Shutdown device cloud policy. |
| @@ -171,6 +172,9 @@ void BrowserPolicyConnector::Shutdown() { |
| if (device_cloud_policy_manager_) |
| device_cloud_policy_manager_->Shutdown(); |
| + if (user_cloud_policy_manager_) |
| + user_cloud_policy_manager_->Shutdown(); |
| + global_user_cloud_policy_provider_.Shutdown(); |
| #endif |
| // Shutdown user cloud policy. |
| @@ -183,46 +187,6 @@ void BrowserPolicyConnector::Shutdown() { |
| device_management_service_.reset(); |
| } |
| -scoped_ptr<UserCloudPolicyManager> |
| - BrowserPolicyConnector::CreateCloudPolicyManager( |
| - Profile* profile, |
| - bool force_immediate_policy_load) { |
| - scoped_ptr<UserCloudPolicyManager> manager; |
| - const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| - if (command_line->HasSwitch(switches::kEnableCloudPolicyService)) { |
| - UserCloudPolicyManager::PolicyInit policy_init = |
| - UserCloudPolicyManager::POLICY_INIT_IN_BACKGROUND; |
| -#if defined(OS_CHROMEOS) |
| - // TODO(mnissler): Revisit once Chrome OS gains multi-profiles support. |
| - // Don't wait for a policy fetch if there's no logged in user. |
| - if (chromeos::UserManager::Get()->IsUserLoggedIn()) { |
| - std::string email = |
| - chromeos::UserManager::Get()->GetLoggedInUser()->email(); |
| - if (GetUserAffiliation(email) == USER_AFFILIATION_MANAGED) |
| - policy_init = UserCloudPolicyManager::POLICY_INIT_REFRESH_FROM_SERVER; |
| - } |
| -#else |
| - // On desktop, there's no way to figure out if a user is logged in yet |
| - // because prefs are not yet initialized, and further there's no way to know |
| - // if the user is managed. So this code does not request a policy refresh |
| - // from the server because that would inhibit startup for non-signed-in |
| - // users. This code relies on the fact that a signed-in profile should |
| - // already have policy downloaded. If no policy is available |
| - // (due to a previous fetch failing), the normal policy refresh mechanism |
| - // will cause it to get downloaded eventually. |
| - if (force_immediate_policy_load) { |
| - // On desktop, profile creation on startup requires that policies get |
| - // loaded immediately (the normal asynchronous policy initialization |
| - // does not happen because services are initialized before the |
| - // MessageLoop runs). So load policy immediately if desired. |
| - policy_init = UserCloudPolicyManager::POLICY_INIT_IMMEDIATELY; |
| - } |
| -#endif |
| - manager = UserCloudPolicyManager::Create(profile, policy_init); |
| - } |
| - return manager.Pass(); |
| -} |
| - |
| scoped_ptr<PolicyService> BrowserPolicyConnector::CreatePolicyService( |
| Profile* profile) { |
| DCHECK(profile); |
| @@ -232,10 +196,8 @@ scoped_ptr<PolicyService> BrowserPolicyConnector::CreatePolicyService( |
| } |
| PolicyService* BrowserPolicyConnector::GetPolicyService() { |
| - if (!policy_service_) { |
| - policy_service_ = |
| - CreatePolicyServiceWithProviders(&user_cloud_policy_provider_, NULL); |
| - } |
| + if (!policy_service_) |
| + policy_service_ = CreatePolicyServiceWithProviders(NULL, NULL); |
| return policy_service_.get(); |
| } |
| @@ -346,6 +308,12 @@ void BrowserPolicyConnector::InitializeUserPolicy( |
| // and before user policy is loaded. |
| GetNetworkConfigurationUpdater()->set_allow_web_trust( |
| GetUserAffiliation(user_name) == USER_AFFILIATION_MANAGED); |
| + |
| + if (user_cloud_policy_manager_.get()) { |
| + global_user_cloud_policy_provider_.SetDelegate(NULL); |
| + user_cloud_policy_manager_->Shutdown(); |
| + user_cloud_policy_manager_.reset(); |
| + } |
| #endif |
| // Throw away the old backend. |
| @@ -360,16 +328,33 @@ void BrowserPolicyConnector::InitializeUserPolicy( |
| int64 startup_delay = |
| wait_for_policy_fetch ? 0 : kServiceInitializationStartupDelay; |
| - if (!command_line->HasSwitch(switches::kEnableCloudPolicyService)) { |
| - FilePath profile_dir; |
| - PathService::Get(chrome::DIR_USER_DATA, &profile_dir); |
| + 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); |
| + 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); |
| + |
| + if (command_line->HasSwitch(switches::kEnableCloudPolicyService)) { |
| +#if defined(OS_CHROMEOS) |
| + scoped_ptr<CloudPolicyStore> store( |
| + new UserCloudPolicyStoreChromeOS( |
| + chromeos::DBusThreadManager::Get()->GetSessionManagerClient(), |
| + policy_cache_file, token_cache_file)); |
| + user_cloud_policy_manager_.reset( |
| + new UserCloudPolicyManagerChromeOS(store.Pass(), |
| + wait_for_policy_fetch)); |
| + user_cloud_policy_manager_->Init(); |
| + user_cloud_policy_manager_->Initialize(g_browser_process->local_state(), |
| + device_management_service_.get(), |
| + GetUserAffiliation(user_name)); |
| + global_user_cloud_policy_provider_.SetDelegate( |
| + user_cloud_policy_manager_.get()); |
| +#endif |
| + } else { |
| CloudPolicyCacheBase* user_policy_cache = NULL; |
| user_data_store_.reset(CloudPolicyDataStore::CreateForUserPolicies()); |
| @@ -565,7 +550,6 @@ void BrowserPolicyConnector::CompleteInitialization() { |
| platform_provider_->Init(); |
| if (cloud_provider_) |
| cloud_provider_->Init(); |
| - user_cloud_policy_provider_.Init(); |
| #if defined(OS_CHROMEOS) |
|
Joao da Silva
2012/11/21 17:06:34
global_user_cloud_policy_provider_.Init()
Mattias Nissler (ping if slow)
2012/11/22 20:51:59
Done, good catch.
|
| @@ -654,6 +638,8 @@ scoped_ptr<PolicyService> |
| #if defined(OS_CHROMEOS) |
| if (device_cloud_policy_manager_.get()) |
| providers.push_back(device_cloud_policy_manager_.get()); |
| + if (!user_cloud_policy_provider) |
| + user_cloud_policy_provider = &global_user_cloud_policy_provider_; |
| #endif |
| if (user_cloud_policy_provider) |