Extract PrefServiceBase into chrome/browser/api. Use in api and autofill.
TBR=owners other than for prefs and api, since other changes are trivial and mechanical
BUG=140037
Review URL: https://chromiumcodereview.appspot.com/10828345
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152569 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/api/prefs/DEPS b/chrome/browser/api/prefs/DEPS
index 25e98a4..79439f0 100644
--- a/chrome/browser/api/prefs/DEPS
+++ b/chrome/browser/api/prefs/DEPS
@@ -1,6 +1,6 @@
# TODO(joi): Bring back to zero.
specific_include_rules = {
- ".*\.cc": [
+ ".*[a-z]+test\.cc": [
"!chrome/browser/prefs",
],
}
diff --git a/chrome/browser/api/prefs/pref_change_registrar.cc b/chrome/browser/api/prefs/pref_change_registrar.cc
index 23589d73..2b05f5b 100644
--- a/chrome/browser/api/prefs/pref_change_registrar.cc
+++ b/chrome/browser/api/prefs/pref_change_registrar.cc
@@ -5,7 +5,7 @@
#include "chrome/browser/api/prefs/pref_change_registrar.h"
#include "base/logging.h"
-#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/api/prefs/pref_service_base.h"
PrefChangeRegistrar::PrefChangeRegistrar() : service_(NULL) {}
@@ -17,7 +17,7 @@
RemoveAll();
}
-void PrefChangeRegistrar::Init(PrefService* service) {
+void PrefChangeRegistrar::Init(PrefServiceBase* service) {
DCHECK(IsEmpty() || service_ == service);
service_ = service;
}
diff --git a/chrome/browser/api/prefs/pref_change_registrar.h b/chrome/browser/api/prefs/pref_change_registrar.h
index 0b17d0d..6f2d296 100644
--- a/chrome/browser/api/prefs/pref_change_registrar.h
+++ b/chrome/browser/api/prefs/pref_change_registrar.h
@@ -10,7 +10,7 @@
#include "base/basictypes.h"
-class PrefService;
+class PrefServiceBase;
namespace content {
class NotificationObserver;
@@ -27,7 +27,7 @@
// Must be called before adding or removing observers. Can be called more
// than once as long as the value of |service| doesn't change.
- void Init(PrefService* service);
+ void Init(PrefServiceBase* service);
// Adds an pref observer for the specified pref |path| and |obs| observer
// object. All registered observers will be automatically unregistered
@@ -52,7 +52,7 @@
ObserverRegistration;
std::set<ObserverRegistration> observers_;
- PrefService* service_;
+ PrefServiceBase* service_;
DISALLOW_COPY_AND_ASSIGN(PrefChangeRegistrar);
};
diff --git a/chrome/browser/api/prefs/pref_member.cc b/chrome/browser/api/prefs/pref_member.cc
index 42a9d15..e3fae0c 100644
--- a/chrome/browser/api/prefs/pref_member.cc
+++ b/chrome/browser/api/prefs/pref_member.cc
@@ -7,7 +7,7 @@
#include "base/bind.h"
#include "base/logging.h"
#include "base/value_conversions.h"
-#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/api/prefs/pref_service_base.h"
#include "chrome/common/chrome_notification_types.h"
using content::BrowserThread;
@@ -26,7 +26,7 @@
void PrefMemberBase::Init(const char* pref_name,
- PrefService* prefs,
+ PrefServiceBase* prefs,
content::NotificationObserver* observer) {
DCHECK(pref_name);
DCHECK(prefs);
@@ -69,7 +69,7 @@
void PrefMemberBase::UpdateValueFromPref() const {
VerifyValuePrefName();
- const PrefService::Preference* pref =
+ const PrefServiceBase::Preference* pref =
prefs_->FindPreference(pref_name_.c_str());
DCHECK(pref);
if (!internal())
diff --git a/chrome/browser/api/prefs/pref_member.h b/chrome/browser/api/prefs/pref_member.h
index 7553dce..eb96c17d 100644
--- a/chrome/browser/api/prefs/pref_member.h
+++ b/chrome/browser/api/prefs/pref_member.h
@@ -34,7 +34,7 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_observer.h"
-class PrefService;
+class PrefServiceBase;
namespace subtle {
@@ -81,7 +81,7 @@
virtual ~PrefMemberBase();
// See PrefMember<> for description.
- void Init(const char* pref_name, PrefService* prefs,
+ void Init(const char* pref_name, PrefServiceBase* prefs,
content::NotificationObserver* observer);
virtual void CreateInternal() const = 0;
@@ -110,8 +110,8 @@
void VerifyPref() const;
const std::string& pref_name() const { return pref_name_; }
- PrefService* prefs() { return prefs_; }
- const PrefService* prefs() const { return prefs_; }
+ PrefServiceBase* prefs() { return prefs_; }
+ const PrefServiceBase* prefs() const { return prefs_; }
virtual Internal* internal() const = 0;
@@ -119,7 +119,7 @@
// Ordered the members to compact the class instance.
std::string pref_name_;
content::NotificationObserver* observer_;
- PrefService* prefs_;
+ PrefServiceBase* prefs_;
protected:
bool setting_value_;
@@ -138,7 +138,7 @@
// Do the actual initialization of the class. |observer| may be null if you
// don't want any notifications of changes.
// This method should only be called on the UI thread.
- void Init(const char* pref_name, PrefService* prefs,
+ void Init(const char* pref_name, PrefServiceBase* prefs,
content::NotificationObserver* observer) {
subtle::PrefMemberBase::Init(pref_name, prefs, observer);
}
diff --git a/chrome/browser/api/prefs/pref_service_base.h b/chrome/browser/api/prefs/pref_service_base.h
new file mode 100644
index 0000000..dbdb051
--- /dev/null
+++ b/chrome/browser/api/prefs/pref_service_base.h
@@ -0,0 +1,271 @@
+// Copyright (c) 2012 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.
+
+// This is the base interface for a preference services that provides
+// a way to access the application's current preferences.
+//
+// This base interface assumes all preferences are local. See
+// SyncablePrefServiceBase for the interface to a preference service
+// that stores preferences that can be synced.
+//
+// Chromium settings and storage represent user-selected preferences and
+// information and MUST not be extracted, overwritten or modified except
+// through Chromium defined APIs.
+
+#ifndef CHROME_BROWSER_API_PREFS_PREF_SERVICE_BASE_H_
+#define CHROME_BROWSER_API_PREFS_PREF_SERVICE_BASE_H_
+
+#include "base/values.h"
+
+namespace content {
+class NotificationObserver;
+}
+
+namespace subtle {
+class PrefMemberBase;
+}
+
+class FilePath;
+class Profile;
+class TabContents;
+
+class PrefServiceBase {
+ public:
+ // Retrieves a PrefServiceBase for the given profile.
+ static PrefServiceBase* ForProfile(Profile* profile);
+
+ virtual ~PrefServiceBase() {}
+
+ // Enum used when registering preferences to determine if it should be synced
+ // or not. This is only used for profile prefs, not local state prefs.
+ // See the Register*Pref methods for profile prefs below.
+ enum PrefSyncStatus {
+ UNSYNCABLE_PREF,
+ SYNCABLE_PREF
+ };
+
+ // Interface to a single preference.
+ class Preference {
+ public:
+ virtual ~Preference() {}
+
+ // Returns the name of the Preference (i.e., the key, e.g.,
+ // browser.window_placement).
+ virtual const std::string name() const = 0;
+
+ // Returns the registered type of the preference.
+ virtual base::Value::Type GetType() const = 0;
+
+ // Returns the value of the Preference, falling back to the registered
+ // default value if no other has been set.
+ virtual const base::Value* GetValue() const = 0;
+
+ // Returns the value recommended by the admin, if any.
+ virtual const base::Value* GetRecommendedValue() const = 0;
+
+ // Returns true if the Preference is managed, i.e. set by an admin policy.
+ // Since managed prefs have the highest priority, this also indicates
+ // whether the pref is actually being controlled by the policy setting.
+ virtual bool IsManaged() const = 0;
+
+ // Returns true if the Preference is recommended, i.e. set by an admin
+ // policy but the user is allowed to change it.
+ virtual bool IsRecommended() const = 0;
+
+ // Returns true if the Preference has a value set by an extension, even if
+ // that value is being overridden by a higher-priority source.
+ virtual bool HasExtensionSetting() const = 0;
+
+ // Returns true if the Preference has a user setting, even if that value is
+ // being overridden by a higher-priority source.
+ virtual bool HasUserSetting() const = 0;
+
+ // Returns true if the Preference value is currently being controlled by an
+ // extension, and not by any higher-priority source.
+ virtual bool IsExtensionControlled() const = 0;
+
+ // Returns true if the Preference value is currently being controlled by a
+ // user setting, and not by any higher-priority source.
+ virtual bool IsUserControlled() const = 0;
+
+ // Returns true if the Preference is currently using its default value,
+ // and has not been set by any higher-priority source (even with the same
+ // value).
+ virtual bool IsDefaultValue() const = 0;
+
+ // Returns true if the user can change the Preference value, which is the
+ // case if no higher-priority source than the user store controls the
+ // Preference.
+ virtual bool IsUserModifiable() const = 0;
+
+ // Returns true if an extension can change the Preference value, which is
+ // the case if no higher-priority source than the extension store controls
+ // the Preference.
+ virtual bool IsExtensionModifiable() const = 0;
+ };
+
+ // Returns true if the preference for the given preference name is available
+ // and is managed.
+ virtual bool IsManagedPreference(const char* pref_name) const = 0;
+
+ // Returns |true| if a preference with the given name is available and its
+ // value can be changed by the user.
+ virtual bool IsUserModifiablePreference(const char* pref_name) const = 0;
+
+ // Make the PrefService aware of a pref.
+ // TODO(zea): split local state and profile prefs into their own subclasses.
+ // ---------- Local state prefs ----------
+ virtual void RegisterBooleanPref(const char* path,
+ bool default_value) = 0;
+ virtual void RegisterIntegerPref(const char* path,
+ int default_value) = 0;
+ virtual void RegisterDoublePref(const char* path,
+ double default_value) = 0;
+ virtual void RegisterStringPref(const char* path,
+ const std::string& default_value) = 0;
+ virtual void RegisterFilePathPref(const char* path,
+ const FilePath& default_value) = 0;
+ virtual void RegisterListPref(const char* path) = 0;
+ virtual void RegisterDictionaryPref(const char* path) = 0;
+ // These take ownership of the default_value:
+ virtual void RegisterListPref(const char* path,
+ base::ListValue* default_value) = 0;
+ virtual void RegisterDictionaryPref(
+ const char* path, base::DictionaryValue* default_value) = 0;
+ // These variants use a default value from the locale dll instead.
+ virtual void RegisterLocalizedBooleanPref(
+ const char* path, int locale_default_message_id) = 0;
+ virtual void RegisterLocalizedIntegerPref(
+ const char* path, int locale_default_message_id) = 0;
+ virtual void RegisterLocalizedDoublePref(
+ const char* path, int locale_default_message_id) = 0;
+ virtual void RegisterLocalizedStringPref(
+ const char* path, int locale_default_message_id) = 0;
+ virtual void RegisterInt64Pref(const char* path,
+ int64 default_value) = 0;
+
+ // ---------- Profile prefs ----------
+ // Profile prefs must specify whether the pref should be synchronized across
+ // machines or not (see PrefSyncStatus enum above).
+ virtual void RegisterBooleanPref(const char* path,
+ bool default_value,
+ PrefSyncStatus sync_status) = 0;
+ virtual void RegisterIntegerPref(const char* path,
+ int default_value,
+ PrefSyncStatus sync_status) = 0;
+ virtual void RegisterDoublePref(const char* path,
+ double default_value,
+ PrefSyncStatus sync_status) = 0;
+ virtual void RegisterStringPref(const char* path,
+ const std::string& default_value,
+ PrefSyncStatus sync_status) = 0;
+ virtual void RegisterFilePathPref(const char* path,
+ const FilePath& default_value,
+ PrefSyncStatus sync_status) = 0;
+ virtual void RegisterListPref(const char* path,
+ PrefSyncStatus sync_status) = 0;
+ virtual void RegisterDictionaryPref(const char* path,
+ PrefSyncStatus sync_status) = 0;
+ // These take ownership of the default_value:
+ virtual void RegisterListPref(const char* path,
+ base::ListValue* default_value,
+ PrefSyncStatus sync_status) = 0;
+ virtual void RegisterDictionaryPref(const char* path,
+ base::DictionaryValue* default_value,
+ PrefSyncStatus sync_status) = 0;
+ // These variants use a default value from the locale dll instead.
+ virtual void RegisterLocalizedBooleanPref(
+ const char* path,
+ int locale_default_message_id,
+ PrefSyncStatus sync_status) = 0;
+ virtual void RegisterLocalizedIntegerPref(
+ const char* path,
+ int locale_default_message_id,
+ PrefSyncStatus sync_status) = 0;
+ virtual void RegisterLocalizedDoublePref(
+ const char* path,
+ int locale_default_message_id,
+ PrefSyncStatus sync_status) = 0;
+ virtual void RegisterLocalizedStringPref(
+ const char* path,
+ int locale_default_message_id,
+ PrefSyncStatus sync_status) = 0;
+ virtual void RegisterInt64Pref(const char* path,
+ int64 default_value,
+ PrefSyncStatus sync_status) = 0;
+ virtual void RegisterUint64Pref(const char* path,
+ uint64 default_value,
+ PrefSyncStatus sync_status) = 0;
+ // Unregisters a preference.
+ virtual void UnregisterPreference(const char* path) = 0;
+
+ // Look up a preference. Returns NULL if the preference is not
+ // registered.
+ virtual const Preference* FindPreference(const char* pref_name) const = 0;
+
+ // If the path is valid and the value at the end of the path matches the type
+ // specified, it will return the specified value. Otherwise, the default
+ // value (set when the pref was registered) will be returned.
+ virtual bool GetBoolean(const char* path) const = 0;
+ virtual int GetInteger(const char* path) const = 0;
+ virtual double GetDouble(const char* path) const = 0;
+ virtual std::string GetString(const char* path) const = 0;
+ virtual FilePath GetFilePath(const char* path) const = 0;
+
+ // Returns the branch if it exists, or the registered default value otherwise.
+ // Note that |path| must point to a registered preference. In that case, these
+ // functions will never return NULL.
+ virtual const base::DictionaryValue* GetDictionary(
+ const char* path) const = 0;
+ virtual const base::ListValue* GetList(const char* path) const = 0;
+
+ // Removes a user pref and restores the pref to its default value.
+ virtual void ClearPref(const char* path) = 0;
+
+ // If the path is valid (i.e., registered), update the pref value in the user
+ // prefs.
+ // To set the value of dictionary or list values in the pref tree use
+ // Set(), but to modify the value of a dictionary or list use either
+ // ListPrefUpdate or DictionaryPrefUpdate from scoped_user_pref_update.h.
+ virtual void Set(const char* path, const base::Value& value) = 0;
+ virtual void SetBoolean(const char* path, bool value) = 0;
+ virtual void SetInteger(const char* path, int value) = 0;
+ virtual void SetDouble(const char* path, double value) = 0;
+ virtual void SetString(const char* path, const std::string& value) = 0;
+ virtual void SetFilePath(const char* path, const FilePath& value) = 0;
+
+ // Int64 helper methods that actually store the given value as a string.
+ // Note that if obtaining the named value via GetDictionary or GetList, the
+ // Value type will be TYPE_STRING.
+ virtual void SetInt64(const char* path, int64 value) = 0;
+ virtual int64 GetInt64(const char* path) const = 0;
+
+ // As above, but for unsigned values.
+ virtual void SetUint64(const char* path, uint64 value) = 0;
+ virtual uint64 GetUint64(const char* path) const = 0;
+
+ protected:
+ // Registration of pref change observers must be done using the
+ // PrefChangeRegistrar, which is declared as a friend here to grant it
+ // access to the otherwise protected members Add/RemovePrefObserver.
+ // PrefMember registers for preferences changes notification directly to
+ // avoid the storage overhead of the registrar, so its base class must be
+ // declared as a friend, too.
+ friend class PrefChangeRegistrar;
+ friend class subtle::PrefMemberBase;
+
+ // These are protected so they can only be accessed by the friend
+ // classes listed above.
+ //
+ // If the pref at the given path changes, we call the observer's Observe
+ // method with PREF_CHANGED. Note that observers should not call these methods
+ // directly but rather use a PrefChangeRegistrar to make sure the observer
+ // gets cleaned up properly.
+ virtual void AddPrefObserver(const char* path,
+ content::NotificationObserver* obs) = 0;
+ virtual void RemovePrefObserver(const char* path,
+ content::NotificationObserver* obs) = 0;
+};
+
+#endif // CHROME_BROWSER_API_PREFS_PREF_SERVICE_BASE_H_
diff --git a/chrome/browser/autofill/DEPS b/chrome/browser/autofill/DEPS
index 133da1b..743b66f 100644
--- a/chrome/browser/autofill/DEPS
+++ b/chrome/browser/autofill/DEPS
@@ -15,7 +15,6 @@
# Do not add to the list of temporarily-allowed dependencies below,
# and please do not introduce more #includes of these files.
"!chrome/browser/password_manager/password_manager.h",
- "!chrome/browser/prefs/pref_service.h",
"!chrome/browser/profiles/profile.h",
"!chrome/browser/profiles/profile_dependency_manager.h",
"!chrome/browser/profiles/profile_keyed_service.h",
diff --git a/chrome/browser/autofill/autocomplete_history_manager.cc b/chrome/browser/autofill/autocomplete_history_manager.cc
index 44a4644..042e837 100644
--- a/chrome/browser/autofill/autocomplete_history_manager.cc
+++ b/chrome/browser/autofill/autocomplete_history_manager.cc
@@ -9,6 +9,7 @@
#include "base/string16.h"
#include "base/string_number_conversions.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/api/prefs/pref_service_base.h"
#include "chrome/browser/autofill/autofill_external_delegate.h"
#include "chrome/browser/autofill/credit_card.h"
#include "chrome/browser/profiles/profile.h"
@@ -117,7 +118,8 @@
// May be NULL in unit tests.
web_data_service_ = WebDataServiceFactory::GetForProfile(
profile_, Profile::EXPLICIT_ACCESS);
- autofill_enabled_.Init(prefs::kAutofillEnabled, profile_->GetPrefs(), NULL);
+ autofill_enabled_.Init(
+ prefs::kAutofillEnabled, PrefServiceBase::ForProfile(profile_), NULL);
}
AutocompleteHistoryManager::~AutocompleteHistoryManager() {
@@ -244,7 +246,7 @@
query_id_(0),
external_delegate_(NULL) {
autofill_enabled_.Init(
- prefs::kAutofillEnabled, profile_->GetPrefs(), NULL);
+ prefs::kAutofillEnabled, PrefServiceBase::ForProfile(profile_), NULL);
}
void AutocompleteHistoryManager::CancelPendingQuery() {
diff --git a/chrome/browser/autofill/autofill_common_test.cc b/chrome/browser/autofill/autofill_common_test.cc
index 99ff3ac..26e93447 100644
--- a/chrome/browser/autofill/autofill_common_test.cc
+++ b/chrome/browser/autofill/autofill_common_test.cc
@@ -5,10 +5,10 @@
#include "chrome/browser/autofill/autofill_common_test.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/api/prefs/pref_service_base.h"
#include "chrome/browser/autofill/autofill_profile.h"
#include "chrome/browser/autofill/credit_card.h"
#include "chrome/browser/password_manager/encryptor.h"
-#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h"
#include "webkit/forms/form_field.h"
@@ -83,8 +83,8 @@
// Disable auxiliary profiles for unit testing. These reach out to system
// services on the Mac.
if (profile) {
- profile->GetPrefs()->SetBoolean(prefs::kAutofillAuxiliaryProfilesEnabled,
- false);
+ PrefServiceBase::ForProfile(profile)->SetBoolean(
+ prefs::kAutofillAuxiliaryProfilesEnabled, false);
}
}
diff --git a/chrome/browser/autofill/autofill_download.cc b/chrome/browser/autofill/autofill_download.cc
index cdd56a12..46c7707d 100644
--- a/chrome/browser/autofill/autofill_download.cc
+++ b/chrome/browser/autofill/autofill_download.cc
@@ -15,7 +15,7 @@
#include "chrome/browser/autofill/autofill_metrics.h"
#include "chrome/browser/autofill/autofill_xml_parser.h"
#include "chrome/browser/autofill/form_structure.h"
-#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/api/prefs/pref_service_base.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h"
#include "googleurl/src/gurl.h"
@@ -56,7 +56,7 @@
negative_upload_rate_(0),
fetcher_id_for_unittest_(0) {
DCHECK(observer_);
- PrefService* preferences = profile_->GetPrefs();
+ PrefServiceBase* preferences = PrefServiceBase::ForProfile(profile_);
positive_upload_rate_ =
preferences->GetDouble(prefs::kAutofillPositiveUploadRate);
negative_upload_rate_ =
@@ -143,7 +143,7 @@
positive_upload_rate_ = rate;
DCHECK_GE(rate, 0.0);
DCHECK_LE(rate, 1.0);
- PrefService* preferences = profile_->GetPrefs();
+ PrefServiceBase* preferences = PrefServiceBase::ForProfile(profile_);
preferences->SetDouble(prefs::kAutofillPositiveUploadRate, rate);
}
@@ -153,7 +153,7 @@
negative_upload_rate_ = rate;
DCHECK_GE(rate, 0.0);
DCHECK_LE(rate, 1.0);
- PrefService* preferences = profile_->GetPrefs();
+ PrefServiceBase* preferences = PrefServiceBase::ForProfile(profile_);
preferences->SetDouble(prefs::kAutofillNegativeUploadRate, rate);
}
diff --git a/chrome/browser/autofill/autofill_manager.cc b/chrome/browser/autofill/autofill_manager.cc
index d609038..c8b5b503 100644
--- a/chrome/browser/autofill/autofill_manager.cc
+++ b/chrome/browser/autofill/autofill_manager.cc
@@ -37,7 +37,7 @@
#include "chrome/browser/autofill/phone_number_i18n.h"
#include "chrome/browser/autofill/select_control_handler.h"
#include "chrome/browser/password_manager/password_manager.h"
-#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/api/prefs/pref_service_base.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
@@ -197,7 +197,7 @@
personal_data_ = PersonalDataManagerFactory::GetForProfile(
tab_contents->profile()->GetOriginalProfile());
RegisterWithSyncService();
- registrar_.Init(tab_contents->profile()->GetPrefs());
+ registrar_.Init(PrefServiceBase::ForProfile(tab_contents->profile()));
registrar_.Add(prefs::kPasswordGenerationEnabled, this);
notification_registrar_.Add(this,
chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED,
@@ -208,28 +208,28 @@
}
// static
-void AutofillManager::RegisterUserPrefs(PrefService* prefs) {
+void AutofillManager::RegisterUserPrefs(PrefServiceBase* prefs) {
prefs->RegisterBooleanPref(prefs::kAutofillEnabled,
true,
- PrefService::SYNCABLE_PREF);
+ PrefServiceBase::SYNCABLE_PREF);
prefs->RegisterBooleanPref(prefs::kPasswordGenerationEnabled,
true,
- PrefService::SYNCABLE_PREF);
+ PrefServiceBase::SYNCABLE_PREF);
#if defined(OS_MACOSX)
prefs->RegisterBooleanPref(prefs::kAutofillAuxiliaryProfilesEnabled,
true,
- PrefService::SYNCABLE_PREF);
+ PrefServiceBase::SYNCABLE_PREF);
#else
prefs->RegisterBooleanPref(prefs::kAutofillAuxiliaryProfilesEnabled,
false,
- PrefService::UNSYNCABLE_PREF);
+ PrefServiceBase::UNSYNCABLE_PREF);
#endif
prefs->RegisterDoublePref(prefs::kAutofillPositiveUploadRate,
kAutofillPositiveUploadRateDefaultValue,
- PrefService::UNSYNCABLE_PREF);
+ PrefServiceBase::UNSYNCABLE_PREF);
prefs->RegisterDoublePref(prefs::kAutofillNegativeUploadRate,
kAutofillNegativeUploadRateDefaultValue,
- PrefService::UNSYNCABLE_PREF);
+ PrefServiceBase::UNSYNCABLE_PREF);
}
void AutofillManager::RegisterWithSyncService() {
@@ -267,8 +267,8 @@
Profile* profile = Profile::FromBrowserContext(
web_contents()->GetBrowserContext());
- bool preference_checked =
- profile->GetPrefs()->GetBoolean(prefs::kPasswordGenerationEnabled);
+ bool preference_checked = PrefServiceBase::ForProfile(profile)->GetBoolean(
+ prefs::kPasswordGenerationEnabled);
bool new_password_generation_enabled =
password_sync_enabled &&
@@ -815,7 +815,8 @@
bool AutofillManager::IsAutofillEnabled() const {
Profile* profile = Profile::FromBrowserContext(
const_cast<AutofillManager*>(this)->web_contents()->GetBrowserContext());
- return profile->GetPrefs()->GetBoolean(prefs::kAutofillEnabled);
+ return PrefServiceBase::ForProfile(profile)->GetBoolean(
+ prefs::kAutofillEnabled);
}
void AutofillManager::SendAutofillTypePredictions(
diff --git a/chrome/browser/autofill/autofill_manager.h b/chrome/browser/autofill/autofill_manager.h
index a2c769e..f2db3ce 100644
--- a/chrome/browser/autofill/autofill_manager.h
+++ b/chrome/browser/autofill/autofill_manager.h
@@ -76,7 +76,7 @@
explicit AutofillManager(TabContents* tab_contents);
// Registers our Enable/Disable Autofill pref.
- static void RegisterUserPrefs(PrefService* prefs);
+ static void RegisterUserPrefs(PrefServiceBase* prefs);
// Set our external delegate.
// TODO(jrg): consider passing delegate into the ctor. That won't
diff --git a/chrome/browser/autofill/autofill_manager_unittest.cc b/chrome/browser/autofill/autofill_manager_unittest.cc
index 408a4ce..abec88c 100644
--- a/chrome/browser/autofill/autofill_manager_unittest.cc
+++ b/chrome/browser/autofill/autofill_manager_unittest.cc
@@ -14,6 +14,7 @@
#include "base/time.h"
#include "base/tuple.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/api/prefs/pref_service_base.h"
#include "chrome/browser/autofill/autocomplete_history_manager.h"
#include "chrome/browser/autofill/autofill_common_test.h"
#include "chrome/browser/autofill/autofill_manager.h"
@@ -22,7 +23,6 @@
#include "chrome/browser/autofill/personal_data_manager.h"
#include "chrome/browser/autofill/personal_data_manager_factory.h"
#include "chrome/browser/autofill/test_autofill_external_delegate.h"
-#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
@@ -2618,24 +2618,19 @@
// Checks that resetting the auxiliary profile enabled preference does the right
// thing on all platforms.
TEST_F(AutofillManagerTest, AuxiliaryProfilesReset) {
+ PrefServiceBase* prefs = PrefServiceBase::ForProfile(profile());
#if defined(OS_MACOSX)
// Auxiliary profiles is implemented on Mac only. It enables Mac Address
// Book integration.
- ASSERT_TRUE(profile()->GetPrefs()->GetBoolean(
- prefs::kAutofillAuxiliaryProfilesEnabled));
- profile()->GetPrefs()->SetBoolean(
- prefs::kAutofillAuxiliaryProfilesEnabled, false);
- profile()->GetPrefs()->ClearPref(prefs::kAutofillAuxiliaryProfilesEnabled);
- ASSERT_TRUE(profile()->GetPrefs()->GetBoolean(
- prefs::kAutofillAuxiliaryProfilesEnabled));
+ ASSERT_TRUE(prefs->GetBoolean(prefs::kAutofillAuxiliaryProfilesEnabled));
+ prefs->SetBoolean(prefs::kAutofillAuxiliaryProfilesEnabled, false);
+ prefs->ClearPref(prefs::kAutofillAuxiliaryProfilesEnabled);
+ ASSERT_TRUE(prefs->GetBoolean(prefs::kAutofillAuxiliaryProfilesEnabled));
#else
- ASSERT_FALSE(profile()->GetPrefs()->GetBoolean(
- prefs::kAutofillAuxiliaryProfilesEnabled));
- profile()->GetPrefs()->SetBoolean(
- prefs::kAutofillAuxiliaryProfilesEnabled, true);
- profile()->GetPrefs()->ClearPref(prefs::kAutofillAuxiliaryProfilesEnabled);
- ASSERT_FALSE(profile()->GetPrefs()->GetBoolean(
- prefs::kAutofillAuxiliaryProfilesEnabled));
+ ASSERT_FALSE(prefs->GetBoolean(prefs::kAutofillAuxiliaryProfilesEnabled));
+ prefs->SetBoolean(prefs::kAutofillAuxiliaryProfilesEnabled, true);
+ prefs->ClearPref(prefs::kAutofillAuxiliaryProfilesEnabled);
+ ASSERT_FALSE(prefs->GetBoolean(prefs::kAutofillAuxiliaryProfilesEnabled));
#endif
}
@@ -2919,11 +2914,13 @@
}
TEST_F(AutofillManagerTest, UpdatePasswordSyncState) {
+ PrefServiceBase* prefs = PrefServiceBase::ForProfile(profile());
+
// Allow this test to control what should get synced.
- profile()->GetPrefs()->SetBoolean(prefs::kSyncKeepEverythingSynced, false);
+ prefs->SetBoolean(prefs::kSyncKeepEverythingSynced, false);
// Always set password generation enabled check box so we can test the
// behavior of password sync.
- profile()->GetPrefs()->SetBoolean(prefs::kPasswordGenerationEnabled, true);
+ prefs->SetBoolean(prefs::kPasswordGenerationEnabled, true);
// Sync some things, but not passwords. Shouldn't send anything since
// password generation is disabled by default.
@@ -2975,9 +2972,11 @@
}
TEST_F(AutofillManagerTest, UpdatePasswordGenerationState) {
+ PrefServiceBase* prefs = PrefServiceBase::ForProfile(profile());
+
// Always set password sync enabled so we can test the behavior of password
// generation.
- profile()->GetPrefs()->SetBoolean(prefs::kSyncKeepEverythingSynced, false);
+ prefs->SetBoolean(prefs::kSyncKeepEverythingSynced, false);
ProfileSyncService* sync_service = ProfileSyncServiceFactory::GetForProfile(
profile());
sync_service->SetSyncSetupCompleted();
@@ -2986,24 +2985,24 @@
sync_service->ChangePreferredDataTypes(preferred_set);
// Enabled state remains false, should not sent.
- profile()->GetPrefs()->SetBoolean(prefs::kPasswordGenerationEnabled, false);
+ prefs->SetBoolean(prefs::kPasswordGenerationEnabled, false);
UpdatePasswordGenerationState(false);
EXPECT_EQ(0u, autofill_manager_->GetSentStates().size());
// Enabled state from false to true, should sent true.
- profile()->GetPrefs()->SetBoolean(prefs::kPasswordGenerationEnabled, true);
+ prefs->SetBoolean(prefs::kPasswordGenerationEnabled, true);
UpdatePasswordGenerationState(false);
EXPECT_EQ(1u, autofill_manager_->GetSentStates().size());
EXPECT_TRUE(autofill_manager_->GetSentStates()[0]);
autofill_manager_->ClearSentStates();
// Enabled states remains true, should not sent.
- profile()->GetPrefs()->SetBoolean(prefs::kPasswordGenerationEnabled, true);
+ prefs->SetBoolean(prefs::kPasswordGenerationEnabled, true);
UpdatePasswordGenerationState(false);
EXPECT_EQ(0u, autofill_manager_->GetSentStates().size());
// Enabled states from true to false, should sent false.
- profile()->GetPrefs()->SetBoolean(prefs::kPasswordGenerationEnabled, false);
+ prefs->SetBoolean(prefs::kPasswordGenerationEnabled, false);
UpdatePasswordGenerationState(false);
EXPECT_EQ(1u, autofill_manager_->GetSentStates().size());
EXPECT_FALSE(autofill_manager_->GetSentStates()[0]);
diff --git a/chrome/browser/autofill/personal_data_manager.cc b/chrome/browser/autofill/personal_data_manager.cc
index 161a9cc..4e86198 100644
--- a/chrome/browser/autofill/personal_data_manager.cc
+++ b/chrome/browser/autofill/personal_data_manager.cc
@@ -19,7 +19,7 @@
#include "chrome/browser/autofill/phone_number.h"
#include "chrome/browser/autofill/phone_number_i18n.h"
#include "chrome/browser/autofill/select_control_handler.h"
-#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/api/prefs/pref_service_base.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
@@ -170,7 +170,8 @@
ProfileSyncService* sync_service =
ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_);
if (sync_service && (!sync_service->HasSyncSetupCompleted() ||
- !profile_->GetPrefs()->GetBoolean(prefs::kSyncAutofill))) {
+ !PrefServiceBase::ForProfile(profile_)->GetBoolean(
+ prefs::kSyncAutofill))) {
scoped_refptr<WebDataService> web_data_service =
WebDataServiceFactory::GetForProfile(profile_,
Profile::EXPLICIT_ACCESS);
@@ -533,8 +534,10 @@
const std::vector<AutofillProfile*>& PersonalDataManager::profiles() const {
// |profile_| is NULL in AutofillManagerTest.
- bool auxiliary_profiles_enabled = profile_ ? profile_->GetPrefs()->GetBoolean(
- prefs::kAutofillAuxiliaryProfilesEnabled) : false;
+ bool auxiliary_profiles_enabled = profile_ ?
+ PrefServiceBase::ForProfile(profile_)->GetBoolean(
+ prefs::kAutofillAuxiliaryProfilesEnabled) :
+ false;
if (!auxiliary_profiles_enabled)
return web_profiles();
@@ -595,7 +598,8 @@
}
bool PersonalDataManager::IsAutofillEnabled() const {
- return profile_->GetPrefs()->GetBoolean(prefs::kAutofillEnabled);
+ return PrefServiceBase::ForProfile(profile_)->GetBoolean(
+ prefs::kAutofillEnabled);
}
// static
diff --git a/chrome/browser/captive_portal/captive_portal_service.cc b/chrome/browser/captive_portal/captive_portal_service.cc
index e449ae0..ec73711 100644
--- a/chrome/browser/captive_portal/captive_portal_service.cc
+++ b/chrome/browser/captive_portal/captive_portal_service.cc
@@ -11,6 +11,7 @@
#include "base/metrics/histogram.h"
#include "base/rand_util.h"
#include "base/string_number_conversions.h"
+#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/pref_names.h"
diff --git a/chrome/browser/chromeos/input_method/browser_state_monitor.h b/chrome/browser/chromeos/input_method/browser_state_monitor.h
index 193e184..5043de4 100644
--- a/chrome/browser/chromeos/input_method/browser_state_monitor.h
+++ b/chrome/browser/chromeos/input_method/browser_state_monitor.h
@@ -13,6 +13,8 @@
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_types.h"
+class PrefService;
+
namespace chromeos {
namespace input_method {
diff --git a/chrome/browser/download/download_prefs.cc b/chrome/browser/download/download_prefs.cc
index e5590b6e..6bf07ff 100644
--- a/chrome/browser/download/download_prefs.cc
+++ b/chrome/browser/download/download_prefs.cc
@@ -67,26 +67,26 @@
}
// static
-void DownloadPrefs::RegisterUserPrefs(PrefService* prefs) {
+void DownloadPrefs::RegisterUserPrefs(PrefServiceBase* prefs) {
prefs->RegisterBooleanPref(prefs::kPromptForDownload,
false,
- PrefService::SYNCABLE_PREF);
+ PrefServiceBase::SYNCABLE_PREF);
prefs->RegisterStringPref(prefs::kDownloadExtensionsToOpen,
"",
- PrefService::UNSYNCABLE_PREF);
+ PrefServiceBase::UNSYNCABLE_PREF);
prefs->RegisterBooleanPref(prefs::kDownloadDirUpgraded,
false,
- PrefService::UNSYNCABLE_PREF);
+ PrefServiceBase::UNSYNCABLE_PREF);
prefs->RegisterIntegerPref(prefs::kSaveFileType,
content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML,
- PrefService::UNSYNCABLE_PREF);
+ PrefServiceBase::UNSYNCABLE_PREF);
// The default download path is userprofile\download.
const FilePath& default_download_path =
download_util::GetDefaultDownloadDirectory();
prefs->RegisterFilePathPref(prefs::kDownloadDefaultDirectory,
default_download_path,
- PrefService::UNSYNCABLE_PREF);
+ PrefServiceBase::UNSYNCABLE_PREF);
#if defined(OS_CHROMEOS)
// Ensure that the download directory specified in the preferences exists.
diff --git a/chrome/browser/download/download_prefs.h b/chrome/browser/download/download_prefs.h
index 7d214b5..75c16d7 100644
--- a/chrome/browser/download/download_prefs.h
+++ b/chrome/browser/download/download_prefs.h
@@ -23,7 +23,7 @@
explicit DownloadPrefs(Profile* profile);
~DownloadPrefs();
- static void RegisterUserPrefs(PrefService* prefs);
+ static void RegisterUserPrefs(PrefServiceBase* prefs);
// Returns the DownloadPrefs corresponding to the given DownloadManager
// or BrowserContext.
diff --git a/chrome/browser/extensions/api/font_settings/font_settings_api.h b/chrome/browser/extensions/api/font_settings/font_settings_api.h
index 35e8e94..152cf51 100644
--- a/chrome/browser/extensions/api/font_settings/font_settings_api.h
+++ b/chrome/browser/extensions/api/font_settings/font_settings_api.h
@@ -14,6 +14,7 @@
#include "chrome/browser/api/prefs/pref_change_registrar.h"
#include "chrome/browser/extensions/extension_function.h"
+#include "chrome/browser/prefs/pref_service.h"
namespace extensions {
diff --git a/chrome/browser/net/chrome_network_delegate.cc b/chrome/browser/net/chrome_network_delegate.cc
index f4835852..027c7bd 100644
--- a/chrome/browser/net/chrome_network_delegate.cc
+++ b/chrome/browser/net/chrome_network_delegate.cc
@@ -16,6 +16,7 @@
#include "chrome/browser/extensions/extension_info_map.h"
#include "chrome/browser/extensions/extension_process_manager.h"
#include "chrome/browser/net/load_time_stats.h"
+#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/task_manager/task_manager.h"
#include "chrome/common/pref_names.h"
diff --git a/chrome/browser/net/net_pref_observer.h b/chrome/browser/net/net_pref_observer.h
index 242661f..f1f2ac25 100644
--- a/chrome/browser/net/net_pref_observer.h
+++ b/chrome/browser/net/net_pref_observer.h
@@ -19,6 +19,8 @@
class PrerenderManager;
}
+class PrefService;
+
// Monitors network-related preferences for changes and applies them.
// The supplied PrefService must outlive this NetPrefObserver.
// Must be used only on the UI thread.
diff --git a/chrome/browser/plugin_prefs.h b/chrome/browser/plugin_prefs.h
index d27875c..eddb0250 100644
--- a/chrome/browser/plugin_prefs.h
+++ b/chrome/browser/plugin_prefs.h
@@ -13,6 +13,7 @@
#include "base/file_path.h"
#include "base/synchronization/lock.h"
#include "chrome/browser/api/prefs/pref_change_registrar.h"
+#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/refcounted_profile_keyed_service.h"
#include "content/public/browser/notification_observer.h"
diff --git a/chrome/browser/policy/cloud_policy_refresh_scheduler.cc b/chrome/browser/policy/cloud_policy_refresh_scheduler.cc
index 10a319d5..dc19b5d 100644
--- a/chrome/browser/policy/cloud_policy_refresh_scheduler.cc
+++ b/chrome/browser/policy/cloud_policy_refresh_scheduler.cc
@@ -8,6 +8,7 @@
#include "base/task_runner.h"
#include "chrome/browser/policy/cloud_policy_constants.h"
+#include "chrome/browser/prefs/pref_service.h"
#include "chrome/common/chrome_notification_types.h"
#include "content/public/browser/notification_details.h"
diff --git a/chrome/browser/prefs/pref_service.cc b/chrome/browser/prefs/pref_service.cc
index 31ad5da..825eee3 100644
--- a/chrome/browser/prefs/pref_service.cc
+++ b/chrome/browser/prefs/pref_service.cc
@@ -27,6 +27,7 @@
#include "chrome/browser/prefs/pref_model_associator.h"
#include "chrome/browser/prefs/pref_notifier_impl.h"
#include "chrome/browser/prefs/pref_value_store.h"
+#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/prefs/prefs_tab_helper.h"
#include "chrome/browser/ui/profile_error_dialog.h"
#include "chrome/common/json_pref_store.h"
@@ -113,6 +114,10 @@
} // namespace
+PrefServiceBase* PrefServiceBase::ForProfile(Profile* profile) {
+ return profile->GetPrefs();
+}
+
// static
PrefService* PrefService::CreatePrefService(
const FilePath& pref_filename,
@@ -976,6 +981,10 @@
DCHECK(service);
}
+const std::string PrefService::Preference::name() const {
+ return name_;
+}
+
base::Value::Type PrefService::Preference::GetType() const {
return type_;
}
diff --git a/chrome/browser/prefs/pref_service.h b/chrome/browser/prefs/pref_service.h
index 1d43a8a1..a083cc9 100644
--- a/chrome/browser/prefs/pref_service.h
+++ b/chrome/browser/prefs/pref_service.h
@@ -17,11 +17,10 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/threading/non_thread_safe.h"
-#include "base/values.h"
+#include "chrome/browser/api/prefs/pref_service_base.h"
class CommandLine;
class DefaultPrefStore;
-class FilePath;
class PersistentPrefStore;
class PrefModelAssociator;
class PrefNotifier;
@@ -29,10 +28,6 @@
class PrefStore;
class PrefValueStore;
-namespace content {
-class NotificationObserver;
-}
-
namespace syncer {
class SyncableService;
}
@@ -42,20 +37,11 @@
}
namespace subtle {
-class PrefMemberBase;
class ScopedUserPrefUpdateBase;
};
-class PrefService : public base::NonThreadSafe {
+class PrefService : public PrefServiceBase, public base::NonThreadSafe {
public:
- // Enum used when registering preferences to determine if it should be synced
- // or not. This is only used for profile prefs, not local state prefs.
- // See the Register*Pref methods for profile prefs below.
- enum PrefSyncStatus {
- UNSYNCABLE_PREF,
- SYNCABLE_PREF
- };
-
enum PrefInitializationStatus {
INITIALIZATION_STATUS_WAITING,
INITIALIZATION_STATUS_SUCCESS,
@@ -64,7 +50,7 @@
};
// A helper class to store all the information associated with a preference.
- class Preference {
+ class Preference : public PrefServiceBase::Preference {
public:
// The type of the preference is determined by the type with which it is
// registered. This type needs to be a boolean, integer, double, string,
@@ -73,61 +59,22 @@
Preference(const PrefService* service,
const char* name,
base::Value::Type type);
- ~Preference() {}
+ virtual ~Preference() {}
- // Returns the name of the Preference (i.e., the key, e.g.,
- // browser.window_placement).
- const std::string name() const { return name_; }
-
- // Returns the registered type of the preference.
- base::Value::Type GetType() const;
-
- // Returns the value of the Preference, falling back to the registered
- // default value if no other has been set.
- const base::Value* GetValue() const;
-
- // Returns the value recommended by the admin, if any.
- const base::Value* GetRecommendedValue() const;
-
- // Returns true if the Preference is managed, i.e. set by an admin policy.
- // Since managed prefs have the highest priority, this also indicates
- // whether the pref is actually being controlled by the policy setting.
- bool IsManaged() const;
-
- // Returns true if the Preference is recommended, i.e. set by an admin
- // policy but the user is allowed to change it.
- bool IsRecommended() const;
-
- // Returns true if the Preference has a value set by an extension, even if
- // that value is being overridden by a higher-priority source.
- bool HasExtensionSetting() const;
-
- // Returns true if the Preference has a user setting, even if that value is
- // being overridden by a higher-priority source.
- bool HasUserSetting() const;
-
- // Returns true if the Preference value is currently being controlled by an
- // extension, and not by any higher-priority source.
- bool IsExtensionControlled() const;
-
- // Returns true if the Preference value is currently being controlled by a
- // user setting, and not by any higher-priority source.
- bool IsUserControlled() const;
-
- // Returns true if the Preference is currently using its default value,
- // and has not been set by any higher-priority source (even with the same
- // value).
- bool IsDefaultValue() const;
-
- // Returns true if the user can change the Preference value, which is the
- // case if no higher-priority source than the user store controls the
- // Preference.
- bool IsUserModifiable() const;
-
- // Returns true if an extension can change the Preference value, which is
- // the case if no higher-priority source than the extension store controls
- // the Preference.
- bool IsExtensionModifiable() const;
+ // PrefServiceBase::Preference implementation.
+ virtual const std::string name() const OVERRIDE;
+ virtual base::Value::Type GetType() const OVERRIDE;
+ virtual const base::Value* GetValue() const OVERRIDE;
+ virtual const base::Value* GetRecommendedValue() const OVERRIDE;
+ virtual bool IsManaged() const OVERRIDE;
+ virtual bool IsRecommended() const OVERRIDE;
+ virtual bool HasExtensionSetting() const OVERRIDE;
+ virtual bool HasUserSetting() const OVERRIDE;
+ virtual bool IsExtensionControlled() const OVERRIDE;
+ virtual bool IsUserControlled() const OVERRIDE;
+ virtual bool IsDefaultValue() const OVERRIDE;
+ virtual bool IsUserModifiable() const OVERRIDE;
+ virtual bool IsExtensionModifiable() const OVERRIDE;
private:
friend class PrefService;
@@ -177,107 +124,108 @@
// values while the importer process is running. Returns true on success.
bool ReloadPersistentPrefs();
- // Returns true if the preference for the given preference name is available
- // and is managed.
- bool IsManagedPreference(const char* pref_name) const;
-
- // Returns |true| if a preference with the given name is available and its
- // value can be changed by the user.
- bool IsUserModifiablePreference(const char* pref_name) const;
-
// Lands pending writes to disk. This should only be used if we need to save
// immediately (basically, during shutdown).
void CommitPendingWrite();
- // Make the PrefService aware of a pref.
- // TODO(zea): split local state and profile prefs into their own subclasses.
- // ---------- Local state prefs ----------
- void RegisterBooleanPref(const char* path, bool default_value);
- void RegisterIntegerPref(const char* path, int default_value);
- void RegisterDoublePref(const char* path, double default_value);
- void RegisterStringPref(const char* path, const std::string& default_value);
- void RegisterFilePathPref(const char* path, const FilePath& default_value);
- void RegisterListPref(const char* path);
- void RegisterDictionaryPref(const char* path);
- // These take ownership of the default_value:
- void RegisterListPref(const char* path,
- base::ListValue* default_value);
- void RegisterDictionaryPref(const char* path,
- base::DictionaryValue* default_value);
- // These variants use a default value from the locale dll instead.
- void RegisterLocalizedBooleanPref(const char* path,
- int locale_default_message_id);
- void RegisterLocalizedIntegerPref(const char* path,
- int locale_default_message_id);
- void RegisterLocalizedDoublePref(const char* path,
- int locale_default_message_id);
- void RegisterLocalizedStringPref(const char* path,
- int locale_default_message_id);
- void RegisterInt64Pref(const char* path, int64 default_value);
-
- // ---------- Profile prefs ----------
- // Profile prefs must specify whether the pref should be synchronized across
- // machines or not (see PrefSyncStatus enum above).
- void RegisterBooleanPref(const char* path,
- bool default_value,
- PrefSyncStatus sync_status);
- void RegisterIntegerPref(const char* path,
- int default_value,
- PrefSyncStatus sync_status);
- void RegisterDoublePref(const char* path,
- double default_value,
- PrefSyncStatus sync_status);
- void RegisterStringPref(const char* path,
- const std::string& default_value,
- PrefSyncStatus sync_status);
- void RegisterFilePathPref(const char* path,
- const FilePath& default_value,
- PrefSyncStatus sync_status);
- void RegisterListPref(const char* path, PrefSyncStatus sync_status);
- void RegisterDictionaryPref(const char* path, PrefSyncStatus sync_status);
- // These take ownership of the default_value:
- void RegisterListPref(const char* path,
- base::ListValue* default_value,
- PrefSyncStatus sync_status);
- void RegisterDictionaryPref(const char* path,
- base::DictionaryValue* default_value,
- PrefSyncStatus sync_status);
- // These variants use a default value from the locale dll instead.
- void RegisterLocalizedBooleanPref(const char* path,
- int locale_default_message_id,
- PrefSyncStatus sync_status);
- void RegisterLocalizedIntegerPref(const char* path,
- int locale_default_message_id,
- PrefSyncStatus sync_status);
- void RegisterLocalizedDoublePref(const char* path,
- int locale_default_message_id,
- PrefSyncStatus sync_status);
- void RegisterLocalizedStringPref(const char* path,
- int locale_default_message_id,
- PrefSyncStatus sync_status);
- void RegisterInt64Pref(const char* path,
- int64 default_value,
- PrefSyncStatus sync_status);
- void RegisterUint64Pref(const char* path,
- uint64 default_value,
- PrefSyncStatus sync_status);
- // Unregisters a preference.
- void UnregisterPreference(const char* path);
-
- // If the path is valid and the value at the end of the path matches the type
- // specified, it will return the specified value. Otherwise, the default
- // value (set when the pref was registered) will be returned.
- bool GetBoolean(const char* path) const;
- int GetInteger(const char* path) const;
- double GetDouble(const char* path) const;
- std::string GetString(const char* path) const;
- FilePath GetFilePath(const char* path) const;
-
- // Returns the branch if it exists, or the registered default value otherwise.
- // Note that |path| must point to a registered preference. In that case, these
- // functions will never return NULL.
- const base::DictionaryValue* GetDictionary(const char* path) const;
- const base::ListValue* GetList(const char* path) const;
+ // PrefServiceBase implementation.
+ virtual bool IsManagedPreference(const char* pref_name) const OVERRIDE;
+ virtual bool IsUserModifiablePreference(const char* pref_name) const OVERRIDE;
+ virtual void RegisterBooleanPref(const char* path,
+ bool default_value) OVERRIDE;
+ virtual void RegisterIntegerPref(const char* path,
+ int default_value) OVERRIDE;
+ virtual void RegisterDoublePref(const char* path,
+ double default_value) OVERRIDE;
+ virtual void RegisterStringPref(const char* path,
+ const std::string& default_value) OVERRIDE;
+ virtual void RegisterFilePathPref(const char* path,
+ const FilePath& default_value) OVERRIDE;
+ virtual void RegisterListPref(const char* path) OVERRIDE;
+ virtual void RegisterDictionaryPref(const char* path) OVERRIDE;
+ virtual void RegisterListPref(const char* path,
+ base::ListValue* default_value) OVERRIDE;
+ virtual void RegisterDictionaryPref(
+ const char* path, base::DictionaryValue* default_value) OVERRIDE;
+ virtual void RegisterLocalizedBooleanPref(
+ const char* path, int locale_default_message_id) OVERRIDE;
+ virtual void RegisterLocalizedIntegerPref(
+ const char* path, int locale_default_message_id) OVERRIDE;
+ virtual void RegisterLocalizedDoublePref(
+ const char* path, int locale_default_message_id) OVERRIDE;
+ virtual void RegisterLocalizedStringPref(
+ const char* path, int locale_default_message_id) OVERRIDE;
+ virtual void RegisterInt64Pref(const char* path,
+ int64 default_value) OVERRIDE;
+ virtual void RegisterBooleanPref(const char* path,
+ bool default_value,
+ PrefSyncStatus sync_status) OVERRIDE;
+ virtual void RegisterIntegerPref(const char* path,
+ int default_value,
+ PrefSyncStatus sync_status) OVERRIDE;
+ virtual void RegisterDoublePref(const char* path,
+ double default_value,
+ PrefSyncStatus sync_status) OVERRIDE;
+ virtual void RegisterStringPref(const char* path,
+ const std::string& default_value,
+ PrefSyncStatus sync_status) OVERRIDE;
+ virtual void RegisterFilePathPref(const char* path,
+ const FilePath& default_value,
+ PrefSyncStatus sync_status) OVERRIDE;
+ virtual void RegisterListPref(const char* path,
+ PrefSyncStatus sync_status) OVERRIDE;
+ virtual void RegisterDictionaryPref(const char* path,
+ PrefSyncStatus sync_status) OVERRIDE;
+ virtual void RegisterListPref(const char* path,
+ base::ListValue* default_value,
+ PrefSyncStatus sync_status) OVERRIDE;
+ virtual void RegisterDictionaryPref(const char* path,
+ base::DictionaryValue* default_value,
+ PrefSyncStatus sync_status) OVERRIDE;
+ virtual void RegisterLocalizedBooleanPref(
+ const char* path,
+ int locale_default_message_id,
+ PrefSyncStatus sync_status) OVERRIDE;
+ virtual void RegisterLocalizedIntegerPref(
+ const char* path,
+ int locale_default_message_id,
+ PrefSyncStatus sync_status) OVERRIDE;
+ virtual void RegisterLocalizedDoublePref(
+ const char* path,
+ int locale_default_message_id,
+ PrefSyncStatus sync_status) OVERRIDE;
+ virtual void RegisterLocalizedStringPref(
+ const char* path,
+ int locale_default_message_id,
+ PrefSyncStatus sync_status) OVERRIDE;
+ virtual void RegisterInt64Pref(const char* path,
+ int64 default_value,
+ PrefSyncStatus sync_status) OVERRIDE;
+ virtual void RegisterUint64Pref(const char* path,
+ uint64 default_value,
+ PrefSyncStatus sync_status) OVERRIDE;
+ virtual void UnregisterPreference(const char* path) OVERRIDE;
+ virtual const PrefService::Preference* FindPreference(
+ const char* path) const OVERRIDE;
+ virtual bool GetBoolean(const char* path) const OVERRIDE;
+ virtual int GetInteger(const char* path) const OVERRIDE;
+ virtual double GetDouble(const char* path) const OVERRIDE;
+ virtual std::string GetString(const char* path) const OVERRIDE;
+ virtual FilePath GetFilePath(const char* path) const OVERRIDE;
+ virtual const base::DictionaryValue* GetDictionary(
+ const char* path) const OVERRIDE;
+ virtual const base::ListValue* GetList(const char* path) const OVERRIDE;
+ virtual void ClearPref(const char* path) OVERRIDE;
+ virtual void Set(const char* path, const base::Value& value) OVERRIDE;
+ virtual void SetBoolean(const char* path, bool value) OVERRIDE;
+ virtual void SetInteger(const char* path, int value) OVERRIDE;
+ virtual void SetDouble(const char* path, double value) OVERRIDE;
+ virtual void SetString(const char* path, const std::string& value) OVERRIDE;
+ virtual void SetFilePath(const char* path, const FilePath& value) OVERRIDE;
+ virtual void SetInt64(const char* path, int64 value) OVERRIDE;
+ virtual int64 GetInt64(const char* path) const OVERRIDE;
+ virtual void SetUint64(const char* path, uint64 value) OVERRIDE;
+ virtual uint64 GetUint64(const char* path) const OVERRIDE;
// Returns the value of the given preference, from the user pref store. If
// the preference is not set in the user pref store, returns NULL.
@@ -287,31 +235,6 @@
// registered preference. In that case, will never return NULL.
const base::Value* GetDefaultPrefValue(const char* path) const;
- // Removes a user pref and restores the pref to its default value.
- void ClearPref(const char* path);
-
- // If the path is valid (i.e., registered), update the pref value in the user
- // prefs.
- // To set the value of dictionary or list values in the pref tree use
- // Set(), but to modify the value of a dictionary or list use either
- // ListPrefUpdate or DictionaryPrefUpdate from scoped_user_pref_update.h.
- void Set(const char* path, const base::Value& value);
- void SetBoolean(const char* path, bool value);
- void SetInteger(const char* path, int value);
- void SetDouble(const char* path, double value);
- void SetString(const char* path, const std::string& value);
- void SetFilePath(const char* path, const FilePath& value);
-
- // Int64 helper methods that actually store the given value as a string.
- // Note that if obtaining the named value via GetDictionary or GetList, the
- // Value type will be TYPE_STRING.
- void SetInt64(const char* path, int64 value);
- int64 GetInt64(const char* path) const;
-
- // As above, but for unsigned values.
- void SetUint64(const char* path, uint64 value);
- uint64 GetUint64(const char* path) const;
-
// Returns true if a value has been set for the specified path.
// NOTE: this is NOT the same as FindPreference. In particular
// FindPreference returns whether RegisterXXX has been invoked, where as
@@ -322,10 +245,6 @@
// is passed to the caller.
base::DictionaryValue* GetPreferenceValues() const;
- // A helper method to quickly look up a preference. Returns NULL if the
- // preference is not registered.
- const Preference* FindPreference(const char* pref_name) const;
-
bool ReadOnly() const;
PrefInitializationStatus GetInitializationStatus() const;
@@ -364,31 +283,19 @@
friend class PrefServiceMockBuilder;
- // Registration of pref change observers must be done using the
- // PrefChangeRegistrar, which is declared as a friend here to grant it
- // access to the otherwise protected members Add/RemovePrefObserver.
- // PrefMember registers for preferences changes notification directly to
- // avoid the storage overhead of the registrar, so its base class must be
- // declared as a friend, too.
- friend class PrefChangeRegistrar;
- friend class subtle::PrefMemberBase;
-
// Give access to ReportUserPrefChanged() and GetMutableUserPref().
friend class subtle::ScopedUserPrefUpdateBase;
+ // PrefServiceBase implementation (protected in base, private here).
+ virtual void AddPrefObserver(const char* path,
+ content::NotificationObserver* obs) OVERRIDE;
+ virtual void RemovePrefObserver(const char* path,
+ content::NotificationObserver* obs) OVERRIDE;
+
// Sends notification of a changed preference. This needs to be called by
// a ScopedUserPrefUpdate if a DictionaryValue or ListValue is changed.
void ReportUserPrefChanged(const std::string& key);
- // If the pref at the given path changes, we call the observer's Observe
- // method with PREF_CHANGED. Note that observers should not call these methods
- // directly but rather use a PrefChangeRegistrar to make sure the observer
- // gets cleaned up properly.
- virtual void AddPrefObserver(const char* path,
- content::NotificationObserver* obs);
- virtual void RemovePrefObserver(const char* path,
- content::NotificationObserver* obs);
-
// Registers a new preference at |path|. The |default_value| must not be
// NULL as it determines the preference value's type.
// RegisterPreference must not be called twice for the same path.
diff --git a/chrome/browser/printing/print_view_manager.cc b/chrome/browser/printing/print_view_manager.cc
index e8fce2e..001f656 100644
--- a/chrome/browser/printing/print_view_manager.cc
+++ b/chrome/browser/printing/print_view_manager.cc
@@ -13,6 +13,7 @@
#include "base/timer.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/printing/print_error_dialog.h"
#include "chrome/browser/printing/print_job.h"
#include "chrome/browser/printing/print_job_manager.h"
diff --git a/chrome/browser/profiles/gaia_info_update_service.cc b/chrome/browser/profiles/gaia_info_update_service.cc
index ec4fe5b..efd5188 100644
--- a/chrome/browser/profiles/gaia_info_update_service.cc
+++ b/chrome/browser/profiles/gaia_info_update_service.cc
@@ -76,11 +76,11 @@
}
// static
-void GAIAInfoUpdateService::RegisterUserPrefs(PrefService* prefs) {
+void GAIAInfoUpdateService::RegisterUserPrefs(PrefServiceBase* prefs) {
prefs->RegisterInt64Pref(
- prefs::kProfileGAIAInfoUpdateTime, 0, PrefService::UNSYNCABLE_PREF);
+ prefs::kProfileGAIAInfoUpdateTime, 0, PrefServiceBase::UNSYNCABLE_PREF);
prefs->RegisterStringPref(
- prefs::kProfileGAIAInfoPictureURL, "", PrefService::UNSYNCABLE_PREF);
+ prefs::kProfileGAIAInfoPictureURL, "", PrefServiceBase::UNSYNCABLE_PREF);
}
bool GAIAInfoUpdateService::NeedsProfilePicture() const {
diff --git a/chrome/browser/profiles/gaia_info_update_service.h b/chrome/browser/profiles/gaia_info_update_service.h
index a4b289b..7129328 100644
--- a/chrome/browser/profiles/gaia_info_update_service.h
+++ b/chrome/browser/profiles/gaia_info_update_service.h
@@ -32,7 +32,7 @@
static bool ShouldUseGAIAProfileInfo(Profile* profile);
// Register prefs for a profile.
- static void RegisterUserPrefs(PrefService* prefs);
+ static void RegisterUserPrefs(PrefServiceBase* prefs);
// ProfileDownloaderDelegate:
virtual bool NeedsProfilePicture() const OVERRIDE;
diff --git a/chrome/browser/profiles/off_the_record_profile_io_data.cc b/chrome/browser/profiles/off_the_record_profile_io_data.cc
index d9fc22e..615c030 100644
--- a/chrome/browser/profiles/off_the_record_profile_io_data.cc
+++ b/chrome/browser/profiles/off_the_record_profile_io_data.cc
@@ -15,6 +15,7 @@
#include "chrome/browser/net/chrome_net_log.h"
#include "chrome/browser/net/chrome_network_delegate.h"
#include "chrome/browser/net/chrome_url_request_context.h"
+#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/chrome_url_data_manager_backend.h"
#include "chrome/common/chrome_switches.h"
diff --git a/chrome/browser/profiles/profile_impl_io_data.cc b/chrome/browser/profiles/profile_impl_io_data.cc
index f82ab2f0..d71357a 100644
--- a/chrome/browser/profiles/profile_impl_io_data.cc
+++ b/chrome/browser/profiles/profile_impl_io_data.cc
@@ -20,6 +20,7 @@
#include "chrome/browser/net/predictor.h"
#include "chrome/browser/net/sqlite_persistent_cookie_store.h"
#include "chrome/browser/net/sqlite_server_bound_cert_store.h"
+#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/chrome_url_data_manager_backend.h"
#include "chrome/common/chrome_constants.h"
diff --git a/chrome/browser/renderer_host/plugin_info_message_filter.cc b/chrome/browser/renderer_host/plugin_info_message_filter.cc
index 88e1d17..a00f5d8 100644
--- a/chrome/browser/renderer_host/plugin_info_message_filter.cc
+++ b/chrome/browser/renderer_host/plugin_info_message_filter.cc
@@ -9,6 +9,7 @@
#include "base/utf_string_conversions.h"
#include "chrome/browser/content_settings/content_settings_utils.h"
#include "chrome/browser/content_settings/host_content_settings_map.h"
+#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_content_client.h"
#include "chrome/common/content_settings.h"
diff --git a/chrome/browser/spellchecker/spellcheck_host.cc b/chrome/browser/spellchecker/spellcheck_host.cc
index a3c9064..0483c8b 100644
--- a/chrome/browser/spellchecker/spellcheck_host.cc
+++ b/chrome/browser/spellchecker/spellcheck_host.cc
@@ -7,6 +7,7 @@
#include "base/string_split.h"
#include "base/synchronization/waitable_event.h"
#include "chrome/browser/api/prefs/pref_member.h"
+#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/spellchecker/spellcheck_host_impl.h"
#include "chrome/browser/spellchecker/spellcheck_platform_mac.h"
diff --git a/chrome/browser/ui/alternate_error_tab_observer.h b/chrome/browser/ui/alternate_error_tab_observer.h
index 4b1ca5c..9bacdd1 100644
--- a/chrome/browser/ui/alternate_error_tab_observer.h
+++ b/chrome/browser/ui/alternate_error_tab_observer.h
@@ -6,6 +6,7 @@
#define CHROME_BROWSER_UI_ALTERNATE_ERROR_TAB_OBSERVER_H_
#include "chrome/browser/api/prefs/pref_change_registrar.h"
+#include "chrome/browser/prefs/pref_service.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/web_contents_observer.h"
diff --git a/chrome/browser/ui/browser_instant_controller.cc b/chrome/browser/ui/browser_instant_controller.cc
index 293d9f5..1065dc57f 100644
--- a/chrome/browser/ui/browser_instant_controller.cc
+++ b/chrome/browser/ui/browser_instant_controller.cc
@@ -8,6 +8,7 @@
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/instant/instant_controller.h"
#include "chrome/browser/instant/instant_unload_handler.h"
+#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_tabstrip.h"
diff --git a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm
index ca7c8b5..54c85c5 100644
--- a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm
+++ b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm
@@ -22,6 +22,7 @@
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/location_bar_controller.h"
#include "chrome/browser/extensions/tab_helper.h"
+#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/search_engines/template_url_service.h"
diff --git a/chrome/browser/ui/gtk/browser_window_gtk.h b/chrome/browser/ui/gtk/browser_window_gtk.h
index d7207c5..8da72d50 100644
--- a/chrome/browser/ui/gtk/browser_window_gtk.h
+++ b/chrome/browser/ui/gtk/browser_window_gtk.h
@@ -35,6 +35,7 @@
class GlobalMenuBar;
class InfoBarContainerGtk;
class LocationBar;
+class PrefService;
class StatusBubbleGtk;
class TabContentsContainerGtk;
class TabStripGtk;
diff --git a/chrome/browser/ui/gtk/location_bar_view_gtk.cc b/chrome/browser/ui/gtk/location_bar_view_gtk.cc
index bc9d5595..5522b9e 100644
--- a/chrome/browser/ui/gtk/location_bar_view_gtk.cc
+++ b/chrome/browser/ui/gtk/location_bar_view_gtk.cc
@@ -33,6 +33,7 @@
#include "chrome/browser/extensions/location_bar_controller.h"
#include "chrome/browser/extensions/tab_helper.h"
#include "chrome/browser/favicon/favicon_tab_helper.h"
+#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/search_engines/template_url_service.h"
diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.cc b/chrome/browser/ui/views/location_bar/location_bar_view.cc
index 71df6e6..d1464492 100644
--- a/chrome/browser/ui/views/location_bar/location_bar_view.cc
+++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc
@@ -21,6 +21,7 @@
#include "chrome/browser/extensions/location_bar_controller.h"
#include "chrome/browser/extensions/tab_helper.h"
#include "chrome/browser/favicon/favicon_tab_helper.h"
+#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/search_engines/template_url_service.h"
diff --git a/chrome/browser/ui/webui/ntp/app_launcher_handler.cc b/chrome/browser/ui/webui/ntp/app_launcher_handler.cc
index c90bc0a3..305dac0 100644
--- a/chrome/browser/ui/webui/ntp/app_launcher_handler.cc
+++ b/chrome/browser/ui/webui/ntp/app_launcher_handler.cc
@@ -792,7 +792,7 @@
}
// static
-void AppLauncherHandler::RegisterUserPrefs(PrefService* pref_service) {
+void AppLauncherHandler::RegisterUserPrefs(PrefServiceBase* pref_service) {
pref_service->RegisterListPref(prefs::kNtpAppPageNames,
PrefService::SYNCABLE_PREF);
}
diff --git a/chrome/browser/ui/webui/ntp/app_launcher_handler.h b/chrome/browser/ui/webui/ntp/app_launcher_handler.h
index 715a12a..aee51b68 100644
--- a/chrome/browser/ui/webui/ntp/app_launcher_handler.h
+++ b/chrome/browser/ui/webui/ntp/app_launcher_handler.h
@@ -102,7 +102,7 @@
void HandleSetNotificationsDisabled(const base::ListValue* args);
// Register app launcher preferences.
- static void RegisterUserPrefs(PrefService* pref_service);
+ static void RegisterUserPrefs(PrefServiceBase* pref_service);
// Records the given type of app launch for UMA.
static void RecordAppLaunchType(extension_misc::AppLaunchBucket bucket);
diff --git a/chrome/browser/ui/webui/options/startup_pages_handler.cc b/chrome/browser/ui/webui/options/startup_pages_handler.cc
index 68c9897..29892b03 100644
--- a/chrome/browser/ui/webui/options/startup_pages_handler.cc
+++ b/chrome/browser/ui/webui/options/startup_pages_handler.cc
@@ -12,6 +12,7 @@
#include "chrome/browser/autocomplete/autocomplete_result.h"
#include "chrome/browser/custom_home_pages_table_model.h"
#include "chrome/browser/net/url_fixer_upper.h"
+#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/prefs/session_startup_pref.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_notification_types.h"
diff --git a/chrome/browser/ui/zoom/zoom_controller.cc b/chrome/browser/ui/zoom/zoom_controller.cc
index b828b3b0..ddb8e73e 100644
--- a/chrome/browser/ui/zoom/zoom_controller.cc
+++ b/chrome/browser/ui/zoom/zoom_controller.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/ui/zoom/zoom_controller.h"
+#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/tab_contents/tab_contents.h"