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

Unified Diff: chrome/browser/interstitials/security_interstitial_uma_helper.cc

Issue 839183002: Remove redundancy in security interstitial UMA logic (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Answering mattm's questions 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_uma_helper.cc
diff --git a/chrome/browser/interstitials/security_interstitial_uma_helper.cc b/chrome/browser/interstitials/security_interstitial_uma_helper.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ebebe7f36fa9aea4df2c3c34af5dced1019916a5
--- /dev/null
+++ b/chrome/browser/interstitials/security_interstitial_uma_helper.cc
@@ -0,0 +1,140 @@
+// Copyright (c) 2014 The Chromium Authors. All rights reserved.
+// 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 "base/metrics/histogram.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 "content/public/browser/web_contents.h"
+
+#if defined(ENABLE_EXTENSIONS)
+#include "chrome/browser/extensions/api/experience_sampling_private/experience_sampling.h"
+#endif
+
+SecurityInterstitialUmaHelper::SecurityInterstitialUmaHelper(
+ content::WebContents* web_contents,
+ const GURL& request_url,
+ const std::string& histogram_prefix,
+ const std::string& sampling_event_name)
+ : web_contents_(web_contents),
+ request_url_(request_url),
+ histogram_prefix_(histogram_prefix),
+ sampling_event_name_(sampling_event_name),
+ num_visits_(-1) {
+ 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::Unretained(this)),
+ &request_tracker_);
+ }
+}
+
+SecurityInterstitialUmaHelper::~SecurityInterstitialUmaHelper() {
+}
+
+content::WebContents* SecurityInterstitialUmaHelper::web_contents() const {
+ return web_contents_;
+}
+
+GURL SecurityInterstitialUmaHelper::request_url() const {
+ return request_url_;
+}
+
+// Directly adds to the histograms, using the same properties as
+// UMA_HISTOGRAM_ENUMERATION, because the macro doesn't allow non-constant
+// histogram names.
+void SecurityInterstitialUmaHelper::RecordUserDecision(
+ SecurityInterstitialDecision decision) {
+ std::string decision_histogram_name(
+ "interstitial." + histogram_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);
+
+#if defined(ENABLE_EXTENSIONS)
+ if (!sampling_event_.get()) {
+ sampling_event_.reset(new extensions::ExperienceSamplingEvent(
+ sampling_event_name_,
+ request_url(),
+ web_contents()->GetLastCommittedURL(),
+ web_contents()->GetBrowserContext()));
+ }
+ switch (decision) {
+ case PROCEED:
+ sampling_event_->CreateUserDecisionEvent(
+ extensions::ExperienceSamplingEvent::kProceed);
+ break;
+ case DONT_PROCEED:
+ sampling_event_->CreateUserDecisionEvent(
+ extensions::ExperienceSamplingEvent::kDeny);
+ break;
+ case SHOW:
+ case PROCEEDING_DISABLED:
+ case MAX_DECISION:
+ break;
+ }
+#endif
+
+ // Record additional information about sites that users have
+ // visited before.
+ if (num_visits_ < 1 || (decision != PROCEED && decision != DONT_PROCEED))
+ return;
+ std::string history_histogram_name(
+ "interstitial." + histogram_prefix_ + ".decision.repeat_visit");
+ base::HistogramBase* history_histogram = base::LinearHistogram::FactoryGet(
+ history_histogram_name, 1, MAX_DECISION, MAX_DECISION + 1,
+ base::HistogramBase::kUmaTargetedHistogramFlag);
+ history_histogram->Add(SHOW);
+ history_histogram->Add(decision);
+}
+
+void SecurityInterstitialUmaHelper::RecordUserInteraction(
+ SecurityInterstitialInteraction interaction) {
+ std::string interaction_histogram_name(
+ "interstitial." + histogram_prefix_ + ".interaction");
+ base::HistogramBase* interaction_histogram =
+ base::LinearHistogram::FactoryGet(
+ interaction_histogram_name, 1, MAX_INTERACTION, MAX_INTERACTION + 1,
+ base::HistogramBase::kUmaTargetedHistogramFlag);
+ interaction_histogram->Add(interaction);
+
+#if defined(ENABLE_EXTENSIONS)
+ if (!sampling_event_.get()) {
+ sampling_event_.reset(new extensions::ExperienceSamplingEvent(
+ sampling_event_name_,
+ request_url(),
+ web_contents()->GetLastCommittedURL(),
+ web_contents()->GetBrowserContext()));
+ }
+ switch (interaction) {
+ case SHOW_LEARN_MORE:
+ sampling_event_->set_has_viewed_learn_more(true);
+ break;
+ case SHOW_ADVANCED:
+ sampling_event_->set_has_viewed_details(true);
+ break;
+ case SHOW_PRIVACY_POLICY:
+ case SHOW_DIAGNOSTIC:
+ case RELOAD:
+ case OPEN_TIME_SETTINGS:
+ case TOTAL_VISITS:
+ case MAX_INTERACTION:
+ break;
+ }
+#endif
+}
+
+void SecurityInterstitialUmaHelper::OnGotHistoryCount(
+ bool success, int num_visits, base::Time first_visit) {
Alexei Svitkine (slow) 2015/01/14 22:12:33 Nit: When params wrap in a decl, put one param on
palmer 2015/01/15 01:09:32 Or whatever "git cl format" does :)
felt 2015/01/15 06:47:22 Done.
+ if (success)
+ num_visits_ = num_visits;
+}

Powered by Google App Engine
This is Rietveld 408576698