diff options
author | mnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-08 09:49:11 +0000 |
---|---|---|
committer | mnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-08 09:49:11 +0000 |
commit | acd78969cf6569dcbf409dceb0b6511751afd026 (patch) | |
tree | ed2168c663ae3e8a15d857838b78ed2386da3281 /chrome/test | |
parent | 5138bbffd1b2d5151ad74b4e7ae8091fc7d44114 (diff) | |
download | chromium_src-acd78969cf6569dcbf409dceb0b6511751afd026.zip chromium_src-acd78969cf6569dcbf409dceb0b6511751afd026.tar.gz chromium_src-acd78969cf6569dcbf409dceb0b6511751afd026.tar.bz2 |
Clean up pref change notification handling.
This is a complete overhaul of PrefValueStore, PrefStore, PrefNotifier, and PrefService. Specifically:
- Add an observer interface to PrefStore that can be used to notify the upper layers of the pref system about value changes. Currently, it's unused mostly, but that'll change when we refactor ExtensionPrefStore and ConfigurationPolicyPrefStore.
- Make PrefNotifier be a dependency of PrefValueStore. That helps in keeping the pref change detection handling local to PrefValueStore.
- Clean up related unit tests, removing redundant mocks and gmockify others.
BUG=64893
TEST=Compiles and passes tests
Review URL: http://codereview.chromium.org/5441002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68574 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r-- | chrome/test/testing_pref_service.cc | 34 | ||||
-rw-r--r-- | chrome/test/testing_pref_service.h | 8 | ||||
-rw-r--r-- | chrome/test/testing_pref_value_store.h | 26 |
3 files changed, 21 insertions, 47 deletions
diff --git a/chrome/test/testing_pref_service.cc b/chrome/test/testing_pref_service.cc index 3713c8c..9cc5321 100644 --- a/chrome/test/testing_pref_service.cc +++ b/chrome/test/testing_pref_service.cc @@ -5,52 +5,52 @@ #include "chrome/test/testing_pref_service.h" #include "chrome/browser/prefs/command_line_pref_store.h" -#include "chrome/browser/prefs/dummy_pref_store.h" +#include "chrome/browser/prefs/testing_pref_store.h" +#include "chrome/browser/prefs/pref_notifier.h" #include "chrome/browser/prefs/pref_value_store.h" #include "chrome/browser/policy/configuration_policy_pref_store.h" -#include "chrome/test/testing_pref_value_store.h" // TODO(pamg): Instantiate no PrefStores by default. Allow callers to specify // which they want, and expand usage of this class to more unit tests. TestingPrefService::TestingPrefService() - : PrefService(new TestingPrefValueStore( - managed_platform_prefs_ = new DummyPrefStore(), - device_management_prefs_ = new DummyPrefStore(), - NULL, - NULL, - user_prefs_ = new DummyPrefStore(), - NULL, - default_prefs_ = new DummyPrefStore())) { + : PrefService( + managed_platform_prefs_ = new TestingPrefStore(), + device_management_prefs_ = new TestingPrefStore(), + NULL, + NULL, + user_prefs_ = new TestingPrefStore(), + NULL, + NULL) { } TestingPrefService::TestingPrefService( policy::ConfigurationPolicyProvider* managed_platform_provider, policy::ConfigurationPolicyProvider* device_management_provider, CommandLine* command_line) - : PrefService(new TestingPrefValueStore( + : PrefService( managed_platform_prefs_ = CreatePolicyPrefStoreFromProvider( managed_platform_provider), device_management_prefs_ = CreatePolicyPrefStoreFromProvider(device_management_provider), NULL, CreateCommandLinePrefStore(command_line), - user_prefs_ = new DummyPrefStore(), + user_prefs_ = new TestingPrefStore(), NULL, - default_prefs_ = new DummyPrefStore())) { + NULL) { } PrefStore* TestingPrefService::CreatePolicyPrefStoreFromProvider( policy::ConfigurationPolicyProvider* provider) { if (provider) return new policy::ConfigurationPolicyPrefStore(provider); - return new DummyPrefStore(); + return new TestingPrefStore(); } PrefStore* TestingPrefService::CreateCommandLinePrefStore( CommandLine* command_line) { if (command_line) return new CommandLinePrefStore(command_line); - return new DummyPrefStore(); + return new TestingPrefStore(); } const Value* TestingPrefService::GetManagedPref(const char* path) { @@ -97,11 +97,11 @@ void TestingPrefService::SetPref(PrefStore* pref_store, const char* path, Value* value) { pref_store->prefs()->Set(path, value); - pref_notifier()->FireObservers(path); + pref_notifier()->OnPreferenceChanged(path); } void TestingPrefService::RemovePref(PrefStore* pref_store, const char* path) { pref_store->prefs()->Remove(path, NULL); - pref_notifier()->FireObservers(path); + pref_notifier()->OnPreferenceChanged(path); } diff --git a/chrome/test/testing_pref_service.h b/chrome/test/testing_pref_service.h index 6c60fcf..c5adc021 100644 --- a/chrome/test/testing_pref_service.h +++ b/chrome/test/testing_pref_service.h @@ -25,10 +25,10 @@ class TestingPrefService : public PrefService { // Create an instance that has a managed PrefStore and a command- line // PrefStore. |managed_platform_provider| contains the provider with which to // initialize the managed platform PrefStore. If it is NULL, then a - // DummyPrefStore will be created. |device_management_provider| contains the + // TestingPrefStore will be created. |device_management_provider| contains the // provider with which to initialize the device management // PrefStore. |command_line| contains the provider with which to initialize - // the command line PrefStore. If it is NULL then a DummyPrefStore will be + // the command line PrefStore. If it is NULL then a TestingPrefStore will be // created as the command line PrefStore. TestingPrefService( policy::ConfigurationPolicyProvider* managed_platform_provider, @@ -66,12 +66,12 @@ class TestingPrefService : public PrefService { private: // Creates a ConfigurationPolicyPrefStore based on the provided - // |provider| or a DummyPrefStore if |provider| is NULL. + // |provider| or a TestingPrefStore if |provider| is NULL. PrefStore* CreatePolicyPrefStoreFromProvider( policy::ConfigurationPolicyProvider* provider); // Creates a CommandLinePrefStore based on the supplied - // |command_line| or a DummyPrefStore if |command_line| is NULL. + // |command_line| or a TestingPrefStore if |command_line| is NULL. PrefStore* CreateCommandLinePrefStore(CommandLine* command_line); // Reads the value of the preference indicated by |path| from |pref_store|. diff --git a/chrome/test/testing_pref_value_store.h b/chrome/test/testing_pref_value_store.h deleted file mode 100644 index 01ae898..0000000 --- a/chrome/test/testing_pref_value_store.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_TEST_TESTING_PREF_VALUE_STORE_H_ -#define CHROME_TEST_TESTING_PREF_VALUE_STORE_H_ -#pragma once - -#include "chrome/browser/prefs/pref_value_store.h" - -// PrefValueStore subclass that allows directly setting PrefStores. -class TestingPrefValueStore : public PrefValueStore { - public: - TestingPrefValueStore(PrefStore* managed_platform_prefs, - PrefStore* device_management_prefs, - PrefStore* extension_prefs, - PrefStore* command_line_prefs, - PrefStore* user_prefs, - PrefStore* recommended_prefs, - PrefStore* default_prefs) - : PrefValueStore(managed_platform_prefs, device_management_prefs, - extension_prefs, command_line_prefs, - user_prefs, recommended_prefs, default_prefs, NULL) {} -}; - -#endif // CHROME_TEST_TESTING_PREF_VALUE_STORE_H_ |