diff options
author | joaodasilva@chromium.org <joaodasilva@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-12 21:38:53 +0000 |
---|---|---|
committer | joaodasilva@chromium.org <joaodasilva@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-12 21:38:53 +0000 |
commit | 9fedf4f8e0a23359b4fde38ce1f11e2f2968ffdc (patch) | |
tree | 9fc91158287e1b17ff0168254bf2dfccb185c693 | |
parent | ef686fc356849fb7cf464ceeff12e440321877b2 (diff) | |
download | chromium_src-9fedf4f8e0a23359b4fde38ce1f11e2f2968ffdc.zip chromium_src-9fedf4f8e0a23359b4fde38ce1f11e2f2968ffdc.tar.gz chromium_src-9fedf4f8e0a23359b4fde38ce1f11e2f2968ffdc.tar.bz2 |
Refactored ConfigurationPolicyPrefStore to not depend on chrome/.
Some of the chrome/browser/policy code will be moved to a new layered component.
This change prepares the ConfigurationPolicyPrefStore class for the move, by
removing its dependency on g_browser_process and BrowserThread.
BUG=271392
Review URL: https://chromiumcodereview.appspot.com/22812002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@217084 0039d316-1c4b-4281-b951-d872f2087c98
6 files changed, 53 insertions, 59 deletions
diff --git a/chrome/browser/policy/DEPS b/chrome/browser/policy/DEPS index 245cd81..de734d3 100644 --- a/chrome/browser/policy/DEPS +++ b/chrome/browser/policy/DEPS @@ -80,11 +80,6 @@ specific_include_rules = { "+chrome/common/pref_names.h", ], - r"configuration_policy_pref_store\.cc": [ - "+chrome/browser/browser_process.h", - "+content/public/browser/browser_thread.h", - ], - r"configuration_policy_pref_store_unittest\.cc": [ "+chrome/browser/prefs/incognito_mode_prefs.h", "+chrome/browser/prefs/proxy_config_dictionary.h", diff --git a/chrome/browser/policy/configuration_policy_pref_store.cc b/chrome/browser/policy/configuration_policy_pref_store.cc index 8b7d10a..63ca6a9 100644 --- a/chrome/browser/policy/configuration_policy_pref_store.cc +++ b/chrome/browser/policy/configuration_policy_pref_store.cc @@ -9,18 +9,14 @@ #include "base/bind.h" #include "base/logging.h" +#include "base/message_loop/message_loop.h" #include "base/prefs/pref_value_map.h" #include "base/strings/string16.h" #include "base/strings/utf_string_conversions.h" -#include "chrome/browser/browser_process.h" -#include "chrome/browser/policy/browser_policy_connector.h" #include "chrome/browser/policy/configuration_policy_handler_list.h" #include "chrome/browser/policy/policy_error_map.h" -#include "content/public/browser/browser_thread.h" #include "policy/policy_constants.h" -using content::BrowserThread; - namespace policy { namespace { @@ -40,8 +36,10 @@ void LogErrors(PolicyErrorMap* errors) { ConfigurationPolicyPrefStore::ConfigurationPolicyPrefStore( PolicyService* service, + const ConfigurationPolicyHandlerList* handler_list, PolicyLevel level) : policy_service_(service), + handler_list_(handler_list), level_(level) { // Read initial policy. prefs_.reset(CreatePreferencesFromPolicies()); @@ -93,22 +91,6 @@ void ConfigurationPolicyPrefStore::OnPolicyServiceInitialized( } } -// static -ConfigurationPolicyPrefStore* -ConfigurationPolicyPrefStore::CreateMandatoryPolicyPrefStore( - PolicyService* policy_service) { - return new ConfigurationPolicyPrefStore(policy_service, - POLICY_LEVEL_MANDATORY); -} - -// static -ConfigurationPolicyPrefStore* -ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore( - PolicyService* policy_service) { - return new ConfigurationPolicyPrefStore(policy_service, - POLICY_LEVEL_RECOMMENDED); -} - ConfigurationPolicyPrefStore::~ConfigurationPolicyPrefStore() { policy_service_->RemoveObserver(POLICY_DOMAIN_CHROME, this); } @@ -137,18 +119,14 @@ PrefValueMap* ConfigurationPolicyPrefStore::CreatePreferencesFromPolicies() { scoped_ptr<PolicyErrorMap> errors(new PolicyErrorMap); - const ConfigurationPolicyHandlerList* handler_list = - g_browser_process->browser_policy_connector()->GetHandlerList(); - handler_list->ApplyPolicySettings(filtered_policies, - prefs.get(), - errors.get()); + handler_list_->ApplyPolicySettings(filtered_policies, + prefs.get(), + errors.get()); // Retrieve and log the errors once the UI loop is ready. This is only an // issue during startup. - BrowserThread::PostTask(BrowserThread::UI, - FROM_HERE, - base::Bind(&LogErrors, - base::Owned(errors.release()))); + base::MessageLoop::current()->PostTask( + FROM_HERE, base::Bind(&LogErrors, base::Owned(errors.release()))); return prefs.release(); } diff --git a/chrome/browser/policy/configuration_policy_pref_store.h b/chrome/browser/policy/configuration_policy_pref_store.h index a3e5397..62a6850 100644 --- a/chrome/browser/policy/configuration_policy_pref_store.h +++ b/chrome/browser/policy/configuration_policy_pref_store.h @@ -14,11 +14,14 @@ #include "base/values.h" #include "chrome/browser/policy/policy_map.h" #include "chrome/browser/policy/policy_service.h" +#include "chrome/browser/policy/policy_types.h" class PrefValueMap; namespace policy { +class ConfigurationPolicyHandlerList; + // An implementation of PrefStore that bridges policy settings as read from the // PolicyService to preferences. Converts POLICY_DOMAIN_CHROME policies a given // PolicyLevel to their corresponding preferences. @@ -26,9 +29,12 @@ class ConfigurationPolicyPrefStore : public PrefStore, public PolicyService::Observer { public: - // Does not take ownership of |service|. Only policies of the given |level| - // will be mapped. - ConfigurationPolicyPrefStore(PolicyService* service, PolicyLevel level); + // Does not take ownership of |service| nor |handler_list|, which must outlive + // the store. Only policies of the given |level| will be mapped. + ConfigurationPolicyPrefStore( + PolicyService* service, + const ConfigurationPolicyHandlerList* handler_list, + PolicyLevel level); // PrefStore methods: virtual void AddObserver(PrefStore::Observer* observer) OVERRIDE; @@ -44,16 +50,6 @@ class ConfigurationPolicyPrefStore const PolicyMap& current) OVERRIDE; virtual void OnPolicyServiceInitialized(PolicyDomain domain) OVERRIDE; - // Creates a ConfigurationPolicyPrefStore that only provides policies that - // have POLICY_LEVEL_MANDATORY level. - static ConfigurationPolicyPrefStore* CreateMandatoryPolicyPrefStore( - PolicyService* policy_service); - - // Creates a ConfigurationPolicyPrefStore that only provides policies that - // have POLICY_LEVEL_RECOMMENDED level. - static ConfigurationPolicyPrefStore* CreateRecommendedPolicyPrefStore( - PolicyService* policy_service); - private: virtual ~ConfigurationPolicyPrefStore(); @@ -68,6 +64,10 @@ class ConfigurationPolicyPrefStore // The PolicyService from which policy settings are read. PolicyService* policy_service_; + // The policy handlers used to convert policies into their corresponding + // preferences. + const ConfigurationPolicyHandlerList* handler_list_; + // The policy level that this PrefStore uses. PolicyLevel level_; diff --git a/chrome/browser/policy/configuration_policy_pref_store_unittest.cc b/chrome/browser/policy/configuration_policy_pref_store_unittest.cc index dce901a..400d53b 100644 --- a/chrome/browser/policy/configuration_policy_pref_store_unittest.cc +++ b/chrome/browser/policy/configuration_policy_pref_store_unittest.cc @@ -11,6 +11,7 @@ #include "base/prefs/pref_store_observer_mock.h" #include "base/run_loop.h" #include "chrome/browser/policy/configuration_policy_handler.h" +#include "chrome/browser/policy/configuration_policy_handler_list.h" #include "chrome/browser/policy/configuration_policy_pref_store.h" #include "chrome/browser/policy/external_data_fetcher.h" #include "chrome/browser/policy/mock_configuration_policy_provider.h" @@ -55,6 +56,7 @@ class ConfigurationPolicyPrefStoreTest : public testing::Test { providers.push_back(&provider_); policy_service_.reset(new PolicyServiceImpl(providers)); store_ = new ConfigurationPolicyPrefStore(policy_service_.get(), + &handler_list_, POLICY_LEVEL_MANDATORY); } @@ -68,6 +70,7 @@ class ConfigurationPolicyPrefStoreTest : public testing::Test { loop.RunUntilIdle(); } + ConfigurationPolicyHandlerList handler_list_; MockConfigurationPolicyProvider provider_; scoped_ptr<PolicyServiceImpl> policy_service_; scoped_refptr<ConfigurationPolicyPrefStore> store_; diff --git a/chrome/browser/prefs/chrome_pref_service_factory.cc b/chrome/browser/prefs/chrome_pref_service_factory.cc index c28c479..fef26a8 100644 --- a/chrome/browser/prefs/chrome_pref_service_factory.cc +++ b/chrome/browser/prefs/chrome_pref_service_factory.cc @@ -15,7 +15,7 @@ #include "base/prefs/pref_registry.h" #include "base/prefs/pref_service.h" #include "base/prefs/pref_value_store.h" -#include "chrome/browser/policy/configuration_policy_pref_store.h" +#include "chrome/browser/browser_process.h" #include "chrome/browser/prefs/command_line_pref_store.h" #include "chrome/browser/prefs/pref_model_associator.h" #include "chrome/browser/prefs/pref_service_syncable_builder.h" @@ -26,6 +26,12 @@ #include "grit/chromium_strings.h" #include "grit/generated_resources.h" +#if defined(ENABLE_CONFIGURATION_POLICY) +#include "chrome/browser/policy/browser_policy_connector.h" +#include "chrome/browser/policy/configuration_policy_pref_store.h" +#include "chrome/browser/policy/policy_types.h" +#endif + using content::BrowserContext; using content::BrowserThread; @@ -75,12 +81,14 @@ void PrepareBuilder( #if defined(ENABLE_CONFIGURATION_POLICY) using policy::ConfigurationPolicyPrefStore; - builder->WithManagedPrefs( - ConfigurationPolicyPrefStore::CreateMandatoryPolicyPrefStore( - policy_service)); - builder->WithRecommendedPrefs( - ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore( - policy_service)); + builder->WithManagedPrefs(new ConfigurationPolicyPrefStore( + policy_service, + g_browser_process->browser_policy_connector()->GetHandlerList(), + policy::POLICY_LEVEL_MANDATORY)); + builder->WithRecommendedPrefs(new ConfigurationPolicyPrefStore( + policy_service, + g_browser_process->browser_policy_connector()->GetHandlerList(), + policy::POLICY_LEVEL_RECOMMENDED)); #endif // ENABLE_CONFIGURATION_POLICY builder->WithAsync(async); diff --git a/chrome/browser/prefs/pref_service_syncable_builder.cc b/chrome/browser/prefs/pref_service_syncable_builder.cc index 69a090c..4b58eb7 100644 --- a/chrome/browser/prefs/pref_service_syncable_builder.cc +++ b/chrome/browser/prefs/pref_service_syncable_builder.cc @@ -8,12 +8,18 @@ #include "base/prefs/default_pref_store.h" #include "base/prefs/pref_notifier_impl.h" #include "base/prefs/pref_value_store.h" -#include "chrome/browser/policy/configuration_policy_pref_store.h" -#include "chrome/browser/policy/policy_service.h" +#include "chrome/browser/browser_process.h" #include "chrome/browser/prefs/command_line_pref_store.h" #include "chrome/browser/prefs/pref_service_syncable.h" #include "components/user_prefs/pref_registry_syncable.h" +#if defined(ENABLE_CONFIGURATION_POLICY) +#include "chrome/browser/policy/browser_policy_connector.h" +#include "chrome/browser/policy/configuration_policy_pref_store.h" +#include "chrome/browser/policy/policy_service.h" +#include "chrome/browser/policy/policy_types.h" +#endif + PrefServiceSyncableBuilder::PrefServiceSyncableBuilder() { } @@ -24,14 +30,18 @@ PrefServiceSyncableBuilder::~PrefServiceSyncableBuilder() { PrefServiceSyncableBuilder& PrefServiceSyncableBuilder::WithManagedPolicies( policy::PolicyService* service) { WithManagedPrefs(new policy::ConfigurationPolicyPrefStore( - service, policy::POLICY_LEVEL_MANDATORY)); + service, + g_browser_process->browser_policy_connector()->GetHandlerList(), + policy::POLICY_LEVEL_MANDATORY)); return *this; } PrefServiceSyncableBuilder& PrefServiceSyncableBuilder::WithRecommendedPolicies( policy::PolicyService* service) { WithRecommendedPrefs(new policy::ConfigurationPolicyPrefStore( - service, policy::POLICY_LEVEL_RECOMMENDED)); + service, + g_browser_process->browser_policy_connector()->GetHandlerList(), + policy::POLICY_LEVEL_RECOMMENDED)); return *this; } #endif |