| Index: chrome/browser/policy/profile_policy_connector.cc
|
| diff --git a/chrome/browser/policy/profile_policy_connector.cc b/chrome/browser/policy/profile_policy_connector.cc
|
| index 734a0ab1959f4258f03c5216aa30d11ffda9480f..7dd0dde5e96c3098e2d9d16b9f3f1355951d4e75 100644
|
| --- a/chrome/browser/policy/profile_policy_connector.cc
|
| +++ b/chrome/browser/policy/profile_policy_connector.cc
|
| @@ -6,17 +6,25 @@
|
| #include <string>
|
|
|
| #include "base/command_line.h"
|
| -#include "base/file_util.h"
|
| #include "chrome/browser/browser_process.h"
|
| +#include "chrome/browser/net/gaia/token_service.h"
|
| #include "chrome/browser/policy/browser_policy_connector.h"
|
| #include "chrome/browser/policy/cloud_policy_subsystem.h"
|
| #include "chrome/browser/policy/configuration_policy_pref_store.h"
|
| #include "chrome/browser/policy/profile_policy_connector.h"
|
| #include "chrome/browser/policy/user_policy_cache.h"
|
| +#include "chrome/browser/policy/cloud_policy_cache_base.h"
|
| #include "chrome/browser/policy/user_policy_identity_strategy.h"
|
| #include "chrome/browser/prefs/pref_service.h"
|
| -#include "chrome/browser/profiles/profile.h"
|
| +#include "chrome/common/net/gaia/gaia_constants.h"
|
| #include "chrome/common/chrome_switches.h"
|
| +#include "content/common/notification_details.h"
|
| +#include "content/common/notification_service.h"
|
| +#include "content/common/notification_source.h"
|
| +
|
| +#if defined(OS_CHROMEOS)
|
| +#include "chrome/browser/chromeos/login/user_manager.h"
|
| +#endif
|
|
|
| namespace {
|
|
|
| @@ -28,30 +36,18 @@ const FilePath::CharType kPolicyCacheFile[] = FILE_PATH_LITERAL("Policy");
|
|
|
| namespace policy {
|
|
|
| -ProfilePolicyConnector::ProfilePolicyConnector(Profile* profile)
|
| - : profile_(profile) {
|
| - CommandLine* command_line = CommandLine::ForCurrentProcess();
|
| - if (command_line->HasSwitch(switches::kDeviceManagementUrl)) {
|
| - FilePath policy_cache_dir(profile_->GetPath());
|
| - policy_cache_dir = policy_cache_dir.Append(kPolicyDir);
|
| -
|
| - identity_strategy_.reset(new UserPolicyIdentityStrategy(
|
| - profile_,
|
| - policy_cache_dir.Append(kTokenCacheFile)));
|
| - cloud_policy_subsystem_.reset(new CloudPolicySubsystem(
|
| - identity_strategy_.get(),
|
| - new UserPolicyCache(policy_cache_dir.Append(kPolicyCacheFile))));
|
| -
|
| - BrowserPolicyConnector* browser_connector =
|
| - g_browser_process->browser_policy_connector();
|
| +// static
|
| +ProfilePolicyConnector* ProfilePolicyConnector::Create() {
|
| + return new ProfilePolicyConnector();
|
| +}
|
|
|
| - managed_cloud_provider_.reset(new MergingPolicyProvider(
|
| - browser_connector->GetManagedCloudProvider(),
|
| - cloud_policy_subsystem_->GetManagedPolicyProvider()));
|
| - recommended_cloud_provider_.reset(new MergingPolicyProvider(
|
| - browser_connector->GetRecommendedCloudProvider(),
|
| - cloud_policy_subsystem_->GetRecommendedPolicyProvider()));
|
| - }
|
| +ProfilePolicyConnector::ProfilePolicyConnector() {
|
| + managed_cloud_provider_.reset(new CloudPolicyProvider(
|
| + ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(),
|
| + CloudPolicyCacheBase::POLICY_LEVEL_MANDATORY));
|
| + recommended_cloud_provider_.reset(new CloudPolicyProvider(
|
| + ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(),
|
| + CloudPolicyCacheBase::POLICY_LEVEL_RECOMMENDED));
|
| }
|
|
|
| ProfilePolicyConnector::~ProfilePolicyConnector() {
|
| @@ -61,94 +57,88 @@ ProfilePolicyConnector::~ProfilePolicyConnector() {
|
| identity_strategy_.reset();
|
| }
|
|
|
| -void ProfilePolicyConnector::Initialize() {
|
| - // TODO(jkummerow, mnissler): Move this out of the browser startup path.
|
| - if (identity_strategy_.get())
|
| - identity_strategy_->LoadTokenCache();
|
| - if (cloud_policy_subsystem_.get())
|
| - cloud_policy_subsystem_->Initialize(profile_->GetPrefs());
|
| -}
|
| -
|
| -void ProfilePolicyConnector::Shutdown() {
|
| - if (cloud_policy_subsystem_.get())
|
| - cloud_policy_subsystem_->Shutdown();
|
| -}
|
| -
|
| -ConfigurationPolicyProvider*
|
| - ProfilePolicyConnector::GetManagedCloudProvider() {
|
| - return managed_cloud_provider_.get();
|
| -}
|
| -
|
| -ConfigurationPolicyProvider*
|
| - ProfilePolicyConnector::GetRecommendedCloudProvider() {
|
| - return recommended_cloud_provider_.get();
|
| -}
|
| +void ProfilePolicyConnector::Initialize(std::string& user_name,
|
| + const FilePath& policy_dir,
|
| + TokenService* token_service) {
|
| + // Throw away the old backend.
|
| + cloud_policy_subsystem_.reset();
|
| + identity_strategy_.reset();
|
| + registrar_.RemoveAll();
|
|
|
| -MergingPolicyProvider::MergingPolicyProvider(
|
| - ConfigurationPolicyProvider* browser_policy_provider,
|
| - ConfigurationPolicyProvider* profile_policy_provider)
|
| - : ConfigurationPolicyProvider(
|
| - ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList()),
|
| - browser_policy_provider_(browser_policy_provider),
|
| - profile_policy_provider_(profile_policy_provider),
|
| - browser_registrar_(new ConfigurationPolicyObserverRegistrar()),
|
| - profile_registrar_(new ConfigurationPolicyObserverRegistrar()) {
|
| - if (browser_policy_provider_)
|
| - browser_registrar_->Init(browser_policy_provider_, this);
|
| - if (profile_policy_provider_)
|
| - profile_registrar_->Init(profile_policy_provider_, this);
|
| -}
|
| + CommandLine* command_line = CommandLine::ForCurrentProcess();
|
| + if (command_line->HasSwitch(switches::kDeviceManagementUrl)) {
|
| + token_service_ = token_service;
|
| + registrar_.Add(this,
|
| + NotificationType::TOKEN_AVAILABLE,
|
| + Source<TokenService>(token_service_));
|
| +
|
| + // Register for the event of user login on CrOS to make sure that the user
|
| + // is not changing while the ProfilePolicyConnector is active.
|
| +#if defined(OS_CHROMEOS)
|
| + registrar_.Add(this,
|
| + NotificationType::LOGIN_USER_CHANGED,
|
| + NotificationService::AllSources());
|
| +#endif
|
| + FilePath policy_cache_dir = policy_dir.Append(kPolicyDir);
|
| + UserPolicyCache* user_policy_cache =
|
| + new UserPolicyCache(policy_cache_dir.Append(kPolicyCacheFile));
|
| + managed_cloud_provider_->set_cache(user_policy_cache);
|
| + recommended_cloud_provider_->set_cache(user_policy_cache);
|
| + identity_strategy_.reset(new UserPolicyIdentityStrategy(user_name,
|
| + policy_cache_dir.Append(kTokenCacheFile)));
|
| + cloud_policy_subsystem_.reset(new CloudPolicySubsystem(
|
| + identity_strategy_.get(),
|
| + user_policy_cache));
|
|
|
| -MergingPolicyProvider::~MergingPolicyProvider() {
|
| - if (browser_policy_provider_ || profile_policy_provider_) {
|
| - FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer,
|
| - observer_list_, OnProviderGoingAway());
|
| - }
|
| -}
|
| + // Initiate the DM-Token load.
|
| + identity_strategy_->LoadTokenCache();
|
|
|
| -bool MergingPolicyProvider::Provide(ConfigurationPolicyStoreInterface* store) {
|
| - // First, apply the profile policies and observe if interesting policies
|
| - // have been applied.
|
| - ObservingPolicyStoreInterface observe(store);
|
| - bool rv = true;
|
| - if (profile_policy_provider_)
|
| - rv = profile_policy_provider_->Provide(&observe);
|
| -
|
| - // Now apply policies from the browser provider, if they were not applied
|
| - // by the profile provider.
|
| - // Currently, these include only the proxy settings.
|
| - if (browser_policy_provider_) {
|
| - FilteringPolicyStoreInterface filter(store,
|
| - !observe.IsProxyPolicyApplied());
|
| - rv = rv && browser_policy_provider_->Provide(&filter);
|
| + // In case the token of |token_service_| is already available we set it
|
| + // directly, since there will be no notification for it.
|
| + if (token_service_->HasTokenForService(
|
| + GaiaConstants::kDeviceManagementService)) {
|
| + identity_strategy_->SetAuthToken(
|
| + token_service_->GetTokenForService(
|
| + GaiaConstants::kDeviceManagementService));
|
| + }
|
| +
|
| + // TODO(sfeuz): This already assumes that user policy refresh rate
|
| + // preference lives in local_state. Adapted once the PolicyRefreshRate CL is
|
| + // landed.
|
| + cloud_policy_subsystem_->Initialize(g_browser_process->local_state());
|
| }
|
| -
|
| - return rv;
|
| }
|
|
|
| -void MergingPolicyProvider::AddObserver(
|
| - ConfigurationPolicyProvider::Observer* observer) {
|
| - observer_list_.AddObserver(observer);
|
| -}
|
| -
|
| -void MergingPolicyProvider::RemoveObserver(
|
| - ConfigurationPolicyProvider::Observer* observer) {
|
| - observer_list_.RemoveObserver(observer);
|
| +CloudPolicyProvider*
|
| + ProfilePolicyConnector::GetManagedCloudProvider() const {
|
| + return managed_cloud_provider_.get();
|
| }
|
|
|
| -void MergingPolicyProvider::OnUpdatePolicy() {
|
| - FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer,
|
| - observer_list_, OnUpdatePolicy());
|
| +CloudPolicyProvider*
|
| + ProfilePolicyConnector::GetRecommendedCloudProvider() const {
|
| + return recommended_cloud_provider_.get();
|
| }
|
|
|
| -void MergingPolicyProvider::OnProviderGoingAway() {
|
| - if (browser_policy_provider_ || profile_policy_provider_) {
|
| - FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer,
|
| - observer_list_, OnProviderGoingAway());
|
| - browser_registrar_.reset();
|
| - profile_registrar_.reset();
|
| - browser_policy_provider_ = NULL;
|
| - profile_policy_provider_ = NULL;
|
| +void ProfilePolicyConnector::Observe(NotificationType type,
|
| + const NotificationSource& source,
|
| + const NotificationDetails& details) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| + if (type == NotificationType::TOKEN_AVAILABLE) {
|
| + const TokenService::TokenAvailableDetails* token_details =
|
| + Details<const TokenService::TokenAvailableDetails>(details).ptr();
|
| + if (token_details->service() == GaiaConstants::kDeviceManagementService)
|
| + if (identity_strategy_.get())
|
| + identity_strategy_->SetAuthToken(token_details->token());
|
| +#if defined(OS_CHROMEOS)
|
| + } else if (type == NotificationType::LOGIN_USER_CHANGED) {
|
| + const chromeos::UserManager::User* user_details =
|
| + Details<const chromeos::UserManager::User>(details).ptr();
|
| + std::string current_username, current_auth_token;
|
| + identity_strategy_->GetCredentials(¤t_username, ¤t_auth_token);
|
| + DCHECK_EQ(current_username, user_details->email());
|
| +#endif
|
| + } else {
|
| + NOTREACHED();
|
| }
|
| }
|
|
|
|
|