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 541b0233a55d8d7fe886d9ce7c25efe6c5c50ca0..4dbc6d292e6f235af573f5326941348856cf9e8d 100644 |
| --- a/chrome/browser/policy/browser_policy_connector.cc |
| +++ b/chrome/browser/policy/browser_policy_connector.cc |
| @@ -21,7 +21,6 @@ |
| #include "chrome/browser/policy/managed_mode_policy_provider.h" |
| #include "chrome/browser/policy/policy_service_impl.h" |
| #include "chrome/browser/policy/policy_statistics_collector.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/profiles/profile.h" |
| @@ -62,7 +61,12 @@ |
| #include "chrome/browser/policy/device_local_account_policy_service.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" |
| +#else |
| +#include "chrome/browser/policy/user_cloud_policy_manager.h" |
| +#include "chrome/browser/policy/user_cloud_policy_manager_factory.h" |
| #endif |
| using content::BrowserThread; |
| @@ -162,7 +166,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. |
| @@ -178,6 +181,9 @@ void BrowserPolicyConnector::Shutdown() { |
| device_cloud_policy_manager_->Shutdown(); |
| if (device_local_account_policy_service_) |
| device_local_account_policy_service_->Shutdown(); |
| + if (user_cloud_policy_manager_) |
| + user_cloud_policy_manager_->Shutdown(); |
| + global_user_cloud_policy_provider_.Shutdown(); |
| #endif |
| // Shutdown user cloud policy. |
| @@ -190,59 +196,22 @@ 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); |
| + ConfigurationPolicyProvider* user_cloud_policy_provider = NULL; |
| +#if !defined(OS_CHROMEOS) |
| + user_cloud_policy_provider = |
| + UserCloudPolicyManagerFactory::GetForProfile(profile); |
| +#endif |
| return CreatePolicyServiceWithProviders( |
| - profile->GetUserCloudPolicyManager(), |
| + user_cloud_policy_provider, |
|
Andrew T Wilson (Slow)
2012/11/23 15:04:20
Just out of curiosity, why are we making UCPM PKS-
Mattias Nissler (ping if slow)
2012/11/23 17:36:06
That'd indeed be the right thing to do. Then again
|
| profile->GetManagedModePolicyProvider()); |
| } |
| 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(); |
| } |
| @@ -353,6 +322,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. |
| @@ -367,16 +342,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()); |
| @@ -572,9 +564,9 @@ void BrowserPolicyConnector::CompleteInitialization() { |
| platform_provider_->Init(); |
| if (cloud_provider_) |
| cloud_provider_->Init(); |
| - user_cloud_policy_provider_.Init(); |
| #if defined(OS_CHROMEOS) |
| + global_user_cloud_policy_provider_.Init(); |
| // Create the AppPackUpdater to start updating the cache. It requires the |
| // system request context, which isn't available in Init(); therefore it is |
| @@ -666,6 +658,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) |