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