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

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

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

Powered by Google App Engine
This is Rietveld 408576698