OLD | NEW |
---|---|
(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_PREFERENCE_H_ | |
6 #define CHROME_BROWSER_PREFS_TRACKED_PREFERENCE_H_ | |
7 | |
8 #include "base/macros.h" | |
9 #include "chrome/browser/prefs/pref_hash_store.h" | |
10 | |
11 namespace base { | |
12 class DictionaryValue; | |
13 class Value; | |
14 } | |
15 | |
16 // A TrackedPreference is an abstract class which handles decision making and | |
17 // reporting for its subclasses. Its subclasses are responsible for implementing | |
18 // StoreHash and EnforceAndReport. | |
19 class TrackedPreference { | |
20 public: | |
21 // Enforcement levels are defined in order of intensity; the next level always | |
22 // implies the previous one and more. | |
23 enum EnforcementLevel { | |
24 NO_ENFORCEMENT, | |
25 ENFORCE, | |
26 ENFORCE_NO_SEEDING, | |
27 ENFORCE_NO_SEEDING_NO_MIGRATION, | |
28 // ENFORCE_ALL must always remain last; it is meant to be used when the | |
29 // desired level is underdetermined and the caller wants to enforce the | |
30 // strongest level to be safe. | |
31 ENFORCE_ALL | |
32 }; | |
33 | |
34 TrackedPreference(size_t reporting_id, | |
35 size_t reporting_ids_count, | |
36 EnforcementLevel enforcement_level); | |
37 virtual ~TrackedPreference() {} | |
38 | |
39 // Stores a new hash in |pref_hash_store| for this preference's |value|. | |
40 virtual void StoreHash(const base::Value* value, | |
41 PrefHashStore* pref_hash_store) const = 0; | |
42 | |
43 // Enforces that the value of this tracked preference in |pref_store_contents| | |
44 // is valid according to |pref_hash_store|; otherwise discarding the value in | |
45 // |pref_store_contents|. Reports on its findings via UMA. | |
46 virtual void EnforceAndReport( | |
47 PrefHashStore* pref_hash_store, | |
48 base::DictionaryValue* pref_store_contents) const = 0; | |
49 | |
50 protected: | |
51 enum ResetAction { | |
52 DONT_RESET, | |
53 WANTED_RESET, | |
54 DO_RESET, | |
55 }; | |
56 | |
57 // Returns an action stating whether a reset is desired (DO_RESET) based on | |
erikwright (departed)
2014/01/15 22:27:42
Consider extracting all of this into a helper clas
gab
2014/01/16 01:28:02
I had considered this; it's nice if you have one h
erikwright (departed)
2014/01/16 16:48:32
I don't think the caller needs to know about it. A
gab
2014/01/16 18:58:06
Done, as discussed I don't think it's much greater
| |
58 // observing |value_state| or not (DONT_RESET). |allow_changes_|, | |
59 // |allow_seeding_|, and |allow_migration_| make the decision softer in favor | |
60 // of WANTED_RESET over DO_RESET in various scenarios. | |
robertshield
2014/01/16 03:59:30
It's not clear to me reading this comment what the
gab
2014/01/16 18:58:06
Done.
| |
61 ResetAction GetAction(PrefHashStore::ValueState value_state) const; | |
62 | |
63 // Reports |value_state| via UMA under |reporting_id_|. | |
64 void ReportValidationResult(PrefHashStore::ValueState value_state) const; | |
65 | |
66 // Reports |reset_action| via UMA under |reporting_id_|. | |
67 void ReportAction(ResetAction reset_action) const; | |
68 | |
69 private: | |
70 size_t reporting_id_; | |
71 size_t reporting_ids_count_; | |
72 | |
73 // Allow setting changes. | |
74 bool allow_changes_; | |
75 // Allow seeding unknown values for atomic preferences. | |
76 bool allow_seeding_; | |
77 // Allow migration of values validated by the old MAC algorithm. | |
78 bool allow_migration_; | |
79 | |
80 DISALLOW_COPY_AND_ASSIGN(TrackedPreference); | |
81 }; | |
82 | |
83 #endif // CHROME_BROWSER_PREFS_TRACKED_PREFERENCE_H_ | |
OLD | NEW |