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" |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "components/syncable_prefs/pref_service_syncable.h" | 28 #include "components/syncable_prefs/pref_service_syncable.h" |
29 #include "components/syncable_prefs/synced_pref_change_registrar.h" | 29 #include "components/syncable_prefs/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 // Record a sample for the Settings.NewTabPage rappor metric. | 39 // Record a sample for the Settings.NewTabPage rappor metric. |
39 void SampleNewTabPageURL(Profile* profile) { | 40 void SampleNewTabPageURL(Profile* profile) { |
40 GURL ntp_url(chrome::kChromeUINewTabURL); | 41 GURL ntp_url(chrome::kChromeUINewTabURL); |
41 bool reverse_on_redirect = false; | 42 bool reverse_on_redirect = false; |
42 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary( | 43 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary( |
43 &ntp_url, | 44 &ntp_url, |
44 profile, | 45 profile, |
45 &reverse_on_redirect); | 46 &reverse_on_redirect); |
46 if (ntp_url.is_valid()) { | 47 if (ntp_url.is_valid()) { |
47 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(), | 48 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(), |
48 "Settings.NewTabPage", ntp_url); | 49 "Settings.NewTabPage", ntp_url); |
49 } | 50 } |
50 } | 51 } |
| 52 #endif |
51 | 53 |
52 } // namespace | 54 } // namespace |
53 | 55 |
54 PrefMetricsService::PrefMetricsService(Profile* profile) | 56 PrefMetricsService::PrefMetricsService(Profile* profile) |
55 : profile_(profile), | 57 : profile_(profile), |
56 prefs_(profile_->GetPrefs()), | 58 prefs_(profile_->GetPrefs()), |
57 local_state_(g_browser_process->local_state()), | 59 local_state_(g_browser_process->local_state()), |
58 weak_factory_(this) { | 60 weak_factory_(this) { |
59 RecordLaunchPrefs(); | 61 RecordLaunchPrefs(); |
60 | 62 |
(...skipping 10 matching lines...) Expand all Loading... |
71 PrefService* local_state) | 73 PrefService* local_state) |
72 : profile_(profile), | 74 : profile_(profile), |
73 prefs_(profile->GetPrefs()), | 75 prefs_(profile->GetPrefs()), |
74 local_state_(local_state), | 76 local_state_(local_state), |
75 weak_factory_(this) { | 77 weak_factory_(this) { |
76 } | 78 } |
77 | 79 |
78 PrefMetricsService::~PrefMetricsService() { | 80 PrefMetricsService::~PrefMetricsService() { |
79 } | 81 } |
80 | 82 |
81 void PrefMetricsService::RecordLaunchPrefs() { | 83 // static |
82 bool show_home_button = prefs_->GetBoolean(prefs::kShowHomeButton); | 84 void PrefMetricsService::RecordHomePageLaunchMetrics(bool show_home_button, |
83 bool home_page_is_ntp = prefs_->GetBoolean(prefs::kHomePageIsNewTabPage); | 85 bool homepage_is_ntp, |
| 86 const GURL& homepage_url) { |
84 UMA_HISTOGRAM_BOOLEAN("Settings.ShowHomeButton", show_home_button); | 87 UMA_HISTOGRAM_BOOLEAN("Settings.ShowHomeButton", show_home_button); |
85 if (show_home_button) { | 88 if (show_home_button) { |
86 UMA_HISTOGRAM_BOOLEAN("Settings.GivenShowHomeButton_HomePageIsNewTabPage", | 89 UMA_HISTOGRAM_BOOLEAN("Settings.GivenShowHomeButton_HomePageIsNewTabPage", |
87 home_page_is_ntp); | 90 homepage_is_ntp); |
88 } | 91 } |
89 | 92 |
90 // For non-NTP homepages, see if the URL comes from the same TLD+1 as a known | 93 // For non-NTP homepages, see if the URL comes from the same TLD+1 as a known |
91 // search engine. Note that this is only an approximation of search engine | 94 // search engine. Note that this is only an approximation of search engine |
92 // use, due to both false negatives (pages that come from unknown TLD+1 X but | 95 // use, due to both false negatives (pages that come from unknown TLD+1 X but |
93 // consist of a search box that sends to known TLD+1 Y) and false positives | 96 // consist of a search box that sends to known TLD+1 Y) and false positives |
94 // (pages that share a TLD+1 with a known engine but aren't actually search | 97 // (pages that share a TLD+1 with a known engine but aren't actually search |
95 // pages, e.g. plus.google.com). Additionally, record the TLD+1 of non-NTP | 98 // pages, e.g. plus.google.com). Additionally, record the TLD+1 of non-NTP |
96 // homepages through the privacy-preserving Rappor service. | 99 // homepages through the privacy-preserving Rappor service. |
97 if (!home_page_is_ntp) { | 100 if (!homepage_is_ntp) { |
98 GURL homepage_url(prefs_->GetString(prefs::kHomePage)); | |
99 if (homepage_url.is_valid()) { | 101 if (homepage_url.is_valid()) { |
100 UMA_HISTOGRAM_ENUMERATION( | 102 UMA_HISTOGRAM_ENUMERATION( |
101 "Settings.HomePageEngineType", | 103 "Settings.HomePageEngineType", |
102 TemplateURLPrepopulateData::GetEngineType(homepage_url), | 104 TemplateURLPrepopulateData::GetEngineType(homepage_url), |
103 SEARCH_ENGINE_MAX); | 105 SEARCH_ENGINE_MAX); |
104 rappor::SampleDomainAndRegistryFromGURL( | 106 rappor::SampleDomainAndRegistryFromGURL( |
105 g_browser_process->rappor_service(), "Settings.HomePage2", | 107 g_browser_process->rappor_service(), "Settings.HomePage2", |
106 homepage_url); | 108 homepage_url); |
107 } | 109 } |
108 } | 110 } |
| 111 } |
109 | 112 |
| 113 void PrefMetricsService::RecordLaunchPrefs() { |
| 114 // On Android, determining whether the homepage is enabled requires waiting |
| 115 // for a response from a third party provider installed on the device. So, |
| 116 // it will be logged later once all the dependent information is available. |
| 117 // See DeferredStartupHandler.java. |
| 118 #if !defined(OS_ANDROID) |
| 119 GURL homepage_url(prefs_->GetString(prefs::kHomePage)); |
| 120 RecordHomePageLaunchMetrics(prefs_->GetBoolean(prefs::kShowHomeButton), |
| 121 prefs_->GetBoolean(prefs::kHomePageIsNewTabPage), |
| 122 homepage_url); |
| 123 #endif |
| 124 |
| 125 // Android does not support overriding the NTP URL. |
| 126 #if !defined(OS_ANDROID) |
110 SampleNewTabPageURL(profile_); | 127 SampleNewTabPageURL(profile_); |
| 128 #endif |
111 | 129 |
| 130 // Tab restoring is always done on Android, so these metrics are not |
| 131 // applicable. Also, startup pages are not supported on Android |
| 132 #if !defined(OS_ANDROID) |
112 int restore_on_startup = prefs_->GetInteger(prefs::kRestoreOnStartup); | 133 int restore_on_startup = prefs_->GetInteger(prefs::kRestoreOnStartup); |
113 UMA_HISTOGRAM_ENUMERATION("Settings.StartupPageLoadSettings", | 134 UMA_HISTOGRAM_ENUMERATION("Settings.StartupPageLoadSettings", |
114 restore_on_startup, kSessionStartupPrefValueMax); | 135 restore_on_startup, kSessionStartupPrefValueMax); |
115 if (restore_on_startup == SessionStartupPref::kPrefValueURLs) { | 136 if (restore_on_startup == SessionStartupPref::kPrefValueURLs) { |
116 const base::ListValue* url_list = | 137 const base::ListValue* url_list = |
117 prefs_->GetList(prefs::kURLsToRestoreOnStartup); | 138 prefs_->GetList(prefs::kURLsToRestoreOnStartup); |
118 UMA_HISTOGRAM_CUSTOM_COUNTS("Settings.StartupPageLoadURLs", | 139 UMA_HISTOGRAM_CUSTOM_COUNTS("Settings.StartupPageLoadURLs", |
119 url_list->GetSize(), 1, 50, 20); | 140 url_list->GetSize(), 1, 50, 20); |
120 // Similarly, check startup pages for known search engine TLD+1s. | 141 // Similarly, check startup pages for known search engine TLD+1s. |
121 std::string url_text; | 142 std::string url_text; |
122 for (size_t i = 0; i < url_list->GetSize(); ++i) { | 143 for (size_t i = 0; i < url_list->GetSize(); ++i) { |
123 if (url_list->GetString(i, &url_text)) { | 144 if (url_list->GetString(i, &url_text)) { |
124 GURL start_url(url_text); | 145 GURL start_url(url_text); |
125 if (start_url.is_valid()) { | 146 if (start_url.is_valid()) { |
126 UMA_HISTOGRAM_ENUMERATION( | 147 UMA_HISTOGRAM_ENUMERATION( |
127 "Settings.StartupPageEngineTypes", | 148 "Settings.StartupPageEngineTypes", |
128 TemplateURLPrepopulateData::GetEngineType(start_url), | 149 TemplateURLPrepopulateData::GetEngineType(start_url), |
129 SEARCH_ENGINE_MAX); | 150 SEARCH_ENGINE_MAX); |
130 if (i == 0) { | 151 if (i == 0) { |
131 rappor::SampleDomainAndRegistryFromGURL( | 152 rappor::SampleDomainAndRegistryFromGURL( |
132 g_browser_process->rappor_service(), | 153 g_browser_process->rappor_service(), |
133 "Settings.FirstStartupPage", start_url); | 154 "Settings.FirstStartupPage", start_url); |
134 } | 155 } |
135 } | 156 } |
136 } | 157 } |
137 } | 158 } |
138 } | 159 } |
| 160 #endif |
139 | 161 |
| 162 // Android does not support pinned tabs. |
140 #if !defined(OS_ANDROID) | 163 #if !defined(OS_ANDROID) |
141 StartupTabs startup_tabs = PinnedTabCodec::ReadPinnedTabs(profile_); | 164 StartupTabs startup_tabs = PinnedTabCodec::ReadPinnedTabs(profile_); |
142 UMA_HISTOGRAM_CUSTOM_COUNTS("Settings.PinnedTabs", | 165 UMA_HISTOGRAM_CUSTOM_COUNTS("Settings.PinnedTabs", |
143 startup_tabs.size(), 1, 50, 20); | 166 startup_tabs.size(), 1, 50, 20); |
144 for (size_t i = 0; i < startup_tabs.size(); ++i) { | 167 for (size_t i = 0; i < startup_tabs.size(); ++i) { |
145 GURL start_url(startup_tabs.at(i).url); | 168 GURL start_url(startup_tabs.at(i).url); |
146 if (start_url.is_valid()) { | 169 if (start_url.is_valid()) { |
147 UMA_HISTOGRAM_ENUMERATION( | 170 UMA_HISTOGRAM_ENUMERATION( |
148 "Settings.PinnedTabEngineTypes", | 171 "Settings.PinnedTabEngineTypes", |
149 TemplateURLPrepopulateData::GetEngineType(start_url), | 172 TemplateURLPrepopulateData::GetEngineType(start_url), |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 } | 272 } |
250 | 273 |
251 bool PrefMetricsService::Factory::ServiceIsNULLWhileTesting() const { | 274 bool PrefMetricsService::Factory::ServiceIsNULLWhileTesting() const { |
252 return false; | 275 return false; |
253 } | 276 } |
254 | 277 |
255 content::BrowserContext* PrefMetricsService::Factory::GetBrowserContextToUse( | 278 content::BrowserContext* PrefMetricsService::Factory::GetBrowserContextToUse( |
256 content::BrowserContext* context) const { | 279 content::BrowserContext* context) const { |
257 return chrome::GetBrowserContextRedirectedInIncognito(context); | 280 return chrome::GetBrowserContextRedirectedInIncognito(context); |
258 } | 281 } |
OLD | NEW |