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

Side by Side Diff: chrome/browser/interstitials/security_interstitial_uma_helper.cc

Issue 872813003: Add Rappor metrics for Safe Browsing and SSL interstitials. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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 (c) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2014 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
5 #include "chrome/browser/interstitials/security_interstitial_uma_helper.h" 6 #include "chrome/browser/interstitials/security_interstitial_uma_helper.h"
6 7
8 #include <string>
9
7 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
11 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/history/history_service.h" 12 #include "chrome/browser/history/history_service.h"
9 #include "chrome/browser/history/history_service_factory.h" 13 #include "chrome/browser/history/history_service_factory.h"
10 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/webdata/web_data_service_factory.h" 15 #include "chrome/browser/webdata/web_data_service_factory.h"
16 #include "components/rappor/rappor_service.h"
12 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
18 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
13 19
14 #if defined(ENABLE_EXTENSIONS) 20 #if defined(ENABLE_EXTENSIONS)
15 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s ampling.h" 21 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s ampling.h"
16 #endif 22 #endif
17 23
18 SecurityInterstitialUmaHelper::SecurityInterstitialUmaHelper( 24 SecurityInterstitialUmaHelper::SecurityInterstitialUmaHelper(
19 content::WebContents* web_contents, 25 content::WebContents* web_contents,
20 const GURL& request_url, 26 const GURL& request_url,
21 const std::string& histogram_prefix, 27 const std::string& uma_prefix,
28 const std::string& rappor_prefix,
22 const std::string& sampling_event_name) 29 const std::string& sampling_event_name)
23 : web_contents_(web_contents), 30 : web_contents_(web_contents),
24 request_url_(request_url), 31 request_url_(request_url),
25 histogram_prefix_(histogram_prefix), 32 uma_prefix_(uma_prefix),
33 rappor_prefix_(rappor_prefix),
26 sampling_event_name_(sampling_event_name), 34 sampling_event_name_(sampling_event_name),
27 num_visits_(-1) { 35 num_visits_(-1) {
28 HistoryService* history_service = HistoryServiceFactory::GetForProfile( 36 HistoryService* history_service = HistoryServiceFactory::GetForProfile(
29 Profile::FromBrowserContext(web_contents->GetBrowserContext()), 37 Profile::FromBrowserContext(web_contents->GetBrowserContext()),
30 ServiceAccessType::EXPLICIT_ACCESS); 38 ServiceAccessType::EXPLICIT_ACCESS);
31 if (history_service) { 39 if (history_service) {
32 history_service->GetVisibleVisitCountToHost( 40 history_service->GetVisibleVisitCountToHost(
33 request_url_, 41 request_url_,
34 base::Bind(&SecurityInterstitialUmaHelper::OnGotHistoryCount, 42 base::Bind(&SecurityInterstitialUmaHelper::OnGotHistoryCount,
35 base::Unretained(this)), 43 base::Unretained(this)),
36 &request_tracker_); 44 &request_tracker_);
37 } 45 }
38 } 46 }
39 47
40 SecurityInterstitialUmaHelper::~SecurityInterstitialUmaHelper() { 48 SecurityInterstitialUmaHelper::~SecurityInterstitialUmaHelper() {
41 } 49 }
42 50
43 // Directly adds to the histograms, using the same properties as 51 // Directly adds to the UMA histograms, using the same properties as
44 // UMA_HISTOGRAM_ENUMERATION, because the macro doesn't allow non-constant 52 // UMA_HISTOGRAM_ENUMERATION, because the macro doesn't allow non-constant
45 // histogram names. 53 // histogram names. Reports to Rappor for certain decisions.
46 void SecurityInterstitialUmaHelper::RecordUserDecision( 54 void SecurityInterstitialUmaHelper::RecordUserDecision(
47 SecurityInterstitialDecision decision) { 55 SecurityInterstitialDecision decision) {
56 // UMA
48 std::string decision_histogram_name( 57 std::string decision_histogram_name(
49 "interstitial." + histogram_prefix_ + ".decision"); 58 "interstitial." + uma_prefix_ + ".decision");
50 base::HistogramBase* decision_histogram = base::LinearHistogram::FactoryGet( 59 base::HistogramBase* decision_histogram = base::LinearHistogram::FactoryGet(
51 decision_histogram_name, 1, MAX_DECISION, MAX_DECISION + 1, 60 decision_histogram_name, 1, MAX_DECISION, MAX_DECISION + 1,
52 base::HistogramBase::kUmaTargetedHistogramFlag); 61 base::HistogramBase::kUmaTargetedHistogramFlag);
53 decision_histogram->Add(decision); 62 decision_histogram->Add(decision);
54 63
64 // Rappor
65 rappor::RapporService* rappor_service = g_browser_process->rappor_service();
66 if (rappor_service && !rappor_prefix_.empty()) {
67 if (decision == SHOW) {
felt 2015/01/28 19:19:17 nit: can you make this a single if-statement until
Nathan Parker 2015/01/29 01:36:02 Done.
68 const std::string domain =
69 net::registry_controlled_domains::GetDomainAndRegistry(
70 request_url_,
71 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
72
73 // e.g. "Interstitial.Malware.Domain"
74 const std::string metric_name =
75 "Interstitial." + rappor_prefix_ + ".Domain";
felt 2015/01/28 19:19:17 Do we really need to have both uma_prefix and rapp
Nathan Parker 2015/01/29 01:36:02 Unfortunately they have different capitalization.
Steven Holte 2015/01/29 02:46:12 I would lean towards being consistent with the rel
Nathan Parker 2015/01/30 00:39:51 In that case I'll user lowercase for both. I'll u
76 rappor_service->RecordSample(metric_name, rappor::COARSE_RAPPOR_TYPE,
77 domain);
78 }
79 // TODO(nparker): Add Rappor reporting at PROCEED and DONT_PROCEED once
80 // crbug.com/451647 is fixed.
81 }
82
55 #if defined(ENABLE_EXTENSIONS) 83 #if defined(ENABLE_EXTENSIONS)
56 if (!sampling_event_.get()) { 84 if (!sampling_event_.get()) {
57 sampling_event_.reset(new extensions::ExperienceSamplingEvent( 85 sampling_event_.reset(new extensions::ExperienceSamplingEvent(
58 sampling_event_name_, 86 sampling_event_name_,
59 request_url_, 87 request_url_,
60 web_contents_->GetLastCommittedURL(), 88 web_contents_->GetLastCommittedURL(),
61 web_contents_->GetBrowserContext())); 89 web_contents_->GetBrowserContext()));
62 } 90 }
63 switch (decision) { 91 switch (decision) {
64 case PROCEED: 92 case PROCEED:
65 sampling_event_->CreateUserDecisionEvent( 93 sampling_event_->CreateUserDecisionEvent(
66 extensions::ExperienceSamplingEvent::kProceed); 94 extensions::ExperienceSamplingEvent::kProceed);
67 break; 95 break;
68 case DONT_PROCEED: 96 case DONT_PROCEED:
69 sampling_event_->CreateUserDecisionEvent( 97 sampling_event_->CreateUserDecisionEvent(
70 extensions::ExperienceSamplingEvent::kDeny); 98 extensions::ExperienceSamplingEvent::kDeny);
71 break; 99 break;
72 case SHOW: 100 case SHOW:
73 case PROCEEDING_DISABLED: 101 case PROCEEDING_DISABLED:
74 case MAX_DECISION: 102 case MAX_DECISION:
75 break; 103 break;
76 } 104 }
77 #endif 105 #endif
78 106
79 // Record additional information about sites that users have 107 // Record additional information about sites that users have
80 // visited before. 108 // visited before.
81 if (num_visits_ < 1 || (decision != PROCEED && decision != DONT_PROCEED)) 109 if (num_visits_ < 1 || (decision != PROCEED && decision != DONT_PROCEED))
82 return; 110 return;
83 std::string history_histogram_name( 111 std::string history_histogram_name(
84 "interstitial." + histogram_prefix_ + ".decision.repeat_visit"); 112 "interstitial." + uma_prefix_ + ".decision.repeat_visit");
85 base::HistogramBase* history_histogram = base::LinearHistogram::FactoryGet( 113 base::HistogramBase* history_histogram = base::LinearHistogram::FactoryGet(
86 history_histogram_name, 1, MAX_DECISION, MAX_DECISION + 1, 114 history_histogram_name, 1, MAX_DECISION, MAX_DECISION + 1,
87 base::HistogramBase::kUmaTargetedHistogramFlag); 115 base::HistogramBase::kUmaTargetedHistogramFlag);
88 history_histogram->Add(SHOW); 116 history_histogram->Add(SHOW);
89 history_histogram->Add(decision); 117 history_histogram->Add(decision);
90 } 118 }
91 119
92 void SecurityInterstitialUmaHelper::RecordUserInteraction( 120 void SecurityInterstitialUmaHelper::RecordUserInteraction(
93 SecurityInterstitialInteraction interaction) { 121 SecurityInterstitialInteraction interaction) {
94 std::string interaction_histogram_name( 122 std::string interaction_histogram_name(
95 "interstitial." + histogram_prefix_ + ".interaction"); 123 "interstitial." + uma_prefix_ + ".interaction");
96 base::HistogramBase* interaction_histogram = 124 base::HistogramBase* interaction_histogram =
97 base::LinearHistogram::FactoryGet( 125 base::LinearHistogram::FactoryGet(
98 interaction_histogram_name, 1, MAX_INTERACTION, MAX_INTERACTION + 1, 126 interaction_histogram_name, 1, MAX_INTERACTION, MAX_INTERACTION + 1,
99 base::HistogramBase::kUmaTargetedHistogramFlag); 127 base::HistogramBase::kUmaTargetedHistogramFlag);
100 interaction_histogram->Add(interaction); 128 interaction_histogram->Add(interaction);
101 129
102 #if defined(ENABLE_EXTENSIONS) 130 #if defined(ENABLE_EXTENSIONS)
103 if (!sampling_event_.get()) { 131 if (!sampling_event_.get()) {
104 sampling_event_.reset(new extensions::ExperienceSamplingEvent( 132 sampling_event_.reset(new extensions::ExperienceSamplingEvent(
105 sampling_event_name_, 133 sampling_event_name_,
(...skipping 19 matching lines...) Expand all
125 #endif 153 #endif
126 } 154 }
127 155
128 void SecurityInterstitialUmaHelper::OnGotHistoryCount( 156 void SecurityInterstitialUmaHelper::OnGotHistoryCount(
129 bool success, 157 bool success,
130 int num_visits, 158 int num_visits,
131 base::Time first_visit) { 159 base::Time first_visit) {
132 if (success) 160 if (success)
133 num_visits_ = num_visits; 161 num_visits_ = num_visits;
134 } 162 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698