Commit 10015671 authored by Colin Blundell's avatar Colin Blundell Committed by Commit Bot

[SSL] Componentize CaptivePortalMetricsRecorder

This class is a dependency of ChromeMetricsReporter, which we are going
to componentize for sharing with WebLayer.

Bug: 1030692
Change-Id: Ib233440b5768b2123c972d61537c2e6b75da0e6d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2039456Reviewed-by: default avatarCarlos IL <carlosil@chromium.org>
Commit-Queue: Colin Blundell <blundell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#739049}
parent e125c932
......@@ -4542,8 +4542,6 @@ jumbo_static_library("browser") {
sources += [
"captive_portal/captive_portal_service_factory.cc",
"captive_portal/captive_portal_service_factory.h",
"ssl/captive_portal_metrics_recorder.cc",
"ssl/captive_portal_metrics_recorder.h",
]
}
......
......@@ -12,7 +12,9 @@
#include "content/public/browser/web_contents.h"
#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
#include "chrome/browser/ssl/captive_portal_metrics_recorder.h"
#include "chrome/browser/captive_portal/captive_portal_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "components/security_interstitials/content/captive_portal_metrics_recorder.h"
#endif
ChromeMetricsHelper::ChromeMetricsHelper(
......@@ -35,8 +37,10 @@ ChromeMetricsHelper::~ChromeMetricsHelper() {}
void ChromeMetricsHelper::StartRecordingCaptivePortalMetrics(bool overridable) {
#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
captive_portal_recorder_.reset(
new CaptivePortalMetricsRecorder(web_contents_, overridable));
captive_portal_recorder_.reset(new CaptivePortalMetricsRecorder(
CaptivePortalServiceFactory::GetForProfile(
Profile::FromBrowserContext(web_contents_->GetBrowserContext())),
overridable));
#endif
}
......
......@@ -89,6 +89,10 @@ static_library("security_interstitial_page") {
]
if (enable_captive_portal_detection) {
sources += [
"captive_portal_metrics_recorder.cc",
"captive_portal_metrics_recorder.h",
]
deps += [ "//components/captive_portal/content" ]
}
......
......@@ -2,15 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ssl/captive_portal_metrics_recorder.h"
#include <vector>
#include "components/security_interstitials/content/captive_portal_metrics_recorder.h"
#include "base/metrics/histogram_macros.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/captive_portal/captive_portal_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "content/public/browser/web_contents.h"
namespace {
......@@ -36,21 +30,16 @@ void RecordCaptivePortalEventStats(SSLInterstitialCauseCaptivePortal event) {
} // namespace
CaptivePortalMetricsRecorder::CaptivePortalMetricsRecorder(
content::WebContents* web_contents,
captive_portal::CaptivePortalService* captive_portal_service,
bool overridable)
: overridable_(overridable),
captive_portal_detection_enabled_(false),
captive_portal_probe_completed_(false),
captive_portal_no_response_(false),
captive_portal_detected_(false) {
Profile* profile =
Profile::FromBrowserContext(web_contents->GetBrowserContext());
captive_portal_detection_enabled_ =
CaptivePortalServiceFactory::GetForProfile(profile)->enabled();
subscription_ =
CaptivePortalServiceFactory::GetForProfile(profile)->RegisterCallback(
base::Bind(&CaptivePortalMetricsRecorder::Observe,
base::Unretained(this)));
captive_portal_detection_enabled_ = captive_portal_service->enabled();
subscription_ = captive_portal_service->RegisterCallback(base::Bind(
&CaptivePortalMetricsRecorder::Observe, base::Unretained(this)));
}
CaptivePortalMetricsRecorder::~CaptivePortalMetricsRecorder() = default;
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_SSL_CAPTIVE_PORTAL_METRICS_RECORDER_H_
#define CHROME_BROWSER_SSL_CAPTIVE_PORTAL_METRICS_RECORDER_H_
#ifndef COMPONENTS_SECURITY_INTERSTITIALS_CONTENT_CAPTIVE_PORTAL_METRICS_RECORDER_H_
#define COMPONENTS_SECURITY_INTERSTITIALS_CONTENT_CAPTIVE_PORTAL_METRICS_RECORDER_H_
#include <string>
#include <vector>
......@@ -13,18 +13,15 @@
#include "net/cert/x509_certificate.h"
#include "url/gurl.h"
namespace content {
class WebContents;
}
// This class helps the SSL interstitial record captive portal-specific
// metrics. It should only be used on the UI thread because its implementation
// uses captive_portal::CaptivePortalService which can only be
// accessed on the UI thread.
class CaptivePortalMetricsRecorder {
public:
CaptivePortalMetricsRecorder(content::WebContents* web_contents,
bool overridable);
CaptivePortalMetricsRecorder(
captive_portal::CaptivePortalService* captive_portal_service,
bool overridable);
~CaptivePortalMetricsRecorder();
// Should be called when the interstitial is closing.
......@@ -47,4 +44,4 @@ class CaptivePortalMetricsRecorder {
subscription_;
};
#endif // CHROME_BROWSER_SSL_CAPTIVE_PORTAL_METRICS_RECORDER_H_
#endif // COMPONENTS_SECURITY_INTERSTITIALS_CONTENT_CAPTIVE_PORTAL_METRICS_RECORDER_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment