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

Side by Side Diff: components/user_prefs/tracked/tracked_split_preference.cc

Issue 2782803002: Move tracked prefs into services/preferences/tracked. (Closed)
Patch Set: rebase Created 3 years, 8 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
« no previous file with comments | « components/user_prefs/tracked/tracked_split_preference.h ('k') | services/preferences/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 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 #include "components/user_prefs/tracked/tracked_split_preference.h"
6
7 #include <vector>
8
9 #include "base/logging.h"
10 #include "base/values.h"
11 #include "components/user_prefs/tracked/pref_hash_store_transaction.h"
12 #include "services/preferences/public/interfaces/tracked_preference_validation_d elegate.mojom.h"
13
14 TrackedSplitPreference::TrackedSplitPreference(
15 const std::string& pref_path,
16 size_t reporting_id,
17 size_t reporting_ids_count,
18 PrefHashFilter::EnforcementLevel enforcement_level,
19 PrefHashFilter::ValueType value_type,
20 prefs::mojom::TrackedPreferenceValidationDelegate* delegate)
21 : pref_path_(pref_path),
22 helper_(pref_path,
23 reporting_id,
24 reporting_ids_count,
25 enforcement_level,
26 value_type),
27 delegate_(delegate) {}
28
29 TrackedPreferenceType TrackedSplitPreference::GetType() const {
30 return TrackedPreferenceType::SPLIT;
31 }
32
33 void TrackedSplitPreference::OnNewValue(
34 const base::Value* value,
35 PrefHashStoreTransaction* transaction) const {
36 const base::DictionaryValue* dict_value = NULL;
37 if (value && !value->GetAsDictionary(&dict_value)) {
38 NOTREACHED();
39 return;
40 }
41 transaction->StoreSplitHash(pref_path_, dict_value);
42 }
43
44 bool TrackedSplitPreference::EnforceAndReport(
45 base::DictionaryValue* pref_store_contents,
46 PrefHashStoreTransaction* transaction,
47 PrefHashStoreTransaction* external_validation_transaction) const {
48 base::DictionaryValue* dict_value = NULL;
49 if (!pref_store_contents->GetDictionary(pref_path_, &dict_value) &&
50 pref_store_contents->Get(pref_path_, NULL)) {
51 // There should be a dictionary or nothing at |pref_path_|.
52 NOTREACHED();
53 return false;
54 }
55
56 std::vector<std::string> invalid_keys;
57 PrefHashStoreTransaction::ValueState value_state =
58 transaction->CheckSplitValue(pref_path_, dict_value, &invalid_keys);
59
60 if (value_state == PrefHashStoreTransaction::CHANGED)
61 helper_.ReportSplitPreferenceChangedCount(invalid_keys.size());
62
63 helper_.ReportValidationResult(value_state, transaction->GetStoreUMASuffix());
64
65 PrefHashStoreTransaction::ValueState external_validation_value_state =
66 PrefHashStoreTransaction::UNSUPPORTED;
67 std::vector<std::string> external_validation_invalid_keys;
68 if (external_validation_transaction) {
69 external_validation_value_state =
70 external_validation_transaction->CheckSplitValue(
71 pref_path_, dict_value, &external_validation_invalid_keys);
72 helper_.ReportValidationResult(
73 external_validation_value_state,
74 external_validation_transaction->GetStoreUMASuffix());
75 }
76
77 if (delegate_) {
78 delegate_->OnSplitPreferenceValidation(
79 pref_path_, invalid_keys, external_validation_invalid_keys, value_state,
80 external_validation_value_state, helper_.IsPersonal());
81 }
82 TrackedPreferenceHelper::ResetAction reset_action =
83 helper_.GetAction(value_state);
84 helper_.ReportAction(reset_action);
85
86 bool was_reset = false;
87 if (reset_action == TrackedPreferenceHelper::DO_RESET) {
88 if (value_state == PrefHashStoreTransaction::CHANGED) {
89 DCHECK(!invalid_keys.empty());
90
91 for (std::vector<std::string>::const_iterator it = invalid_keys.begin();
92 it != invalid_keys.end(); ++it) {
93 dict_value->Remove(*it, NULL);
94 }
95 } else {
96 pref_store_contents->RemovePath(pref_path_, NULL);
97 }
98 was_reset = true;
99 }
100
101 if (value_state != PrefHashStoreTransaction::UNCHANGED) {
102 // Store the hash for the new value (whether it was reset or not).
103 const base::DictionaryValue* new_dict_value = NULL;
104 pref_store_contents->GetDictionary(pref_path_, &new_dict_value);
105 transaction->StoreSplitHash(pref_path_, new_dict_value);
106 }
107
108 // Update MACs in the external store if there is one and there either was a
109 // reset or external validation failed.
110 if (external_validation_transaction &&
111 (was_reset ||
112 external_validation_value_state !=
113 PrefHashStoreTransaction::UNCHANGED)) {
114 const base::DictionaryValue* new_dict_value = nullptr;
115 pref_store_contents->GetDictionary(pref_path_, &new_dict_value);
116 external_validation_transaction->StoreSplitHash(pref_path_, new_dict_value);
117 }
118
119 return was_reset;
120 }
OLDNEW
« no previous file with comments | « components/user_prefs/tracked/tracked_split_preference.h ('k') | services/preferences/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698