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

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: Canonicalize hosts, enumerate all start pages. Created 7 years, 5 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"
9 #include "chrome/browser/profiles/incognito_helpers.h" 11 #include "chrome/browser/profiles/incognito_helpers.h"
10 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/search_engines/template_url_prepopulate_data.h"
14 #include "chrome/browser/search_engines/template_url_service.h"
15 #include "chrome/browser/search_engines/template_url_service_factory.h"
11 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
12 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h" 17 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h"
18 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
19
20 namespace {
21
22 // We are adding some common search engine hosts that are not prepopulated.
23 // These hosts are assigned id numbers 102-114 which extend the prepopulated
24 // engines histogram enum. If these new histograms are removed, restore this
25 // range to the list of available ids in the prepopulated_engines.json file.
26 static const int kMaxHostHistogramValue = 114;
27
28 typedef std::map<std::string, int> HostIdMap;
29
30 std::string CanonicalizeHost(const std::string& host) {
Mark P 2013/07/26 23:30:23 If this effectively returns the domain name, pleas
bbudge 2013/07/27 01:33:01 Done. HostIdMap -> DomainIdMap CanonicalizeHost ->
31 return std::string(
32 net::registry_controlled_domains::GetDomainAndRegistry(
33 host,
34 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES));
35 }
36
37 void AddHostToMap(HostIdMap* host_id_map,
Mark P 2013/07/26 23:30:23 nit: style has input parameters before modified an
bbudge 2013/07/27 01:33:01 Done.
38 const std::string& host,
39 int host_id) {
40 host_id_map->insert(std::make_pair(CanonicalizeHost(host), host_id));
41 }
42
43 // Builds a map that associated host name strings with histogram enum values,
Mark P 2013/07/26 23:30:23 nit: associated -> associates
bbudge 2013/07/27 01:33:01 Done.
44 // for prepopulated DSEs and select non-prepopulated ones.
45 void BuildHostIdMap(Profile* profile, HostIdMap* host_id_map) {
46 // Add prepopulated search engine hosts to the map.
47 ScopedVector<TemplateURL> prepopulated_urls;
48 size_t default_search_index;
49 TemplateURLPrepopulateData::GetPrepopulatedEngines(profile,
50 &prepopulated_urls.get(), &default_search_index);
51 for (size_t i = 0; i < prepopulated_urls.size(); ++i) {
52 AddHostToMap(host_id_map,
53 prepopulated_urls[i]->url_ref().GetHost(),
Mark P 2013/07/26 23:30:23 Why don't you canonicalize these too?
bbudge 2013/07/27 01:33:01 The AddHostToMap did the conversion. It is now don
54 prepopulated_urls[i]->prepopulate_id());
55 }
56 // Add non-prepopulated hosts to the map.
57 AddHostToMap(host_id_map, "searchnu.com", 102);
58 AddHostToMap(host_id_map, "babylon.com", 103);
59 AddHostToMap(host_id_map, "delta-search.com", 104);
60 AddHostToMap(host_id_map, "deltasearch.com", 104);
61 AddHostToMap(host_id_map, "iminent.com", 105);
62 AddHostToMap(host_id_map, "hao123.com", 106);
63 AddHostToMap(host_id_map, "sweetim.com", 107);
64 AddHostToMap(host_id_map, "snap.do", 108);
65 AddHostToMap(host_id_map, "snapdo.com", 109);
66 AddHostToMap(host_id_map, "softonic.com", 110);
67 AddHostToMap(host_id_map, "searchfunmoods.com", 111);
68 AddHostToMap(host_id_map, "incredibar.com", 112);
69 AddHostToMap(host_id_map, "sweetpacks.com", 113);
70 AddHostToMap(host_id_map, "imesh.net", 114);
Mark P 2013/07/26 23:30:23 Please do something, whether here or elsewhere, to
bbudge 2013/07/27 01:33:01 Done. Added a comment.
71 // These hosts may not be prepopulated, depending on the country settings.
72 // Add them here, using their existing ids. See histograms.xml.
73 AddHostToMap(host_id_map, "conduit.com", 36);
74 AddHostToMap(host_id_map, "avg.com", 50);
Mark P 2013/07/26 23:30:23 Introduce the 36 and 50 to the histograms.xml enum
bbudge 2013/07/27 01:33:01 Good catch. Done.
75 AddHostToMap(host_id_map, "mail.ru", 83);
76 }
77
78 // Maps a host name to a histogram enum value. The enum value '0' represents
79 // 'Unknown', i.e. an unrecognized host.
80 int MapHostToId(const HostIdMap& host_id_map, const std::string& host) {
81 HostIdMap::const_iterator it = host_id_map.find(CanonicalizeHost(host));
82 if (it != host_id_map.end())
83 return it->second;
84 return 0;
85 }
86
87 } // namespace
13 88
14 PrefMetricsService::PrefMetricsService(Profile* profile) 89 PrefMetricsService::PrefMetricsService(Profile* profile)
15 : profile_(profile) { 90 : profile_(profile) {
16 RecordLaunchPrefs(); 91 RecordLaunchPrefs();
17 } 92 }
18 93
19 PrefMetricsService::~PrefMetricsService() { 94 PrefMetricsService::~PrefMetricsService() {
20 } 95 }
21 96
22 void PrefMetricsService::RecordLaunchPrefs() { 97 void PrefMetricsService::RecordLaunchPrefs() {
23 UMA_HISTOGRAM_BOOLEAN("Settings.ShowHomeButton", 98 PrefService* prefs = profile_->GetPrefs();
24 profile_->GetPrefs()->GetBoolean(prefs::kShowHomeButton)); 99 bool show_home_button = prefs->GetBoolean(prefs::kShowHomeButton);
25 UMA_HISTOGRAM_BOOLEAN("Settings.HomePageIsNewTabPage", 100 bool home_page_is_ntp = prefs->GetBoolean(prefs::kHomePageIsNewTabPage);
Mark P 2013/07/26 23:30:23 nit: make both of these const
bbudge 2013/07/27 01:33:01 Done.
26 profile_->GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage)); 101
102 UMA_HISTOGRAM_BOOLEAN("Settings.ShowHomeButton", show_home_button);
103 UMA_HISTOGRAM_BOOLEAN("Settings.HomePageIsNewTabPage", home_page_is_ntp);
104
105 HostIdMap host_id_map;
106 BuildHostIdMap(profile_, &host_id_map);
107
108 // Record the default search engine host.
109 TemplateURLService* template_url_service =
110 TemplateURLServiceFactory::GetForProfile(profile_);
111 if (template_url_service) {
112 TemplateURL* template_url =
113 template_url_service->GetDefaultSearchProvider();
Mark P 2013/07/26 23:30:23 Please check the return value. Occasionally we've
bbudge 2013/07/27 01:33:01 Done.
114 int host_id = MapHostToId(host_id_map, template_url->url_ref().GetHost());
115 UMA_HISTOGRAM_ENUMERATION("Settings.DefaultSearchProvider",
116 host_id, kMaxHostHistogramValue);
117 }
118 // Record the home page URL host.
119 if (!home_page_is_ntp) {
120 GURL homepage_url(prefs->GetString(prefs::kHomePage));
121 if (homepage_url.is_valid()) {
122 int host_id = MapHostToId(host_id_map, homepage_url.host());
123 UMA_HISTOGRAM_ENUMERATION("Settings.HomePageURL",
124 host_id, kMaxHostHistogramValue);
125 }
126 }
127 // If page restore on startup is set (value == 4), record all startup pages.
Mark P 2013/07/26 23:30:23 nit: "page restore on startup" almost sounds like
bbudge 2013/07/27 01:33:01 Done.
128 int restore_setting = prefs->GetInteger(prefs::kRestoreOnStartup);
129 if (restore_setting == 4) {
130 const ListValue* url_list = prefs->GetList(prefs::kURLsToRestoreOnStartup);
131 for (size_t i = 0; i < url_list->GetSize(); i++) {
132 std::string url_text;
133 if (url_list->GetString(i, &url_text)) {
134 GURL start_url(url_text);
135 if (start_url.is_valid()) {
136 int host_id = MapHostToId(host_id_map, start_url.host());
137 UMA_HISTOGRAM_ENUMERATION("Settings.FirstStartPageURL",
Mark P 2013/07/26 23:30:23 "FirstStartPageURL" is a wrong name for this.
bbudge 2013/07/27 01:33:01 Done.
138 host_id, kMaxHostHistogramValue);
139 }
140 }
141 }
142 }
27 } 143 }
28 144
29 // static 145 // static
30 PrefMetricsService::Factory* PrefMetricsService::Factory::GetInstance() { 146 PrefMetricsService::Factory* PrefMetricsService::Factory::GetInstance() {
31 return Singleton<PrefMetricsService::Factory>::get(); 147 return Singleton<PrefMetricsService::Factory>::get();
32 } 148 }
33 149
34 // static 150 // static
35 PrefMetricsService* PrefMetricsService::Factory::GetForProfile( 151 PrefMetricsService* PrefMetricsService::Factory::GetForProfile(
36 Profile* profile) { 152 Profile* profile) {
37 return static_cast<PrefMetricsService*>( 153 return static_cast<PrefMetricsService*>(
38 GetInstance()->GetServiceForBrowserContext(profile, true)); 154 GetInstance()->GetServiceForBrowserContext(profile, true));
39 } 155 }
40 156
41 PrefMetricsService::Factory::Factory() 157 PrefMetricsService::Factory::Factory()
42 : BrowserContextKeyedServiceFactory( 158 : BrowserContextKeyedServiceFactory(
43 "PrefMetricsService", 159 "PrefMetricsService",
44 BrowserContextDependencyManager::GetInstance()) { 160 BrowserContextDependencyManager::GetInstance()) {
161 DependsOn(TemplateURLServiceFactory::GetInstance());
45 } 162 }
46 163
47 PrefMetricsService::Factory::~Factory() { 164 PrefMetricsService::Factory::~Factory() {
48 } 165 }
49 166
50 BrowserContextKeyedService* 167 BrowserContextKeyedService*
51 PrefMetricsService::Factory::BuildServiceInstanceFor( 168 PrefMetricsService::Factory::BuildServiceInstanceFor(
52 content::BrowserContext* profile) const { 169 content::BrowserContext* profile) const {
53 return new PrefMetricsService(static_cast<Profile*>(profile)); 170 return new PrefMetricsService(static_cast<Profile*>(profile));
54 } 171 }
55 172
56 bool PrefMetricsService::Factory::ServiceIsCreatedWithBrowserContext() const { 173 bool PrefMetricsService::Factory::ServiceIsCreatedWithBrowserContext() const {
57 return true; 174 return true;
58 } 175 }
59 176
60 bool PrefMetricsService::Factory::ServiceIsNULLWhileTesting() const { 177 bool PrefMetricsService::Factory::ServiceIsNULLWhileTesting() const {
61 return false; 178 return false;
62 } 179 }
63 180
64 content::BrowserContext* PrefMetricsService::Factory::GetBrowserContextToUse( 181 content::BrowserContext* PrefMetricsService::Factory::GetBrowserContextToUse(
65 content::BrowserContext* context) const { 182 content::BrowserContext* context) const {
66 return chrome::GetBrowserContextRedirectedInIncognito(context); 183 return chrome::GetBrowserContextRedirectedInIncognito(context);
67 } 184 }
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