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