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

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: Eliminate duplicate constant. 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
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"
11 #include "chrome/browser/prefs/session_startup_pref.h"
9 #include "chrome/browser/profiles/incognito_helpers.h" 12 #include "chrome/browser/profiles/incognito_helpers.h"
10 #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"
11 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
12 #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 typedef std::map<std::string, int> DomainIdMap;
26
27 // Returns the domain of the host name for easier matching.
28 std::string GetDomain(const std::string& host) {
29 return std::string(
30 net::registry_controlled_domains::GetDomainAndRegistry(
31 host,
32 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES));
33 }
34
35 void AddDomain(const std::string& domain,
36 int domain_id,
37 DomainIdMap* domain_id_map) {
38 domain_id_map->insert(std::make_pair(domain, domain_id));
39 }
40
41 // Builds a map that associates domain name strings with histogram enum values,
42 // for prepopulated DSEs and select non-prepopulated ones.
43 void BuildDomainIdMap(Profile* profile, DomainIdMap* domain_id_map) {
44 // Add prepopulated search engine hosts to the map.
45 ScopedVector<TemplateURL> prepopulated_urls;
46 size_t default_search_index;
47 TemplateURLPrepopulateData::GetPrepopulatedEngines(profile,
48 &prepopulated_urls.get(), &default_search_index);
49 for (size_t i = 0; i < prepopulated_urls.size(); ++i) {
50 std::string domain(GetDomain(prepopulated_urls[i]->url_ref().GetHost()));
Mark P 2013/07/30 15:32:56 nit: This intermediate variable doesn't buy you an
bbudge 2013/07/30 18:47:08 Done.
51 AddDomain(domain,
52 prepopulated_urls[i]->prepopulate_id(),
53 domain_id_map);
54 }
55 // Add some common search engine domains that are not prepopulated. Assign
56 // these domains id numbers 102-114 which extend the prepopulated engines
57 // histogram enum. If these new domains are removed, restore this range to
58 // the list of available ids in the prepopulated_engines.json file.
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("deltasearch.com", 104, domain_id_map);
bbudge 2013/07/29 16:27:16 whoops, need to remove this.
63 AddDomain("iminent.com", 105, domain_id_map);
64 AddDomain("hao123.com", 106, domain_id_map);
65 AddDomain("sweetim.com", 107, domain_id_map);
66 AddDomain("snap.do", 108, domain_id_map);
67 AddDomain("snapdo.com", 109, domain_id_map);
68 AddDomain("softonic.com", 110, domain_id_map);
69 AddDomain("searchfunmoods.com", 111, domain_id_map);
70 AddDomain("incredibar.com", 112, domain_id_map);
71 AddDomain("sweetpacks.com", 113, domain_id_map);
72 AddDomain("imesh.net", 114, domain_id_map);
73 // IMPORTANT: If you add more domains here, be sure to update the
74 // kMaxPrepopulatedEngineID and available ids in prepopulated_engines.json.
75
76 // The following hosts may not be prepopulated, depending on the country
77 // settings. Add them here, using their existing ids. See histograms.xml.
78 AddDomain("conduit.com", 36, domain_id_map);
79 AddDomain("avg.com", 50, domain_id_map);
80 AddDomain("mail.ru", 83, domain_id_map);
81 }
82
83 // Maps a host name to a histogram enum value. The enum value '0' represents
84 // 'Unknown', i.e. an unrecognized host.
85 int MapHostToId(const DomainIdMap& domain_id_map, const std::string& host) {
86 std::string domain(GetDomain(host));
87 DomainIdMap::const_iterator it = domain_id_map.find(domain);
88 if (it != domain_id_map.end())
89 return it->second;
90 return 0;
91 }
92
93 } // namespace
13 94
14 PrefMetricsService::PrefMetricsService(Profile* profile) 95 PrefMetricsService::PrefMetricsService(Profile* profile)
15 : profile_(profile) { 96 : profile_(profile) {
16 RecordLaunchPrefs(); 97 RecordLaunchPrefs();
17 } 98 }
18 99
19 PrefMetricsService::~PrefMetricsService() { 100 PrefMetricsService::~PrefMetricsService() {
20 } 101 }
21 102
22 void PrefMetricsService::RecordLaunchPrefs() { 103 void PrefMetricsService::RecordLaunchPrefs() {
23 UMA_HISTOGRAM_BOOLEAN("Settings.ShowHomeButton", 104 PrefService* prefs = profile_->GetPrefs();
24 profile_->GetPrefs()->GetBoolean(prefs::kShowHomeButton)); 105 const bool show_home_button = prefs->GetBoolean(prefs::kShowHomeButton);
25 UMA_HISTOGRAM_BOOLEAN("Settings.HomePageIsNewTabPage", 106 const bool home_page_is_ntp = prefs->GetBoolean(prefs::kHomePageIsNewTabPage);
26 profile_->GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage)); 107
108 UMA_HISTOGRAM_BOOLEAN("Settings.ShowHomeButton", show_home_button);
109 UMA_HISTOGRAM_BOOLEAN("Settings.HomePageIsNewTabPage", home_page_is_ntp);
110
111 DomainIdMap domain_id_map;
112 BuildDomainIdMap(profile_, &domain_id_map);
113
114 // Record the default search engine id.
115 TemplateURLService* template_url_service =
116 TemplateURLServiceFactory::GetForProfile(profile_);
117 if (template_url_service) {
118 TemplateURL* template_url =
119 template_url_service->GetDefaultSearchProvider();
120 if (template_url) {
121 int domain_id =
122 MapHostToId(domain_id_map, template_url->url_ref().GetHost());
123 UMA_HISTOGRAM_ENUMERATION("Settings.DefaultSearchProvider",
124 domain_id, kMaxPrepopulatedEngineID);
125 }
126 }
127 // If the home page isn't the NTP, record the home page domain id.
128 if (!home_page_is_ntp) {
129 GURL homepage_url(prefs->GetString(prefs::kHomePage));
130 if (homepage_url.is_valid()) {
131 int domain_id = MapHostToId(domain_id_map, homepage_url.host());
132 UMA_HISTOGRAM_ENUMERATION("Settings.HomePageDomain",
133 domain_id, kMaxPrepopulatedEngineID);
134 }
135 }
136 // If startup pages are set, record all startup page domain ids.
137 int restore_on_startup = prefs->GetInteger(prefs::kRestoreOnStartup);
138 if (restore_on_startup == SessionStartupPref::kPrefValueURLs) {
139 const ListValue* url_list = prefs->GetList(prefs::kURLsToRestoreOnStartup);
140 for (size_t i = 0; i < url_list->GetSize(); i++) {
141 std::string url_text;
142 if (url_list->GetString(i, &url_text)) {
143 GURL start_url(url_text);
144 if (start_url.is_valid()) {
145 int domain_id = MapHostToId(domain_id_map, start_url.host());
146 UMA_HISTOGRAM_ENUMERATION("Settings.StartPageDomains",
147 domain_id, kMaxPrepopulatedEngineID);
148 }
149 }
150 }
151 }
27 } 152 }
28 153
29 // static 154 // static
30 PrefMetricsService::Factory* PrefMetricsService::Factory::GetInstance() { 155 PrefMetricsService::Factory* PrefMetricsService::Factory::GetInstance() {
31 return Singleton<PrefMetricsService::Factory>::get(); 156 return Singleton<PrefMetricsService::Factory>::get();
32 } 157 }
33 158
34 // static 159 // static
35 PrefMetricsService* PrefMetricsService::Factory::GetForProfile( 160 PrefMetricsService* PrefMetricsService::Factory::GetForProfile(
36 Profile* profile) { 161 Profile* profile) {
37 return static_cast<PrefMetricsService*>( 162 return static_cast<PrefMetricsService*>(
38 GetInstance()->GetServiceForBrowserContext(profile, true)); 163 GetInstance()->GetServiceForBrowserContext(profile, true));
39 } 164 }
40 165
41 PrefMetricsService::Factory::Factory() 166 PrefMetricsService::Factory::Factory()
42 : BrowserContextKeyedServiceFactory( 167 : BrowserContextKeyedServiceFactory(
43 "PrefMetricsService", 168 "PrefMetricsService",
44 BrowserContextDependencyManager::GetInstance()) { 169 BrowserContextDependencyManager::GetInstance()) {
170 DependsOn(TemplateURLServiceFactory::GetInstance());
45 } 171 }
46 172
47 PrefMetricsService::Factory::~Factory() { 173 PrefMetricsService::Factory::~Factory() {
48 } 174 }
49 175
50 BrowserContextKeyedService* 176 BrowserContextKeyedService*
51 PrefMetricsService::Factory::BuildServiceInstanceFor( 177 PrefMetricsService::Factory::BuildServiceInstanceFor(
52 content::BrowserContext* profile) const { 178 content::BrowserContext* profile) const {
53 return new PrefMetricsService(static_cast<Profile*>(profile)); 179 return new PrefMetricsService(static_cast<Profile*>(profile));
54 } 180 }
55 181
56 bool PrefMetricsService::Factory::ServiceIsCreatedWithBrowserContext() const { 182 bool PrefMetricsService::Factory::ServiceIsCreatedWithBrowserContext() const {
57 return true; 183 return true;
58 } 184 }
59 185
60 bool PrefMetricsService::Factory::ServiceIsNULLWhileTesting() const { 186 bool PrefMetricsService::Factory::ServiceIsNULLWhileTesting() const {
61 return false; 187 return false;
62 } 188 }
63 189
64 content::BrowserContext* PrefMetricsService::Factory::GetBrowserContextToUse( 190 content::BrowserContext* PrefMetricsService::Factory::GetBrowserContextToUse(
65 content::BrowserContext* context) const { 191 content::BrowserContext* context) const {
66 return chrome::GetBrowserContextRedirectedInIncognito(context); 192 return chrome::GetBrowserContextRedirectedInIncognito(context);
67 } 193 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/search_engines/prepopulated_engines.json » ('j') | tools/metrics/histograms/histograms.xml » ('J')

Powered by Google App Engine
This is Rietveld 408576698