OLD | NEW |
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 #include "chrome/browser/interstitials/security_interstitial_uma_helper.h" | 5 #include "chrome/browser/interstitials/security_interstitial_metrics_helper.h" |
| 6 |
| 7 #include <string> |
6 | 8 |
7 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "chrome/browser/browser_process.h" |
8 #include "chrome/browser/history/history_service.h" | 11 #include "chrome/browser/history/history_service.h" |
9 #include "chrome/browser/history/history_service_factory.h" | 12 #include "chrome/browser/history/history_service_factory.h" |
10 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/webdata/web_data_service_factory.h" | 14 #include "chrome/browser/webdata/web_data_service_factory.h" |
| 15 #include "components/rappor/rappor_service.h" |
12 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 17 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
13 | 18 |
14 #if defined(ENABLE_EXTENSIONS) | 19 #if defined(ENABLE_EXTENSIONS) |
15 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s
ampling.h" | 20 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s
ampling.h" |
16 #endif | 21 #endif |
17 | 22 |
18 SecurityInterstitialUmaHelper::SecurityInterstitialUmaHelper( | 23 SecurityInterstitialMetricsHelper::SecurityInterstitialMetricsHelper( |
19 content::WebContents* web_contents, | 24 content::WebContents* web_contents, |
20 const GURL& request_url, | 25 const GURL& request_url, |
21 const std::string& histogram_prefix, | 26 const std::string& uma_prefix, |
| 27 const std::string& rappor_prefix, |
22 const std::string& sampling_event_name) | 28 const std::string& sampling_event_name) |
23 : web_contents_(web_contents), | 29 : web_contents_(web_contents), |
24 request_url_(request_url), | 30 request_url_(request_url), |
25 histogram_prefix_(histogram_prefix), | 31 uma_prefix_(uma_prefix), |
| 32 rappor_prefix_(rappor_prefix), |
26 sampling_event_name_(sampling_event_name), | 33 sampling_event_name_(sampling_event_name), |
27 num_visits_(-1) { | 34 num_visits_(-1) { |
28 HistoryService* history_service = HistoryServiceFactory::GetForProfile( | 35 HistoryService* history_service = HistoryServiceFactory::GetForProfile( |
29 Profile::FromBrowserContext(web_contents->GetBrowserContext()), | 36 Profile::FromBrowserContext(web_contents->GetBrowserContext()), |
30 ServiceAccessType::EXPLICIT_ACCESS); | 37 ServiceAccessType::EXPLICIT_ACCESS); |
31 if (history_service) { | 38 if (history_service) { |
32 history_service->GetVisibleVisitCountToHost( | 39 history_service->GetVisibleVisitCountToHost( |
33 request_url_, | 40 request_url_, |
34 base::Bind(&SecurityInterstitialUmaHelper::OnGotHistoryCount, | 41 base::Bind(&SecurityInterstitialMetricsHelper::OnGotHistoryCount, |
35 base::Unretained(this)), | 42 base::Unretained(this)), |
36 &request_tracker_); | 43 &request_tracker_); |
37 } | 44 } |
38 } | 45 } |
39 | 46 |
40 SecurityInterstitialUmaHelper::~SecurityInterstitialUmaHelper() { | 47 SecurityInterstitialMetricsHelper::~SecurityInterstitialMetricsHelper() { |
41 } | 48 } |
42 | 49 |
43 // Directly adds to the histograms, using the same properties as | 50 // Directly adds to the UMA histograms, using the same properties as |
44 // UMA_HISTOGRAM_ENUMERATION, because the macro doesn't allow non-constant | 51 // UMA_HISTOGRAM_ENUMERATION, because the macro doesn't allow non-constant |
45 // histogram names. | 52 // histogram names. Reports to Rappor for certain decisions. |
46 void SecurityInterstitialUmaHelper::RecordUserDecision( | 53 void SecurityInterstitialMetricsHelper::RecordUserDecision( |
47 SecurityInterstitialDecision decision) { | 54 SecurityInterstitialDecision decision) { |
| 55 // UMA |
48 std::string decision_histogram_name( | 56 std::string decision_histogram_name( |
49 "interstitial." + histogram_prefix_ + ".decision"); | 57 "interstitial." + uma_prefix_ + ".decision"); |
50 base::HistogramBase* decision_histogram = base::LinearHistogram::FactoryGet( | 58 base::HistogramBase* decision_histogram = base::LinearHistogram::FactoryGet( |
51 decision_histogram_name, 1, MAX_DECISION, MAX_DECISION + 1, | 59 decision_histogram_name, 1, MAX_DECISION, MAX_DECISION + 1, |
52 base::HistogramBase::kUmaTargetedHistogramFlag); | 60 base::HistogramBase::kUmaTargetedHistogramFlag); |
53 decision_histogram->Add(decision); | 61 decision_histogram->Add(decision); |
54 | 62 |
| 63 // Rappor |
| 64 rappor::RapporService* rappor_service = g_browser_process->rappor_service(); |
| 65 if (rappor_service && !rappor_prefix_.empty() && decision == SHOW) { |
| 66 // |domain| will be empty for hosts w/o TLDs (localhost, ip addrs) |
| 67 const std::string domain = |
| 68 net::registry_controlled_domains::GetDomainAndRegistry( |
| 69 request_url_, |
| 70 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); |
| 71 |
| 72 // e.g. "interstitial.malware.domain" or "interstitial.ssl.domain" |
| 73 const std::string metric_name = |
| 74 "interstitial." + rappor_prefix_ + ".domain"; |
| 75 rappor_service->RecordSample(metric_name, rappor::COARSE_RAPPOR_TYPE, |
| 76 domain); |
| 77 // TODO(nparker): Add Rappor reporting at PROCEED and DONT_PROCEED once |
| 78 // crbug.com/451647 is fixed. |
| 79 } |
| 80 |
55 #if defined(ENABLE_EXTENSIONS) | 81 #if defined(ENABLE_EXTENSIONS) |
56 if (!sampling_event_.get()) { | 82 if (!sampling_event_.get()) { |
57 sampling_event_.reset(new extensions::ExperienceSamplingEvent( | 83 sampling_event_.reset(new extensions::ExperienceSamplingEvent( |
58 sampling_event_name_, | 84 sampling_event_name_, |
59 request_url_, | 85 request_url_, |
60 web_contents_->GetLastCommittedURL(), | 86 web_contents_->GetLastCommittedURL(), |
61 web_contents_->GetBrowserContext())); | 87 web_contents_->GetBrowserContext())); |
62 } | 88 } |
63 switch (decision) { | 89 switch (decision) { |
64 case PROCEED: | 90 case PROCEED: |
65 sampling_event_->CreateUserDecisionEvent( | 91 sampling_event_->CreateUserDecisionEvent( |
66 extensions::ExperienceSamplingEvent::kProceed); | 92 extensions::ExperienceSamplingEvent::kProceed); |
67 break; | 93 break; |
68 case DONT_PROCEED: | 94 case DONT_PROCEED: |
69 sampling_event_->CreateUserDecisionEvent( | 95 sampling_event_->CreateUserDecisionEvent( |
70 extensions::ExperienceSamplingEvent::kDeny); | 96 extensions::ExperienceSamplingEvent::kDeny); |
71 break; | 97 break; |
72 case SHOW: | 98 case SHOW: |
73 case PROCEEDING_DISABLED: | 99 case PROCEEDING_DISABLED: |
74 case MAX_DECISION: | 100 case MAX_DECISION: |
75 break; | 101 break; |
76 } | 102 } |
77 #endif | 103 #endif |
78 | 104 |
79 // Record additional information about sites that users have | 105 // Record additional information about sites that users have |
80 // visited before. | 106 // visited before. |
81 if (num_visits_ < 1 || (decision != PROCEED && decision != DONT_PROCEED)) | 107 if (num_visits_ < 1 || (decision != PROCEED && decision != DONT_PROCEED)) |
82 return; | 108 return; |
83 std::string history_histogram_name( | 109 std::string history_histogram_name( |
84 "interstitial." + histogram_prefix_ + ".decision.repeat_visit"); | 110 "interstitial." + uma_prefix_ + ".decision.repeat_visit"); |
85 base::HistogramBase* history_histogram = base::LinearHistogram::FactoryGet( | 111 base::HistogramBase* history_histogram = base::LinearHistogram::FactoryGet( |
86 history_histogram_name, 1, MAX_DECISION, MAX_DECISION + 1, | 112 history_histogram_name, 1, MAX_DECISION, MAX_DECISION + 1, |
87 base::HistogramBase::kUmaTargetedHistogramFlag); | 113 base::HistogramBase::kUmaTargetedHistogramFlag); |
88 history_histogram->Add(SHOW); | 114 history_histogram->Add(SHOW); |
89 history_histogram->Add(decision); | 115 history_histogram->Add(decision); |
90 } | 116 } |
91 | 117 |
92 void SecurityInterstitialUmaHelper::RecordUserInteraction( | 118 void SecurityInterstitialMetricsHelper::RecordUserInteraction( |
93 SecurityInterstitialInteraction interaction) { | 119 SecurityInterstitialInteraction interaction) { |
94 std::string interaction_histogram_name( | 120 std::string interaction_histogram_name( |
95 "interstitial." + histogram_prefix_ + ".interaction"); | 121 "interstitial." + uma_prefix_ + ".interaction"); |
96 base::HistogramBase* interaction_histogram = | 122 base::HistogramBase* interaction_histogram = |
97 base::LinearHistogram::FactoryGet( | 123 base::LinearHistogram::FactoryGet( |
98 interaction_histogram_name, 1, MAX_INTERACTION, MAX_INTERACTION + 1, | 124 interaction_histogram_name, 1, MAX_INTERACTION, MAX_INTERACTION + 1, |
99 base::HistogramBase::kUmaTargetedHistogramFlag); | 125 base::HistogramBase::kUmaTargetedHistogramFlag); |
100 interaction_histogram->Add(interaction); | 126 interaction_histogram->Add(interaction); |
101 | 127 |
102 #if defined(ENABLE_EXTENSIONS) | 128 #if defined(ENABLE_EXTENSIONS) |
103 if (!sampling_event_.get()) { | 129 if (!sampling_event_.get()) { |
104 sampling_event_.reset(new extensions::ExperienceSamplingEvent( | 130 sampling_event_.reset(new extensions::ExperienceSamplingEvent( |
105 sampling_event_name_, | 131 sampling_event_name_, |
(...skipping 12 matching lines...) Expand all Loading... |
118 case SHOW_DIAGNOSTIC: | 144 case SHOW_DIAGNOSTIC: |
119 case RELOAD: | 145 case RELOAD: |
120 case OPEN_TIME_SETTINGS: | 146 case OPEN_TIME_SETTINGS: |
121 case TOTAL_VISITS: | 147 case TOTAL_VISITS: |
122 case MAX_INTERACTION: | 148 case MAX_INTERACTION: |
123 break; | 149 break; |
124 } | 150 } |
125 #endif | 151 #endif |
126 } | 152 } |
127 | 153 |
128 void SecurityInterstitialUmaHelper::OnGotHistoryCount( | 154 void SecurityInterstitialMetricsHelper::OnGotHistoryCount( |
129 bool success, | 155 bool success, |
130 int num_visits, | 156 int num_visits, |
131 base::Time first_visit) { | 157 base::Time first_visit) { |
132 if (success) | 158 if (success) |
133 num_visits_ = num_visits; | 159 num_visits_ = num_visits; |
134 } | 160 } |
OLD | NEW |