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

Unified Diff: components/safe_browsing/base_ping_manager.cc

Issue 2650973005: Componentize ping_manager (Closed)
Patch Set: rebase Created 3 years, 10 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: components/safe_browsing/base_ping_manager.cc
diff --git a/chrome/browser/safe_browsing/ping_manager.cc b/components/safe_browsing/base_ping_manager.cc
similarity index 78%
copy from chrome/browser/safe_browsing/ping_manager.cc
copy to components/safe_browsing/base_ping_manager.cc
index b223a15f2e44da561bb03974ddb00866de5dd54f..ed54971a028be7cff61ea957006193ee43231b1b 100644
--- a/chrome/browser/safe_browsing/ping_manager.cc
+++ b/components/safe_browsing/base_ping_manager.cc
@@ -1,8 +1,8 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright (c) 2017 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/safe_browsing/ping_manager.h"
+#include "components/safe_browsing/base_ping_manager.h"
#include <utility>
@@ -12,20 +12,16 @@
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/values.h"
-#include "chrome/browser/safe_browsing/notification_image_reporter.h"
-#include "chrome/browser/safe_browsing/permission_reporter.h"
#include "components/data_use_measurement/core/data_use_user_data.h"
#include "content/public/browser/browser_thread.h"
#include "google_apis/google_api_keys.h"
#include "net/base/escape.h"
#include "net/base/load_flags.h"
#include "net/log/net_log_source_type.h"
-#include "net/ssl/ssl_info.h"
#include "net/url_request/url_fetcher.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
#include "net/url_request/url_request_status.h"
-#include "third_party/skia/include/core/SkBitmap.h"
#include "url/gurl.h"
using content::BrowserThread;
@@ -67,15 +63,14 @@ namespace safe_browsing {
// SafeBrowsingPingManager implementation ----------------------------------
// static
-std::unique_ptr<SafeBrowsingPingManager> SafeBrowsingPingManager::Create(
+std::unique_ptr<BasePingManager> BasePingManager::Create(
net::URLRequestContextGetter* request_context_getter,
const SafeBrowsingProtocolConfig& config) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- return base::WrapUnique(
- new SafeBrowsingPingManager(request_context_getter, config));
+ return base::WrapUnique(new BasePingManager(request_context_getter, config));
}
-SafeBrowsingPingManager::SafeBrowsingPingManager(
+BasePingManager::BasePingManager(
net::URLRequestContextGetter* request_context_getter,
const SafeBrowsingProtocolConfig& config)
: client_name_(config.client_name),
@@ -84,27 +79,20 @@ SafeBrowsingPingManager::SafeBrowsingPingManager(
DCHECK(!url_prefix_.empty());
if (request_context_getter) {
- permission_reporter_ = base::MakeUnique<PermissionReporter>(
- request_context_getter->GetURLRequestContext());
- notification_image_reporter_ = base::MakeUnique<NotificationImageReporter>(
- request_context_getter->GetURLRequestContext());
-
net_log_ = net::NetLogWithSource::Make(
request_context_getter->GetURLRequestContext()->net_log(),
net::NetLogSourceType::SAFE_BROWSING);
}
- version_ = SafeBrowsingProtocolManagerHelper::Version();
+ version_ = ProtocolManagerHelper::Version();
}
-SafeBrowsingPingManager::~SafeBrowsingPingManager() {
-}
+BasePingManager::~BasePingManager() {}
// net::URLFetcherDelegate implementation ----------------------------------
// All SafeBrowsing request responses are handled here.
-void SafeBrowsingPingManager::OnURLFetchComplete(
- const net::URLFetcher* source) {
+void BasePingManager::OnURLFetchComplete(const net::URLFetcher* source) {
net_log_.EndEvent(
net::NetLogEventType::SAFE_BROWSING_PING,
base::Bind(&NetLogPingEndCallback, net_log_, source->GetStatus()));
@@ -118,12 +106,13 @@ void SafeBrowsingPingManager::OnURLFetchComplete(
}
// Sends a SafeBrowsing "hit" report.
-void SafeBrowsingPingManager::ReportSafeBrowsingHit(
+void BasePingManager::ReportSafeBrowsingHit(
const safe_browsing::HitReport& hit_report) {
GURL report_url = SafeBrowsingHitUrl(hit_report);
std::unique_ptr<net::URLFetcher> report_ptr = net::URLFetcher::Create(
- report_url, hit_report.post_data.empty() ? net::URLFetcher::GET
- : net::URLFetcher::POST,
+ report_url,
+ hit_report.post_data.empty() ? net::URLFetcher::GET
+ : net::URLFetcher::POST,
this);
net::URLFetcher* report = report_ptr.get();
data_use_measurement::DataUseUserData::AttachToFetcher(
@@ -146,7 +135,7 @@ void SafeBrowsingPingManager::ReportSafeBrowsingHit(
}
// Sends threat details for users who opt-in.
-void SafeBrowsingPingManager::ReportThreatDetails(const std::string& report) {
+void BasePingManager::ReportThreatDetails(const std::string& report) {
GURL report_url = ThreatDetailsUrl();
std::unique_ptr<net::URLFetcher> fetcher =
net::URLFetcher::Create(report_url, net::URLFetcher::POST, this);
@@ -160,30 +149,15 @@ void SafeBrowsingPingManager::ReportThreatDetails(const std::string& report) {
std::string report_base64;
base::Base64Encode(report, &report_base64);
- net_log_.BeginEvent(
- net::NetLogEventType::SAFE_BROWSING_PING,
- base::Bind(&NetLogPingStartCallback, net_log_, fetcher->GetOriginalURL(),
- report_base64));
+ net_log_.BeginEvent(net::NetLogEventType::SAFE_BROWSING_PING,
+ base::Bind(&NetLogPingStartCallback, net_log_,
+ fetcher->GetOriginalURL(), report_base64));
fetcher->Start();
safebrowsing_reports_.insert(std::move(fetcher));
}
-void SafeBrowsingPingManager::ReportPermissionAction(
- const PermissionReportInfo& report_info) {
- permission_reporter_->SendReport(report_info);
-}
-
-void SafeBrowsingPingManager::ReportNotificationImage(
- Profile* profile,
- const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager,
- const GURL& origin,
- const SkBitmap& image) {
- notification_image_reporter_->ReportNotificationImageOnIO(
- profile, database_manager, origin, image);
-}
-
-GURL SafeBrowsingPingManager::SafeBrowsingHitUrl(
+GURL BasePingManager::SafeBrowsingHitUrl(
const safe_browsing::HitReport& hit_report) const {
DCHECK(hit_report.threat_type == SB_THREAT_TYPE_URL_MALWARE ||
hit_report.threat_type == SB_THREAT_TYPE_URL_PHISHING ||
@@ -191,7 +165,7 @@ GURL SafeBrowsingPingManager::SafeBrowsingHitUrl(
hit_report.threat_type == SB_THREAT_TYPE_BINARY_MALWARE_URL ||
hit_report.threat_type == SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL ||
hit_report.threat_type == SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL);
- std::string url = SafeBrowsingProtocolManagerHelper::ComposeUrl(
+ std::string url = ProtocolManagerHelper::ComposeUrl(
url_prefix_, "report", client_name_, version_, std::string(),
hit_report.extended_reporting_level);
@@ -265,12 +239,10 @@ GURL SafeBrowsingPingManager::SafeBrowsingHitUrl(
hit_report.is_metrics_reporting_active, user_population_comp.c_str()));
}
-GURL SafeBrowsingPingManager::ThreatDetailsUrl() const {
+GURL BasePingManager::ThreatDetailsUrl() const {
std::string url = base::StringPrintf(
- "%s/clientreport/malware?client=%s&appver=%s&pver=1.0",
- url_prefix_.c_str(),
- client_name_.c_str(),
- version_.c_str());
+ "%s/clientreport/malware?client=%s&appver=%s&pver=1.0",
+ url_prefix_.c_str(), client_name_.c_str(), version_.c_str());
std::string api_key = google_apis::GetAPIKey();
if (!api_key.empty()) {
base::StringAppendF(&url, "&key=%s",
« no previous file with comments | « components/safe_browsing/base_ping_manager.h ('k') | components/safe_browsing/base_ping_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698