OLD | NEW |
---|---|
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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 | 73 |
74 } // namespace | 74 } // namespace |
75 | 75 |
76 PrefMetricsService::PrefMetricsService(Profile* profile) | 76 PrefMetricsService::PrefMetricsService(Profile* profile) |
77 : profile_(profile), | 77 : profile_(profile), |
78 prefs_(profile_->GetPrefs()), | 78 prefs_(profile_->GetPrefs()), |
79 local_state_(g_browser_process->local_state()), | 79 local_state_(g_browser_process->local_state()), |
80 profile_name_(profile_->GetPath().AsUTF8Unsafe()), | 80 profile_name_(profile_->GetPath().AsUTF8Unsafe()), |
81 tracked_pref_paths_(kTrackedPrefs), | 81 tracked_pref_paths_(kTrackedPrefs), |
82 tracked_pref_path_count_(arraysize(kTrackedPrefs)), | 82 tracked_pref_path_count_(arraysize(kTrackedPrefs)), |
83 checked_tracked_prefs_(false), | |
84 weak_factory_(this) { | 83 weak_factory_(this) { |
85 pref_hash_seed_ = ResourceBundle::GetSharedInstance().GetRawDataResource( | 84 pref_hash_seed_ = ResourceBundle::GetSharedInstance().GetRawDataResource( |
86 IDR_PREF_HASH_SEED_BIN).as_string(); | 85 IDR_PREF_HASH_SEED_BIN).as_string(); |
87 | 86 |
88 RecordLaunchPrefs(); | 87 RecordLaunchPrefs(); |
89 | 88 |
90 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_); | 89 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_); |
91 synced_pref_change_registrar_.reset(new SyncedPrefChangeRegistrar(prefs)); | 90 synced_pref_change_registrar_.reset(new SyncedPrefChangeRegistrar(prefs)); |
92 | 91 |
93 RegisterSyncedPrefObservers(); | 92 RegisterSyncedPrefObservers(); |
(...skipping 17 matching lines...) Expand all Loading... | |
111 const char** tracked_pref_paths, | 110 const char** tracked_pref_paths, |
112 int tracked_pref_path_count) | 111 int tracked_pref_path_count) |
113 : profile_(profile), | 112 : profile_(profile), |
114 prefs_(profile->GetPrefs()), | 113 prefs_(profile->GetPrefs()), |
115 local_state_(local_state), | 114 local_state_(local_state), |
116 profile_name_(profile_->GetPath().AsUTF8Unsafe()), | 115 profile_name_(profile_->GetPath().AsUTF8Unsafe()), |
117 pref_hash_seed_(kSHA256DigestSize, 0), | 116 pref_hash_seed_(kSHA256DigestSize, 0), |
118 device_id_(device_id), | 117 device_id_(device_id), |
119 tracked_pref_paths_(tracked_pref_paths), | 118 tracked_pref_paths_(tracked_pref_paths), |
120 tracked_pref_path_count_(tracked_pref_path_count), | 119 tracked_pref_path_count_(tracked_pref_path_count), |
121 checked_tracked_prefs_(false), | |
122 weak_factory_(this) { | 120 weak_factory_(this) { |
123 CheckTrackedPreferences(); | 121 CheckTrackedPreferences(); |
124 } | 122 } |
125 | 123 |
126 PrefMetricsService::~PrefMetricsService() { | 124 PrefMetricsService::~PrefMetricsService() { |
127 } | 125 } |
128 | 126 |
129 void PrefMetricsService::RecordLaunchPrefs() { | 127 void PrefMetricsService::RecordLaunchPrefs() { |
130 bool show_home_button = prefs_->GetBoolean(prefs::kShowHomeButton); | 128 bool show_home_button = prefs_->GetBoolean(prefs::kShowHomeButton); |
131 bool home_page_is_ntp = prefs_->GetBoolean(prefs::kHomePageIsNewTabPage); | 129 bool home_page_is_ntp = prefs_->GetBoolean(prefs::kHomePageIsNewTabPage); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
253 base::HistogramBase* histogram = base::LinearHistogram::FactoryGet( | 251 base::HistogramBase* histogram = base::LinearHistogram::FactoryGet( |
254 histogram_name, | 252 histogram_name, |
255 1, | 253 1, |
256 boundary_value, | 254 boundary_value, |
257 boundary_value + 1, | 255 boundary_value + 1, |
258 base::HistogramBase::kUmaTargetedHistogramFlag); | 256 base::HistogramBase::kUmaTargetedHistogramFlag); |
259 histogram->Add(integer_value); | 257 histogram->Add(integer_value); |
260 } | 258 } |
261 | 259 |
262 void PrefMetricsService::GetDeviceIdCallback(const std::string& device_id) { | 260 void PrefMetricsService::GetDeviceIdCallback(const std::string& device_id) { |
261 #if defined(ENABLE_DCHECK) | |
262 // Make sure this callback is only called once. | |
263 static bool called = false; | |
Jeffrey Yasskin
2013/11/21 22:23:22
This is dangerous because it's process-wide. How s
gab
2013/11/22 01:52:13
Oops, indeed, this is currently only called for th
| |
264 DCHECK(!called); | |
265 #endif | |
266 | |
267 #if !defined(OS_WIN) || defined(ENABLE_RLZ) | |
268 // Always expect a non-empty device ID, except on Windows if RLZ is disabled. | |
Jeffrey Yasskin
2013/11/21 22:23:22
This has too many negatives. Can you make it easie
gab
2013/11/22 01:52:13
Done.
| |
269 DCHECK(!device_id.empty()); | |
270 #endif | |
271 | |
263 device_id_ = device_id; | 272 device_id_ = device_id; |
264 // On Aura, this seems to be called twice. | 273 CheckTrackedPreferences(); |
265 if (!checked_tracked_prefs_) | 274 |
266 CheckTrackedPreferences(); | 275 #if defined(ENABLE_DCHECK) |
276 called = true; | |
Jeffrey Yasskin
2013/11/21 22:23:22
Move this just after the DCHECK(!called) to reduce
gab
2013/11/22 01:52:13
Done.
| |
277 #endif | |
267 } | 278 } |
268 | 279 |
269 // To detect changes to Preferences that happen outside of Chrome, we hash | 280 // To detect changes to Preferences that happen outside of Chrome, we hash |
270 // selected pref values and save them in local state. CheckTrackedPreferences | 281 // 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 | 282 // 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 | 283 // 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 | 284 // profile. To make the system more resistant to spoofing, pref values are |
274 // hashed with the pref path and the device id. | 285 // hashed with the pref path and the device id. |
275 void PrefMetricsService::CheckTrackedPreferences() { | 286 void PrefMetricsService::CheckTrackedPreferences() { |
276 DCHECK(!checked_tracked_prefs_); | |
277 | |
278 const base::DictionaryValue* pref_hash_dicts = | 287 const base::DictionaryValue* pref_hash_dicts = |
279 local_state_->GetDictionary(prefs::kProfilePreferenceHashes); | 288 local_state_->GetDictionary(prefs::kProfilePreferenceHashes); |
280 // Get the hashed prefs dictionary if it exists. If it doesn't, it will be | 289 // Get the hashed prefs dictionary if it exists. If it doesn't, it will be |
281 // created if we set preference values below. | 290 // created if we set preference values below. |
282 const base::DictionaryValue* hashed_prefs = NULL; | 291 const base::DictionaryValue* hashed_prefs = NULL; |
283 pref_hash_dicts->GetDictionaryWithoutPathExpansion(profile_name_, | 292 pref_hash_dicts->GetDictionaryWithoutPathExpansion(profile_name_, |
284 &hashed_prefs); | 293 &hashed_prefs); |
285 for (int i = 0; i < tracked_pref_path_count_; ++i) { | 294 for (int i = 0; i < tracked_pref_path_count_; ++i) { |
286 // Skip prefs that haven't been registered. | 295 // Skip prefs that haven't been registered. |
287 if (!prefs_->FindPreference(tracked_pref_paths_[i])) | 296 if (!prefs_->FindPreference(tracked_pref_paths_[i])) |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
330 } | 339 } |
331 } else { | 340 } else { |
332 // Record that we haven't tracked this preference yet, or the hash in | 341 // Record that we haven't tracked this preference yet, or the hash in |
333 // local state was removed. | 342 // local state was removed. |
334 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceInitialized", | 343 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceInitialized", |
335 i, tracked_pref_path_count_); | 344 i, tracked_pref_path_count_); |
336 UpdateTrackedPreference(tracked_pref_paths_[i]); | 345 UpdateTrackedPreference(tracked_pref_paths_[i]); |
337 } | 346 } |
338 } | 347 } |
339 | 348 |
340 checked_tracked_prefs_ = true; | |
341 | |
342 // Now that we've checked the incoming preferences, register for change | 349 // Now that we've checked the incoming preferences, register for change |
343 // notifications, unless this is test code. | 350 // notifications, unless this is test code. |
344 // TODO(bbudge) Fix failing browser_tests and so we can remove this test. | 351 // TODO(bbudge) Fix failing browser_tests and so we can remove this test. |
345 // Several tests fail when they shutdown before they can write local state. | 352 // Several tests fail when they shutdown before they can write local state. |
346 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType) && | 353 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType) && |
347 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kChromeFrame)) { | 354 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kChromeFrame)) { |
348 InitializePrefObservers(); | 355 InitializePrefObservers(); |
349 } | 356 } |
350 } | 357 } |
351 | 358 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
455 } | 462 } |
456 | 463 |
457 bool PrefMetricsService::Factory::ServiceIsNULLWhileTesting() const { | 464 bool PrefMetricsService::Factory::ServiceIsNULLWhileTesting() const { |
458 return false; | 465 return false; |
459 } | 466 } |
460 | 467 |
461 content::BrowserContext* PrefMetricsService::Factory::GetBrowserContextToUse( | 468 content::BrowserContext* PrefMetricsService::Factory::GetBrowserContextToUse( |
462 content::BrowserContext* context) const { | 469 content::BrowserContext* context) const { |
463 return chrome::GetBrowserContextRedirectedInIncognito(context); | 470 return chrome::GetBrowserContextRedirectedInIncognito(context); |
464 } | 471 } |
OLD | NEW |