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

Side by Side Diff: chrome/browser/prefs/pref_hash_store_impl.cc

Issue 151003004: Add an automatic settings reset banner. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Pre-review cleanup. Created 6 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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 "chrome/browser/prefs/pref_hash_store_impl.h" 5 #include "chrome/browser/prefs/pref_hash_store_impl.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/prefs/pref_registry_simple.h" 9 #include "base/prefs/pref_registry_simple.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
11 #include "base/time/time.h"
11 #include "base/values.h" 12 #include "base/values.h"
12 #include "chrome/common/pref_names.h" 13 #include "chrome/common/pref_names.h"
13 14
14 PrefHashStoreImpl::PrefHashStoreImpl(const std::string& hash_store_id, 15 PrefHashStoreImpl::PrefHashStoreImpl(const std::string& hash_store_id,
15 const std::string& seed, 16 const std::string& seed,
16 const std::string& device_id, 17 const std::string& device_id,
17 PrefService* local_state) 18 PrefService* local_state)
18 : hash_store_id_(hash_store_id), 19 : hash_store_id_(hash_store_id),
19 pref_hash_calculator_(seed, device_id), 20 pref_hash_calculator_(seed, device_id),
20 local_state_(local_state), 21 local_state_(local_state),
21 initial_hashes_dictionary_trusted_(IsHashDictionaryTrusted()) { 22 initial_hashes_dictionary_trusted_(IsHashDictionaryTrusted()) {
22 UMA_HISTOGRAM_BOOLEAN("Settings.HashesDictionaryTrusted", 23 UMA_HISTOGRAM_BOOLEAN("Settings.HashesDictionaryTrusted",
23 initial_hashes_dictionary_trusted_); 24 initial_hashes_dictionary_trusted_);
24 } 25 }
25 26
26 // static 27 // static
27 void PrefHashStoreImpl::RegisterPrefs(PrefRegistrySimple* registry) { 28 void PrefHashStoreImpl::RegisterPrefs(PrefRegistrySimple* registry) {
28 // Register the top level dictionary to map profile names to dictionaries of 29 // Register the top level dictionary to map profile names to dictionaries of
29 // tracked preferences. 30 // tracked preferences.
30 registry->RegisterDictionaryPref(prefs::kProfilePreferenceHashes); 31 registry->RegisterDictionaryPref(prefs::kProfilePreferenceHashes);
32 // Register the pref that maintains state about the last time a reset event
33 // occurred. Used to decide whether to show UI.
34 registry->RegisterInt64Pref(prefs::kProfilePreferenceResetTime, 0L);
31 } 35 }
32 36
33 void PrefHashStoreImpl::Reset() { 37 void PrefHashStoreImpl::Reset() {
34 DictionaryPrefUpdate update(local_state_, prefs::kProfilePreferenceHashes); 38 DictionaryPrefUpdate update(local_state_, prefs::kProfilePreferenceHashes);
35 39
36 // Remove the dictionary corresponding to the profile name, which may have a 40 // Remove the dictionary corresponding to the profile name, which may have a
37 // '.' 41 // '.'
38 update->RemoveWithoutPathExpansion(hash_store_id_, NULL); 42 update->RemoveWithoutPathExpansion(hash_store_id_, NULL);
39 } 43 }
40 44
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 for (base::DictionaryValue::Iterator it(*split_value); !it.IsAtEnd(); 158 for (base::DictionaryValue::Iterator it(*split_value); !it.IsAtEnd();
155 it.Advance()) { 159 it.Advance()) {
156 // Keep the common part from the old |keyed_path| and replace the key to 160 // Keep the common part from the old |keyed_path| and replace the key to
157 // get the new |keyed_path|. 161 // get the new |keyed_path|.
158 keyed_path.replace(common_part_length, std::string::npos, it.key()); 162 keyed_path.replace(common_part_length, std::string::npos, it.key());
159 StoreHashInternal(keyed_path, &it.value(), &update); 163 StoreHashInternal(keyed_path, &it.value(), &update);
160 } 164 }
161 } 165 }
162 } 166 }
163 167
168 void PrefHashStoreImpl::RecordResetEvent() {
gab 2014/02/05 15:23:52 I think this method belongs on TrackedPreferenceHe
robertshield 2014/02/06 18:56:50 Erik convinced me it should go on PrefHashFilter.
169 local_state_->SetInt64(prefs::kProfilePreferenceResetTime,
170 base::Time::Now().ToInternalValue());
171 }
172
164 void PrefHashStoreImpl::ClearPath(const std::string& path, 173 void PrefHashStoreImpl::ClearPath(const std::string& path,
165 DictionaryPrefUpdate* update) { 174 DictionaryPrefUpdate* update) {
166 base::DictionaryValue* hashes_dict = NULL; 175 base::DictionaryValue* hashes_dict = NULL;
167 if (update->Get()->GetDictionaryWithoutPathExpansion(hash_store_id_, 176 if (update->Get()->GetDictionaryWithoutPathExpansion(hash_store_id_,
168 &hashes_dict)) { 177 &hashes_dict)) {
169 hashes_dict->Remove(path, NULL); 178 hashes_dict->Remove(path, NULL);
170 } 179 }
171 UpdateHashOfHashes(hashes_dict, update); 180 UpdateHashOfHashes(hashes_dict, update);
172 } 181 }
173 182
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 !pref_hash_dicts->GetDictionaryWithoutPathExpansion( 239 !pref_hash_dicts->GetDictionaryWithoutPathExpansion(
231 internals::kHashOfHashesPref, &hash_of_hashes_dict) || 240 internals::kHashOfHashesPref, &hash_of_hashes_dict) ||
232 !hash_of_hashes_dict->GetStringWithoutPathExpansion( 241 !hash_of_hashes_dict->GetStringWithoutPathExpansion(
233 hash_store_id_, &hash_of_hashes)) { 242 hash_store_id_, &hash_of_hashes)) {
234 return false; 243 return false;
235 } 244 }
236 245
237 return pref_hash_calculator_.Validate( 246 return pref_hash_calculator_.Validate(
238 hash_store_id_, hashes_dict, hash_of_hashes) == PrefHashCalculator::VALID; 247 hash_store_id_, hashes_dict, hash_of_hashes) == PrefHashCalculator::VALID;
239 } 248 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698