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") { ...@@ -4542,8 +4542,6 @@ jumbo_static_library("browser") {
sources += [ sources += [
"captive_portal/captive_portal_service_factory.cc", "captive_portal/captive_portal_service_factory.cc",
"captive_portal/captive_portal_service_factory.h", "captive_portal/captive_portal_service_factory.h",
"ssl/captive_portal_metrics_recorder.cc",
"ssl/captive_portal_metrics_recorder.h",
] ]
} }
......
...@@ -12,7 +12,9 @@ ...@@ -12,7 +12,9 @@
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) #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 #endif
ChromeMetricsHelper::ChromeMetricsHelper( ChromeMetricsHelper::ChromeMetricsHelper(
...@@ -35,8 +37,10 @@ ChromeMetricsHelper::~ChromeMetricsHelper() {} ...@@ -35,8 +37,10 @@ ChromeMetricsHelper::~ChromeMetricsHelper() {}
void ChromeMetricsHelper::StartRecordingCaptivePortalMetrics(bool overridable) { void ChromeMetricsHelper::StartRecordingCaptivePortalMetrics(bool overridable) {
#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
captive_portal_recorder_.reset( captive_portal_recorder_.reset(new CaptivePortalMetricsRecorder(
new CaptivePortalMetricsRecorder(web_contents_, overridable)); CaptivePortalServiceFactory::GetForProfile(
Profile::FromBrowserContext(web_contents_->GetBrowserContext())),
overridable));
#endif #endif
} }
......
...@@ -89,6 +89,10 @@ static_library("security_interstitial_page") { ...@@ -89,6 +89,10 @@ static_library("security_interstitial_page") {
] ]
if (enable_captive_portal_detection) { if (enable_captive_portal_detection) {
sources += [
"captive_portal_metrics_recorder.cc",
"captive_portal_metrics_recorder.h",
]
deps += [ "//components/captive_portal/content" ] deps += [ "//components/captive_portal/content" ]
} }
......
...@@ -2,15 +2,9 @@ ...@@ -2,15 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/ssl/captive_portal_metrics_recorder.h" #include "components/security_interstitials/content/captive_portal_metrics_recorder.h"
#include <vector>
#include "base/metrics/histogram_macros.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 { namespace {
...@@ -36,21 +30,16 @@ void RecordCaptivePortalEventStats(SSLInterstitialCauseCaptivePortal event) { ...@@ -36,21 +30,16 @@ void RecordCaptivePortalEventStats(SSLInterstitialCauseCaptivePortal event) {
} // namespace } // namespace
CaptivePortalMetricsRecorder::CaptivePortalMetricsRecorder( CaptivePortalMetricsRecorder::CaptivePortalMetricsRecorder(
content::WebContents* web_contents, captive_portal::CaptivePortalService* captive_portal_service,
bool overridable) bool overridable)
: overridable_(overridable), : overridable_(overridable),
captive_portal_detection_enabled_(false), captive_portal_detection_enabled_(false),
captive_portal_probe_completed_(false), captive_portal_probe_completed_(false),
captive_portal_no_response_(false), captive_portal_no_response_(false),
captive_portal_detected_(false) { captive_portal_detected_(false) {
Profile* profile = captive_portal_detection_enabled_ = captive_portal_service->enabled();
Profile::FromBrowserContext(web_contents->GetBrowserContext()); subscription_ = captive_portal_service->RegisterCallback(base::Bind(
captive_portal_detection_enabled_ = &CaptivePortalMetricsRecorder::Observe, base::Unretained(this)));
CaptivePortalServiceFactory::GetForProfile(profile)->enabled();
subscription_ =
CaptivePortalServiceFactory::GetForProfile(profile)->RegisterCallback(
base::Bind(&CaptivePortalMetricsRecorder::Observe,
base::Unretained(this)));
} }
CaptivePortalMetricsRecorder::~CaptivePortalMetricsRecorder() = default; CaptivePortalMetricsRecorder::~CaptivePortalMetricsRecorder() = default;
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_BROWSER_SSL_CAPTIVE_PORTAL_METRICS_RECORDER_H_ #ifndef COMPONENTS_SECURITY_INTERSTITIALS_CONTENT_CAPTIVE_PORTAL_METRICS_RECORDER_H_
#define CHROME_BROWSER_SSL_CAPTIVE_PORTAL_METRICS_RECORDER_H_ #define COMPONENTS_SECURITY_INTERSTITIALS_CONTENT_CAPTIVE_PORTAL_METRICS_RECORDER_H_
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -13,17 +13,14 @@ ...@@ -13,17 +13,14 @@
#include "net/cert/x509_certificate.h" #include "net/cert/x509_certificate.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace content {
class WebContents;
}
// This class helps the SSL interstitial record captive portal-specific // This class helps the SSL interstitial record captive portal-specific
// metrics. It should only be used on the UI thread because its implementation // metrics. It should only be used on the UI thread because its implementation
// uses captive_portal::CaptivePortalService which can only be // uses captive_portal::CaptivePortalService which can only be
// accessed on the UI thread. // accessed on the UI thread.
class CaptivePortalMetricsRecorder { class CaptivePortalMetricsRecorder {
public: public:
CaptivePortalMetricsRecorder(content::WebContents* web_contents, CaptivePortalMetricsRecorder(
captive_portal::CaptivePortalService* captive_portal_service,
bool overridable); bool overridable);
~CaptivePortalMetricsRecorder(); ~CaptivePortalMetricsRecorder();
...@@ -47,4 +44,4 @@ class CaptivePortalMetricsRecorder { ...@@ -47,4 +44,4 @@ class CaptivePortalMetricsRecorder {
subscription_; 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