Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3677)

Unified Diff: chrome/browser/api/prefs/pref_service_base.h

Issue 10828345: Extract PrefServiceBase into chrome/browser/api. Use in api and autofill. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/api/prefs/pref_service_base.h
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 0000000000000000000000000000000000000000..388f35e41b23fcdfc502cac121dfb4f9415f2f86
--- /dev/null
+++ b/chrome/browser/api/prefs/pref_service_base.h
@@ -0,0 +1,216 @@
+// 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.
erikwright (departed) 2012/08/16 15:12:40 I'm not a big fan of this. Is there a reason why P
Jói 2012/08/16 15:35:56 First off I should note that we want to stop depen
+ 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
+ };
+
+ // 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;
+
+ // 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;
+
+ // 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.
+ virtual const base::Value* GetUserPrefValue(const char* path) const = 0;
+
+ // Returns the default value of the given preference. |path| must point to a
+ // registered preference. In that case, will never return NULL.
+ virtual const base::Value* GetDefaultPrefValue(
+ 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_

Powered by Google App Engine
This is Rietveld 408576698