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

Unified Diff: chrome/browser/prefs/pref_service.h

Issue 3323022: Create a DefaultPrefStore to hold registered application-default preference v... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 3 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/prefs/pref_service.h
===================================================================
--- chrome/browser/prefs/pref_service.h (revision 59196)
+++ chrome/browser/prefs/pref_service.h (working copy)
@@ -28,14 +28,13 @@
class Preference {
public:
- // The type of the preference is determined by the type of |default_value|.
- // Therefore, the type needs to be a boolean, integer, real, string,
+ // The type of the preference is determined by the type with which it is
+ // registered. This type needs to be a boolean, integer, real, string,
// dictionary (a branch), or list. You shouldn't need to construct this on
- // your own, use the PrefService::Register*Pref methods instead.
- // |default_value| will be owned by the Preference object.
- Preference(PrefValueStore* pref_value_store,
+ // your own; use the PrefService::Register*Pref methods instead.
+ Preference(const PrefService* service,
const char* name,
- Value* default_value);
+ Value::ValueType type);
~Preference() {}
Value::ValueType type() const { return type_; }
@@ -44,13 +43,10 @@
// browser.window_placement).
const std::string name() const { return name_; }
- // Returns the value of the Preference. If there is no user specified
- // value, it returns the default value.
+ // Returns the value of the Preference, falling back to the registered
+ // default value if no other has been set.
const Value* GetValue() const;
- // Returns true if the current value matches the default value.
- bool IsDefaultValue() 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.
@@ -72,6 +68,11 @@
// 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.
@@ -82,10 +83,9 @@
Value::ValueType type_;
std::string name_;
- scoped_ptr<Value> default_value_;
- // A reference to the pref service's pref_value_store_.
- PrefValueStore* pref_value_store_;
+ // Reference to the PrefService in which this pref was created.
+ const PrefService* pref_service_;
DISALLOW_COPY_AND_ASSIGN(Preference);
};
@@ -100,8 +100,8 @@
// Convenience factory method for use in unit tests. Creates a new
// PrefService that uses a PrefValueStore with user preferences at the given
- // |pref_filename|, and no other PrefStores (i.e., no other types of
- // preferences).
+ // |pref_filename|, a default PrefStore, and no other PrefStores (i.e., no
+ // other types of preferences).
static PrefService* CreateUserPrefService(const FilePath& pref_filename);
// This constructor is primarily used by tests. The |pref_value_store|
@@ -171,7 +171,9 @@
void ClearPref(const char* path);
// If the path is valid (i.e., registered), update the pref value in the user
- // prefs.
+ // prefs. Seting a null value on a preference of List or Dictionary type is
+ // equivalent to removing the user value for that preference, allowing the
+ // default value to take effect unless another value takes precedence.
void Set(const char* path, const Value& value);
void SetBoolean(const char* path, bool value);
void SetInteger(const char* path, int value);
@@ -219,6 +221,8 @@
PrefNotifier* pref_notifier() const { return pref_notifier_.get(); }
+ PrefValueStore* pref_value_store() const { return pref_value_store_.get(); }
+
protected:
// The PrefNotifier handles registering and notifying preference observers.
// It is created and owned by this PrefService. Subclasses may access it for
@@ -227,13 +231,17 @@
private:
// Add a preference to the PreferenceMap. If the pref already exists, return
- // false. This method takes ownership of |pref|.
- void RegisterPreference(Preference* pref);
+ // false. This method takes ownership of |default_value|.
+ void RegisterPreference(const char* path, Value* default_value);
// Returns a copy of the current pref value. The caller is responsible for
// deleting the returned object.
Value* GetPrefCopy(const char* pref_name);
+ // Sets the value for this pref path in the user pref store and informs the
+ // PrefNotifier of the change.
+ void SetUserPrefValue(const char* path, Value* new_value);
+
// Load from disk. Returns a non-zero error code on failure.
PrefStore::PrefReadError LoadPersistentPrefs();

Powered by Google App Engine
This is Rietveld 408576698