| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_PREF_FILTER_H_ | 5 #ifndef BASE_PREFS_PREF_FILTER_H_ |
| 6 #define BASE_PREFS_PREF_FILTER_H_ | 6 #define BASE_PREFS_PREF_FILTER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback_forward.h" |
| 11 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/prefs/base_prefs_export.h" | 12 #include "base/prefs/base_prefs_export.h" |
| 11 | 13 |
| 12 namespace base { | 14 namespace base { |
| 13 class DictionaryValue; | 15 class DictionaryValue; |
| 14 class Value; | 16 class Value; |
| 15 } // namespace base | 17 } // namespace base |
| 16 | 18 |
| 17 // Filters preferences as they are loaded from disk or updated at runtime. | 19 // Filters preferences as they are loaded from disk or updated at runtime. |
| 18 // Currently supported only by JsonPrefStore. | 20 // Currently supported only by JsonPrefStore. |
| 19 class BASE_PREFS_EXPORT PrefFilter { | 21 class BASE_PREFS_EXPORT PrefFilter { |
| 20 public: | 22 public: |
| 23 // A callback to be invoked when |prefs| have been read (and possibly |
| 24 // pre-modified) and are now ready to be handed back to this callback's |
| 25 // builder. |schedule_write| indicates whether a write should be immediately |
| 26 // scheduled (typically because the |prefs| were pre-modified). |
| 27 typedef base::Callback<void(scoped_ptr<base::DictionaryValue> prefs, |
| 28 bool schedule_write)> PostFilterOnLoadCallback; |
| 29 |
| 21 virtual ~PrefFilter() {} | 30 virtual ~PrefFilter() {} |
| 22 | 31 |
| 23 // Receives notification when the pref store data has been loaded but before | 32 // This method is given ownership of the |pref_store_contents| read from disk |
| 24 // Observers are notified. | 33 // before the underlying PersistentPrefStore gets to use them. It must hand |
| 25 // Changes made by a PrefFilter during FilterOnLoad do not result in | 34 // them back via |post_filter_on_load_callback|, but may modify them first. |
| 26 // notifications to |PrefStore::Observer|s. | 35 // Note: This method is asynchronous, which may make calls like |
| 27 // Implementations should return true if they modify the dictionary, to allow | 36 // PersistentPrefStore::ReadPrefs() asynchronous. The owner of filtered |
| 28 // the changes to be persisted. | 37 // PersistentPrefStores should handle this to make the reads look synchronous |
| 29 virtual bool FilterOnLoad(base::DictionaryValue* pref_store_contents) = 0; | 38 // to external users (see SegregatedPrefStore::ReadPrefs() for an example). |
| 39 virtual void FilterOnLoad( |
| 40 const PostFilterOnLoadCallback& post_filter_on_load_callback, |
| 41 scoped_ptr<base::DictionaryValue> pref_store_contents) = 0; |
| 30 | 42 |
| 31 // Receives notification when a pref store value is changed, before Observers | 43 // Receives notification when a pref store value is changed, before Observers |
| 32 // are notified. | 44 // are notified. |
| 33 virtual void FilterUpdate(const std::string& path) = 0; | 45 virtual void FilterUpdate(const std::string& path) = 0; |
| 34 | 46 |
| 35 // Receives notification when the pref store is about to serialize data | 47 // Receives notification when the pref store is about to serialize data |
| 36 // contained in |pref_store_contents| to a string. | 48 // contained in |pref_store_contents| to a string. |
| 37 virtual void FilterSerializeData( | 49 virtual void FilterSerializeData( |
| 38 const base::DictionaryValue* pref_store_contents) = 0; | 50 const base::DictionaryValue* pref_store_contents) = 0; |
| 39 }; | 51 }; |
| 40 | 52 |
| 41 #endif // BASE_PREFS_PREF_FILTER_H_ | 53 #endif // BASE_PREFS_PREF_FILTER_H_ |
| OLD | NEW |