| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/prefs/pref_service_syncable_util.h" | 15 #include "chrome/browser/prefs/pref_service_syncable_util.h" |
| 16 #include "chrome/browser/prefs/session_startup_pref.h" | 16 #include "chrome/browser/prefs/session_startup_pref.h" |
| 17 #include "chrome/browser/profiles/incognito_helpers.h" | 17 #include "chrome/browser/profiles/incognito_helpers.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/search_engines/template_url_service_factory.h" | 19 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 20 #include "chrome/browser/ui/tabs/pinned_tab_codec.h" | 20 #include "chrome/browser/ui/tabs/pinned_tab_codec.h" |
| 21 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
| 22 #include "chrome/common/url_constants.h" | 22 #include "chrome/common/url_constants.h" |
| 23 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 23 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 24 #include "components/prefs/pref_registry_simple.h" | 24 #include "components/prefs/pref_registry_simple.h" |
| 25 #include "components/prefs/pref_service.h" | 25 #include "components/prefs/pref_service.h" |
| 26 #include "components/rappor/rappor_utils.h" | 26 #include "components/rappor/rappor_utils.h" |
| 27 #include "components/search_engines/template_url_prepopulate_data.h" | 27 #include "components/search_engines/template_url_prepopulate_data.h" |
| 28 #include "components/syncable_prefs/pref_service_syncable.h" | 28 #include "components/sync_preferences/pref_service_syncable.h" |
| 29 #include "components/syncable_prefs/synced_pref_change_registrar.h" | 29 #include "components/sync_preferences/synced_pref_change_registrar.h" |
| 30 #include "content/public/browser/browser_url_handler.h" | 30 #include "content/public/browser/browser_url_handler.h" |
| 31 #include "crypto/hmac.h" | 31 #include "crypto/hmac.h" |
| 32 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 32 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 const int kSessionStartupPrefValueMax = SessionStartupPref::kPrefValueMax; | 36 const int kSessionStartupPrefValueMax = SessionStartupPref::kPrefValueMax; |
| 37 | 37 |
| 38 #if !defined(OS_ANDROID) | 38 #if !defined(OS_ANDROID) |
| 39 // Record a sample for the Settings.NewTabPage rappor metric. | 39 // Record a sample for the Settings.NewTabPage rappor metric. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 53 | 53 |
| 54 } // namespace | 54 } // namespace |
| 55 | 55 |
| 56 PrefMetricsService::PrefMetricsService(Profile* profile) | 56 PrefMetricsService::PrefMetricsService(Profile* profile) |
| 57 : profile_(profile), | 57 : profile_(profile), |
| 58 prefs_(profile_->GetPrefs()), | 58 prefs_(profile_->GetPrefs()), |
| 59 local_state_(g_browser_process->local_state()), | 59 local_state_(g_browser_process->local_state()), |
| 60 weak_factory_(this) { | 60 weak_factory_(this) { |
| 61 RecordLaunchPrefs(); | 61 RecordLaunchPrefs(); |
| 62 | 62 |
| 63 syncable_prefs::PrefServiceSyncable* prefs = | 63 sync_preferences::PrefServiceSyncable* prefs = |
| 64 PrefServiceSyncableFromProfile(profile_); | 64 PrefServiceSyncableFromProfile(profile_); |
| 65 synced_pref_change_registrar_.reset( | 65 synced_pref_change_registrar_.reset( |
| 66 new syncable_prefs::SyncedPrefChangeRegistrar(prefs)); | 66 new sync_preferences::SyncedPrefChangeRegistrar(prefs)); |
| 67 | 67 |
| 68 RegisterSyncedPrefObservers(); | 68 RegisterSyncedPrefObservers(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 // For unit testing only. | 71 // For unit testing only. |
| 72 PrefMetricsService::PrefMetricsService(Profile* profile, | 72 PrefMetricsService::PrefMetricsService(Profile* profile, |
| 73 PrefService* local_state) | 73 PrefService* local_state) |
| 74 : profile_(profile), | 74 : profile_(profile), |
| 75 prefs_(profile->GetPrefs()), | 75 prefs_(profile->GetPrefs()), |
| 76 local_state_(local_state), | 76 local_state_(local_state), |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 base::Bind(&PrefMetricsService::OnPrefChanged, | 198 base::Bind(&PrefMetricsService::OnPrefChanged, |
| 199 base::Unretained(this), | 199 base::Unretained(this), |
| 200 histogram_name_prefix, callback)); | 200 histogram_name_prefix, callback)); |
| 201 } | 201 } |
| 202 | 202 |
| 203 void PrefMetricsService::OnPrefChanged( | 203 void PrefMetricsService::OnPrefChanged( |
| 204 const std::string& histogram_name_prefix, | 204 const std::string& histogram_name_prefix, |
| 205 const LogHistogramValueCallback& callback, | 205 const LogHistogramValueCallback& callback, |
| 206 const std::string& path, | 206 const std::string& path, |
| 207 bool from_sync) { | 207 bool from_sync) { |
| 208 syncable_prefs::PrefServiceSyncable* prefs = | 208 sync_preferences::PrefServiceSyncable* prefs = |
| 209 PrefServiceSyncableFromProfile(profile_); | 209 PrefServiceSyncableFromProfile(profile_); |
| 210 const PrefService::Preference* pref = prefs->FindPreference(path.c_str()); | 210 const PrefService::Preference* pref = prefs->FindPreference(path.c_str()); |
| 211 DCHECK(pref); | 211 DCHECK(pref); |
| 212 std::string source_name( | 212 std::string source_name( |
| 213 from_sync ? ".PulledFromSync" : ".PushedToSync"); | 213 from_sync ? ".PulledFromSync" : ".PushedToSync"); |
| 214 std::string histogram_name("Settings." + histogram_name_prefix + source_name); | 214 std::string histogram_name("Settings." + histogram_name_prefix + source_name); |
| 215 callback.Run(histogram_name, pref->GetValue()); | 215 callback.Run(histogram_name, pref->GetValue()); |
| 216 } | 216 } |
| 217 | 217 |
| 218 void PrefMetricsService::LogBooleanPrefChange(const std::string& histogram_name, | 218 void PrefMetricsService::LogBooleanPrefChange(const std::string& histogram_name, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 } | 272 } |
| 273 | 273 |
| 274 bool PrefMetricsService::Factory::ServiceIsNULLWhileTesting() const { | 274 bool PrefMetricsService::Factory::ServiceIsNULLWhileTesting() const { |
| 275 return false; | 275 return false; |
| 276 } | 276 } |
| 277 | 277 |
| 278 content::BrowserContext* PrefMetricsService::Factory::GetBrowserContextToUse( | 278 content::BrowserContext* PrefMetricsService::Factory::GetBrowserContextToUse( |
| 279 content::BrowserContext* context) const { | 279 content::BrowserContext* context) const { |
| 280 return chrome::GetBrowserContextRedirectedInIncognito(context); | 280 return chrome::GetBrowserContextRedirectedInIncognito(context); |
| 281 } | 281 } |
| OLD | NEW |