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

Side by Side Diff: chrome/common/pref_store.h

Issue 5441002: Clean up pref change notification handling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 10 years 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_COMMON_PREF_STORE_H_ 5 #ifndef CHROME_COMMON_PREF_STORE_H_
6 #define CHROME_COMMON_PREF_STORE_H_ 6 #define CHROME_COMMON_PREF_STORE_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string>
10
11 #include "base/basictypes.h"
12
9 class DictionaryValue; 13 class DictionaryValue;
10 class Value; 14 class Value;
11 15
12 // This is an abstract interface for reading and writing from/to a persistent 16 // This is an abstract interface for reading and writing from/to a persistent
13 // preference store, used by |PrefService|. An implementation using a JSON file 17 // preference store, used by PrefService. An implementation using a JSON file
14 // can be found in |JsonPrefStore|, while an implementation without any backing 18 // can be found in JsonPrefStore, while an implementation without any backing
15 // store (currently used for testing) can be found in |DummyPrefStore|. 19 // store for testing can be found in TestingPrefStore. Furthermore, there is
20 // CommandLinePrefStore, which bridges command line options to preferences and
21 // ConfigurationPolicyPrefStore, which is used for hooking up configuration
22 // policy with the preference subsystem.
16 class PrefStore { 23 class PrefStore {
17 public: 24 public:
25 // Observer interface for monitoring PrefStore.
26 class ObserverInterface {
27 public:
28 virtual ~ObserverInterface() {}
29
30 // Called when the value for the given |key| in the store changes.
31 virtual void OnPrefValueChanged(const std::string& key) = 0;
32 // Notification about the PrefStore being fully initialized.
33 virtual void OnInitializationCompleted() = 0;
34 };
35
18 // Unique integer code for each type of error so we can report them 36 // Unique integer code for each type of error so we can report them
19 // distinctly in a histogram. 37 // distinctly in a histogram.
20 // NOTE: Don't change the order here as it will change the server's meaning 38 // NOTE: Don't change the order here as it will change the server's meaning
21 // of the histogram. 39 // of the histogram.
22 enum PrefReadError { 40 enum PrefReadError {
23 PREF_READ_ERROR_NONE = 0, 41 PREF_READ_ERROR_NONE = 0,
24 PREF_READ_ERROR_JSON_PARSE, 42 PREF_READ_ERROR_JSON_PARSE,
25 PREF_READ_ERROR_JSON_TYPE, 43 PREF_READ_ERROR_JSON_TYPE,
26 PREF_READ_ERROR_ACCESS_DENIED, 44 PREF_READ_ERROR_ACCESS_DENIED,
27 PREF_READ_ERROR_FILE_OTHER, 45 PREF_READ_ERROR_FILE_OTHER,
28 PREF_READ_ERROR_FILE_LOCKED, 46 PREF_READ_ERROR_FILE_LOCKED,
29 PREF_READ_ERROR_NO_FILE, 47 PREF_READ_ERROR_NO_FILE,
30 PREF_READ_ERROR_JSON_REPEAT, 48 PREF_READ_ERROR_JSON_REPEAT,
31 PREF_READ_ERROR_OTHER, 49 PREF_READ_ERROR_OTHER,
32 PREF_READ_ERROR_FILE_NOT_SPECIFIED 50 PREF_READ_ERROR_FILE_NOT_SPECIFIED
33 }; 51 };
34 52
35 // To require that the default value be used for a preference, a 53 // To require that the default value be used for a preference, a
36 // PrefStore can set the value in its own prefs dictionary to the 54 // PrefStore can set the value in its own prefs dictionary to the
37 // sentinel Value returned by this function. 55 // sentinel Value returned by this function.
38 // TODO(danno): Instead of having a sentinel value, pref stores 56 // TODO(danno): Instead of having a sentinel value, pref stores
39 // should return a richer set of information from the property 57 // should return a richer set of information from the property
40 // accessor methods to indicate that the default should be used. 58 // accessor methods to indicate that the default should be used.
41 static Value* CreateUseDefaultSentinelValue(); 59 static Value* CreateUseDefaultSentinelValue();
42 60
43 // Returns true if a value is the special sentinel value created by 61 // Returns true if a value is the special sentinel value created by
44 // CreateUseDefaultSentinelValue. 62 // CreateUseDefaultSentinelValue.
45 static bool IsUseDefaultSentinelValue(Value* value); 63 static bool IsUseDefaultSentinelValue(Value* value);
46 64
47 virtual ~PrefStore() { } 65 PrefStore() {}
66 virtual ~PrefStore() {}
67
68 // Add and remove observers.
69 virtual void AddObserver(ObserverInterface* observer) {};
danno 2010/12/02 10:31:52 = 0? If not, please check multiple inheritance gui
Mattias Nissler (ping if slow) 2010/12/02 16:38:24 There are no cases of multiple inheritance concern
70 virtual void RemoveObserver(ObserverInterface* observer) {};
71
72 // Whether the store has completed all asynchronous initialization.
73 virtual bool IsInitializationComplete() { return true; }
48 74
49 // Whether the store is in a pseudo-read-only mode where changes are not 75 // Whether the store is in a pseudo-read-only mode where changes are not
50 // actually persisted to disk. This happens in some cases when there are 76 // actually persisted to disk. This happens in some cases when there are
51 // read errors during startup. 77 // read errors during startup.
52 virtual bool ReadOnly() { return true; } 78 virtual bool ReadOnly() { return true; }
53 79
54 // TODO(danno): PrefValueStore shouldn't allow direct access to the 80 // TODO(danno): PrefValueStore shouldn't allow direct access to the
55 // DictionaryValue. Instead, it should have getters that return a 81 // DictionaryValue. Instead, it should have getters that return a
56 // richer set of information for a pref, including if the store 82 // richer set of information for a pref, including if the store
57 // wants to return the default value for a preference. 83 // wants to return the default value for a preference.
58 virtual DictionaryValue* prefs() const = 0; 84 virtual DictionaryValue* prefs() const = 0;
59 85
60 virtual PrefReadError ReadPrefs() = 0; 86 virtual PrefReadError ReadPrefs() = 0;
61 87
62 virtual bool WritePrefs() { return true; } 88 virtual bool WritePrefs() { return true; }
63 89
64 virtual void ScheduleWritePrefs() { } 90 virtual void ScheduleWritePrefs() { }
91
92 DISALLOW_COPY_AND_ASSIGN(PrefStore);
65 }; 93 };
66 94
67 #endif // CHROME_COMMON_PREF_STORE_H_ 95 #endif // CHROME_COMMON_PREF_STORE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698