| Index: chrome/browser/policy/profile_policy_context.cc
|
| diff --git a/chrome/browser/policy/profile_policy_context.cc b/chrome/browser/policy/profile_policy_context.cc
|
| index 7adffd3e8c562d46b44e42967003df0bc8ebee5c..aad608efa6018fd711c6384bd10edd0e1c820a98 100644
|
| --- a/chrome/browser/policy/profile_policy_context.cc
|
| +++ b/chrome/browser/policy/profile_policy_context.cc
|
| @@ -3,15 +3,14 @@
|
| // found in the LICENSE file.
|
|
|
| #include "base/command_line.h"
|
| -#include "chrome/browser/policy/configuration_policy_pref_store.h"
|
| -#include "chrome/browser/policy/device_management_policy_provider.h"
|
| -#include "chrome/browser/policy/device_management_service.h"
|
| +#include "base/file_util.h"
|
| +#include "chrome/browser/policy/cloud_policy_context.h"
|
| #include "chrome/browser/policy/profile_policy_context.h"
|
| +#include "chrome/browser/policy/user_policy_controller.h"
|
| #include "chrome/browser/prefs/pref_service.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| #include "chrome/common/chrome_switches.h"
|
| -#include "chrome/common/notification_details.h"
|
| -#include "chrome/common/notification_source.h"
|
| +#include "chrome/common/net/url_request_context_getter.h"
|
| #include "chrome/common/pref_names.h"
|
|
|
| namespace {
|
| @@ -20,74 +19,81 @@ namespace {
|
| const int64 kPolicyRefreshRateMinMs = 30 * 60 * 1000; // 30 minutes
|
| const int64 kPolicyRefreshRateMaxMs = 24 * 60 * 60 * 1000; // 1 day
|
|
|
| +const FilePath::CharType kPolicyDir[] = FILE_PATH_LITERAL("Device Management");
|
| +const FilePath::CharType kTokenCacheFile[] = FILE_PATH_LITERAL("Token");
|
| +const FilePath::CharType kPolicyCacheFile[] = FILE_PATH_LITERAL("Policy");
|
| +
|
| }
|
|
|
| namespace policy {
|
|
|
| ProfilePolicyContext::ProfilePolicyContext(Profile* profile)
|
| : profile_(profile) {
|
| + // TODO(mnissler): We access the file system here. The cloud policy context
|
| + // below needs to do so anyway, since it needs to read the policy cache from
|
| + // disk. If this proves to be a problem, we need to do this initialization
|
| + // asynchronously on the file thread and put in synchronization that allows us
|
| + // to wait for the cache to be read during the browser startup code paths.
|
| + // Another option would be to provide a generic IO-safe initializer called
|
| + // from the PrefService that we could hook up with through the policy
|
| + // provider.
|
| CommandLine* command_line = CommandLine::ForCurrentProcess();
|
| if (command_line->HasSwitch(switches::kDeviceManagementUrl)) {
|
| - device_management_service_.reset(new DeviceManagementService(
|
| - command_line->GetSwitchValueASCII(switches::kDeviceManagementUrl)));
|
| - device_management_policy_provider_.reset(
|
| - new policy::DeviceManagementPolicyProvider(
|
| - ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(),
|
| - device_management_service_->CreateBackend(),
|
| - profile_));
|
| + FilePath policy_cache_dir(profile_->GetPath());
|
| + policy_cache_dir = policy_cache_dir.Append(kPolicyDir);
|
| + if (!file_util::CreateDirectory(policy_cache_dir)) {
|
| + LOG(WARNING) << "Failed to create policy state dir "
|
| + << policy_cache_dir.value()
|
| + << ", skipping cloud policy initialization.";
|
| + return;
|
| + }
|
| +
|
| + controller_.reset(
|
| + new UserPolicyController(profile_,
|
| + policy_cache_dir.Append(kTokenCacheFile)));
|
| + cloud_context_.reset(
|
| + new CloudPolicyContext(policy_cache_dir.Append(kPolicyCacheFile),
|
| + controller_.get()));
|
| }
|
| }
|
|
|
| ProfilePolicyContext::~ProfilePolicyContext() {
|
| - device_management_policy_provider_.reset();
|
| - device_management_service_.reset();
|
| + cloud_context_.reset();
|
| + controller_.reset();
|
| }
|
|
|
| void ProfilePolicyContext::Initialize() {
|
| - if (device_management_service_.get())
|
| - device_management_service_->Initialize(profile_->GetRequestContext());
|
| -
|
| - policy_refresh_rate_.Init(prefs::kPolicyRefreshRate, profile_->GetPrefs(),
|
| - this);
|
| - UpdatePolicyRefreshRate();
|
| + if (cloud_context_.get()) {
|
| + cloud_context_->Initialize(profile_->GetPrefs(),
|
| + prefs::kPolicyUserPolicyRefreshRate,
|
| + profile_->GetRequestContext());
|
| + }
|
| }
|
|
|
| void ProfilePolicyContext::Shutdown() {
|
| - if (device_management_service_.get())
|
| - device_management_service_->Shutdown();
|
| + if (cloud_context_.get())
|
| + cloud_context_->Shutdown();
|
| }
|
|
|
| -DeviceManagementPolicyProvider*
|
| -ProfilePolicyContext::GetDeviceManagementPolicyProvider() {
|
| - return device_management_policy_provider_.get();
|
| -}
|
| +ConfigurationPolicyProvider* ProfilePolicyContext::GetManagedPolicyProvider() {
|
| + if (cloud_context_.get())
|
| + return cloud_context_->GetManagedPolicyProvider();
|
|
|
| -// static
|
| -void ProfilePolicyContext::RegisterUserPrefs(PrefService* user_prefs) {
|
| - user_prefs->RegisterIntegerPref(prefs::kPolicyRefreshRate,
|
| - kDefaultPolicyRefreshRateInMilliseconds);
|
| + return NULL;
|
| }
|
|
|
| -void ProfilePolicyContext::UpdatePolicyRefreshRate() {
|
| - if (device_management_policy_provider_.get()) {
|
| - // Clamp to sane values.
|
| - int64 refresh_rate = policy_refresh_rate_.GetValue();
|
| - refresh_rate = std::max(kPolicyRefreshRateMinMs, refresh_rate);
|
| - refresh_rate = std::min(kPolicyRefreshRateMaxMs, refresh_rate);
|
| - device_management_policy_provider_->SetRefreshRate(refresh_rate);
|
| - }
|
| +ConfigurationPolicyProvider*
|
| + ProfilePolicyContext::GetRecommendedPolicyProvider() {
|
| + if (cloud_context_.get())
|
| + return cloud_context_->GetRecommendedPolicyProvider();
|
| +
|
| + return NULL;
|
| }
|
|
|
| -void ProfilePolicyContext::Observe(NotificationType type,
|
| - const NotificationSource& source,
|
| - const NotificationDetails& details) {
|
| - if (type == NotificationType::PREF_CHANGED &&
|
| - prefs::kPolicyRefreshRate == *(Details<std::string>(details).ptr()) &&
|
| - profile_->GetPrefs() == Source<PrefService>(source).ptr()) {
|
| - UpdatePolicyRefreshRate();
|
| - } else {
|
| - NOTREACHED();
|
| - }
|
| +// static
|
| +void ProfilePolicyContext::RegisterPrefs(PrefService* user_prefs) {
|
| + user_prefs->RegisterIntegerPref(prefs::kPolicyUserPolicyRefreshRate,
|
| + kDefaultPolicyRefreshRateInMilliseconds);
|
| }
|
|
|
| } // namespace policy
|
|
|