| 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 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 base::HistogramBase* histogram = base::LinearHistogram::FactoryGet( | 256 base::HistogramBase* histogram = base::LinearHistogram::FactoryGet( |
| 257 histogram_name, | 257 histogram_name, |
| 258 1, | 258 1, |
| 259 boundary_value, | 259 boundary_value, |
| 260 boundary_value + 1, | 260 boundary_value + 1, |
| 261 base::HistogramBase::kUmaTargetedHistogramFlag); | 261 base::HistogramBase::kUmaTargetedHistogramFlag); |
| 262 histogram->Add(integer_value); | 262 histogram->Add(integer_value); |
| 263 } | 263 } |
| 264 | 264 |
| 265 void PrefMetricsService::GetDeviceIdCallback(const std::string& device_id) { | 265 void PrefMetricsService::GetDeviceIdCallback(const std::string& device_id) { |
| 266 #if !defined(OS_WIN) || defined(ENABLE_RLZ) |
| 267 // A device_id is expected in all scenarios except when RLZ is disabled on |
| 268 // Windows. |
| 269 DCHECK(!device_id.empty()); |
| 270 #endif |
| 271 |
| 266 device_id_ = device_id; | 272 device_id_ = device_id; |
| 267 // On Aura, this seems to be called twice. | 273 CheckTrackedPreferences(); |
| 268 if (!checked_tracked_prefs_) | |
| 269 CheckTrackedPreferences(); | |
| 270 } | 274 } |
| 271 | 275 |
| 272 void PrefMetricsService::MarkNeedsEmptyValueForTrackedPreferences() { | 276 void PrefMetricsService::MarkNeedsEmptyValueForTrackedPreferences() { |
| 273 for (int i = 0; i < tracked_pref_path_count_; ++i) { | 277 for (int i = 0; i < tracked_pref_path_count_; ++i) { |
| 274 // Skip prefs that haven't been registered. | 278 // Skip prefs that haven't been registered. |
| 275 if (!prefs_->FindPreference(tracked_pref_paths_[i])) | 279 if (!prefs_->FindPreference(tracked_pref_paths_[i])) |
| 276 continue; | 280 continue; |
| 277 | 281 |
| 278 // Make sure tracked prefs are saved to disk even if empty. | 282 // 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 | 283 // TODO(gab): Guarantee this for all prefs at a lower level and remove this |
| 280 // hack. | 284 // hack. |
| 281 prefs_->MarkUserStoreNeedsEmptyValue(tracked_pref_paths_[i]); | 285 prefs_->MarkUserStoreNeedsEmptyValue(tracked_pref_paths_[i]); |
| 282 } | 286 } |
| 283 } | 287 } |
| 284 | 288 |
| 285 // To detect changes to Preferences that happen outside of Chrome, we hash | 289 // To detect changes to Preferences that happen outside of Chrome, we hash |
| 286 // selected pref values and save them in local state. CheckTrackedPreferences | 290 // selected pref values and save them in local state. CheckTrackedPreferences |
| 287 // compares the saved values to the values observed in the profile's prefs. A | 291 // compares the saved values to the values observed in the profile's prefs. A |
| 288 // dictionary of dictionaries in local state holds the hashed values, grouped by | 292 // dictionary of dictionaries in local state holds the hashed values, grouped by |
| 289 // profile. To make the system more resistant to spoofing, pref values are | 293 // profile. To make the system more resistant to spoofing, pref values are |
| 290 // hashed with the pref path and the device id. | 294 // hashed with the pref path and the device id. |
| 291 void PrefMetricsService::CheckTrackedPreferences() { | 295 void PrefMetricsService::CheckTrackedPreferences() { |
| 296 // Make sure this is only called once per instance of this service. |
| 292 DCHECK(!checked_tracked_prefs_); | 297 DCHECK(!checked_tracked_prefs_); |
| 298 checked_tracked_prefs_ = true; |
| 293 | 299 |
| 294 const base::DictionaryValue* pref_hash_dicts = | 300 const base::DictionaryValue* pref_hash_dicts = |
| 295 local_state_->GetDictionary(prefs::kProfilePreferenceHashes); | 301 local_state_->GetDictionary(prefs::kProfilePreferenceHashes); |
| 296 // Get the hashed prefs dictionary if it exists. If it doesn't, it will be | 302 // Get the hashed prefs dictionary if it exists. If it doesn't, it will be |
| 297 // created if we set preference values below. | 303 // created if we set preference values below. |
| 298 const base::DictionaryValue* hashed_prefs = NULL; | 304 const base::DictionaryValue* hashed_prefs = NULL; |
| 299 pref_hash_dicts->GetDictionaryWithoutPathExpansion(profile_name_, | 305 pref_hash_dicts->GetDictionaryWithoutPathExpansion(profile_name_, |
| 300 &hashed_prefs); | 306 &hashed_prefs); |
| 301 for (int i = 0; i < tracked_pref_path_count_; ++i) { | 307 for (int i = 0; i < tracked_pref_path_count_; ++i) { |
| 302 // Skip prefs that haven't been registered. | 308 // Skip prefs that haven't been registered. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 } | 347 } |
| 342 } else { | 348 } else { |
| 343 // Record that we haven't tracked this preference yet, or the hash in | 349 // Record that we haven't tracked this preference yet, or the hash in |
| 344 // local state was removed. | 350 // local state was removed. |
| 345 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceInitialized", | 351 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceInitialized", |
| 346 i, tracked_pref_path_count_); | 352 i, tracked_pref_path_count_); |
| 347 UpdateTrackedPreference(tracked_pref_paths_[i]); | 353 UpdateTrackedPreference(tracked_pref_paths_[i]); |
| 348 } | 354 } |
| 349 } | 355 } |
| 350 | 356 |
| 351 checked_tracked_prefs_ = true; | |
| 352 | |
| 353 // Now that we've checked the incoming preferences, register for change | 357 // Now that we've checked the incoming preferences, register for change |
| 354 // notifications, unless this is test code. | 358 // notifications, unless this is test code. |
| 355 // TODO(bbudge) Fix failing browser_tests and so we can remove this test. | 359 // TODO(bbudge) Fix failing browser_tests and so we can remove this test. |
| 356 // Several tests fail when they shutdown before they can write local state. | 360 // Several tests fail when they shutdown before they can write local state. |
| 357 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType) && | 361 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType) && |
| 358 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kChromeFrame)) { | 362 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kChromeFrame)) { |
| 359 InitializePrefObservers(); | 363 InitializePrefObservers(); |
| 360 } | 364 } |
| 361 } | 365 } |
| 362 | 366 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 } | 470 } |
| 467 | 471 |
| 468 bool PrefMetricsService::Factory::ServiceIsNULLWhileTesting() const { | 472 bool PrefMetricsService::Factory::ServiceIsNULLWhileTesting() const { |
| 469 return false; | 473 return false; |
| 470 } | 474 } |
| 471 | 475 |
| 472 content::BrowserContext* PrefMetricsService::Factory::GetBrowserContextToUse( | 476 content::BrowserContext* PrefMetricsService::Factory::GetBrowserContextToUse( |
| 473 content::BrowserContext* context) const { | 477 content::BrowserContext* context) const { |
| 474 return chrome::GetBrowserContextRedirectedInIncognito(context); | 478 return chrome::GetBrowserContextRedirectedInIncognito(context); |
| 475 } | 479 } |
| OLD | NEW |