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

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: Address Ken's comment, guard startup page UMA on restore setting 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
« 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/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"
13 18
19 namespace {
20
21 // We are adding some common search engine hosts that are not prepopulated.
22 // These hosts are assigned id numbers 102-114 which extend the prepopulated
23 // engines histogram enum. If these new histograms are removed, restore this
24 // range to the list of available ids in the prepopulated_engines.json file.
25 static const int kMaxHostHistogramValue = 114;
26
27 typedef std::map<std::string, int> HostIdMap;
28
29 void AddHostToMap(HostIdMap* host_id_map,
30 const std::string& host,
31 int host_id) {
32 host_id_map->insert(std::make_pair(host, host_id));
33 }
34
35 // Builds a map that associated host name strings with histogram enum values,
36 // for prepopulated DSEs and select non-prepopulated ones.
37 void BuildHostIdMap(Profile* profile, HostIdMap* host_id_map) {
38 // Add prepopulated search engine hosts to the map.
39 ScopedVector<TemplateURL> prepopulated_urls;
40 size_t default_search_index;
41 TemplateURLPrepopulateData::GetPrepopulatedEngines(profile,
42 &prepopulated_urls.get(), &default_search_index);
43 for (size_t i = 0; i < prepopulated_urls.size(); ++i) {
44 AddHostToMap(host_id_map,
45 prepopulated_urls[i]->url_ref().GetHost(),
46 prepopulated_urls[i]->prepopulate_id());
47 }
48 // Add non-prepopulated hosts to the map.
49 AddHostToMap(host_id_map, "searchnu.com", 102);
50 AddHostToMap(host_id_map, "babylon.com", 103);
51 AddHostToMap(host_id_map, "delta-search.com", 104);
52 AddHostToMap(host_id_map, "iminent.com", 105);
53 AddHostToMap(host_id_map, "hao123.com", 106);
54 AddHostToMap(host_id_map, "sweetim.com", 107);
55 AddHostToMap(host_id_map, "snap.do", 108);
56 AddHostToMap(host_id_map, "snapdo.com", 109);
57 AddHostToMap(host_id_map, "softonic.com", 110);
58 AddHostToMap(host_id_map, "searchfunmoods.com", 111);
59 AddHostToMap(host_id_map, "incredibar.com", 112);
60 AddHostToMap(host_id_map, "sweetpacks.com", 113);
61 AddHostToMap(host_id_map, "imesh.net", 114);
62 // These hosts may not be prepopulated, depending on the country settings.
63 // Add them here, using their existing ids. See histograms.xml.
64 AddHostToMap(host_id_map, "conduit.com", 36);
65 AddHostToMap(host_id_map, "avg.com", 50);
66 AddHostToMap(host_id_map, "mail.ru", 83);
67 }
68
69 // Maps a host name to a histogram enum value. The enum value '0' represents
70 // 'Unknown', i.e. an unrecognized host.
71 int MapHostToId(const HostIdMap& host_id_map, const std::string& host) {
72 HostIdMap::const_iterator it = host_id_map.find(host);
73 if (it != host_id_map.end())
74 return it->second;
75 return 0;
76 }
77
78 } // namespace
79
14 PrefMetricsService::PrefMetricsService(Profile* profile) 80 PrefMetricsService::PrefMetricsService(Profile* profile)
15 : profile_(profile) { 81 : profile_(profile) {
16 RecordLaunchPrefs(); 82 RecordLaunchPrefs();
17 } 83 }
18 84
19 PrefMetricsService::~PrefMetricsService() { 85 PrefMetricsService::~PrefMetricsService() {
20 } 86 }
21 87
22 void PrefMetricsService::RecordLaunchPrefs() { 88 void PrefMetricsService::RecordLaunchPrefs() {
23 UMA_HISTOGRAM_BOOLEAN("Settings.ShowHomeButton", 89 PrefService* prefs = profile_->GetPrefs();
24 profile_->GetPrefs()->GetBoolean(prefs::kShowHomeButton)); 90 bool show_home_button = prefs->GetBoolean(prefs::kShowHomeButton);
25 UMA_HISTOGRAM_BOOLEAN("Settings.HomePageIsNewTabPage", 91 bool home_page_is_ntp = prefs->GetBoolean(prefs::kHomePageIsNewTabPage);
26 profile_->GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage)); 92
93 UMA_HISTOGRAM_BOOLEAN("Settings.ShowHomeButton", show_home_button);
94 UMA_HISTOGRAM_BOOLEAN("Settings.HomePageIsNewTabPage", home_page_is_ntp);
95
96 HostIdMap host_id_map;
97 BuildHostIdMap(profile_, &host_id_map);
98
99 // Record the default search engine host.
100 TemplateURLService* template_url_service =
101 TemplateURLServiceFactory::GetForProfile(profile_);
102 if (template_url_service) {
103 TemplateURL* template_url =
104 template_url_service->GetDefaultSearchProvider();
105 int host_id = MapHostToId(host_id_map, template_url->url_ref().GetHost());
106 UMA_HISTOGRAM_ENUMERATION("Settings.DefaultSearchProvider",
107 host_id, kMaxHostHistogramValue);
108 }
109 // Record the home page URL host.
110 if (!home_page_is_ntp) {
111 GURL homepage_url(prefs->GetString(prefs::kHomePage));
112 if (homepage_url.is_valid()) {
113 int host_id = MapHostToId(host_id_map, homepage_url.host());
battre 2013/07/26 19:27:51 This does not work. You can have www.foo.com, www2
bbudge 2013/07/26 22:13:55 Changed to canonicalize hosts using GetDomainAndRe
114 UMA_HISTOGRAM_ENUMERATION("Settings.HomePageURL",
115 host_id, kMaxHostHistogramValue);
116 }
117 }
118 // If page restore is set, record the first startup page host. This is the
119 // page that is in the active tab after startup.
120 int restore_setting;
121 if (prefs->GetInteger(prefs::kRestoreOnStartup, &restore_setting) &&
122 restore_setting == 4) {
123 const ListValue* url_list = prefs->GetList(prefs::kURLsToRestoreOnStartup);
124 if (url_list->GetSize() > 0) {
battre 2013/07/26 19:27:51 I think this should be a for loop iterating over t
bbudge 2013/07/26 22:13:55 There was some discussion about multiple start pag
125 std::string url_text;
126 if (url_list->GetString(0, &url_text)) {
127 GURL start_url(url_text);
128 if (start_url.is_valid()) {
129 int host_id = MapHostToId(host_id_map, start_url.host());
130 UMA_HISTOGRAM_ENUMERATION("Settings.FirstStartPageURL",
131 host_id, kMaxHostHistogramValue);
132 }
133 }
134 }
135 }
27 } 136 }
28 137
29 // static 138 // static
30 PrefMetricsService::Factory* PrefMetricsService::Factory::GetInstance() { 139 PrefMetricsService::Factory* PrefMetricsService::Factory::GetInstance() {
31 return Singleton<PrefMetricsService::Factory>::get(); 140 return Singleton<PrefMetricsService::Factory>::get();
32 } 141 }
33 142
34 // static 143 // static
35 PrefMetricsService* PrefMetricsService::Factory::GetForProfile( 144 PrefMetricsService* PrefMetricsService::Factory::GetForProfile(
36 Profile* profile) { 145 Profile* profile) {
37 return static_cast<PrefMetricsService*>( 146 return static_cast<PrefMetricsService*>(
38 GetInstance()->GetServiceForBrowserContext(profile, true)); 147 GetInstance()->GetServiceForBrowserContext(profile, true));
39 } 148 }
40 149
41 PrefMetricsService::Factory::Factory() 150 PrefMetricsService::Factory::Factory()
42 : BrowserContextKeyedServiceFactory( 151 : BrowserContextKeyedServiceFactory(
43 "PrefMetricsService", 152 "PrefMetricsService",
44 BrowserContextDependencyManager::GetInstance()) { 153 BrowserContextDependencyManager::GetInstance()) {
154 DependsOn(TemplateURLServiceFactory::GetInstance());
45 } 155 }
46 156
47 PrefMetricsService::Factory::~Factory() { 157 PrefMetricsService::Factory::~Factory() {
48 } 158 }
49 159
50 BrowserContextKeyedService* 160 BrowserContextKeyedService*
51 PrefMetricsService::Factory::BuildServiceInstanceFor( 161 PrefMetricsService::Factory::BuildServiceInstanceFor(
52 content::BrowserContext* profile) const { 162 content::BrowserContext* profile) const {
53 return new PrefMetricsService(static_cast<Profile*>(profile)); 163 return new PrefMetricsService(static_cast<Profile*>(profile));
54 } 164 }
55 165
56 bool PrefMetricsService::Factory::ServiceIsCreatedWithBrowserContext() const { 166 bool PrefMetricsService::Factory::ServiceIsCreatedWithBrowserContext() const {
57 return true; 167 return true;
58 } 168 }
59 169
60 bool PrefMetricsService::Factory::ServiceIsNULLWhileTesting() const { 170 bool PrefMetricsService::Factory::ServiceIsNULLWhileTesting() const {
61 return false; 171 return false;
62 } 172 }
63 173
64 content::BrowserContext* PrefMetricsService::Factory::GetBrowserContextToUse( 174 content::BrowserContext* PrefMetricsService::Factory::GetBrowserContextToUse(
65 content::BrowserContext* context) const { 175 content::BrowserContext* context) const {
66 return chrome::GetBrowserContextRedirectedInIncognito(context); 176 return chrome::GetBrowserContextRedirectedInIncognito(context);
67 } 177 }
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