Index: chrome/browser/prefs/pref_metrics_service.cc |
diff --git a/chrome/browser/prefs/pref_metrics_service.cc b/chrome/browser/prefs/pref_metrics_service.cc |
index ed1d5380e5849a2e828a2951ac73b4e25d494df8..58be22ab14a1863c2c04c4a1569227ba8de31b67 100644 |
--- a/chrome/browser/prefs/pref_metrics_service.cc |
+++ b/chrome/browser/prefs/pref_metrics_service.cc |
@@ -4,13 +4,79 @@ |
#include "chrome/browser/prefs/pref_metrics_service.h" |
+#include <map> |
+ |
#include "base/metrics/histogram.h" |
#include "base/prefs/pref_service.h" |
#include "chrome/browser/profiles/incognito_helpers.h" |
#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
+#include "chrome/browser/search_engines/template_url_service.h" |
+#include "chrome/browser/search_engines/template_url_service_factory.h" |
#include "chrome/common/pref_names.h" |
#include "components/browser_context_keyed_service/browser_context_dependency_manager.h" |
+namespace { |
+ |
+// We are adding some common search engine hosts that are not prepopulated. |
+// These hosts are assigned id numbers 102-114 which extend the prepopulated |
+// engines histogram enum. If these new histograms are removed, restore this |
+// range to the list of available ids in the prepopulated_engines.json file. |
+static const int kMaxHostHistogramValue = 114; |
+ |
+typedef std::map<std::string, int> HostIdMap; |
+ |
+void AddHostToMap(HostIdMap* host_id_map, |
+ const std::string& host, |
+ int host_id) { |
+ host_id_map->insert(std::make_pair(host, host_id)); |
+} |
+ |
+// Builds a map that associated host name strings with histogram enum values, |
+// for prepopulated DSEs and select non-prepopulated ones. |
+void BuildHostIdMap(Profile* profile, HostIdMap* host_id_map) { |
+ // Add prepopulated search engine hosts to the map. |
+ ScopedVector<TemplateURL> prepopulated_urls; |
+ size_t default_search_index; |
+ TemplateURLPrepopulateData::GetPrepopulatedEngines(profile, |
+ &prepopulated_urls.get(), &default_search_index); |
+ for (size_t i = 0; i < prepopulated_urls.size(); ++i) { |
+ AddHostToMap(host_id_map, |
+ prepopulated_urls[i]->url_ref().GetHost(), |
+ prepopulated_urls[i]->prepopulate_id()); |
+ } |
+ // Add non-prepopulated hosts to the map. |
+ AddHostToMap(host_id_map, "searchnu.com", 102); |
+ AddHostToMap(host_id_map, "babylon.com", 103); |
+ AddHostToMap(host_id_map, "delta-search.com", 104); |
+ AddHostToMap(host_id_map, "iminent.com", 105); |
+ AddHostToMap(host_id_map, "hao123.com", 106); |
+ AddHostToMap(host_id_map, "sweetim.com", 107); |
+ AddHostToMap(host_id_map, "snap.do", 108); |
+ AddHostToMap(host_id_map, "snapdo.com", 109); |
+ AddHostToMap(host_id_map, "softonic.com", 110); |
+ AddHostToMap(host_id_map, "searchfunmoods.com", 111); |
+ AddHostToMap(host_id_map, "incredibar.com", 112); |
+ AddHostToMap(host_id_map, "sweetpacks.com", 113); |
+ AddHostToMap(host_id_map, "imesh.net", 114); |
+ // These hosts may not be prepopulated, depending on the country settings. |
+ // Add them here, using their existing ids. See histograms.xml. |
+ AddHostToMap(host_id_map, "conduit.com", 36); |
+ AddHostToMap(host_id_map, "avg.com", 50); |
+ AddHostToMap(host_id_map, "mail.ru", 83); |
+} |
+ |
+// Maps a host name to a histogram enum value. The enum value '0' represents |
+// 'Unknown', i.e. an unrecognized host. |
+int MapHostToId(const HostIdMap& host_id_map, const std::string& host) { |
+ HostIdMap::const_iterator it = host_id_map.find(host); |
+ if (it != host_id_map.end()) |
+ return it->second; |
+ return 0; |
+} |
+ |
+} // namespace |
+ |
PrefMetricsService::PrefMetricsService(Profile* profile) |
: profile_(profile) { |
RecordLaunchPrefs(); |
@@ -20,10 +86,53 @@ PrefMetricsService::~PrefMetricsService() { |
} |
void PrefMetricsService::RecordLaunchPrefs() { |
- UMA_HISTOGRAM_BOOLEAN("Settings.ShowHomeButton", |
- profile_->GetPrefs()->GetBoolean(prefs::kShowHomeButton)); |
- UMA_HISTOGRAM_BOOLEAN("Settings.HomePageIsNewTabPage", |
- profile_->GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage)); |
+ PrefService* prefs = profile_->GetPrefs(); |
+ bool show_home_button = prefs->GetBoolean(prefs::kShowHomeButton); |
+ bool home_page_is_ntp = prefs->GetBoolean(prefs::kHomePageIsNewTabPage); |
+ |
+ UMA_HISTOGRAM_BOOLEAN("Settings.ShowHomeButton", show_home_button); |
+ UMA_HISTOGRAM_BOOLEAN("Settings.HomePageIsNewTabPage", home_page_is_ntp); |
+ |
+ HostIdMap host_id_map; |
+ BuildHostIdMap(profile_, &host_id_map); |
+ |
+ // Record the default search engine host. |
+ TemplateURLService* template_url_service = |
+ TemplateURLServiceFactory::GetForProfile(profile_); |
+ if (template_url_service) { |
+ TemplateURL* template_url = |
+ template_url_service->GetDefaultSearchProvider(); |
+ int host_id = MapHostToId(host_id_map, template_url->url_ref().GetHost()); |
+ UMA_HISTOGRAM_ENUMERATION("Settings.DefaultSearchProvider", |
+ host_id, kMaxHostHistogramValue); |
+ } |
+ // Record the home page URL host. |
+ if (!home_page_is_ntp) { |
+ GURL homepage_url(prefs->GetString(prefs::kHomePage)); |
+ if (homepage_url.is_valid()) { |
+ 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
|
+ UMA_HISTOGRAM_ENUMERATION("Settings.HomePageURL", |
+ host_id, kMaxHostHistogramValue); |
+ } |
+ } |
+ // If page restore is set, record the first startup page host. This is the |
+ // page that is in the active tab after startup. |
+ int restore_setting; |
+ if (prefs->GetInteger(prefs::kRestoreOnStartup, &restore_setting) && |
+ restore_setting == 4) { |
+ const ListValue* url_list = prefs->GetList(prefs::kURLsToRestoreOnStartup); |
+ 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
|
+ std::string url_text; |
+ if (url_list->GetString(0, &url_text)) { |
+ GURL start_url(url_text); |
+ if (start_url.is_valid()) { |
+ int host_id = MapHostToId(host_id_map, start_url.host()); |
+ UMA_HISTOGRAM_ENUMERATION("Settings.FirstStartPageURL", |
+ host_id, kMaxHostHistogramValue); |
+ } |
+ } |
+ } |
+ } |
} |
// static |
@@ -42,6 +151,7 @@ PrefMetricsService::Factory::Factory() |
: BrowserContextKeyedServiceFactory( |
"PrefMetricsService", |
BrowserContextDependencyManager::GetInstance()) { |
+ DependsOn(TemplateURLServiceFactory::GetInstance()); |
} |
PrefMetricsService::Factory::~Factory() { |