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

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: Remove erroneous domain. 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"
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;
Mark P 2013/07/30 15:32:56 nit: please comment me; what does the int mean / w
bbudge 2013/07/30 18:47:08 Done.
26
27 // Returns the domain of the host name for easier matching.
28 std::string GetDomain(const std::string& host) {
29 return std::string(
Mark P 2013/07/30 15:32:56 Why do you need this std::string()?
bbudge 2013/07/30 18:47:08 Right, I don't need it. Done.
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;
Mark P 2013/07/30 15:32:56 nit: // unused
bbudge 2013/07/30 18:47:08 Done.
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()));
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.
Mark P 2013/07/30 15:32:56 This last sentence is bad advice. We shouldn't re
bbudge 2013/07/30 18:47:08 Yes, I suppose ids are forever. Removed comment.
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 std::string domain(GetDomain(host));
86 DomainIdMap::const_iterator it = domain_id_map.find(domain);
Mark P 2013/07/30 15:32:56 nit: just call GetDomain directly.
bbudge 2013/07/30 18:47:08 Done.
87 if (it != domain_id_map.end())
88 return it->second;
89 return 0;
90 }
91
92 } // namespace
13 93
14 PrefMetricsService::PrefMetricsService(Profile* profile) 94 PrefMetricsService::PrefMetricsService(Profile* profile)
15 : profile_(profile) { 95 : profile_(profile) {
16 RecordLaunchPrefs(); 96 RecordLaunchPrefs();
17 } 97 }
18 98
19 PrefMetricsService::~PrefMetricsService() { 99 PrefMetricsService::~PrefMetricsService() {
20 } 100 }
21 101
22 void PrefMetricsService::RecordLaunchPrefs() { 102 void PrefMetricsService::RecordLaunchPrefs() {
23 UMA_HISTOGRAM_BOOLEAN("Settings.ShowHomeButton", 103 PrefService* prefs = profile_->GetPrefs();
24 profile_->GetPrefs()->GetBoolean(prefs::kShowHomeButton)); 104 const bool show_home_button = prefs->GetBoolean(prefs::kShowHomeButton);
25 UMA_HISTOGRAM_BOOLEAN("Settings.HomePageIsNewTabPage", 105 const bool home_page_is_ntp = prefs->GetBoolean(prefs::kHomePageIsNewTabPage);
26 profile_->GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage)); 106
107 UMA_HISTOGRAM_BOOLEAN("Settings.ShowHomeButton", show_home_button);
108 UMA_HISTOGRAM_BOOLEAN("Settings.HomePageIsNewTabPage", home_page_is_ntp);
109
110 DomainIdMap domain_id_map;
111 BuildDomainIdMap(profile_, &domain_id_map);
112
113 // Record the default search engine id.
114 TemplateURLService* template_url_service =
115 TemplateURLServiceFactory::GetForProfile(profile_);
116 if (template_url_service) {
117 TemplateURL* template_url =
118 template_url_service->GetDefaultSearchProvider();
119 if (template_url) {
120 int domain_id =
Mark P 2013/07/30 15:32:56 const or just put it on the UMA_HISTOGRAM line dir
bbudge 2013/07/30 18:47:08 Made these const. Done.
121 MapHostToId(domain_id_map, template_url->url_ref().GetHost());
122 UMA_HISTOGRAM_ENUMERATION("Settings.DefaultSearchProvider",
123 domain_id, kMaxPrepopulatedEngineID);
124 }
125 }
126 // If the home page isn't the NTP, record the home page domain id.
127 if (!home_page_is_ntp) {
128 GURL homepage_url(prefs->GetString(prefs::kHomePage));
129 if (homepage_url.is_valid()) {
130 int domain_id = MapHostToId(domain_id_map, homepage_url.host());
131 UMA_HISTOGRAM_ENUMERATION("Settings.HomePageDomain",
132 domain_id, kMaxPrepopulatedEngineID);
133 }
134 }
135 // If startup pages are set, record all startup page domain ids.
136 int restore_on_startup = prefs->GetInteger(prefs::kRestoreOnStartup);
137 if (restore_on_startup == SessionStartupPref::kPrefValueURLs) {
138 const ListValue* url_list = prefs->GetList(prefs::kURLsToRestoreOnStartup);
139 for (size_t i = 0; i < url_list->GetSize(); i++) {
140 std::string url_text;
141 if (url_list->GetString(i, &url_text)) {
142 GURL start_url(url_text);
143 if (start_url.is_valid()) {
144 int domain_id = MapHostToId(domain_id_map, start_url.host());
145 UMA_HISTOGRAM_ENUMERATION("Settings.StartPageDomains",
146 domain_id, kMaxPrepopulatedEngineID);
147 }
148 }
149 }
150 }
27 } 151 }
28 152
29 // static 153 // static
30 PrefMetricsService::Factory* PrefMetricsService::Factory::GetInstance() { 154 PrefMetricsService::Factory* PrefMetricsService::Factory::GetInstance() {
31 return Singleton<PrefMetricsService::Factory>::get(); 155 return Singleton<PrefMetricsService::Factory>::get();
32 } 156 }
33 157
34 // static 158 // static
35 PrefMetricsService* PrefMetricsService::Factory::GetForProfile( 159 PrefMetricsService* PrefMetricsService::Factory::GetForProfile(
36 Profile* profile) { 160 Profile* profile) {
37 return static_cast<PrefMetricsService*>( 161 return static_cast<PrefMetricsService*>(
38 GetInstance()->GetServiceForBrowserContext(profile, true)); 162 GetInstance()->GetServiceForBrowserContext(profile, true));
39 } 163 }
40 164
41 PrefMetricsService::Factory::Factory() 165 PrefMetricsService::Factory::Factory()
42 : BrowserContextKeyedServiceFactory( 166 : BrowserContextKeyedServiceFactory(
43 "PrefMetricsService", 167 "PrefMetricsService",
44 BrowserContextDependencyManager::GetInstance()) { 168 BrowserContextDependencyManager::GetInstance()) {
169 DependsOn(TemplateURLServiceFactory::GetInstance());
45 } 170 }
46 171
47 PrefMetricsService::Factory::~Factory() { 172 PrefMetricsService::Factory::~Factory() {
48 } 173 }
49 174
50 BrowserContextKeyedService* 175 BrowserContextKeyedService*
51 PrefMetricsService::Factory::BuildServiceInstanceFor( 176 PrefMetricsService::Factory::BuildServiceInstanceFor(
52 content::BrowserContext* profile) const { 177 content::BrowserContext* profile) const {
53 return new PrefMetricsService(static_cast<Profile*>(profile)); 178 return new PrefMetricsService(static_cast<Profile*>(profile));
54 } 179 }
55 180
56 bool PrefMetricsService::Factory::ServiceIsCreatedWithBrowserContext() const { 181 bool PrefMetricsService::Factory::ServiceIsCreatedWithBrowserContext() const {
57 return true; 182 return true;
58 } 183 }
59 184
60 bool PrefMetricsService::Factory::ServiceIsNULLWhileTesting() const { 185 bool PrefMetricsService::Factory::ServiceIsNULLWhileTesting() const {
61 return false; 186 return false;
62 } 187 }
63 188
64 content::BrowserContext* PrefMetricsService::Factory::GetBrowserContextToUse( 189 content::BrowserContext* PrefMetricsService::Factory::GetBrowserContextToUse(
65 content::BrowserContext* context) const { 190 content::BrowserContext* context) const {
66 return chrome::GetBrowserContextRedirectedInIncognito(context); 191 return chrome::GetBrowserContextRedirectedInIncognito(context);
67 } 192 }
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