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

Side by Side Diff: chrome/browser/prefs/pref_metrics_service.cc

Issue 311133006: Add more Rappor metrics (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 6 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
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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/prefs/pref_registry_simple.h" 10 #include "base/prefs/pref_registry_simple.h"
11 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/browser_shutdown.h" 14 #include "chrome/browser/browser_shutdown.h"
15 #include "chrome/browser/metrics/rappor/sampling.h"
15 #include "chrome/browser/prefs/pref_service_syncable.h" 16 #include "chrome/browser/prefs/pref_service_syncable.h"
16 #include "chrome/browser/prefs/session_startup_pref.h" 17 #include "chrome/browser/prefs/session_startup_pref.h"
17 #include "chrome/browser/prefs/synced_pref_change_registrar.h" 18 #include "chrome/browser/prefs/synced_pref_change_registrar.h"
18 #include "chrome/browser/profiles/incognito_helpers.h" 19 #include "chrome/browser/profiles/incognito_helpers.h"
19 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" 21 #include "chrome/browser/search_engines/template_url_prepopulate_data.h"
21 #include "chrome/browser/ui/tabs/pinned_tab_codec.h" 22 #include "chrome/browser/ui/tabs/pinned_tab_codec.h"
22 #include "chrome/common/chrome_switches.h" 23 #include "chrome/common/chrome_switches.h"
23 #include "chrome/common/pref_names.h" 24 #include "chrome/common/pref_names.h"
24 #include "components/keyed_service/content/browser_context_dependency_manager.h" 25 #include "components/keyed_service/content/browser_context_dependency_manager.h"
25 #include "components/rappor/rappor_service.h"
26 #include "crypto/hmac.h" 26 #include "crypto/hmac.h"
27 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 27 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
28 28
29 namespace { 29 namespace {
30 30
31 const int kSessionStartupPrefValueMax = SessionStartupPref::kPrefValueMax; 31 const int kSessionStartupPrefValueMax = SessionStartupPref::kPrefValueMax;
32 32
33 } // namespace 33 } // namespace
34 34
35 PrefMetricsService::PrefMetricsService(Profile* profile) 35 PrefMetricsService::PrefMetricsService(Profile* profile)
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 // (pages that share a TLD+1 with a known engine but aren't actually search 73 // (pages that share a TLD+1 with a known engine but aren't actually search
74 // pages, e.g. plus.google.com). Additionally, record the TLD+1 of non-NTP 74 // pages, e.g. plus.google.com). Additionally, record the TLD+1 of non-NTP
75 // homepages through the privacy-preserving Rappor service. 75 // homepages through the privacy-preserving Rappor service.
76 if (!home_page_is_ntp) { 76 if (!home_page_is_ntp) {
77 GURL homepage_url(prefs_->GetString(prefs::kHomePage)); 77 GURL homepage_url(prefs_->GetString(prefs::kHomePage));
78 if (homepage_url.is_valid()) { 78 if (homepage_url.is_valid()) {
79 UMA_HISTOGRAM_ENUMERATION( 79 UMA_HISTOGRAM_ENUMERATION(
80 "Settings.HomePageEngineType", 80 "Settings.HomePageEngineType",
81 TemplateURLPrepopulateData::GetEngineType(homepage_url), 81 TemplateURLPrepopulateData::GetEngineType(homepage_url),
82 SEARCH_ENGINE_MAX); 82 SEARCH_ENGINE_MAX);
83 if (g_browser_process->rappor_service()) { 83 rappor::SampleDomainAndRegistryFromGURL("Settings.HomePage2",
84 g_browser_process->rappor_service()->RecordSample( 84 homepage_url);
85 "Settings.HomePage2",
86 rappor::ETLD_PLUS_ONE_RAPPOR_TYPE,
87 net::registry_controlled_domains::GetDomainAndRegistry(homepage_url,
88 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES));
89 }
90 } 85 }
91 } 86 }
92 87
93 int restore_on_startup = prefs_->GetInteger(prefs::kRestoreOnStartup); 88 int restore_on_startup = prefs_->GetInteger(prefs::kRestoreOnStartup);
94 UMA_HISTOGRAM_ENUMERATION("Settings.StartupPageLoadSettings", 89 UMA_HISTOGRAM_ENUMERATION("Settings.StartupPageLoadSettings",
95 restore_on_startup, kSessionStartupPrefValueMax); 90 restore_on_startup, kSessionStartupPrefValueMax);
96 if (restore_on_startup == SessionStartupPref::kPrefValueURLs) { 91 if (restore_on_startup == SessionStartupPref::kPrefValueURLs) {
97 const base::ListValue* url_list = 92 const base::ListValue* url_list =
98 prefs_->GetList(prefs::kURLsToRestoreOnStartup); 93 prefs_->GetList(prefs::kURLsToRestoreOnStartup);
99 UMA_HISTOGRAM_CUSTOM_COUNTS("Settings.StartupPageLoadURLs", 94 UMA_HISTOGRAM_CUSTOM_COUNTS("Settings.StartupPageLoadURLs",
100 url_list->GetSize(), 1, 50, 20); 95 url_list->GetSize(), 1, 50, 20);
101 // Similarly, check startup pages for known search engine TLD+1s. 96 // Similarly, check startup pages for known search engine TLD+1s.
102 std::string url_text; 97 std::string url_text;
103 for (size_t i = 0; i < url_list->GetSize(); ++i) { 98 for (size_t i = 0; i < url_list->GetSize(); ++i) {
104 if (url_list->GetString(i, &url_text)) { 99 if (url_list->GetString(i, &url_text)) {
105 GURL start_url(url_text); 100 GURL start_url(url_text);
106 if (start_url.is_valid()) { 101 if (start_url.is_valid()) {
107 UMA_HISTOGRAM_ENUMERATION( 102 UMA_HISTOGRAM_ENUMERATION(
108 "Settings.StartupPageEngineTypes", 103 "Settings.StartupPageEngineTypes",
109 TemplateURLPrepopulateData::GetEngineType(start_url), 104 TemplateURLPrepopulateData::GetEngineType(start_url),
110 SEARCH_ENGINE_MAX); 105 SEARCH_ENGINE_MAX);
106 if (i == 0) {
107 rappor::SampleDomainAndRegistryFromGURL("Settings.FirstStartupPage",
108 start_url);
109 }
111 } 110 }
112 } 111 }
113 } 112 }
114 } 113 }
115 114
116 #if !defined(OS_ANDROID) 115 #if !defined(OS_ANDROID)
117 StartupTabs startup_tabs = PinnedTabCodec::ReadPinnedTabs(profile_); 116 StartupTabs startup_tabs = PinnedTabCodec::ReadPinnedTabs(profile_);
118 UMA_HISTOGRAM_CUSTOM_COUNTS("Settings.PinnedTabs", 117 UMA_HISTOGRAM_CUSTOM_COUNTS("Settings.PinnedTabs",
119 startup_tabs.size(), 1, 50, 20); 118 startup_tabs.size(), 1, 50, 20);
120 for (size_t i = 0; i < startup_tabs.size(); ++i) { 119 for (size_t i = 0; i < startup_tabs.size(); ++i) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 const LogHistogramValueCallback& callback, 157 const LogHistogramValueCallback& callback,
159 const std::string& path, 158 const std::string& path,
160 bool from_sync) { 159 bool from_sync) {
161 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_); 160 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_);
162 const PrefService::Preference* pref = prefs->FindPreference(path.c_str()); 161 const PrefService::Preference* pref = prefs->FindPreference(path.c_str());
163 DCHECK(pref); 162 DCHECK(pref);
164 std::string source_name( 163 std::string source_name(
165 from_sync ? ".PulledFromSync" : ".PushedToSync"); 164 from_sync ? ".PulledFromSync" : ".PushedToSync");
166 std::string histogram_name("Settings." + histogram_name_prefix + source_name); 165 std::string histogram_name("Settings." + histogram_name_prefix + source_name);
167 callback.Run(histogram_name, pref->GetValue()); 166 callback.Run(histogram_name, pref->GetValue());
168 }; 167 }
169 168
170 void PrefMetricsService::LogBooleanPrefChange(const std::string& histogram_name, 169 void PrefMetricsService::LogBooleanPrefChange(const std::string& histogram_name,
171 const base::Value* value) { 170 const base::Value* value) {
172 bool boolean_value = false; 171 bool boolean_value = false;
173 if (!value->GetAsBoolean(&boolean_value)) 172 if (!value->GetAsBoolean(&boolean_value))
174 return; 173 return;
175 base::HistogramBase* histogram = base::BooleanHistogram::FactoryGet( 174 base::HistogramBase* histogram = base::BooleanHistogram::FactoryGet(
176 histogram_name, base::HistogramBase::kUmaTargetedHistogramFlag); 175 histogram_name, base::HistogramBase::kUmaTargetedHistogramFlag);
177 histogram->Add(boolean_value); 176 histogram->Add(boolean_value);
178 } 177 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 } 222 }
224 223
225 bool PrefMetricsService::Factory::ServiceIsNULLWhileTesting() const { 224 bool PrefMetricsService::Factory::ServiceIsNULLWhileTesting() const {
226 return false; 225 return false;
227 } 226 }
228 227
229 content::BrowserContext* PrefMetricsService::Factory::GetBrowserContextToUse( 228 content::BrowserContext* PrefMetricsService::Factory::GetBrowserContextToUse(
230 content::BrowserContext* context) const { 229 content::BrowserContext* context) const {
231 return chrome::GetBrowserContextRedirectedInIncognito(context); 230 return chrome::GetBrowserContextRedirectedInIncognito(context);
232 } 231 }
OLDNEW
« no previous file with comments | « chrome/browser/metrics/rappor/sampling_unittest.cc ('k') | chrome/browser/search_engines/template_url_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698