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/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/prefs/pref_registry_simple.h" | 10 #include "base/prefs/pref_registry_simple.h" |
11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/browser_shutdown.h" | 14 #include "chrome/browser/browser_shutdown.h" |
15 #include "chrome/browser/prefs/pref_service_syncable.h" | 15 #include "chrome/browser/prefs/pref_service_syncable.h" |
16 #include "chrome/browser/prefs/session_startup_pref.h" | 16 #include "chrome/browser/prefs/session_startup_pref.h" |
17 #include "chrome/browser/prefs/synced_pref_change_registrar.h" | 17 #include "chrome/browser/prefs/synced_pref_change_registrar.h" |
18 #include "chrome/browser/profiles/incognito_helpers.h" | 18 #include "chrome/browser/profiles/incognito_helpers.h" |
19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/search/search.h" | |
20 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" | 21 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
21 #include "chrome/browser/ui/tabs/pinned_tab_codec.h" | 22 #include "chrome/browser/ui/tabs/pinned_tab_codec.h" |
22 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
23 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
24 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 25 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
25 #include "components/rappor/rappor_service.h" | 26 #include "components/rappor/rappor_utils.h" |
26 #include "crypto/hmac.h" | 27 #include "crypto/hmac.h" |
27 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 28 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
28 | 29 |
29 namespace { | 30 namespace { |
30 | 31 |
31 const int kSessionStartupPrefValueMax = SessionStartupPref::kPrefValueMax; | 32 const int kSessionStartupPrefValueMax = SessionStartupPref::kPrefValueMax; |
32 | 33 |
33 } // namespace | 34 } // namespace |
34 | 35 |
35 PrefMetricsService::PrefMetricsService(Profile* profile) | 36 PrefMetricsService::PrefMetricsService(Profile* profile) |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 // (pages that share a TLD+1 with a known engine but aren't actually search | 74 // (pages that share a TLD+1 with a known engine but aren't actually search |
74 // pages, e.g. plus.google.com). Additionally, record the TLD+1 of non-NTP | 75 // pages, e.g. plus.google.com). Additionally, record the TLD+1 of non-NTP |
75 // homepages through the privacy-preserving Rappor service. | 76 // homepages through the privacy-preserving Rappor service. |
76 if (!home_page_is_ntp) { | 77 if (!home_page_is_ntp) { |
77 GURL homepage_url(prefs_->GetString(prefs::kHomePage)); | 78 GURL homepage_url(prefs_->GetString(prefs::kHomePage)); |
78 if (homepage_url.is_valid()) { | 79 if (homepage_url.is_valid()) { |
79 UMA_HISTOGRAM_ENUMERATION( | 80 UMA_HISTOGRAM_ENUMERATION( |
80 "Settings.HomePageEngineType", | 81 "Settings.HomePageEngineType", |
81 TemplateURLPrepopulateData::GetEngineType(homepage_url), | 82 TemplateURLPrepopulateData::GetEngineType(homepage_url), |
82 SEARCH_ENGINE_MAX); | 83 SEARCH_ENGINE_MAX); |
83 if (g_browser_process->rappor_service()) { | 84 rappor::SampleDomainAndRegistryFromGURL( |
84 g_browser_process->rappor_service()->RecordSample( | 85 g_browser_process->rappor_service(), |
85 "Settings.HomePage2", | 86 "Settings.HomePage2", |
86 rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, | 87 homepage_url); |
87 net::registry_controlled_domains::GetDomainAndRegistry(homepage_url, | |
88 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES)); | |
89 } | |
90 } | 88 } |
91 } | 89 } |
92 | 90 |
91 GURL ntp_url = chrome::GetNewTabPageURL(profile_); | |
92 if (ntp_url.is_valid()) { | |
93 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(), | |
94 "Settings.NewTabPageURL", | |
95 ntp_url); | |
battre
2014/06/06 09:49:43
Please check whether this does what you expect if
Steven Holte
2014/06/06 21:00:50
It does not. It records whatever would have been
| |
96 } | |
97 | |
93 int restore_on_startup = prefs_->GetInteger(prefs::kRestoreOnStartup); | 98 int restore_on_startup = prefs_->GetInteger(prefs::kRestoreOnStartup); |
94 UMA_HISTOGRAM_ENUMERATION("Settings.StartupPageLoadSettings", | 99 UMA_HISTOGRAM_ENUMERATION("Settings.StartupPageLoadSettings", |
95 restore_on_startup, kSessionStartupPrefValueMax); | 100 restore_on_startup, kSessionStartupPrefValueMax); |
96 if (restore_on_startup == SessionStartupPref::kPrefValueURLs) { | 101 if (restore_on_startup == SessionStartupPref::kPrefValueURLs) { |
97 const base::ListValue* url_list = | 102 const base::ListValue* url_list = |
98 prefs_->GetList(prefs::kURLsToRestoreOnStartup); | 103 prefs_->GetList(prefs::kURLsToRestoreOnStartup); |
99 UMA_HISTOGRAM_CUSTOM_COUNTS("Settings.StartupPageLoadURLs", | 104 UMA_HISTOGRAM_CUSTOM_COUNTS("Settings.StartupPageLoadURLs", |
100 url_list->GetSize(), 1, 50, 20); | 105 url_list->GetSize(), 1, 50, 20); |
101 // Similarly, check startup pages for known search engine TLD+1s. | 106 // Similarly, check startup pages for known search engine TLD+1s. |
102 std::string url_text; | 107 std::string url_text; |
103 for (size_t i = 0; i < url_list->GetSize(); ++i) { | 108 for (size_t i = 0; i < url_list->GetSize(); ++i) { |
104 if (url_list->GetString(i, &url_text)) { | 109 if (url_list->GetString(i, &url_text)) { |
105 GURL start_url(url_text); | 110 GURL start_url(url_text); |
106 if (start_url.is_valid()) { | 111 if (start_url.is_valid()) { |
107 UMA_HISTOGRAM_ENUMERATION( | 112 UMA_HISTOGRAM_ENUMERATION( |
108 "Settings.StartupPageEngineTypes", | 113 "Settings.StartupPageEngineTypes", |
109 TemplateURLPrepopulateData::GetEngineType(start_url), | 114 TemplateURLPrepopulateData::GetEngineType(start_url), |
110 SEARCH_ENGINE_MAX); | 115 SEARCH_ENGINE_MAX); |
116 rappor::SampleDomainAndRegistryFromGURL( | |
117 g_browser_process->rappor_service(), | |
118 "Settings.StartupPage", | |
119 start_url); | |
battre
2014/06/06 09:49:43
Just be aware that you get >1 sample per user/prof
Steven Holte
2014/06/06 21:38:04
I discussed this with Vasyl and Tyler, and it seem
| |
111 } | 120 } |
112 } | 121 } |
113 } | 122 } |
114 } | 123 } |
115 | 124 |
116 #if !defined(OS_ANDROID) | 125 #if !defined(OS_ANDROID) |
117 StartupTabs startup_tabs = PinnedTabCodec::ReadPinnedTabs(profile_); | 126 StartupTabs startup_tabs = PinnedTabCodec::ReadPinnedTabs(profile_); |
118 UMA_HISTOGRAM_CUSTOM_COUNTS("Settings.PinnedTabs", | 127 UMA_HISTOGRAM_CUSTOM_COUNTS("Settings.PinnedTabs", |
119 startup_tabs.size(), 1, 50, 20); | 128 startup_tabs.size(), 1, 50, 20); |
120 for (size_t i = 0; i < startup_tabs.size(); ++i) { | 129 for (size_t i = 0; i < startup_tabs.size(); ++i) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 const LogHistogramValueCallback& callback, | 167 const LogHistogramValueCallback& callback, |
159 const std::string& path, | 168 const std::string& path, |
160 bool from_sync) { | 169 bool from_sync) { |
161 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_); | 170 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_); |
162 const PrefService::Preference* pref = prefs->FindPreference(path.c_str()); | 171 const PrefService::Preference* pref = prefs->FindPreference(path.c_str()); |
163 DCHECK(pref); | 172 DCHECK(pref); |
164 std::string source_name( | 173 std::string source_name( |
165 from_sync ? ".PulledFromSync" : ".PushedToSync"); | 174 from_sync ? ".PulledFromSync" : ".PushedToSync"); |
166 std::string histogram_name("Settings." + histogram_name_prefix + source_name); | 175 std::string histogram_name("Settings." + histogram_name_prefix + source_name); |
167 callback.Run(histogram_name, pref->GetValue()); | 176 callback.Run(histogram_name, pref->GetValue()); |
168 }; | 177 } |
169 | 178 |
170 void PrefMetricsService::LogBooleanPrefChange(const std::string& histogram_name, | 179 void PrefMetricsService::LogBooleanPrefChange(const std::string& histogram_name, |
171 const base::Value* value) { | 180 const base::Value* value) { |
172 bool boolean_value = false; | 181 bool boolean_value = false; |
173 if (!value->GetAsBoolean(&boolean_value)) | 182 if (!value->GetAsBoolean(&boolean_value)) |
174 return; | 183 return; |
175 base::HistogramBase* histogram = base::BooleanHistogram::FactoryGet( | 184 base::HistogramBase* histogram = base::BooleanHistogram::FactoryGet( |
176 histogram_name, base::HistogramBase::kUmaTargetedHistogramFlag); | 185 histogram_name, base::HistogramBase::kUmaTargetedHistogramFlag); |
177 histogram->Add(boolean_value); | 186 histogram->Add(boolean_value); |
178 } | 187 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
223 } | 232 } |
224 | 233 |
225 bool PrefMetricsService::Factory::ServiceIsNULLWhileTesting() const { | 234 bool PrefMetricsService::Factory::ServiceIsNULLWhileTesting() const { |
226 return false; | 235 return false; |
227 } | 236 } |
228 | 237 |
229 content::BrowserContext* PrefMetricsService::Factory::GetBrowserContextToUse( | 238 content::BrowserContext* PrefMetricsService::Factory::GetBrowserContextToUse( |
230 content::BrowserContext* context) const { | 239 content::BrowserContext* context) const { |
231 return chrome::GetBrowserContextRedirectedInIncognito(context); | 240 return chrome::GetBrowserContextRedirectedInIncognito(context); |
232 } | 241 } |
OLD | NEW |