Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(636)

Side by Side Diff: chrome/browser/prefs/tracked/pref_hash_filter.h

Issue 1227973003: Componentize //chrome/browser/prefs/tracked. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_PREFS_TRACKED_PREF_HASH_FILTER_H_
6 #define CHROME_BROWSER_PREFS_TRACKED_PREF_HASH_FILTER_H_
7
8 #include <map>
9 #include <set>
10 #include <vector>
11
12 #include "base/basictypes.h"
13 #include "base/callback.h"
14 #include "base/compiler_specific.h"
15 #include "base/containers/scoped_ptr_hash_map.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "chrome/browser/prefs/tracked/interceptable_pref_filter.h"
18 #include "chrome/browser/prefs/tracked/tracked_preference.h"
19
20 class PrefHashStore;
21 class PrefService;
22 class PrefStore;
23 class TrackedPreferenceValidationDelegate;
24
25 namespace base {
26 class DictionaryValue;
27 class Time;
28 class Value;
29 } // namespace base
30
31 namespace user_prefs {
32 class PrefRegistrySyncable;
33 } // namespace user_prefs
34
35 // Intercepts preference values as they are loaded from disk and verifies them
36 // using a PrefHashStore. Keeps the PrefHashStore contents up to date as values
37 // are changed.
38 class PrefHashFilter : public InterceptablePrefFilter {
39 public:
40 enum EnforcementLevel {
41 NO_ENFORCEMENT,
42 ENFORCE_ON_LOAD
43 };
44
45 enum PrefTrackingStrategy {
46 // Atomic preferences are tracked as a whole.
47 TRACKING_STRATEGY_ATOMIC,
48 // Split preferences are dictionaries for which each top-level entry is
49 // tracked independently. Note: preferences using this strategy must be kept
50 // in sync with TrackedSplitPreferences in histograms.xml.
51 TRACKING_STRATEGY_SPLIT,
52 };
53
54 enum ValueType {
55 VALUE_IMPERSONAL,
56 // The preference value may contain personal information.
57 VALUE_PERSONAL,
58 };
59
60 struct TrackedPreferenceMetadata {
61 size_t reporting_id;
62 const char* name;
63 EnforcementLevel enforcement_level;
64 PrefTrackingStrategy strategy;
65 ValueType value_type;
66 };
67
68 // Constructs a PrefHashFilter tracking the specified |tracked_preferences|
69 // using |pref_hash_store| to check/store hashes. An optional |delegate| is
70 // notified of the status of each preference as it is checked.
71 // If |on_reset_on_load| is provided, it will be invoked if a reset occurs in
72 // FilterOnLoad.
73 // |reporting_ids_count| is the count of all possible IDs (possibly greater
74 // than |tracked_preferences.size()|). If |report_super_mac_validity| is true,
75 // the state of the super MAC will be reported via UMA during
76 // FinalizeFilterOnLoad.
77 PrefHashFilter(
78 scoped_ptr<PrefHashStore> pref_hash_store,
79 const std::vector<TrackedPreferenceMetadata>& tracked_preferences,
80 const base::Closure& on_reset_on_load,
81 TrackedPreferenceValidationDelegate* delegate,
82 size_t reporting_ids_count,
83 bool report_super_mac_validity);
84
85 ~PrefHashFilter() override;
86
87 // Registers required user preferences.
88 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
89
90 // Retrieves the time of the last reset event, if any, for the provided user
91 // preferences. If no reset has occurred, Returns a null |Time|.
92 static base::Time GetResetTime(PrefService* user_prefs);
93
94 // Clears the time of the last reset event, if any, for the provided user
95 // preferences.
96 static void ClearResetTime(PrefService* user_prefs);
97
98 // Initializes the PrefHashStore with hashes of the tracked preferences in
99 // |pref_store_contents|. |pref_store_contents| will be the |storage| passed
100 // to PrefHashStore::BeginTransaction().
101 void Initialize(base::DictionaryValue* pref_store_contents);
102
103 // PrefFilter remaining implementation.
104 void FilterUpdate(const std::string& path) override;
105 void FilterSerializeData(base::DictionaryValue* pref_store_contents) override;
106
107 private:
108 // InterceptablePrefFilter implementation.
109 void FinalizeFilterOnLoad(
110 const PostFilterOnLoadCallback& post_filter_on_load_callback,
111 scoped_ptr<base::DictionaryValue> pref_store_contents,
112 bool prefs_altered) override;
113
114 // Callback to be invoked only once (and subsequently reset) on the next
115 // FilterOnLoad event. It will be allowed to modify the |prefs| handed to
116 // FilterOnLoad before handing them back to this PrefHashFilter.
117 FilterOnLoadInterceptor filter_on_load_interceptor_;
118
119 // A map of paths to TrackedPreferences; this map owns this individual
120 // TrackedPreference objects.
121 typedef base::ScopedPtrHashMap<std::string, scoped_ptr<TrackedPreference>>
122 TrackedPreferencesMap;
123 // A map from changed paths to their corresponding TrackedPreferences (which
124 // aren't owned by this map).
125 typedef std::map<std::string, const TrackedPreference*> ChangedPathsMap;
126
127 scoped_ptr<PrefHashStore> pref_hash_store_;
128
129 // Invoked if a reset occurs in a call to FilterOnLoad.
130 const base::Closure on_reset_on_load_;
131
132 TrackedPreferencesMap tracked_paths_;
133
134 // The set of all paths whose value has changed since the last call to
135 // FilterSerializeData.
136 ChangedPathsMap changed_paths_;
137
138 // Whether to report the validity of the super MAC at load time (via UMA).
139 bool report_super_mac_validity_;
140
141 DISALLOW_COPY_AND_ASSIGN(PrefHashFilter);
142 };
143
144 #endif // CHROME_BROWSER_PREFS_TRACKED_PREF_HASH_FILTER_H_
OLDNEW
« no previous file with comments | « chrome/browser/prefs/tracked/pref_hash_calculator_unittest.cc ('k') | chrome/browser/prefs/tracked/pref_hash_filter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698