Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / prefs / pref_hash_filter.h
index 783caea..8d7ced5 100644 (file)
 #include <string>
 
 #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/prefs/pref_filter.h"
 #include "chrome/browser/prefs/pref_hash_store.h"
+#include "chrome/browser/prefs/tracked/tracked_preference.h"
 
 class PrefStore;
 
@@ -27,25 +30,27 @@ class Value;
 // are changed.
 class PrefHashFilter : public PrefFilter {
  public:
-  // Enforcement levels are defined in order of intensity; the next level always
-  // implies the previous one and more.
   enum EnforcementLevel {
     NO_ENFORCEMENT,
-    ENFORCE,
-    ENFORCE_NO_SEEDING,
-    ENFORCE_NO_SEEDING_NO_MIGRATION,
-    // ENFORCE_ALL must always remain last; it is meant to be used when the
-    // desired level is underdetermined and the caller wants to enforce the
-    // strongest setting to be safe.
-    ENFORCE_ALL
+    ENFORCE_ON_LOAD
   };
 
-  struct TrackedPreference {
+  enum PrefTrackingStrategy {
+    // Atomic preferences are tracked as a whole.
+    TRACKING_STRATEGY_ATOMIC,
+    // Split preferences are dictionaries for which each top-level entry is
+    // tracked independently. Note: preferences using this strategy must be kept
+    // in sync with TrackedSplitPreferences in histograms.xml.
+    TRACKING_STRATEGY_SPLIT,
+  };
+
+  struct TrackedPreferenceMetadata {
     size_t reporting_id;
     const char* name;
-    // Whether to actually reset this specific preference when everything else
-    // indicates that it should be.
-    bool allow_enforcement;
+    // This preference will not be enforced above this level no matter what the
+    // |enforcement_level| is set to.
+    EnforcementLevel max_enforcement_level;
+    PrefTrackingStrategy strategy;
   };
 
   // Constructs a PrefHashFilter tracking the specified |tracked_preferences|
@@ -53,18 +58,19 @@ class PrefHashFilter : public PrefFilter {
   // |reporting_ids_count| is the count of all possible IDs (possibly greater
   // than |tracked_preferences_size|). |enforcement_level| determines when this
   // filter will enforce factory defaults upon detecting an untrusted preference
-  // value.
+  // value. |reset_callback| is called when a reset event occurs.
   PrefHashFilter(scoped_ptr<PrefHashStore> pref_hash_store,
-                 const TrackedPreference tracked_preferences[],
+                 const TrackedPreferenceMetadata tracked_preferences[],
                  size_t tracked_preferences_size,
                  size_t reporting_ids_count,
-                 EnforcementLevel enforcement_level);
+                 EnforcementLevel enforcement_level,
+                 const base::Closure& reset_callback);
 
   virtual ~PrefHashFilter();
 
-  // Initializes the PrefHashStore with hashes of the tracked preferences
-  // in |pref_store|.
-  void Initialize(PrefStore* pref_store);
+  // Initializes the PrefHashStore with hashes of the tracked preferences in
+  // |pref_store|.
+  void Initialize(const PrefStore& pref_store);
 
   // PrefFilter implementation.
   virtual void FilterOnLoad(base::DictionaryValue* pref_store_contents)
@@ -74,7 +80,13 @@ class PrefHashFilter : public PrefFilter {
       const base::DictionaryValue* pref_store_contents) OVERRIDE;
 
  private:
-  typedef std::map<std::string, const TrackedPreference> TrackedPreferencesMap;
+  // A map of paths to TrackedPreferences; this map owns this individual
+  // TrackedPreference objects.
+  typedef base::ScopedPtrHashMap<std::string, TrackedPreference>
+      TrackedPreferencesMap;
+  // A map from changed paths to their corresponding TrackedPreferences (which
+  // aren't owned by this map).
+  typedef std::map<std::string, const TrackedPreference*> ChangedPathsMap;
 
   scoped_ptr<PrefHashStore> pref_hash_store_;
 
@@ -82,16 +94,9 @@ class PrefHashFilter : public PrefFilter {
 
   // The set of all paths whose value has changed since the last call to
   // FilterSerializeData.
-  std::set<std::string> changed_paths_;
-
-  size_t reporting_ids_count_;
+  ChangedPathsMap changed_paths_;
 
-  // Prevent setting changes.
-  bool enforce_;
-  // Do not seed unknown values.
-  bool no_seeding_;
-  // Do not migrate values validated by the old MAC algorithm.
-  bool no_migration_;
+  base::Closure reset_callback_;
 
   DISALLOW_COPY_AND_ASSIGN(PrefHashFilter);
 };