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 @@ ...@@ -4,45 +4,32 @@
#include "chrome/browser/interstitials/chrome_metrics_helper.h" #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/captive_portal/core/buildflags.h"
#include "components/history/core/browser/history_service.h" #include "components/history/core/browser/history_service.h"
#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/captive_portal/captive_portal_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "components/security_interstitials/content/captive_portal_metrics_recorder.h" #include "components/security_interstitials/content/captive_portal_metrics_recorder.h"
#endif #endif
ChromeMetricsHelper::ChromeMetricsHelper( ChromeMetricsHelper::ChromeMetricsHelper(
content::WebContents* web_contents, history::HistoryService* history_service,
const GURL& request_url, const GURL& request_url,
const security_interstitials::MetricsHelper::ReportDetails settings) const security_interstitials::MetricsHelper::ReportDetails settings)
: security_interstitials::MetricsHelper( : security_interstitials::MetricsHelper(request_url,
request_url, settings,
settings, history_service) {}
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) {
}
ChromeMetricsHelper::~ChromeMetricsHelper() {} ChromeMetricsHelper::~ChromeMetricsHelper() = default;
void ChromeMetricsHelper::StartRecordingCaptivePortalMetrics(bool overridable) {
#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
captive_portal_recorder_.reset(new CaptivePortalMetricsRecorder( void ChromeMetricsHelper::StartRecordingCaptivePortalMetrics(
CaptivePortalServiceFactory::GetForProfile( captive_portal::CaptivePortalService* captive_portal_service,
Profile::FromBrowserContext(web_contents_->GetBrowserContext())), bool overridable) {
overridable)); captive_portal_recorder_.reset(
#endif new CaptivePortalMetricsRecorder(captive_portal_service, overridable));
} }
#endif
void ChromeMetricsHelper::RecordExtraShutdownMetrics() { void ChromeMetricsHelper::RecordExtraShutdownMetrics() {
#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
......
...@@ -12,8 +12,12 @@ ...@@ -12,8 +12,12 @@
#include "components/security_interstitials/core/metrics_helper.h" #include "components/security_interstitials/core/metrics_helper.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace content { namespace captive_portal {
class WebContents; class CaptivePortalService;
}
namespace history {
class HistoryService;
} }
class CaptivePortalMetricsRecorder; class CaptivePortalMetricsRecorder;
...@@ -26,22 +30,22 @@ class CaptivePortalMetricsRecorder; ...@@ -26,22 +30,22 @@ class CaptivePortalMetricsRecorder;
class ChromeMetricsHelper : public security_interstitials::MetricsHelper { class ChromeMetricsHelper : public security_interstitials::MetricsHelper {
public: public:
ChromeMetricsHelper( ChromeMetricsHelper(
content::WebContents* web_contents, history::HistoryService* history_service,
const GURL& url, const GURL& url,
const security_interstitials::MetricsHelper::ReportDetails settings); const security_interstitials::MetricsHelper::ReportDetails settings);
~ChromeMetricsHelper() override; ~ChromeMetricsHelper() override;
void StartRecordingCaptivePortalMetrics(bool overridable); #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
void StartRecordingCaptivePortalMetrics(
captive_portal::CaptivePortalService* captive_portal_service,
bool overridable);
#endif
protected: protected:
// security_interstitials::MetricsHelper methods: // security_interstitials::MetricsHelper methods:
void RecordExtraShutdownMetrics() override; void RecordExtraShutdownMetrics() override;
private: private:
#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
content::WebContents* web_contents_;
#endif
const GURL request_url_;
#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
std::unique_ptr<CaptivePortalMetricsRecorder> captive_portal_recorder_; std::unique_ptr<CaptivePortalMetricsRecorder> captive_portal_recorder_;
#endif #endif
......
...@@ -296,9 +296,11 @@ SafeBrowsingBlockingPage::CreateControllerClient( ...@@ -296,9 +296,11 @@ SafeBrowsingBlockingPage::CreateControllerClient(
DCHECK(profile); DCHECK(profile);
std::unique_ptr<ChromeMetricsHelper> metrics_helper = std::unique_ptr<ChromeMetricsHelper> metrics_helper =
std::make_unique<ChromeMetricsHelper>(web_contents, std::make_unique<ChromeMetricsHelper>(
unsafe_resources[0].url, HistoryServiceFactory::GetForProfile(
GetReportingInfo(unsafe_resources)); Profile::FromBrowserContext(web_contents->GetBrowserContext()),
ServiceAccessType::EXPLICIT_ACCESS),
unsafe_resources[0].url, GetReportingInfo(unsafe_resources));
return std::make_unique<ChromeControllerClient>( return std::make_unique<ChromeControllerClient>(
web_contents, std::move(metrics_helper), profile->GetPrefs(), web_contents, std::move(metrics_helper), profile->GetPrefs(),
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/browser_process.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/interstitials/chrome_metrics_helper.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/renderer_preferences_util.h" #include "chrome/browser/renderer_preferences_util.h"
...@@ -113,9 +114,17 @@ std::unique_ptr<ChromeMetricsHelper> CreateMetricsHelperWithRecording( ...@@ -113,9 +114,17 @@ std::unique_ptr<ChromeMetricsHelper> CreateMetricsHelperWithRecording(
security_interstitials::MetricsHelper::ReportDetails reporting_info; security_interstitials::MetricsHelper::ReportDetails reporting_info;
reporting_info.metric_prefix = metric_prefix; reporting_info.metric_prefix = metric_prefix;
std::unique_ptr<ChromeMetricsHelper> metrics_helper = std::unique_ptr<ChromeMetricsHelper> metrics_helper =
std::make_unique<ChromeMetricsHelper>(web_contents, request_url, std::make_unique<ChromeMetricsHelper>(
reporting_info); HistoryServiceFactory::GetForProfile(
metrics_helper.get()->StartRecordingCaptivePortalMetrics(overridable); 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; 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