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

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

Issue 23528008: Don't use path expansion for profile dictionaries in LocalState (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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_metrics_service.h" 5 #include "chrome/browser/prefs/pref_metrics_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/json/json_string_value_serializer.h" 9 #include "base/json/json_string_value_serializer.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 // profile. To make the system more resistant to spoofing, pref values are 277 // profile. To make the system more resistant to spoofing, pref values are
278 // hashed with the pref path and the device id. 278 // hashed with the pref path and the device id.
279 void PrefMetricsService::CheckTrackedPreferences() { 279 void PrefMetricsService::CheckTrackedPreferences() {
280 DCHECK(!checked_tracked_prefs_); 280 DCHECK(!checked_tracked_prefs_);
281 281
282 const base::DictionaryValue* pref_hash_dicts = 282 const base::DictionaryValue* pref_hash_dicts =
283 local_state_->GetDictionary(prefs::kProfilePreferenceHashes); 283 local_state_->GetDictionary(prefs::kProfilePreferenceHashes);
284 // Get the hashed prefs dictionary if it exists. If it doesn't, it will be 284 // Get the hashed prefs dictionary if it exists. If it doesn't, it will be
285 // created if we set preference values below. 285 // created if we set preference values below.
286 const base::DictionaryValue* hashed_prefs = NULL; 286 const base::DictionaryValue* hashed_prefs = NULL;
287 pref_hash_dicts->GetDictionary(profile_name_, &hashed_prefs); 287 pref_hash_dicts->GetDictionaryWithoutPathExpansion(profile_name_,
battre 2013/09/12 08:38:47 This is pretty error prone. Can you please update
michaelpg 2013/09/14 18:18:32 Done.
288 &hashed_prefs);
288 for (int i = 0; i < tracked_pref_path_count_; ++i) { 289 for (int i = 0; i < tracked_pref_path_count_; ++i) {
289 // Skip prefs that haven't been registered. 290 // Skip prefs that haven't been registered.
290 if (!prefs_->FindPreference(tracked_pref_paths_[i])) 291 if (!prefs_->FindPreference(tracked_pref_paths_[i]))
291 continue; 292 continue;
292 293
293 bool changed = false; 294 bool changed = false;
294 const base::Value* value = prefs_->GetUserPrefValue(tracked_pref_paths_[i]); 295 const base::Value* value = prefs_->GetUserPrefValue(tracked_pref_paths_[i]);
295 if (value) { 296 if (value) {
296 std::string value_hash = 297 std::string value_hash =
297 GetHashedPrefValue(tracked_pref_paths_[i], value); 298 GetHashedPrefValue(tracked_pref_paths_[i], value);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType) && 338 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType) &&
338 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kChromeFrame)) { 339 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kChromeFrame)) {
339 InitializePrefObservers(); 340 InitializePrefObservers();
340 } 341 }
341 } 342 }
342 343
343 void PrefMetricsService::UpdateTrackedPreference(const char* path) { 344 void PrefMetricsService::UpdateTrackedPreference(const char* path) {
344 const base::Value* value = prefs_->GetUserPrefValue(path); 345 const base::Value* value = prefs_->GetUserPrefValue(path);
345 if (value) { 346 if (value) {
346 DictionaryPrefUpdate update(local_state_, prefs::kProfilePreferenceHashes); 347 DictionaryPrefUpdate update(local_state_, prefs::kProfilePreferenceHashes);
347 update->SetString(GetHashedPrefPath(path), 348 DictionaryValue* child_dictionary = NULL;
348 GetHashedPrefValue(path, value)); 349
350 // Get the dictionary corresponding to the profile name,
351 // which may have a .
xiyuan 2013/09/12 16:18:37 nit: which may have a '.'.
michaelpg 2013/09/14 18:18:32 Done.
352 if (!update->GetDictionaryWithoutPathExpansion(profile_name_,
353 &child_dictionary)) {
354 child_dictionary = new DictionaryValue;
355 update->SetWithoutPathExpansion(profile_name_, child_dictionary);
356 }
357 child_dictionary->SetString(path, GetHashedPrefValue(path, value));
349 } else { 358 } else {
350 RemoveTrackedPreference(path); 359 RemoveTrackedPreference(path);
351 } 360 }
352 } 361 }
353 362
354 bool PrefMetricsService::RemoveTrackedPreference(const char* path) { 363 bool PrefMetricsService::RemoveTrackedPreference(const char* path) {
355 DictionaryPrefUpdate update(local_state_, prefs::kProfilePreferenceHashes); 364 DictionaryPrefUpdate update(local_state_, prefs::kProfilePreferenceHashes);
356 return update->Remove(GetHashedPrefPath(path), NULL); 365 DictionaryValue* child_dictionary = NULL;
357 }
358 366
359 std::string PrefMetricsService::GetHashedPrefPath(const char* path) { 367 if (!update->GetDictionaryWithoutPathExpansion(profile_name_,
360 std::string hash_pref_path(profile_name_); 368 &child_dictionary)) {
361 hash_pref_path.append("."); 369 return false;
362 hash_pref_path.append(path); 370 }
363 return hash_pref_path; 371 return child_dictionary->Remove(path, NULL);
364 } 372 }
365 373
366 std::string PrefMetricsService::GetHashedPrefValue( 374 std::string PrefMetricsService::GetHashedPrefValue(
367 const char* path, 375 const char* path,
368 const base::Value* value) { 376 const base::Value* value) {
369 DCHECK(value); 377 DCHECK(value);
370 378
371 // Dictionary values may contain empty lists and sub-dictionaries. Create 379 // Dictionary values may contain empty lists and sub-dictionaries. Create
372 // a deep copy with those stripped to make the hash more stable. 380 // a deep copy with those stripped to make the hash more stable.
373 scoped_ptr<DictionaryValue> dict_value; 381 scoped_ptr<DictionaryValue> dict_value;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 } 448 }
441 449
442 bool PrefMetricsService::Factory::ServiceIsNULLWhileTesting() const { 450 bool PrefMetricsService::Factory::ServiceIsNULLWhileTesting() const {
443 return false; 451 return false;
444 } 452 }
445 453
446 content::BrowserContext* PrefMetricsService::Factory::GetBrowserContextToUse( 454 content::BrowserContext* PrefMetricsService::Factory::GetBrowserContextToUse(
447 content::BrowserContext* context) const { 455 content::BrowserContext* context) const {
448 return chrome::GetBrowserContextRedirectedInIncognito(context); 456 return chrome::GetBrowserContextRedirectedInIncognito(context);
449 } 457 }
OLDNEW
« no previous file with comments | « chrome/browser/prefs/pref_metrics_service.h ('k') | chrome/browser/profiles/profile_info_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698