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

Side by Side Diff: services/preferences/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 | « services/preferences/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 "services/preferences/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"
12 #include "services/preferences/public/interfaces/tracked_preference_validation_d elegate.mojom.h" 11 #include "services/preferences/public/interfaces/tracked_preference_validation_d elegate.mojom.h"
12 #include "services/preferences/tracked/pref_hash_store_transaction.h"
13
14 using ValueState =
15 prefs::mojom::TrackedPreferenceValidationDelegate::ValueState;
13 16
14 TrackedSplitPreference::TrackedSplitPreference( 17 TrackedSplitPreference::TrackedSplitPreference(
15 const std::string& pref_path, 18 const std::string& pref_path,
16 size_t reporting_id, 19 size_t reporting_id,
17 size_t reporting_ids_count, 20 size_t reporting_ids_count,
18 PrefHashFilter::EnforcementLevel enforcement_level, 21 prefs::mojom::TrackedPreferenceMetadata::EnforcementLevel enforcement_level,
19 PrefHashFilter::ValueType value_type, 22 prefs::mojom::TrackedPreferenceMetadata::ValueType value_type,
20 prefs::mojom::TrackedPreferenceValidationDelegate* delegate) 23 prefs::mojom::TrackedPreferenceValidationDelegate* delegate)
21 : pref_path_(pref_path), 24 : pref_path_(pref_path),
22 helper_(pref_path, 25 helper_(pref_path,
23 reporting_id, 26 reporting_id,
24 reporting_ids_count, 27 reporting_ids_count,
25 enforcement_level, 28 enforcement_level,
26 value_type), 29 value_type),
27 delegate_(delegate) {} 30 delegate_(delegate) {}
28 31
29 TrackedPreferenceType TrackedSplitPreference::GetType() const { 32 TrackedPreferenceType TrackedSplitPreference::GetType() const {
(...skipping 17 matching lines...) Expand all
47 PrefHashStoreTransaction* external_validation_transaction) const { 50 PrefHashStoreTransaction* external_validation_transaction) const {
48 base::DictionaryValue* dict_value = NULL; 51 base::DictionaryValue* dict_value = NULL;
49 if (!pref_store_contents->GetDictionary(pref_path_, &dict_value) && 52 if (!pref_store_contents->GetDictionary(pref_path_, &dict_value) &&
50 pref_store_contents->Get(pref_path_, NULL)) { 53 pref_store_contents->Get(pref_path_, NULL)) {
51 // There should be a dictionary or nothing at |pref_path_|. 54 // There should be a dictionary or nothing at |pref_path_|.
52 NOTREACHED(); 55 NOTREACHED();
53 return false; 56 return false;
54 } 57 }
55 58
56 std::vector<std::string> invalid_keys; 59 std::vector<std::string> invalid_keys;
57 PrefHashStoreTransaction::ValueState value_state = 60 ValueState value_state =
58 transaction->CheckSplitValue(pref_path_, dict_value, &invalid_keys); 61 transaction->CheckSplitValue(pref_path_, dict_value, &invalid_keys);
59 62
60 if (value_state == PrefHashStoreTransaction::CHANGED) 63 if (value_state == ValueState::CHANGED)
61 helper_.ReportSplitPreferenceChangedCount(invalid_keys.size()); 64 helper_.ReportSplitPreferenceChangedCount(invalid_keys.size());
62 65
63 helper_.ReportValidationResult(value_state, transaction->GetStoreUMASuffix()); 66 helper_.ReportValidationResult(value_state, transaction->GetStoreUMASuffix());
64 67
65 PrefHashStoreTransaction::ValueState external_validation_value_state = 68 ValueState external_validation_value_state = ValueState::UNSUPPORTED;
66 PrefHashStoreTransaction::UNSUPPORTED;
67 std::vector<std::string> external_validation_invalid_keys; 69 std::vector<std::string> external_validation_invalid_keys;
68 if (external_validation_transaction) { 70 if (external_validation_transaction) {
69 external_validation_value_state = 71 external_validation_value_state =
70 external_validation_transaction->CheckSplitValue( 72 external_validation_transaction->CheckSplitValue(
71 pref_path_, dict_value, &external_validation_invalid_keys); 73 pref_path_, dict_value, &external_validation_invalid_keys);
72 helper_.ReportValidationResult( 74 helper_.ReportValidationResult(
73 external_validation_value_state, 75 external_validation_value_state,
74 external_validation_transaction->GetStoreUMASuffix()); 76 external_validation_transaction->GetStoreUMASuffix());
75 } 77 }
76 78
77 if (delegate_) { 79 if (delegate_) {
78 delegate_->OnSplitPreferenceValidation( 80 delegate_->OnSplitPreferenceValidation(
79 pref_path_, invalid_keys, external_validation_invalid_keys, value_state, 81 pref_path_, invalid_keys, external_validation_invalid_keys, value_state,
80 external_validation_value_state, helper_.IsPersonal()); 82 external_validation_value_state, helper_.IsPersonal());
81 } 83 }
82 TrackedPreferenceHelper::ResetAction reset_action = 84 TrackedPreferenceHelper::ResetAction reset_action =
83 helper_.GetAction(value_state); 85 helper_.GetAction(value_state);
84 helper_.ReportAction(reset_action); 86 helper_.ReportAction(reset_action);
85 87
86 bool was_reset = false; 88 bool was_reset = false;
87 if (reset_action == TrackedPreferenceHelper::DO_RESET) { 89 if (reset_action == TrackedPreferenceHelper::DO_RESET) {
88 if (value_state == PrefHashStoreTransaction::CHANGED) { 90 if (value_state == ValueState::CHANGED) {
89 DCHECK(!invalid_keys.empty()); 91 DCHECK(!invalid_keys.empty());
90 92
91 for (std::vector<std::string>::const_iterator it = invalid_keys.begin(); 93 for (std::vector<std::string>::const_iterator it = invalid_keys.begin();
92 it != invalid_keys.end(); ++it) { 94 it != invalid_keys.end(); ++it) {
93 dict_value->Remove(*it, NULL); 95 dict_value->Remove(*it, NULL);
94 } 96 }
95 } else { 97 } else {
96 pref_store_contents->RemovePath(pref_path_, NULL); 98 pref_store_contents->RemovePath(pref_path_, NULL);
97 } 99 }
98 was_reset = true; 100 was_reset = true;
99 } 101 }
100 102
101 if (value_state != PrefHashStoreTransaction::UNCHANGED) { 103 if (value_state != ValueState::UNCHANGED) {
102 // 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).
103 const base::DictionaryValue* new_dict_value = NULL; 105 const base::DictionaryValue* new_dict_value = NULL;
104 pref_store_contents->GetDictionary(pref_path_, &new_dict_value); 106 pref_store_contents->GetDictionary(pref_path_, &new_dict_value);
105 transaction->StoreSplitHash(pref_path_, new_dict_value); 107 transaction->StoreSplitHash(pref_path_, new_dict_value);
106 } 108 }
107 109
108 // Update MACs in the external store if there is one and there either was a 110 // Update MACs in the external store if there is one and there either was a
109 // reset or external validation failed. 111 // reset or external validation failed.
110 if (external_validation_transaction && 112 if (external_validation_transaction &&
111 (was_reset || 113 (was_reset || external_validation_value_state != ValueState::UNCHANGED)) {
112 external_validation_value_state !=
113 PrefHashStoreTransaction::UNCHANGED)) {
114 const base::DictionaryValue* new_dict_value = nullptr; 114 const base::DictionaryValue* new_dict_value = nullptr;
115 pref_store_contents->GetDictionary(pref_path_, &new_dict_value); 115 pref_store_contents->GetDictionary(pref_path_, &new_dict_value);
116 external_validation_transaction->StoreSplitHash(pref_path_, new_dict_value); 116 external_validation_transaction->StoreSplitHash(pref_path_, new_dict_value);
117 } 117 }
118 118
119 return was_reset; 119 return was_reset;
120 } 120 }
OLDNEW
« no previous file with comments | « services/preferences/tracked/tracked_split_preference.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698