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

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

Issue 79013003: Introduce a temporary workaround to ensure tracked preferences set to empty list/dict are not confu… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: mark in constructor Created 7 years 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
« no previous file with comments | « chrome/browser/prefs/pref_metrics_service.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 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 pref_hash_seed_ = ResourceBundle::GetSharedInstance().GetRawDataResource( 85 pref_hash_seed_ = ResourceBundle::GetSharedInstance().GetRawDataResource(
86 IDR_PREF_HASH_SEED_BIN).as_string(); 86 IDR_PREF_HASH_SEED_BIN).as_string();
87 87
88 RecordLaunchPrefs(); 88 RecordLaunchPrefs();
89 89
90 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_); 90 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_);
91 synced_pref_change_registrar_.reset(new SyncedPrefChangeRegistrar(prefs)); 91 synced_pref_change_registrar_.reset(new SyncedPrefChangeRegistrar(prefs));
92 92
93 RegisterSyncedPrefObservers(); 93 RegisterSyncedPrefObservers();
94 94
95 MarkNeedsEmptyValueForTrackedPreferences();
96
95 // The following code might cause callbacks into this instance before we exit 97 // The following code might cause callbacks into this instance before we exit
96 // the constructor. This instance should be initialized at this point. 98 // the constructor. This instance should be initialized at this point.
97 #if defined(OS_WIN) || defined(OS_MACOSX) 99 #if defined(OS_WIN) || defined(OS_MACOSX)
98 // We need the machine id to compute pref value hashes. Fetch that, and then 100 // We need the machine id to compute pref value hashes. Fetch that, and then
99 // call CheckTrackedPreferences in the callback. 101 // call CheckTrackedPreferences in the callback.
100 extensions::api::DeviceId::GetDeviceId( 102 extensions::api::DeviceId::GetDeviceId(
101 "PrefMetricsService", // non-empty string to obfuscate the device id. 103 "PrefMetricsService", // non-empty string to obfuscate the device id.
102 Bind(&PrefMetricsService::GetDeviceIdCallback, 104 Bind(&PrefMetricsService::GetDeviceIdCallback,
103 weak_factory_.GetWeakPtr())); 105 weak_factory_.GetWeakPtr()));
104 #endif // defined(OS_WIN) || defined(OS_MACOSX) 106 #endif // defined(OS_WIN) || defined(OS_MACOSX)
105 } 107 }
106 108
107 // For unit testing only. 109 // For unit testing only.
108 PrefMetricsService::PrefMetricsService(Profile* profile, 110 PrefMetricsService::PrefMetricsService(Profile* profile,
109 PrefService* local_state, 111 PrefService* local_state,
110 const std::string& device_id, 112 const std::string& device_id,
111 const char** tracked_pref_paths, 113 const char** tracked_pref_paths,
112 int tracked_pref_path_count) 114 int tracked_pref_path_count)
113 : profile_(profile), 115 : profile_(profile),
114 prefs_(profile->GetPrefs()), 116 prefs_(profile->GetPrefs()),
115 local_state_(local_state), 117 local_state_(local_state),
116 profile_name_(profile_->GetPath().AsUTF8Unsafe()), 118 profile_name_(profile_->GetPath().AsUTF8Unsafe()),
117 pref_hash_seed_(kSHA256DigestSize, 0), 119 pref_hash_seed_(kSHA256DigestSize, 0),
118 device_id_(device_id), 120 device_id_(device_id),
119 tracked_pref_paths_(tracked_pref_paths), 121 tracked_pref_paths_(tracked_pref_paths),
120 tracked_pref_path_count_(tracked_pref_path_count), 122 tracked_pref_path_count_(tracked_pref_path_count),
121 checked_tracked_prefs_(false), 123 checked_tracked_prefs_(false),
122 weak_factory_(this) { 124 weak_factory_(this) {
125 MarkNeedsEmptyValueForTrackedPreferences();
123 CheckTrackedPreferences(); 126 CheckTrackedPreferences();
124 } 127 }
125 128
126 PrefMetricsService::~PrefMetricsService() { 129 PrefMetricsService::~PrefMetricsService() {
127 } 130 }
128 131
129 void PrefMetricsService::RecordLaunchPrefs() { 132 void PrefMetricsService::RecordLaunchPrefs() {
130 bool show_home_button = prefs_->GetBoolean(prefs::kShowHomeButton); 133 bool show_home_button = prefs_->GetBoolean(prefs::kShowHomeButton);
131 bool home_page_is_ntp = prefs_->GetBoolean(prefs::kHomePageIsNewTabPage); 134 bool home_page_is_ntp = prefs_->GetBoolean(prefs::kHomePageIsNewTabPage);
132 UMA_HISTOGRAM_BOOLEAN("Settings.ShowHomeButton", show_home_button); 135 UMA_HISTOGRAM_BOOLEAN("Settings.ShowHomeButton", show_home_button);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 histogram->Add(integer_value); 262 histogram->Add(integer_value);
260 } 263 }
261 264
262 void PrefMetricsService::GetDeviceIdCallback(const std::string& device_id) { 265 void PrefMetricsService::GetDeviceIdCallback(const std::string& device_id) {
263 device_id_ = device_id; 266 device_id_ = device_id;
264 // On Aura, this seems to be called twice. 267 // On Aura, this seems to be called twice.
265 if (!checked_tracked_prefs_) 268 if (!checked_tracked_prefs_)
266 CheckTrackedPreferences(); 269 CheckTrackedPreferences();
267 } 270 }
268 271
272 void PrefMetricsService::MarkNeedsEmptyValueForTrackedPreferences() {
273 for (int i = 0; i < tracked_pref_path_count_; ++i) {
274 // Skip prefs that haven't been registered.
275 if (!prefs_->FindPreference(tracked_pref_paths_[i]))
276 continue;
277
278 // Make sure tracked prefs are saved to disk even if empty.
279 // TODO(gab): Guarantee this for all prefs at a lower level and remove this
280 // hack.
281 prefs_->MarkUserStoreNeedsEmptyValue(tracked_pref_paths_[i]);
282 }
283 }
284
269 // To detect changes to Preferences that happen outside of Chrome, we hash 285 // To detect changes to Preferences that happen outside of Chrome, we hash
270 // selected pref values and save them in local state. CheckTrackedPreferences 286 // selected pref values and save them in local state. CheckTrackedPreferences
271 // compares the saved values to the values observed in the profile's prefs. A 287 // compares the saved values to the values observed in the profile's prefs. A
272 // dictionary of dictionaries in local state holds the hashed values, grouped by 288 // dictionary of dictionaries in local state holds the hashed values, grouped by
273 // profile. To make the system more resistant to spoofing, pref values are 289 // profile. To make the system more resistant to spoofing, pref values are
274 // hashed with the pref path and the device id. 290 // hashed with the pref path and the device id.
275 void PrefMetricsService::CheckTrackedPreferences() { 291 void PrefMetricsService::CheckTrackedPreferences() {
276 DCHECK(!checked_tracked_prefs_); 292 DCHECK(!checked_tracked_prefs_);
277 293
278 const base::DictionaryValue* pref_hash_dicts = 294 const base::DictionaryValue* pref_hash_dicts =
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 } 466 }
451 467
452 bool PrefMetricsService::Factory::ServiceIsNULLWhileTesting() const { 468 bool PrefMetricsService::Factory::ServiceIsNULLWhileTesting() const {
453 return false; 469 return false;
454 } 470 }
455 471
456 content::BrowserContext* PrefMetricsService::Factory::GetBrowserContextToUse( 472 content::BrowserContext* PrefMetricsService::Factory::GetBrowserContextToUse(
457 content::BrowserContext* context) const { 473 content::BrowserContext* context) const {
458 return chrome::GetBrowserContextRedirectedInIncognito(context); 474 return chrome::GetBrowserContextRedirectedInIncognito(context);
459 } 475 }
OLDNEW
« no previous file with comments | « chrome/browser/prefs/pref_metrics_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698