OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 BASE_PREFS_WRITEABLE_PREF_STORE_H_ | 5 #ifndef BASE_PREFS_WRITEABLE_PREF_STORE_H_ |
6 #define BASE_PREFS_WRITEABLE_PREF_STORE_H_ | 6 #define BASE_PREFS_WRITEABLE_PREF_STORE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/prefs/pref_store.h" | 11 #include "base/prefs/pref_store.h" |
12 | 12 |
13 namespace base { | 13 namespace base { |
14 class Value; | 14 class Value; |
15 } | 15 } |
16 | 16 |
17 // A pref store that can be written to as well as read from. | 17 // A pref store that can be written to as well as read from. |
18 class BASE_PREFS_EXPORT WriteablePrefStore : public PrefStore { | 18 class BASE_PREFS_EXPORT WriteablePrefStore : public PrefStore { |
19 public: | 19 public: |
| 20 // PrefWriteFlags can be used to change the way a pref will be written to |
| 21 // storage. |
| 22 enum PrefWriteFlags : uint32 { |
| 23 // No flags are specified. |
| 24 DEFAULT_PREF_WRITE_FLAGS = 0, |
| 25 |
| 26 // This marks the pref as "lossy". There is no strict time guarantee on when |
| 27 // a lossy pref will be persisted to permanent storage when it is modified. |
| 28 LOSSY_PREF_WRITE_FLAG = 1 << 1 |
| 29 }; |
| 30 |
20 WriteablePrefStore() {} | 31 WriteablePrefStore() {} |
21 | 32 |
22 // Sets a |value| for |key| in the store. Assumes ownership of |value|, which | 33 // Sets a |value| for |key| in the store. Assumes ownership of |value|, which |
23 // must be non-NULL. | 34 // must be non-NULL. |flags| is a bitmask of PrefWriteFlags. |
24 virtual void SetValue(const std::string& key, base::Value* value) = 0; | 35 virtual void SetValue(const std::string& key, |
| 36 base::Value* value, |
| 37 uint32 flags) = 0; |
25 | 38 |
26 // Removes the value for |key|. | 39 // Removes the value for |key|. |
27 virtual void RemoveValue(const std::string& key) = 0; | 40 virtual void RemoveValue(const std::string& key, uint32 flags) = 0; |
28 | 41 |
29 // Equivalent to PrefStore::GetValue but returns a mutable value. | 42 // Equivalent to PrefStore::GetValue but returns a mutable value. |
30 virtual bool GetMutableValue(const std::string& key, | 43 virtual bool GetMutableValue(const std::string& key, |
31 base::Value** result) = 0; | 44 base::Value** result) = 0; |
32 | 45 |
33 // Triggers a value changed notification. This function needs to be called | 46 // Triggers a value changed notification. This function needs to be called |
34 // if one retrieves a list or dictionary with GetMutableValue and change its | 47 // if one retrieves a list or dictionary with GetMutableValue and change its |
35 // value. SetValue takes care of notifications itself. Note that | 48 // value. SetValue takes care of notifications itself. Note that |
36 // ReportValueChanged will trigger notifications even if nothing has changed. | 49 // ReportValueChanged will trigger notifications even if nothing has changed. |
37 virtual void ReportValueChanged(const std::string& key) = 0; | 50 // |flags| is a bitmask of PrefWriteFlags. |
| 51 virtual void ReportValueChanged(const std::string& key, uint32 flags) = 0; |
38 | 52 |
39 // Same as SetValue, but doesn't generate notifications. This is used by | 53 // Same as SetValue, but doesn't generate notifications. This is used by |
40 // PrefService::GetMutableUserPref() in order to put empty entries | 54 // PrefService::GetMutableUserPref() in order to put empty entries |
41 // into the user pref store. Using SetValue is not an option since existing | 55 // into the user pref store. Using SetValue is not an option since existing |
42 // tests rely on the number of notifications generated. | 56 // tests rely on the number of notifications generated. |flags| is a bitmask |
43 virtual void SetValueSilently(const std::string& key, base::Value* value) = 0; | 57 // of PrefWriteFlags. |
| 58 virtual void SetValueSilently(const std::string& key, |
| 59 base::Value* value, |
| 60 uint32 flags) = 0; |
44 | 61 |
45 protected: | 62 protected: |
46 ~WriteablePrefStore() override {} | 63 ~WriteablePrefStore() override {} |
47 | 64 |
48 private: | 65 private: |
49 DISALLOW_COPY_AND_ASSIGN(WriteablePrefStore); | 66 DISALLOW_COPY_AND_ASSIGN(WriteablePrefStore); |
50 }; | 67 }; |
51 | 68 |
52 #endif // BASE_PREFS_WRITEABLE_PREF_STORE_H_ | 69 #endif // BASE_PREFS_WRITEABLE_PREF_STORE_H_ |
OLD | NEW |