Commit d38b3842 authored by Varun Khaneja's avatar Varun Khaneja Committed by Commit Bot

Remove NotificationImageReporter since it the backend support is not planned

R=nparker

Bug: 837707,836359,831563
Change-Id: Ice5c619948e47a3df6a257fc062ab9d38928bbab
Reviewed-on: https://chromium-review.googlesource.com/1139032Reviewed-by: default avatarNate Fischer <ntfschr@chromium.org>
Reviewed-by: default avatarChristian Dullweber <dullweber@chromium.org>
Reviewed-by: default avatarVarun Khaneja <vakh@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Reviewed-by: default avatarNathan Parker <nparker@chromium.org>
Commit-Queue: Varun Khaneja <vakh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#576175}
parent 28ae7e13
...@@ -12,11 +12,11 @@ ...@@ -12,11 +12,11 @@
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/safe_browsing/base_ping_manager.h"
#include "components/safe_browsing/base_ui_manager.h" #include "components/safe_browsing/base_ui_manager.h"
#include "components/safe_browsing/browser/safe_browsing_network_context.h" #include "components/safe_browsing/browser/safe_browsing_network_context.h"
#include "components/safe_browsing/browser/safe_browsing_url_request_context_getter.h" #include "components/safe_browsing/browser/safe_browsing_url_request_context_getter.h"
#include "components/safe_browsing/common/safebrowsing_constants.h" #include "components/safe_browsing/common/safebrowsing_constants.h"
#include "components/safe_browsing/ping_manager.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "services/network/public/cpp/features.h" #include "services/network/public/cpp/features.h"
#include "services/network/public/mojom/network_service.mojom.h" #include "services/network/public/mojom/network_service.mojom.h"
...@@ -139,7 +139,7 @@ void AwSafeBrowsingUIManager::SendSerializedThreatDetails( ...@@ -139,7 +139,7 @@ void AwSafeBrowsingUIManager::SendSerializedThreatDetails(
::safe_browsing::kSbBackupHttpErrorURLPrefix; ::safe_browsing::kSbBackupHttpErrorURLPrefix;
config.backup_network_error_url_prefix = config.backup_network_error_url_prefix =
::safe_browsing::kSbBackupNetworkErrorURLPrefix; ::safe_browsing::kSbBackupNetworkErrorURLPrefix;
ping_manager_ = ::safe_browsing::BasePingManager::Create( ping_manager_ = ::safe_browsing::PingManager::Create(
network_context_->GetURLLoaderFactory(), config); network_context_->GetURLLoaderFactory(), config);
} }
......
...@@ -20,7 +20,7 @@ class SharedURLLoaderFactory; ...@@ -20,7 +20,7 @@ class SharedURLLoaderFactory;
} }
namespace safe_browsing { namespace safe_browsing {
class BasePingManager; class PingManager;
class SafeBrowsingNetworkContext; class SafeBrowsingNetworkContext;
class SafeBrowsingURLRequestContextGetter; class SafeBrowsingURLRequestContextGetter;
} // namespace } // namespace
...@@ -75,7 +75,7 @@ class AwSafeBrowsingUIManager : public safe_browsing::BaseUIManager { ...@@ -75,7 +75,7 @@ class AwSafeBrowsingUIManager : public safe_browsing::BaseUIManager {
network::mojom::URLLoaderFactoryRequest request); network::mojom::URLLoaderFactoryRequest request);
// Provides phishing and malware statistics. Accessed on IO thread. // Provides phishing and malware statistics. Accessed on IO thread.
std::unique_ptr<safe_browsing::BasePingManager> ping_manager_; std::unique_ptr<safe_browsing::PingManager> ping_manager_;
// The SafeBrowsingURLRequestContextGetter used to access // The SafeBrowsingURLRequestContextGetter used to access
// |url_request_context_|. Accessed on UI thread. // |url_request_context_|. Accessed on UI thread.
......
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_attributes_storage.h" #include "chrome/browser/profiles/profile_attributes_storage.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/safe_browsing/ping_manager.h"
#include "chrome/browser/safe_browsing/safe_browsing_service.h" #include "chrome/browser/safe_browsing/safe_browsing_service.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/browser_list.h"
...@@ -411,16 +410,6 @@ PlatformNotificationServiceImpl::CreateNotificationFromData( ...@@ -411,16 +410,6 @@ PlatformNotificationServiceImpl::CreateNotificationFromData(
notification.set_type(message_center::NOTIFICATION_TYPE_IMAGE); notification.set_type(message_center::NOTIFICATION_TYPE_IMAGE);
notification.set_image( notification.set_image(
gfx::Image::CreateFrom1xBitmap(notification_resources.image)); gfx::Image::CreateFrom1xBitmap(notification_resources.image));
// n.b. this should only be posted once per notification.
if (g_browser_process->safe_browsing_service() &&
g_browser_process->safe_browsing_service()->enabled_by_prefs()) {
g_browser_process->safe_browsing_service()
->ping_manager()
->ReportNotificationImage(
profile,
g_browser_process->safe_browsing_service()->database_manager(),
origin, notification_resources.image);
}
} }
// Badges are only supported on Android, primarily because it's the only // Badges are only supported on Android, primarily because it's the only
......
...@@ -93,10 +93,6 @@ static_library("safe_browsing") { ...@@ -93,10 +93,6 @@ static_library("safe_browsing") {
"certificate_reporting_service.h", "certificate_reporting_service.h",
"certificate_reporting_service_factory.cc", "certificate_reporting_service_factory.cc",
"certificate_reporting_service_factory.h", "certificate_reporting_service_factory.h",
"notification_image_reporter.cc",
"notification_image_reporter.h",
"ping_manager.cc",
"ping_manager.h",
"safe_browsing_blocking_page.cc", "safe_browsing_blocking_page.cc",
"safe_browsing_blocking_page.h", "safe_browsing_blocking_page.h",
"safe_browsing_navigation_observer.cc", "safe_browsing_navigation_observer.cc",
......
// Copyright 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.
#ifndef CHROME_BROWSER_SAFE_BROWSING_NOTIFICATION_IMAGE_REPORTER_H_
#define CHROME_BROWSER_SAFE_BROWSING_NOTIFICATION_IMAGE_REPORTER_H_
#include <memory>
#include "base/containers/queue.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
class GURL;
class Profile;
class SkBitmap;
namespace base {
class RefCountedMemory;
} // namespace base
namespace gfx {
class Size;
} // namespace gfx
namespace network {
class SharedURLLoaderFactory;
} // namespace network
namespace safe_browsing {
class SafeBrowsingDatabaseManager;
// Provides functionality for building and sending reports about notification
// content images to the Safe Browsing CSD server. This class and its member
// methods live on the UI thread.
class NotificationImageReporter {
public:
// CSD server URL to which notification image reports are sent.
static const char kReportingUploadUrl[];
explicit NotificationImageReporter(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory);
virtual ~NotificationImageReporter();
// Report notification content image to SafeBrowsing CSD server if the user
// has opted in, the origin is not whitelisted, and it is randomly sampled.
// Can only be called on UI thread.
void ReportNotificationImage(
Profile* profile,
const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager,
const GURL& origin,
const SkBitmap& image);
protected:
// Get the percentage of images that should be reported from Finch.
virtual double GetReportChance() const;
// Tests may wish to override this to find out if reports are skipped.
virtual void SkippedReporting();
// Send the given report. Virtual to allow tests to override it.
virtual void SendReportInternal(const GURL& url,
const std::string& content_type,
const std::string& report);
private:
// Downscales image to fit within 512x512 if necessary, and encodes as it PNG,
// then invokes SendReport. This should be called on a blocking pool
// thread and will invoke a member function on the UI thread using the
// weakptr.
static void DownscaleNotificationImageOnBlockingPool(
const base::WeakPtr<NotificationImageReporter>& weak_ptr,
const GURL& origin,
const SkBitmap& image);
// Serializes report using NotificationImageReportRequest protobuf defined in
// chrome/common/safe_browsing/csd.proto and sends it to CSD server.
void SendReport(const GURL& origin,
scoped_refptr<base::RefCountedMemory> data,
const gfx::Size& dimensions,
const gfx::Size& original_dimensions);
// Called when the asynchronous CSD whitelist check completes.
void OnWhitelistCheckDone(Profile* profile,
const GURL& origin,
const SkBitmap& image,
bool match_whitelist);
static void OnWhitelistCheckDoneOnIO(
base::WeakPtr<NotificationImageReporter> weak_ptr,
Profile* profile,
const GURL& origin,
const SkBitmap& image,
bool match_whitelist);
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
// Timestamps of when we sent notification images. Used to limit the number
// of requests that we send in a day. Only access on the IO thread.
// TODO(johnme): Serialize this so that it doesn't reset on browser restart.
base::queue<base::Time> report_times_;
base::WeakPtrFactory<NotificationImageReporter> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(NotificationImageReporter);
};
} // namespace safe_browsing
#endif // CHROME_BROWSER_SAFE_BROWSING_NOTIFICATION_IMAGE_REPORTER_H_
// Copyright (c) 2012 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 <memory>
#include "base/memory/ptr_util.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/safe_browsing/notification_image_reporter.h"
#include "components/net_log/chrome_net_log.h"
#include "content/public/browser/browser_thread.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "third_party/skia/include/core/SkBitmap.h"
using content::BrowserThread;
namespace safe_browsing {
// SafeBrowsingPingManager implementation ----------------------------------
// static
std::unique_ptr<SafeBrowsingPingManager> SafeBrowsingPingManager::Create(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const SafeBrowsingProtocolConfig& config) {
return base::WrapUnique(
new SafeBrowsingPingManager(url_loader_factory, config));
}
SafeBrowsingPingManager::SafeBrowsingPingManager(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const SafeBrowsingProtocolConfig& config)
: BasePingManager(url_loader_factory, config) {
if (url_loader_factory) {
notification_image_reporter_ =
std::make_unique<NotificationImageReporter>(url_loader_factory);
}
}
SafeBrowsingPingManager::~SafeBrowsingPingManager() {}
void SafeBrowsingPingManager::ReportNotificationImage(
Profile* profile,
const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager,
const GURL& origin,
const SkBitmap& image) {
notification_image_reporter_->ReportNotificationImage(
profile, database_manager, origin, image);
}
} // namespace safe_browsing
// Copyright (c) 2012 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.
#ifndef CHROME_BROWSER_SAFE_BROWSING_PING_MANAGER_H_
#define CHROME_BROWSER_SAFE_BROWSING_PING_MANAGER_H_
#include "components/safe_browsing/base_ping_manager.h"
class Profile;
class SkBitmap;
namespace network {
class SharedURLLoaderFactory;
} // namespace network
namespace safe_browsing {
class NotificationImageReporter;
class SafeBrowsingDatabaseManager;
class SafeBrowsingPingManager : public BasePingManager {
public:
~SafeBrowsingPingManager() override;
// Create an instance of the safe browsing ping manager.
static std::unique_ptr<SafeBrowsingPingManager> Create(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const SafeBrowsingProtocolConfig& config);
// Report notification content image to SafeBrowsing CSD server if necessary.
void ReportNotificationImage(
Profile* profile,
const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager,
const GURL& origin,
const SkBitmap& image);
private:
friend class NotificationImageReporterTest;
FRIEND_TEST_ALL_PREFIXES(SafeBrowsingPingManagerCertReportingTest,
UMAOnFailure);
// Constructs a SafeBrowsingPingManager that issues network requests
// using |url_loader_factory|.
SafeBrowsingPingManager(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const SafeBrowsingProtocolConfig& config);
// Sends reports of notification content images.
std::unique_ptr<NotificationImageReporter> notification_image_reporter_;
DISALLOW_COPY_AND_ASSIGN(SafeBrowsingPingManager);
};
} // namespace safe_browsing
#endif // CHROME_BROWSER_SAFE_BROWSING_PING_MANAGER_H_
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
#include "chrome/browser/net/default_network_context_params.h" #include "chrome/browser/net/default_network_context_params.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/safe_browsing/ping_manager.h"
#include "chrome/browser/safe_browsing/safe_browsing_navigation_observer_manager.h" #include "chrome/browser/safe_browsing/safe_browsing_navigation_observer_manager.h"
#include "chrome/browser/safe_browsing/ui_manager.h" #include "chrome/browser/safe_browsing/ui_manager.h"
#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_paths.h"
...@@ -43,6 +42,7 @@ ...@@ -43,6 +42,7 @@
#include "components/safe_browsing/db/v4_feature_list.h" #include "components/safe_browsing/db/v4_feature_list.h"
#include "components/safe_browsing/db/v4_get_hash_protocol_manager.h" #include "components/safe_browsing/db/v4_get_hash_protocol_manager.h"
#include "components/safe_browsing/db/v4_local_database_manager.h" #include "components/safe_browsing/db/v4_local_database_manager.h"
#include "components/safe_browsing/ping_manager.h"
#include "components/safe_browsing/triggers/trigger_manager.h" #include "components/safe_browsing/triggers/trigger_manager.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
...@@ -304,7 +304,7 @@ SafeBrowsingProtocolManager* SafeBrowsingService::protocol_manager() const { ...@@ -304,7 +304,7 @@ SafeBrowsingProtocolManager* SafeBrowsingService::protocol_manager() const {
#endif #endif
} }
SafeBrowsingPingManager* SafeBrowsingService::ping_manager() const { PingManager* SafeBrowsingService::ping_manager() const {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
return ping_manager_.get(); return ping_manager_.get();
} }
...@@ -501,8 +501,8 @@ void SafeBrowsingService::Start() { ...@@ -501,8 +501,8 @@ void SafeBrowsingService::Start() {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (!ping_manager_) { if (!ping_manager_) {
ping_manager_ = SafeBrowsingPingManager::Create(GetURLLoaderFactory(), ping_manager_ =
GetProtocolConfig()); PingManager::Create(GetURLLoaderFactory(), GetProtocolConfig());
} }
BrowserThread::PostTask( BrowserThread::PostTask(
......
...@@ -60,6 +60,7 @@ class TrackedPreferenceValidationDelegate; ...@@ -60,6 +60,7 @@ class TrackedPreferenceValidationDelegate;
} // namespace prefs } // namespace prefs
namespace safe_browsing { namespace safe_browsing {
class PingManager;
class ClientSideDetectionService; class ClientSideDetectionService;
class DownloadProtectionService; class DownloadProtectionService;
class PasswordProtectionService; class PasswordProtectionService;
...@@ -68,7 +69,6 @@ struct SafeBrowsingProtocolConfig; ...@@ -68,7 +69,6 @@ struct SafeBrowsingProtocolConfig;
class SafeBrowsingDatabaseManager; class SafeBrowsingDatabaseManager;
class SafeBrowsingNavigationObserverManager; class SafeBrowsingNavigationObserverManager;
class SafeBrowsingNetworkContext; class SafeBrowsingNetworkContext;
class SafeBrowsingPingManager;
class SafeBrowsingProtocolManager; class SafeBrowsingProtocolManager;
class SafeBrowsingProtocolManagerDelegate; class SafeBrowsingProtocolManagerDelegate;
class SafeBrowsingServiceFactory; class SafeBrowsingServiceFactory;
...@@ -176,7 +176,7 @@ class SafeBrowsingService : public base::RefCountedThreadSafe< ...@@ -176,7 +176,7 @@ class SafeBrowsingService : public base::RefCountedThreadSafe<
SafeBrowsingProtocolManager* protocol_manager() const; SafeBrowsingProtocolManager* protocol_manager() const;
// Called on UI thread. // Called on UI thread.
SafeBrowsingPingManager* ping_manager() const; PingManager* ping_manager() const;
// This may be NULL if v4 is not enabled by experiment. // This may be NULL if v4 is not enabled by experiment.
const scoped_refptr<SafeBrowsingDatabaseManager>& v4_local_database_manager() const scoped_refptr<SafeBrowsingDatabaseManager>& v4_local_database_manager()
...@@ -332,7 +332,7 @@ class SafeBrowsingService : public base::RefCountedThreadSafe< ...@@ -332,7 +332,7 @@ class SafeBrowsingService : public base::RefCountedThreadSafe<
#endif #endif
// Provides phishing and malware statistics. Accessed on UI thread. // Provides phishing and malware statistics. Accessed on UI thread.
std::unique_ptr<SafeBrowsingPingManager> ping_manager_; std::unique_ptr<PingManager> ping_manager_;
// Whether SafeBrowsing Extended Reporting is enabled by the current set of // Whether SafeBrowsing Extended Reporting is enabled by the current set of
// profiles. Updated on the UI thread. // profiles. Updated on the UI thread.
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "chrome/browser/safe_browsing/download_protection/download_protection_service.h" #include "chrome/browser/safe_browsing/download_protection/download_protection_service.h"
#include "chrome/browser/safe_browsing/ping_manager.h"
#include "chrome/browser/safe_browsing/ui_manager.h" #include "chrome/browser/safe_browsing/ui_manager.h"
#include "components/safe_browsing/db/database_manager.h" #include "components/safe_browsing/db/database_manager.h"
#include "components/safe_browsing/db/test_database_manager.h" #include "components/safe_browsing/db/test_database_manager.h"
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include "chrome/browser/interstitials/enterprise_util.h" #include "chrome/browser/interstitials/enterprise_util.h"
#include "chrome/browser/metrics/chrome_metrics_service_accessor.h" #include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/safe_browsing/ping_manager.h"
#include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h"
#include "chrome/browser/safe_browsing/safe_browsing_service.h" #include "chrome/browser/safe_browsing/safe_browsing_service.h"
#include "chrome/browser/tab_contents/tab_util.h" #include "chrome/browser/tab_contents/tab_util.h"
...@@ -24,6 +23,7 @@ ...@@ -24,6 +23,7 @@
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/safe_browsing/browser/threat_details.h" #include "components/safe_browsing/browser/threat_details.h"
#include "components/safe_browsing/common/safe_browsing_prefs.h" #include "components/safe_browsing/common/safe_browsing_prefs.h"
#include "components/safe_browsing/ping_manager.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/navigation_entry.h" #include "content/public/browser/navigation_entry.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
......
...@@ -3857,7 +3857,6 @@ test("unit_tests") { ...@@ -3857,7 +3857,6 @@ test("unit_tests") {
"../browser/safe_browsing/local_database_manager_unittest.cc", "../browser/safe_browsing/local_database_manager_unittest.cc",
"../browser/safe_browsing/local_two_phase_testserver.cc", "../browser/safe_browsing/local_two_phase_testserver.cc",
"../browser/safe_browsing/local_two_phase_testserver.h", "../browser/safe_browsing/local_two_phase_testserver.h",
"../browser/safe_browsing/notification_image_reporter_unittest.cc",
"../browser/safe_browsing/protocol_manager_unittest.cc", "../browser/safe_browsing/protocol_manager_unittest.cc",
"../browser/safe_browsing/protocol_parser_unittest.cc", "../browser/safe_browsing/protocol_parser_unittest.cc",
"../browser/safe_browsing/safe_browsing_database_unittest.cc", "../browser/safe_browsing/safe_browsing_database_unittest.cc",
...@@ -3888,7 +3887,7 @@ test("unit_tests") { ...@@ -3888,7 +3887,7 @@ test("unit_tests") {
deps += [ deps += [
":test_proto", ":test_proto",
"//chrome/services/file_util/public/cpp:unit_tests", "//chrome/services/file_util/public/cpp:unit_tests",
"//components/safe_browsing:base_ping_manager_unittest", "//components/safe_browsing:ping_manager_unittest",
"//components/safe_browsing/browser:unittests", "//components/safe_browsing/browser:unittests",
"//components/safe_browsing/db:v4_test_util", "//components/safe_browsing/db:v4_test_util",
"//components/safe_browsing/renderer:websocket_sb_handshake_throttle_unittest", "//components/safe_browsing/renderer:websocket_sb_handshake_throttle_unittest",
......
...@@ -27,8 +27,8 @@ source_set("safe_browsing") { ...@@ -27,8 +27,8 @@ source_set("safe_browsing") {
"//components/security_interstitials/content:security_interstitial_page", "//components/security_interstitials/content:security_interstitial_page",
] ]
deps = [ deps = [
":base_ping_manager",
":features", ":features",
":ping_manager",
"//base:base", "//base:base",
"//base:i18n", "//base:i18n",
"//components/safe_browsing/common:common", "//components/safe_browsing/common:common",
...@@ -42,10 +42,10 @@ source_set("safe_browsing") { ...@@ -42,10 +42,10 @@ source_set("safe_browsing") {
] ]
} }
static_library("base_ping_manager") { static_library("ping_manager") {
sources = [ sources = [
"base_ping_manager.cc", "ping_manager.cc",
"base_ping_manager.h", "ping_manager.h",
] ]
public_deps = [ public_deps = [
...@@ -62,14 +62,14 @@ static_library("base_ping_manager") { ...@@ -62,14 +62,14 @@ static_library("base_ping_manager") {
] ]
} }
source_set("base_ping_manager_unittest") { source_set("ping_manager_unittest") {
testonly = true testonly = true
sources = [ sources = [
"base_ping_manager_unittest.cc", "ping_manager_unittest.cc",
] ]
deps = [ deps = [
":base_ping_manager", ":ping_manager",
"//base:base", "//base:base",
"//net:net", "//net:net",
"//net:test_support", "//net:test_support",
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// 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 "components/safe_browsing/base_ping_manager.h" #include "components/safe_browsing/ping_manager.h"
#include <utility> #include <utility>
...@@ -71,14 +71,13 @@ namespace safe_browsing { ...@@ -71,14 +71,13 @@ namespace safe_browsing {
// SafeBrowsingPingManager implementation ---------------------------------- // SafeBrowsingPingManager implementation ----------------------------------
// static // static
std::unique_ptr<BasePingManager> BasePingManager::Create( std::unique_ptr<PingManager> PingManager::Create(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory, scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const SafeBrowsingProtocolConfig& config) { const SafeBrowsingProtocolConfig& config) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); return base::WrapUnique(new PingManager(url_loader_factory, config));
return base::WrapUnique(new BasePingManager(url_loader_factory, config));
} }
BasePingManager::BasePingManager( PingManager::PingManager(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory, scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const SafeBrowsingProtocolConfig& config) const SafeBrowsingProtocolConfig& config)
: client_name_(config.client_name), : client_name_(config.client_name),
...@@ -89,12 +88,12 @@ BasePingManager::BasePingManager( ...@@ -89,12 +88,12 @@ BasePingManager::BasePingManager(
version_ = ProtocolManagerHelper::Version(); version_ = ProtocolManagerHelper::Version();
} }
BasePingManager::~BasePingManager() {} PingManager::~PingManager() {}
// net::URLFetcherDelegate implementation ---------------------------------- // net::URLFetcherDelegate implementation ----------------------------------
// All SafeBrowsing request responses are handled here. // All SafeBrowsing request responses are handled here.
void BasePingManager::OnURLLoaderComplete( void PingManager::OnURLLoaderComplete(
network::SimpleURLLoader* source, network::SimpleURLLoader* source,
std::unique_ptr<std::string> response_body) { std::unique_ptr<std::string> response_body) {
auto it = std::find_if( auto it = std::find_if(
...@@ -107,7 +106,7 @@ void BasePingManager::OnURLLoaderComplete( ...@@ -107,7 +106,7 @@ void BasePingManager::OnURLLoaderComplete(
} }
// Sends a SafeBrowsing "hit" report. // Sends a SafeBrowsing "hit" report.
void BasePingManager::ReportSafeBrowsingHit( void PingManager::ReportSafeBrowsingHit(
const safe_browsing::HitReport& hit_report) { const safe_browsing::HitReport& hit_report) {
auto resource_request = std::make_unique<network::ResourceRequest>(); auto resource_request = std::make_unique<network::ResourceRequest>();
GURL report_url = SafeBrowsingHitUrl(hit_report); GURL report_url = SafeBrowsingHitUrl(hit_report);
...@@ -124,13 +123,13 @@ void BasePingManager::ReportSafeBrowsingHit( ...@@ -124,13 +123,13 @@ void BasePingManager::ReportSafeBrowsingHit(
report_ptr->DownloadToStringOfUnboundedSizeUntilCrashAndDie( report_ptr->DownloadToStringOfUnboundedSizeUntilCrashAndDie(
url_loader_factory_.get(), url_loader_factory_.get(),
base::BindOnce(&BasePingManager::OnURLLoaderComplete, base::BindOnce(&PingManager::OnURLLoaderComplete, base::Unretained(this),
base::Unretained(this), report_ptr.get())); report_ptr.get()));
safebrowsing_reports_.insert(std::move(report_ptr)); safebrowsing_reports_.insert(std::move(report_ptr));
} }
// Sends threat details for users who opt-in. // Sends threat details for users who opt-in.
void BasePingManager::ReportThreatDetails(const std::string& report) { void PingManager::ReportThreatDetails(const std::string& report) {
GURL report_url = ThreatDetailsUrl(); GURL report_url = ThreatDetailsUrl();
auto resource_request = std::make_unique<network::ResourceRequest>(); auto resource_request = std::make_unique<network::ResourceRequest>();
...@@ -145,12 +144,12 @@ void BasePingManager::ReportThreatDetails(const std::string& report) { ...@@ -145,12 +144,12 @@ void BasePingManager::ReportThreatDetails(const std::string& report) {
loader->DownloadToStringOfUnboundedSizeUntilCrashAndDie( loader->DownloadToStringOfUnboundedSizeUntilCrashAndDie(
url_loader_factory_.get(), url_loader_factory_.get(),
base::BindOnce(&BasePingManager::OnURLLoaderComplete, base::BindOnce(&PingManager::OnURLLoaderComplete, base::Unretained(this),
base::Unretained(this), loader.get())); loader.get()));
safebrowsing_reports_.insert(std::move(loader)); safebrowsing_reports_.insert(std::move(loader));
} }
GURL BasePingManager::SafeBrowsingHitUrl( GURL PingManager::SafeBrowsingHitUrl(
const safe_browsing::HitReport& hit_report) const { const safe_browsing::HitReport& hit_report) const {
DCHECK(hit_report.threat_type == SB_THREAT_TYPE_URL_MALWARE || DCHECK(hit_report.threat_type == SB_THREAT_TYPE_URL_MALWARE ||
hit_report.threat_type == SB_THREAT_TYPE_URL_PHISHING || hit_report.threat_type == SB_THREAT_TYPE_URL_PHISHING ||
...@@ -235,7 +234,7 @@ GURL BasePingManager::SafeBrowsingHitUrl( ...@@ -235,7 +234,7 @@ GURL BasePingManager::SafeBrowsingHitUrl(
hit_report.is_metrics_reporting_active, user_population_comp.c_str())); hit_report.is_metrics_reporting_active, user_population_comp.c_str()));
} }
GURL BasePingManager::ThreatDetailsUrl() const { GURL PingManager::ThreatDetailsUrl() const {
std::string url = base::StringPrintf( std::string url = base::StringPrintf(
"%s/clientreport/malware?client=%s&appver=%s&pver=1.0", "%s/clientreport/malware?client=%s&appver=%s&pver=1.0",
url_prefix_.c_str(), client_name_.c_str(), version_.c_str()); url_prefix_.c_str(), client_name_.c_str(), version_.c_str());
......
...@@ -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 COMPONENTS_SAFE_BROWSING_BASE_PING_MANAGER_H_ #ifndef COMPONENTS_SAFE_BROWSING_PING_MANAGER_H_
#define COMPONENTS_SAFE_BROWSING_BASE_PING_MANAGER_H_ #define COMPONENTS_SAFE_BROWSING_PING_MANAGER_H_
// A class that reports basic safebrowsing statistics to Google's SafeBrowsing // A class that reports basic safebrowsing statistics to Google's SafeBrowsing
// servers. // servers.
...@@ -27,12 +27,12 @@ class SimpleURLLoader; ...@@ -27,12 +27,12 @@ class SimpleURLLoader;
namespace safe_browsing { namespace safe_browsing {
class BasePingManager { class PingManager {
public: public:
virtual ~BasePingManager(); virtual ~PingManager();
// Create an instance of the safe browsing ping manager. // Create an instance of the safe browsing ping manager.
static std::unique_ptr<BasePingManager> Create( static std::unique_ptr<PingManager> Create(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory, scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const SafeBrowsingProtocolConfig& config); const SafeBrowsingProtocolConfig& config);
...@@ -49,18 +49,17 @@ class BasePingManager { ...@@ -49,18 +49,17 @@ class BasePingManager {
void ReportThreatDetails(const std::string& report); void ReportThreatDetails(const std::string& report);
protected: protected:
friend class BasePingManagerTest; friend class PingManagerTest;
// Constructs a BasePingManager that issues network requests // Constructs a PingManager that issues network requests
// using |url_loader_factory|. // using |url_loader_factory|.
BasePingManager( PingManager(scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory, const SafeBrowsingProtocolConfig& config);
const SafeBrowsingProtocolConfig& config);
private: private:
FRIEND_TEST_ALL_PREFIXES(BasePingManagerTest, TestSafeBrowsingHitUrl); FRIEND_TEST_ALL_PREFIXES(PingManagerTest, TestSafeBrowsingHitUrl);
FRIEND_TEST_ALL_PREFIXES(BasePingManagerTest, TestThreatDetailsUrl); FRIEND_TEST_ALL_PREFIXES(PingManagerTest, TestThreatDetailsUrl);
FRIEND_TEST_ALL_PREFIXES(BasePingManagerTest, TestReportThreatDetails); FRIEND_TEST_ALL_PREFIXES(PingManagerTest, TestReportThreatDetails);
FRIEND_TEST_ALL_PREFIXES(BasePingManagerTest, TestReportSafeBrowsingHit); FRIEND_TEST_ALL_PREFIXES(PingManagerTest, TestReportSafeBrowsingHit);
typedef std::set<std::unique_ptr<network::SimpleURLLoader>> Reports; typedef std::set<std::unique_ptr<network::SimpleURLLoader>> Reports;
...@@ -87,9 +86,9 @@ class BasePingManager { ...@@ -87,9 +86,9 @@ class BasePingManager {
// We add both "hit" and "detail" fetchers in this set. // We add both "hit" and "detail" fetchers in this set.
Reports safebrowsing_reports_; Reports safebrowsing_reports_;
DISALLOW_COPY_AND_ASSIGN(BasePingManager); DISALLOW_COPY_AND_ASSIGN(PingManager);
}; };
} // namespace safe_browsing } // namespace safe_browsing
#endif // COMPONENTS_SAFE_BROWSING_BASE_PING_MANAGER_H_ #endif // COMPONENTS_SAFE_BROWSING_PING_MANAGER_H_
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
// //
#include "components/safe_browsing/base_ping_manager.h" #include "components/safe_browsing/ping_manager.h"
#include "base/base64.h" #include "base/base64.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/run_loop.h" #include "base/run_loop.h"
...@@ -25,9 +25,9 @@ static const char kAppVer[] = "1.0"; ...@@ -25,9 +25,9 @@ static const char kAppVer[] = "1.0";
namespace safe_browsing { namespace safe_browsing {
class BasePingManagerTest : public testing::Test { class PingManagerTest : public testing::Test {
public: public:
BasePingManagerTest() {} PingManagerTest() {}
protected: protected:
void SetUp() override { void SetUp() override {
...@@ -40,17 +40,17 @@ class BasePingManagerTest : public testing::Test { ...@@ -40,17 +40,17 @@ class BasePingManagerTest : public testing::Test {
SafeBrowsingProtocolConfig config; SafeBrowsingProtocolConfig config;
config.client_name = kClient; config.client_name = kClient;
config.url_prefix = kUrlPrefix; config.url_prefix = kUrlPrefix;
ping_manager_.reset(new BasePingManager(nullptr, config)); ping_manager_.reset(new PingManager(nullptr, config));
ping_manager_->version_ = kAppVer; ping_manager_->version_ = kAppVer;
} }
BasePingManager* ping_manager() { return ping_manager_.get(); } PingManager* ping_manager() { return ping_manager_.get(); }
std::string key_param_; std::string key_param_;
std::unique_ptr<BasePingManager> ping_manager_; std::unique_ptr<PingManager> ping_manager_;
}; };
TEST_F(BasePingManagerTest, TestSafeBrowsingHitUrl) { TEST_F(PingManagerTest, TestSafeBrowsingHitUrl) {
HitReport base_hp; HitReport base_hp;
base_hp.malicious_url = GURL("http://malicious.url.com"); base_hp.malicious_url = GURL("http://malicious.url.com");
base_hp.page_url = GURL("http://page.url.com"); base_hp.page_url = GURL("http://page.url.com");
...@@ -185,7 +185,7 @@ TEST_F(BasePingManagerTest, TestSafeBrowsingHitUrl) { ...@@ -185,7 +185,7 @@ TEST_F(BasePingManagerTest, TestSafeBrowsingHitUrl) {
} }
} }
TEST_F(BasePingManagerTest, TestThreatDetailsUrl) { TEST_F(PingManagerTest, TestThreatDetailsUrl) {
EXPECT_EQ( EXPECT_EQ(
"https://prefix.com/foo/clientreport/malware?" "https://prefix.com/foo/clientreport/malware?"
"client=unittest&appver=1.0&pver=1.0" + "client=unittest&appver=1.0&pver=1.0" +
......
...@@ -147,7 +147,6 @@ Refer to README.md for content description and update process. ...@@ -147,7 +147,6 @@ Refer to README.md for content description and update process.
<item id="network_location_provider" hash_code="23472048" type="1" second_id="96590038" content_hash_code="41087976" os_list="linux,windows" semantics_fields="1" policy_fields="3,4" file_path="services/device/geolocation/network_location_provider.cc"/> <item id="network_location_provider" hash_code="23472048" type="1" second_id="96590038" content_hash_code="41087976" os_list="linux,windows" semantics_fields="1" policy_fields="3,4" file_path="services/device/geolocation/network_location_provider.cc"/>
<item id="network_location_request" hash_code="96590038" type="2" content_hash_code="59824433" os_list="linux,windows" semantics_fields="2,3,4,5" policy_fields="-1" file_path="services/device/geolocation/network_location_request.cc"/> <item id="network_location_request" hash_code="96590038" type="2" content_hash_code="59824433" os_list="linux,windows" semantics_fields="2,3,4,5" policy_fields="-1" file_path="services/device/geolocation/network_location_request.cc"/>
<item id="network_time_component" hash_code="46188932" type="0" content_hash_code="28051857" os_list="linux,windows" file_path="components/network_time/network_time_tracker.cc"/> <item id="network_time_component" hash_code="46188932" type="0" content_hash_code="28051857" os_list="linux,windows" file_path="components/network_time/network_time_tracker.cc"/>
<item id="notification_image_reporter" hash_code="70126372" type="0" content_hash_code="29754543" os_list="linux,windows" file_path="chrome/browser/safe_browsing/notification_image_reporter.cc"/>
<item id="ntp_contextual_suggestions_fetch" hash_code="95711309" type="0" content_hash_code="107035434" os_list="linux,windows" file_path="components/ntp_snippets/contextual/contextual_suggestions_fetch.cc"/> <item id="ntp_contextual_suggestions_fetch" hash_code="95711309" type="0" content_hash_code="107035434" os_list="linux,windows" file_path="components/ntp_snippets/contextual/contextual_suggestions_fetch.cc"/>
<item id="ntp_icon_source" hash_code="29197139" type="0" content_hash_code="16399294" os_list="linux,windows" file_path="chrome/browser/search/ntp_icon_source.cc"/> <item id="ntp_icon_source" hash_code="29197139" type="0" content_hash_code="16399294" os_list="linux,windows" file_path="chrome/browser/search/ntp_icon_source.cc"/>
<item id="ntp_snippets_fetch" hash_code="15418154" type="0" content_hash_code="10078959" os_list="linux,windows" file_path="components/ntp_snippets/remote/json_request.cc"/> <item id="ntp_snippets_fetch" hash_code="15418154" type="0" content_hash_code="10078959" os_list="linux,windows" file_path="components/ntp_snippets/remote/json_request.cc"/>
...@@ -212,7 +211,7 @@ Refer to README.md for content description and update process. ...@@ -212,7 +211,7 @@ Refer to README.md for content description and update process.
<item id="safe_browsing_chunk_backup_request" hash_code="79957943" type="0" content_hash_code="133850277" os_list="linux,windows" file_path="chrome/browser/safe_browsing/protocol_manager.cc"/> <item id="safe_browsing_chunk_backup_request" hash_code="79957943" type="0" content_hash_code="133850277" os_list="linux,windows" file_path="chrome/browser/safe_browsing/protocol_manager.cc"/>
<item id="safe_browsing_client_side_malware_detector" hash_code="102935425" type="0" content_hash_code="79591279" os_list="linux,windows" file_path="chrome/browser/safe_browsing/client_side_detection_service.cc"/> <item id="safe_browsing_client_side_malware_detector" hash_code="102935425" type="0" content_hash_code="79591279" os_list="linux,windows" file_path="chrome/browser/safe_browsing/client_side_detection_service.cc"/>
<item id="safe_browsing_client_side_phishing_detector" hash_code="1313982" type="0" content_hash_code="50199143" os_list="linux,windows" file_path="chrome/browser/safe_browsing/client_side_detection_service.cc"/> <item id="safe_browsing_client_side_phishing_detector" hash_code="1313982" type="0" content_hash_code="50199143" os_list="linux,windows" file_path="chrome/browser/safe_browsing/client_side_detection_service.cc"/>
<item id="safe_browsing_extended_reporting" hash_code="42848942" type="0" content_hash_code="50089173" os_list="linux,windows" file_path="components/safe_browsing/base_ping_manager.cc"/> <item id="safe_browsing_extended_reporting" hash_code="42848942" type="0" content_hash_code="50089173" os_list="linux,windows" file_path="components/safe_browsing/ping_manager.cc"/>
<item id="safe_browsing_feedback" hash_code="44583821" type="0" content_hash_code="114076664" os_list="linux,windows" file_path="chrome/browser/safe_browsing/download_protection/download_feedback.cc"/> <item id="safe_browsing_feedback" hash_code="44583821" type="0" content_hash_code="114076664" os_list="linux,windows" file_path="chrome/browser/safe_browsing/download_protection/download_feedback.cc"/>
<item id="safe_browsing_g4_update" hash_code="75153841" type="0" content_hash_code="112049516" os_list="linux,windows" file_path="components/safe_browsing/db/v4_update_protocol_manager.cc"/> <item id="safe_browsing_g4_update" hash_code="75153841" type="0" content_hash_code="112049516" os_list="linux,windows" file_path="components/safe_browsing/db/v4_update_protocol_manager.cc"/>
<item id="safe_browsing_get_full_hash" hash_code="68745894" type="0" content_hash_code="21739198" os_list="linux,windows" file_path="chrome/browser/safe_browsing/protocol_manager.cc"/> <item id="safe_browsing_get_full_hash" hash_code="68745894" type="0" content_hash_code="21739198" os_list="linux,windows" file_path="chrome/browser/safe_browsing/protocol_manager.cc"/>
......
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