OLD | NEW |
---|---|
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> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 | 12 |
13 class DictionaryValue; | |
14 class Value; | 13 class Value; |
15 | 14 |
16 // This is an abstract interface for reading and writing from/to a persistent | 15 // This is an abstract interface for reading and writing from/to a persistent |
17 // preference store, used by PrefService. An implementation using a JSON file | 16 // preference store, used by PrefService. An implementation using a JSON file |
18 // can be found in JsonPrefStore, while an implementation without any backing | 17 // can be found in JsonPrefStore, while an implementation without any backing |
19 // store for testing can be found in TestingPrefStore. Furthermore, there is | 18 // store for testing can be found in TestingPrefStore. Furthermore, there is |
20 // CommandLinePrefStore, which bridges command line options to preferences and | 19 // CommandLinePrefStore, which bridges command line options to preferences and |
21 // ConfigurationPolicyPrefStore, which is used for hooking up configuration | 20 // ConfigurationPolicyPrefStore, which is used for hooking up configuration |
22 // policy with the preference subsystem. | 21 // policy with the preference subsystem. |
23 class PrefStore { | 22 class PrefStore { |
24 public: | 23 public: |
25 // Observer interface for monitoring PrefStore. | 24 // Observer interface for monitoring PrefStore. |
26 class ObserverInterface { | 25 class ObserverInterface { |
battre (please use the other)
2010/12/08 12:24:15
Observer instead of ObserverInterface?
grep -r Ob
Mattias Nissler (ping if slow)
2010/12/09 10:20:20
Well, fight with Danno over it, I don't really car
| |
27 public: | 26 public: |
28 virtual ~ObserverInterface() {} | 27 virtual ~ObserverInterface() {} |
29 | 28 |
30 // Called when the value for the given |key| in the store changes. | 29 // Called when the value for the given |key| in the store changes. |
31 virtual void OnPrefValueChanged(const std::string& key) = 0; | 30 virtual void OnPrefValueChanged(const std::string& key) = 0; |
32 // Notification about the PrefStore being fully initialized. | 31 // Notification about the PrefStore being fully initialized. |
33 virtual void OnInitializationCompleted() = 0; | 32 virtual void OnInitializationCompleted() = 0; |
34 }; | 33 }; |
35 | 34 |
36 // Unique integer code for each type of error so we can report them | 35 // Return values for GetValue(). |
37 // distinctly in a histogram. | 36 enum ReadResult { |
38 // NOTE: Don't change the order here as it will change the server's meaning | 37 // Value found and returned. |
39 // of the histogram. | 38 READ_OK, |
40 enum PrefReadError { | 39 // No value present, but skip other pref stores and use default. |
battre (please use the other)
2010/12/08 12:24:15
I don't understand the "but skip other pref stores
Mattias Nissler (ping if slow)
2010/12/09 10:20:20
This kludge is here for proxy prefs and tells the
| |
41 PREF_READ_ERROR_NONE = 0, | 40 READ_USE_DEFAULT, |
42 PREF_READ_ERROR_JSON_PARSE, | 41 // No value present. |
43 PREF_READ_ERROR_JSON_TYPE, | 42 READ_NO_VALUE, |
44 PREF_READ_ERROR_ACCESS_DENIED, | |
45 PREF_READ_ERROR_FILE_OTHER, | |
46 PREF_READ_ERROR_FILE_LOCKED, | |
47 PREF_READ_ERROR_NO_FILE, | |
48 PREF_READ_ERROR_JSON_REPEAT, | |
49 PREF_READ_ERROR_OTHER, | |
50 PREF_READ_ERROR_FILE_NOT_SPECIFIED | |
51 }; | 43 }; |
52 | 44 |
53 // To require that the default value be used for a preference, a | |
54 // PrefStore can set the value in its own prefs dictionary to the | |
55 // sentinel Value returned by this function. | |
56 // TODO(danno): Instead of having a sentinel value, pref stores | |
57 // should return a richer set of information from the property | |
58 // accessor methods to indicate that the default should be used. | |
59 static Value* CreateUseDefaultSentinelValue(); | |
60 | |
61 // Returns true if a value is the special sentinel value created by | |
62 // CreateUseDefaultSentinelValue. | |
63 static bool IsUseDefaultSentinelValue(Value* value); | |
64 | |
65 PrefStore() {} | 45 PrefStore() {} |
66 virtual ~PrefStore() {} | 46 virtual ~PrefStore() {} |
67 | 47 |
68 // Add and remove observers. | 48 // Add and remove observers. |
69 virtual void AddObserver(ObserverInterface* observer) {} | 49 virtual void AddObserver(ObserverInterface* observer) {} |
70 virtual void RemoveObserver(ObserverInterface* observer) {} | 50 virtual void RemoveObserver(ObserverInterface* observer) {} |
71 | 51 |
72 // Whether the store has completed all asynchronous initialization. | 52 // Whether the store has completed all asynchronous initialization. |
73 virtual bool IsInitializationComplete() { return true; } | 53 virtual bool IsInitializationComplete() { return true; } |
74 | 54 |
75 // Whether the store is in a pseudo-read-only mode where changes are not | 55 // Get the value for a given preference |key| and stores it in |result|. |
76 // actually persisted to disk. This happens in some cases when there are | 56 // Ownership remains with the PrefStore. |
battre (please use the other)
2010/12/08 12:24:15
Does not modify |result| if the key does not exist
Mattias Nissler (ping if slow)
2010/12/09 10:20:20
Done.
| |
77 // read errors during startup. | 57 virtual ReadResult GetValue(const std::string& key, Value** result) const = 0; |
78 virtual bool ReadOnly() const { return true; } | |
79 | |
80 // TODO(danno): PrefValueStore shouldn't allow direct access to the | |
81 // DictionaryValue. Instead, it should have getters that return a | |
82 // richer set of information for a pref, including if the store | |
83 // wants to return the default value for a preference. | |
84 virtual DictionaryValue* prefs() const = 0; | |
85 | |
86 virtual PrefReadError ReadPrefs() = 0; | |
87 | |
88 virtual bool WritePrefs() { return true; } | |
89 | |
90 virtual void ScheduleWritePrefs() { } | |
91 | 58 |
92 DISALLOW_COPY_AND_ASSIGN(PrefStore); | 59 DISALLOW_COPY_AND_ASSIGN(PrefStore); |
93 }; | 60 }; |
94 | 61 |
95 #endif // CHROME_COMMON_PREF_STORE_H_ | 62 #endif // CHROME_COMMON_PREF_STORE_H_ |
OLD | NEW |