Index: chrome/browser/prefs/pref_hash_filter.h |
diff --git a/chrome/browser/prefs/pref_hash_filter.h b/chrome/browser/prefs/pref_hash_filter.h |
index 7cb08313d0615faf26bb9bccdc124412af3fdcb0..4ebed33beb87b4f5192df1e31dc9b7e42c46cc82 100644 |
--- a/chrome/browser/prefs/pref_hash_filter.h |
+++ b/chrome/browser/prefs/pref_hash_filter.h |
@@ -11,14 +11,15 @@ |
#include <vector> |
#include "base/basictypes.h" |
+#include "base/callback.h" |
#include "base/compiler_specific.h" |
#include "base/containers/scoped_ptr_hash_map.h" |
#include "base/memory/scoped_ptr.h" |
+#include "base/memory/weak_ptr.h" |
#include "base/prefs/pref_filter.h" |
#include "chrome/browser/prefs/pref_hash_store.h" |
#include "chrome/browser/prefs/tracked/tracked_preference.h" |
-class PersistentPrefStore; |
class PrefService; |
class PrefStore; |
@@ -35,8 +36,23 @@ class PrefRegistrySyncable; |
// Intercepts preference values as they are loaded from disk and verifies them |
// using a PrefHashStore. Keeps the PrefHashStore contents up to date as values |
// are changed. |
-class PrefHashFilter : public PrefFilter { |
+class PrefHashFilter : public PrefFilter, |
+ public base::SupportsWeakPtr<PrefHashFilter> { |
public: |
+ // A callback to be invoked by a FilterOnLoadInterceptor when its ready to |
+ // hand back the |prefs| it was handed for early filtering. |prefs_altered| |
+ // indicates whether the |prefs| were actually altered by the |
+ // FilterOnLoadInterceptor before being handed back. |
+ typedef base::Callback<void(scoped_ptr<base::DictionaryValue> prefs, |
+ bool prefs_altered)> FinalizeFilterOnLoadCallback; |
+ |
+ // A callback to be invoked from FilterOnLoad. It takes ownership of prefs |
+ // and may modify them before handing them back to this PrefHashFilter via |
+ // |finalize_filter_on_load|. |
+ typedef base::Callback< |
+ void(const FinalizeFilterOnLoadCallback& finalize_filter_on_load, |
+ scoped_ptr<base::DictionaryValue> prefs)> FilterOnLoadInterceptor; |
+ |
enum EnforcementLevel { |
NO_ENFORCEMENT, |
ENFORCE_ON_LOAD |
@@ -84,23 +100,38 @@ class PrefHashFilter : public PrefFilter { |
// |pref_store|. |
void Initialize(const PrefStore& pref_store); |
- // Migrates protected values from |source| to |destination|. Values are |
- // migrated if they are protected according to this filter's configuration, |
- // the corresponding key has no value in |destination|, and the value in |
- // |source| is trusted according to this filter's PrefHashStore. Regardless of |
- // the state of |destination| or the trust status, the protected values will |
- // be removed from |source|. |
- void MigrateValues(PersistentPrefStore* source, |
- PersistentPrefStore* destination); |
- |
// PrefFilter implementation. |
- virtual bool FilterOnLoad(base::DictionaryValue* pref_store_contents) |
- OVERRIDE; |
+ virtual void FilterOnLoad( |
+ const PostFilterOnLoadCallback& post_filter_on_load_callback, |
+ scoped_ptr<base::DictionaryValue> pref_store_contents) OVERRIDE; |
virtual void FilterUpdate(const std::string& path) OVERRIDE; |
virtual void FilterSerializeData( |
const base::DictionaryValue* pref_store_contents) OVERRIDE; |
+ // Registers |filter_on_load_interceptor| to intercept the next FilterOnLoad |
+ // event. At most one FilterOnLoadInterceptor should be registered per |
+ // PrefHashFilter. |
+ void InterceptNextFilterOnLoad( |
+ const FilterOnLoadInterceptor& filter_on_load_interceptor); |
+ |
private: |
+ // Validates values in |pref_store_contents| according to stored hashes, |
+ // reports validation results via UMA, and updates hashes in case of mismatch. |
+ // |prefs_altered| is true if the prefs were modified already since they were |
+ // read; in which case this method is guaranteed to report, via the |
+ // |post_filter_on_load_callback|, that a write is required. Hands ownership |
+ // of |pref_store_contents| back to the |post_filter_on_load_callback| when |
+ // done. |
+ void FinalizeFilterOnLoad( |
+ const PostFilterOnLoadCallback& post_filter_on_load_callback, |
+ scoped_ptr<base::DictionaryValue> pref_store_contents, |
+ bool prefs_altered); |
+ |
+ // Callback to be invoked only once (and subsequently reset) on the next |
+ // FilterOnLoad event. It will be allowed to modify the |prefs| handed to |
+ // FilterOnLoad before handing them back to this PrefHashFilter. |
+ FilterOnLoadInterceptor filter_on_load_interceptor_; |
+ |
// A map of paths to TrackedPreferences; this map owns this individual |
// TrackedPreference objects. |
typedef base::ScopedPtrHashMap<std::string, TrackedPreference> |