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

[SSL] Clean ChromeMetricsHelper of //chrome deps

This CL changes
ChromeMetricsHelper::StartRecordingCaptivePortalMetrics() to take in the
CaptivePortalService instance rather than obtaining it internally from
the Profile and similarly changes ChromeMetricsHelper to take in the
HistoryService instance in its constructor. The motivation is to enable
this class to be componentized in a followup in order to make it
available to WebLayer.

Bug: 1030692
Change-Id: I6447dcc21e317d7ed4ba2b01b821575028066d4e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2040412
Commit-Queue: Colin Blundell <blundell@chromium.org>
Reviewed-by: default avatarCarlos IL <carlosil@chromium.org>
Cr-Commit-Position: refs/heads/master@{#739172}
parent 452bba14
......@@ -4,45 +4,32 @@
#include "chrome/browser/interstitials/chrome_metrics_helper.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "components/captive_portal/core/buildflags.h"
#include "components/history/core/browser/history_service.h"
#include "content/public/browser/web_contents.h"
#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
#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(
content::WebContents* web_contents,
history::HistoryService* history_service,
const GURL& request_url,
const security_interstitials::MetricsHelper::ReportDetails settings)
: security_interstitials::MetricsHelper(
request_url,
settings,
HistoryServiceFactory::GetForProfile(
Profile::FromBrowserContext(web_contents->GetBrowserContext()),
ServiceAccessType::EXPLICIT_ACCESS)),
#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
web_contents_(web_contents),
#endif
request_url_(request_url) {
}
: security_interstitials::MetricsHelper(request_url,
settings,
history_service) {}
ChromeMetricsHelper::~ChromeMetricsHelper() {}
ChromeMetricsHelper::~ChromeMetricsHelper() = default;
void ChromeMetricsHelper::StartRecordingCaptivePortalMetrics(bool overridable) {
#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
captive_portal_recorder_.reset(new CaptivePortalMetricsRecorder(
CaptivePortalServiceFactory::GetForProfile(
Profile::FromBrowserContext(web_contents_->GetBrowserContext())),
overridable));
#endif
void ChromeMetricsHelper::StartRecordingCaptivePortalMetrics(
captive_portal::CaptivePortalService* captive_portal_service,
bool overridable) {
captive_portal_recorder_.reset(
new CaptivePortalMetricsRecorder(captive_portal_service, overridable));
}
#endif
void ChromeMetricsHelper::RecordExtraShutdownMetrics() {
#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
......
......@@ -12,8 +12,12 @@
#include "components/security_interstitials/core/metrics_helper.h"
#include "url/gurl.h"
namespace content {
class WebContents;
namespace captive_portal {
class CaptivePortalService;
}
namespace history {
class HistoryService;
}
class CaptivePortalMetricsRecorder;
......@@ -26,22 +30,22 @@ class CaptivePortalMetricsRecorder;
class ChromeMetricsHelper : public security_interstitials::MetricsHelper {
public:
ChromeMetricsHelper(
content::WebContents* web_contents,
history::HistoryService* history_service,
const GURL& url,
const security_interstitials::MetricsHelper::ReportDetails settings);
~ChromeMetricsHelper() override;
void StartRecordingCaptivePortalMetrics(bool overridable);
#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
void StartRecordingCaptivePortalMetrics(
captive_portal::CaptivePortalService* captive_portal_service,
bool overridable);
#endif
protected:
// security_interstitials::MetricsHelper methods:
void RecordExtraShutdownMetrics() override;
private:
#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
content::WebContents* web_contents_;
#endif
const GURL request_url_;
#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
std::unique_ptr<CaptivePortalMetricsRecorder> captive_portal_recorder_;
#endif
......
......@@ -296,9 +296,11 @@ SafeBrowsingBlockingPage::CreateControllerClient(
DCHECK(profile);
std::unique_ptr<ChromeMetricsHelper> metrics_helper =
std::make_unique<ChromeMetricsHelper>(web_contents,
unsafe_resources[0].url,
GetReportingInfo(unsafe_resources));
std::make_unique<ChromeMetricsHelper>(
HistoryServiceFactory::GetForProfile(
Profile::FromBrowserContext(web_contents->GetBrowserContext()),
ServiceAccessType::EXPLICIT_ACCESS),
unsafe_resources[0].url, GetReportingInfo(unsafe_resources));
return std::make_unique<ChromeControllerClient>(
web_contents, std::move(metrics_helper), profile->GetPrefs(),
......
......@@ -8,6 +8,7 @@
#include "base/metrics/histogram_macros.h"
#include "base/time/time.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/interstitials/chrome_metrics_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/renderer_preferences_util.h"
......@@ -113,9 +114,17 @@ std::unique_ptr<ChromeMetricsHelper> CreateMetricsHelperWithRecording(
security_interstitials::MetricsHelper::ReportDetails reporting_info;
reporting_info.metric_prefix = metric_prefix;
std::unique_ptr<ChromeMetricsHelper> metrics_helper =
std::make_unique<ChromeMetricsHelper>(web_contents, request_url,
reporting_info);
metrics_helper.get()->StartRecordingCaptivePortalMetrics(overridable);
std::make_unique<ChromeMetricsHelper>(
HistoryServiceFactory::GetForProfile(
Profile::FromBrowserContext(web_contents->GetBrowserContext()),
ServiceAccessType::EXPLICIT_ACCESS),
request_url, reporting_info);
#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
metrics_helper.get()->StartRecordingCaptivePortalMetrics(
CaptivePortalServiceFactory::GetForProfile(
Profile::FromBrowserContext(web_contents->GetBrowserContext())),
overridable);
#endif
return metrics_helper;
}
......
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