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

Unified Diff: chrome/browser/interstitials/security_interstitial_metrics_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: Report on PROCEED/DONT_PROCEED, and make explicit Rappor switch 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/interstitials/security_interstitial_metrics_helper.cc
diff --git a/chrome/browser/interstitials/security_interstitial_uma_helper.cc b/chrome/browser/interstitials/security_interstitial_metrics_helper.cc
similarity index 64%
rename from chrome/browser/interstitials/security_interstitial_uma_helper.cc
rename to chrome/browser/interstitials/security_interstitial_metrics_helper.cc
index aade7ff796f99560eac7d2bc1e126bfab6720f75..322220e30564173ece0a56dff8ffd54dc6920cb7 100644
--- a/chrome/browser/interstitials/security_interstitial_uma_helper.cc
+++ b/chrome/browser/interstitials/security_interstitial_metrics_helper.cc
@@ -2,56 +2,88 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/interstitials/security_interstitial_uma_helper.h"
+#include "chrome/browser/interstitials/security_interstitial_metrics_helper.h"
+
+#include <string>
#include "base/metrics/histogram.h"
+#include "chrome/browser/browser_process.h"
#include "chrome/browser/history/history_service.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/webdata/web_data_service_factory.h"
+#include "components/rappor/rappor_service.h"
#include "content/public/browser/web_contents.h"
+#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#if defined(ENABLE_EXTENSIONS)
#include "chrome/browser/extensions/api/experience_sampling_private/experience_sampling.h"
#endif
-SecurityInterstitialUmaHelper::SecurityInterstitialUmaHelper(
+SecurityInterstitialMetricsHelper::SecurityInterstitialMetricsHelper(
content::WebContents* web_contents,
const GURL& request_url,
- const std::string& histogram_prefix,
+ const std::string& uma_prefix,
+ const std::string& rappor_prefix,
+ RapporReporting rappor_reporting,
const std::string& sampling_event_name)
: web_contents_(web_contents),
request_url_(request_url),
- histogram_prefix_(histogram_prefix),
+ uma_prefix_(uma_prefix),
+ rappor_prefix_(rappor_prefix),
+ rappor_reporting_(rappor_reporting),
sampling_event_name_(sampling_event_name),
num_visits_(-1) {
+ DCHECK(!uma_prefix_.empty());
+ DCHECK(!rappor_prefix_.empty());
+ DCHECK(!sampling_event_name_.empty());
HistoryService* history_service = HistoryServiceFactory::GetForProfile(
Profile::FromBrowserContext(web_contents->GetBrowserContext()),
ServiceAccessType::EXPLICIT_ACCESS);
if (history_service) {
history_service->GetVisibleVisitCountToHost(
request_url_,
- base::Bind(&SecurityInterstitialUmaHelper::OnGotHistoryCount,
+ base::Bind(&SecurityInterstitialMetricsHelper::OnGotHistoryCount,
base::Unretained(this)),
&request_tracker_);
}
}
-SecurityInterstitialUmaHelper::~SecurityInterstitialUmaHelper() {
+SecurityInterstitialMetricsHelper::~SecurityInterstitialMetricsHelper() {
}
-// Directly adds to the histograms, using the same properties as
+// Directly adds to the UMA histograms, using the same properties as
// UMA_HISTOGRAM_ENUMERATION, because the macro doesn't allow non-constant
-// histogram names.
-void SecurityInterstitialUmaHelper::RecordUserDecision(
+// histogram names. Reports to Rappor for certain decisions.
+void SecurityInterstitialMetricsHelper::RecordUserDecision(
SecurityInterstitialDecision decision) {
+ // UMA
std::string decision_histogram_name(
- "interstitial." + histogram_prefix_ + ".decision");
+ "interstitial." + uma_prefix_ + ".decision");
base::HistogramBase* decision_histogram = base::LinearHistogram::FactoryGet(
decision_histogram_name, 1, MAX_DECISION, MAX_DECISION + 1,
base::HistogramBase::kUmaTargetedHistogramFlag);
decision_histogram->Add(decision);
+ // Rappor
+ rappor::RapporService* rappor_service = g_browser_process->rappor_service();
+ if (rappor_service && rappor_reporting_ == REPORT_RAPPOR &&
+ (decision == PROCEED || decision == DONT_PROCEED)) {
+ // |domain| will be empty for hosts w/o TLDs (localhost, ip addrs)
+ const std::string domain =
+ net::registry_controlled_domains::GetDomainAndRegistry(
+ request_url_,
+ net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
+
+ // e.g. "interstitial.malware.domain" or "interstitial.ssl.domain"
+ const std::string metric_name =
+ "interstitial." + rappor_prefix_ + ".domain";
+ rappor_service->RecordSample(metric_name, rappor::COARSE_RAPPOR_TYPE,
+ domain);
+ // TODO(nparker): Add reporting of (num_visits > 0) and decision
+ // once http://crbug.com/451647 is fixed.
+ }
+
#if defined(ENABLE_EXTENSIONS)
if (!sampling_event_.get()) {
sampling_event_.reset(new extensions::ExperienceSamplingEvent(
@@ -81,7 +113,7 @@ void SecurityInterstitialUmaHelper::RecordUserDecision(
if (num_visits_ < 1 || (decision != PROCEED && decision != DONT_PROCEED))
return;
std::string history_histogram_name(
- "interstitial." + histogram_prefix_ + ".decision.repeat_visit");
+ "interstitial." + uma_prefix_ + ".decision.repeat_visit");
base::HistogramBase* history_histogram = base::LinearHistogram::FactoryGet(
history_histogram_name, 1, MAX_DECISION, MAX_DECISION + 1,
base::HistogramBase::kUmaTargetedHistogramFlag);
@@ -89,10 +121,10 @@ void SecurityInterstitialUmaHelper::RecordUserDecision(
history_histogram->Add(decision);
}
-void SecurityInterstitialUmaHelper::RecordUserInteraction(
+void SecurityInterstitialMetricsHelper::RecordUserInteraction(
SecurityInterstitialInteraction interaction) {
std::string interaction_histogram_name(
- "interstitial." + histogram_prefix_ + ".interaction");
+ "interstitial." + uma_prefix_ + ".interaction");
base::HistogramBase* interaction_histogram =
base::LinearHistogram::FactoryGet(
interaction_histogram_name, 1, MAX_INTERACTION, MAX_INTERACTION + 1,
@@ -125,7 +157,7 @@ void SecurityInterstitialUmaHelper::RecordUserInteraction(
#endif
}
-void SecurityInterstitialUmaHelper::OnGotHistoryCount(
+void SecurityInterstitialMetricsHelper::OnGotHistoryCount(
bool success,
int num_visits,
base::Time first_visit) {

Powered by Google App Engine
This is Rietveld 408576698