| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_PERSISTENT_PREF_STORE_H_ | 5 #ifndef BASE_PREFS_PERSISTENT_PREF_STORE_H_ |
| 6 #define BASE_PREFS_PERSISTENT_PREF_STORE_H_ | 6 #define BASE_PREFS_PERSISTENT_PREF_STORE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/prefs/base_prefs_export.h" | 10 #include "base/prefs/base_prefs_export.h" |
| 11 #include "base/prefs/pref_store.h" | 11 #include "base/prefs/writeable_pref_store.h" |
| 12 | 12 |
| 13 // This interface is complementary to the PrefStore interface, declaring | 13 // This interface is complementary to the PrefStore interface, declaring |
| 14 // additional functionality that adds support for setting values and persisting | 14 // additional functionality that adds support for setting values and persisting |
| 15 // the data to some backing store. | 15 // the data to some backing store. |
| 16 class BASE_PREFS_EXPORT PersistentPrefStore : public PrefStore { | 16 class BASE_PREFS_EXPORT PersistentPrefStore : public WriteablePrefStore { |
| 17 public: | 17 public: |
| 18 // Unique integer code for each type of error so we can report them | 18 // Unique integer code for each type of error so we can report them |
| 19 // distinctly in a histogram. | 19 // distinctly in a histogram. |
| 20 // NOTE: Don't change the order here as it will change the server's meaning | 20 // NOTE: Don't change the order here as it will change the server's meaning |
| 21 // of the histogram. | 21 // of the histogram. |
| 22 enum PrefReadError { | 22 enum PrefReadError { |
| 23 PREF_READ_ERROR_NONE = 0, | 23 PREF_READ_ERROR_NONE = 0, |
| 24 PREF_READ_ERROR_JSON_PARSE, | 24 PREF_READ_ERROR_JSON_PARSE, |
| 25 PREF_READ_ERROR_JSON_TYPE, | 25 PREF_READ_ERROR_JSON_TYPE, |
| 26 PREF_READ_ERROR_ACCESS_DENIED, | 26 PREF_READ_ERROR_ACCESS_DENIED, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 43 // Equivalent to PrefStore::GetValue but returns a mutable value. | 43 // Equivalent to PrefStore::GetValue but returns a mutable value. |
| 44 virtual bool GetMutableValue(const std::string& key, | 44 virtual bool GetMutableValue(const std::string& key, |
| 45 base::Value** result) = 0; | 45 base::Value** result) = 0; |
| 46 | 46 |
| 47 // Triggers a value changed notification. This function needs to be called | 47 // Triggers a value changed notification. This function needs to be called |
| 48 // if one retrieves a list or dictionary with GetMutableValue and change its | 48 // if one retrieves a list or dictionary with GetMutableValue and change its |
| 49 // value. SetValue takes care of notifications itself. Note that | 49 // value. SetValue takes care of notifications itself. Note that |
| 50 // ReportValueChanged will trigger notifications even if nothing has changed. | 50 // ReportValueChanged will trigger notifications even if nothing has changed. |
| 51 virtual void ReportValueChanged(const std::string& key) = 0; | 51 virtual void ReportValueChanged(const std::string& key) = 0; |
| 52 | 52 |
| 53 // Sets a |value| for |key| in the store. Assumes ownership of |value|, which | |
| 54 // must be non-NULL. | |
| 55 virtual void SetValue(const std::string& key, base::Value* value) = 0; | |
| 56 | |
| 57 // 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 |
| 58 // PrefService::GetMutableUserPref() in order to put empty entries | 54 // PrefService::GetMutableUserPref() in order to put empty entries |
| 59 // 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 |
| 60 // tests rely on the number of notifications generated. | 56 // tests rely on the number of notifications generated. |
| 61 virtual void SetValueSilently(const std::string& key, base::Value* value) = 0; | 57 virtual void SetValueSilently(const std::string& key, base::Value* value) = 0; |
| 62 | 58 |
| 63 // Removes the value for |key|. | |
| 64 virtual void RemoveValue(const std::string& key) = 0; | |
| 65 | |
| 66 // Whether the store is in a pseudo-read-only mode where changes are not | 59 // Whether the store is in a pseudo-read-only mode where changes are not |
| 67 // actually persisted to disk. This happens in some cases when there are | 60 // actually persisted to disk. This happens in some cases when there are |
| 68 // read errors during startup. | 61 // read errors during startup. |
| 69 virtual bool ReadOnly() const = 0; | 62 virtual bool ReadOnly() const = 0; |
| 70 | 63 |
| 71 // Gets the read error. Only valid if IsInitializationComplete() returns true. | 64 // Gets the read error. Only valid if IsInitializationComplete() returns true. |
| 72 virtual PrefReadError GetReadError() const = 0; | 65 virtual PrefReadError GetReadError() const = 0; |
| 73 | 66 |
| 74 // Reads the preferences from disk. Notifies observers via | 67 // Reads the preferences from disk. Notifies observers via |
| 75 // "PrefStore::OnInitializationCompleted" when done. | 68 // "PrefStore::OnInitializationCompleted" when done. |
| 76 virtual PrefReadError ReadPrefs() = 0; | 69 virtual PrefReadError ReadPrefs() = 0; |
| 77 | 70 |
| 78 // Reads the preferences from disk asynchronously. Notifies observers via | 71 // Reads the preferences from disk asynchronously. Notifies observers via |
| 79 // "PrefStore::OnInitializationCompleted" when done. Also it fires | 72 // "PrefStore::OnInitializationCompleted" when done. Also it fires |
| 80 // |error_delegate| if it is not NULL and reading error has occurred. | 73 // |error_delegate| if it is not NULL and reading error has occurred. |
| 81 // Owns |error_delegate|. | 74 // Owns |error_delegate|. |
| 82 virtual void ReadPrefsAsync(ReadErrorDelegate* error_delegate) = 0; | 75 virtual void ReadPrefsAsync(ReadErrorDelegate* error_delegate) = 0; |
| 83 | 76 |
| 84 // Lands any pending writes to disk. | 77 // Lands any pending writes to disk. |
| 85 virtual void CommitPendingWrite() = 0; | 78 virtual void CommitPendingWrite() = 0; |
| 86 | 79 |
| 87 protected: | 80 protected: |
| 88 virtual ~PersistentPrefStore() {} | 81 virtual ~PersistentPrefStore() {} |
| 89 }; | 82 }; |
| 90 | 83 |
| 91 #endif // BASE_PREFS_PERSISTENT_PREF_STORE_H_ | 84 #endif // BASE_PREFS_PERSISTENT_PREF_STORE_H_ |
| OLD | NEW |