Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(446)

Side by Side Diff: chrome/browser/prefs/pref_metrics_service.cc

Issue 20012003: Add UMA histograms for home page, start page, and DSE hosts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Redo the patch again. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/search_engines/prepopulated_engines.json » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <map>
8
7 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
8 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/prefs/session_startup_pref.h" 11 #include "chrome/browser/prefs/session_startup_pref.h"
10 #include "chrome/browser/profiles/incognito_helpers.h" 12 #include "chrome/browser/profiles/incognito_helpers.h"
11 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/search_engines/template_url_prepopulate_data.h"
15 #include "chrome/browser/search_engines/template_url_service.h"
16 #include "chrome/browser/search_engines/template_url_service_factory.h"
12 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
13 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h" 18 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h"
19 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
20
21 using TemplateURLPrepopulateData::kMaxPrepopulatedEngineID;
22
23 namespace {
24
25 // Use a map to convert domains to their histogram identifiers. Ids are defined
26 // in tools/metrics/histograms/histograms.xml and (usually) also in
27 // chrome/browser/search_engines/prepopulated_engines.json.
28 typedef std::map<std::string, int> DomainIdMap;
29
30 // Converts a host name into a domain name for easier matching.
31 std::string GetDomain(const std::string& host) {
32 return net::registry_controlled_domains::GetDomainAndRegistry(
33 host,
34 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES);
35 }
36
37 void AddDomain(const std::string& domain,
38 int domain_id,
39 DomainIdMap* domain_id_map) {
40 domain_id_map->insert(std::make_pair(domain, domain_id));
41 }
42
43 // Builds a map that associates domain name strings with histogram enum values,
44 // for prepopulated DSEs and select non-prepopulated ones.
45 void BuildDomainIdMap(Profile* profile, DomainIdMap* domain_id_map) {
46 // Add prepopulated search engine hosts to the map.
47 ScopedVector<TemplateURL> prepopulated_urls;
48 size_t default_search_index; // unused
49 TemplateURLPrepopulateData::GetPrepopulatedEngines(profile,
50 &prepopulated_urls.get(), &default_search_index);
51 for (size_t i = 0; i < prepopulated_urls.size(); ++i) {
52 AddDomain(GetDomain(prepopulated_urls[i]->url_ref().GetHost()),
53 prepopulated_urls[i]->prepopulate_id(),
54 domain_id_map);
55 }
56 // Add some common search engine domains that are not prepopulated. Assign
57 // these domains id numbers 102-114 which extend the prepopulated engines
58 // histogram enum.
59 AddDomain("searchnu.com", 102, domain_id_map);
60 AddDomain("babylon.com", 103, domain_id_map);
61 AddDomain("delta-search.com", 104, domain_id_map);
62 AddDomain("iminent.com", 105, domain_id_map);
63 AddDomain("hao123.com", 106, domain_id_map);
64 AddDomain("sweetim.com", 107, domain_id_map);
65 AddDomain("snap.do", 108, domain_id_map);
66 AddDomain("snapdo.com", 109, domain_id_map);
67 AddDomain("softonic.com", 110, domain_id_map);
68 AddDomain("searchfunmoods.com", 111, domain_id_map);
69 AddDomain("incredibar.com", 112, domain_id_map);
70 AddDomain("sweetpacks.com", 113, domain_id_map);
71 AddDomain("imesh.net", 114, domain_id_map);
72 // IMPORTANT: If you add more domains here, be sure to update the
73 // kMaxPrepopulatedEngineID and available ids in prepopulated_engines.json.
74
75 // The following hosts may not be prepopulated, depending on the country
76 // settings. Add them here, using their existing ids. See histograms.xml.
77 AddDomain("conduit.com", 36, domain_id_map);
78 AddDomain("avg.com", 50, domain_id_map);
79 AddDomain("mail.ru", 83, domain_id_map);
80 }
81
82 // Maps a host name to a histogram enum value. The enum value '0' represents
83 // 'Unknown', i.e. an unrecognized host.
84 int MapHostToId(const DomainIdMap& domain_id_map, const std::string& host) {
85 DomainIdMap::const_iterator it = domain_id_map.find(GetDomain(host));
86 if (it != domain_id_map.end())
87 return it->second;
88 return 0;
89 }
90
91 } // namespace
14 92
15 PrefMetricsService::PrefMetricsService(Profile* profile) 93 PrefMetricsService::PrefMetricsService(Profile* profile)
16 : profile_(profile) { 94 : profile_(profile) {
17 RecordLaunchPrefs(); 95 RecordLaunchPrefs();
18 } 96 }
19 97
20 PrefMetricsService::~PrefMetricsService() { 98 PrefMetricsService::~PrefMetricsService() {
21 } 99 }
22 100
23 void PrefMetricsService::RecordLaunchPrefs() { 101 void PrefMetricsService::RecordLaunchPrefs() {
24 UMA_HISTOGRAM_BOOLEAN("Settings.ShowHomeButton", 102 PrefService* prefs = profile_->GetPrefs();
25 profile_->GetPrefs()->GetBoolean(prefs::kShowHomeButton)); 103 const bool show_home_button = prefs->GetBoolean(prefs::kShowHomeButton);
26 UMA_HISTOGRAM_BOOLEAN("Settings.HomePageIsNewTabPage", 104 const bool home_page_is_ntp = prefs->GetBoolean(prefs::kHomePageIsNewTabPage);
27 profile_->GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage)); 105
106 UMA_HISTOGRAM_BOOLEAN("Settings.ShowHomeButton", show_home_button);
107 UMA_HISTOGRAM_BOOLEAN("Settings.HomePageIsNewTabPage", home_page_is_ntp);
28 108
29 int restore_on_startup = profile_->GetPrefs()->GetInteger( 109 int restore_on_startup = profile_->GetPrefs()->GetInteger(
30 prefs::kRestoreOnStartup); 110 prefs::kRestoreOnStartup);
31 UMA_HISTOGRAM_ENUMERATION("Settings.StartupPageLoadSettings", 111 UMA_HISTOGRAM_ENUMERATION("Settings.StartupPageLoadSettings",
32 restore_on_startup, SessionStartupPref::kPrefValueMax); 112 restore_on_startup, SessionStartupPref::kPrefValueMax);
33 if (restore_on_startup == SessionStartupPref::kPrefValueURLs) { 113 if (restore_on_startup == SessionStartupPref::kPrefValueURLs) {
34 const int url_list_size = profile_->GetPrefs()->GetList( 114 const int url_list_size = profile_->GetPrefs()->GetList(
35 prefs::kURLsToRestoreOnStartup)->GetSize(); 115 prefs::kURLsToRestoreOnStartup)->GetSize();
36 UMA_HISTOGRAM_CUSTOM_COUNTS( 116 UMA_HISTOGRAM_CUSTOM_COUNTS(
37 "Settings.StartupPageLoadURLs", url_list_size, 1, 50, 20); 117 "Settings.StartupPageLoadURLs", url_list_size, 1, 50, 20);
38 } 118 }
119
120 DomainIdMap domain_id_map;
121 BuildDomainIdMap(profile_, &domain_id_map);
122
123 // Record the default search engine id.
124 TemplateURLService* template_url_service =
125 TemplateURLServiceFactory::GetForProfile(profile_);
126 if (template_url_service) {
127 TemplateURL* template_url =
128 template_url_service->GetDefaultSearchProvider();
129 if (template_url) {
130 const int domain_id =
131 MapHostToId(domain_id_map, template_url->url_ref().GetHost());
132 UMA_HISTOGRAM_ENUMERATION("Settings.DefaultSearchProvider",
133 domain_id, kMaxPrepopulatedEngineID);
134 }
135 }
136 // If the home page isn't the NTP, record the home page domain id.
137 if (!home_page_is_ntp) {
138 GURL homepage_url(prefs->GetString(prefs::kHomePage));
139 if (homepage_url.is_valid()) {
140 const int domain_id = MapHostToId(domain_id_map, homepage_url.host());
141 UMA_HISTOGRAM_ENUMERATION("Settings.HomePageDomain",
142 domain_id, kMaxPrepopulatedEngineID);
143 }
144 }
145 // If startup pages are set, record all startup page domain ids.
146 if (restore_on_startup == SessionStartupPref::kPrefValueURLs) {
147 const ListValue* url_list = prefs->GetList(prefs::kURLsToRestoreOnStartup);
148 for (size_t i = 0; i < url_list->GetSize(); i++) {
149 std::string url_text;
150 if (url_list->GetString(i, &url_text)) {
151 GURL start_url(url_text);
152 if (start_url.is_valid()) {
153 const int domain_id = MapHostToId(domain_id_map, start_url.host());
154 UMA_HISTOGRAM_ENUMERATION("Settings.StartupPageDomains",
155 domain_id, kMaxPrepopulatedEngineID);
156 }
157 }
158 }
159 }
39 } 160 }
40 161
41 // static 162 // static
42 PrefMetricsService::Factory* PrefMetricsService::Factory::GetInstance() { 163 PrefMetricsService::Factory* PrefMetricsService::Factory::GetInstance() {
43 return Singleton<PrefMetricsService::Factory>::get(); 164 return Singleton<PrefMetricsService::Factory>::get();
44 } 165 }
45 166
46 // static 167 // static
47 PrefMetricsService* PrefMetricsService::Factory::GetForProfile( 168 PrefMetricsService* PrefMetricsService::Factory::GetForProfile(
48 Profile* profile) { 169 Profile* profile) {
49 return static_cast<PrefMetricsService*>( 170 return static_cast<PrefMetricsService*>(
50 GetInstance()->GetServiceForBrowserContext(profile, true)); 171 GetInstance()->GetServiceForBrowserContext(profile, true));
51 } 172 }
52 173
53 PrefMetricsService::Factory::Factory() 174 PrefMetricsService::Factory::Factory()
54 : BrowserContextKeyedServiceFactory( 175 : BrowserContextKeyedServiceFactory(
55 "PrefMetricsService", 176 "PrefMetricsService",
56 BrowserContextDependencyManager::GetInstance()) { 177 BrowserContextDependencyManager::GetInstance()) {
178 DependsOn(TemplateURLServiceFactory::GetInstance());
57 } 179 }
58 180
59 PrefMetricsService::Factory::~Factory() { 181 PrefMetricsService::Factory::~Factory() {
60 } 182 }
61 183
62 BrowserContextKeyedService* 184 BrowserContextKeyedService*
63 PrefMetricsService::Factory::BuildServiceInstanceFor( 185 PrefMetricsService::Factory::BuildServiceInstanceFor(
64 content::BrowserContext* profile) const { 186 content::BrowserContext* profile) const {
65 return new PrefMetricsService(static_cast<Profile*>(profile)); 187 return new PrefMetricsService(static_cast<Profile*>(profile));
66 } 188 }
67 189
68 bool PrefMetricsService::Factory::ServiceIsCreatedWithBrowserContext() const { 190 bool PrefMetricsService::Factory::ServiceIsCreatedWithBrowserContext() const {
69 return true; 191 return true;
70 } 192 }
71 193
72 bool PrefMetricsService::Factory::ServiceIsNULLWhileTesting() const { 194 bool PrefMetricsService::Factory::ServiceIsNULLWhileTesting() const {
73 return false; 195 return false;
74 } 196 }
75 197
76 content::BrowserContext* PrefMetricsService::Factory::GetBrowserContextToUse( 198 content::BrowserContext* PrefMetricsService::Factory::GetBrowserContextToUse(
77 content::BrowserContext* context) const { 199 content::BrowserContext* context) const {
78 return chrome::GetBrowserContextRedirectedInIncognito(context); 200 return chrome::GetBrowserContextRedirectedInIncognito(context);
79 } 201 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/search_engines/prepopulated_engines.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698