summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkcarattini <kcarattini@chromium.org>2016-02-21 17:51:06 -0800
committerCommit bot <commit-bot@chromium.org>2016-02-22 01:51:59 +0000
commit3110e563a36a59145bfa2c20c1b10460b761c1cc (patch)
tree73fe8d4b774110a7c25d9b66fece9f05ac21dcd5
parent9b92513b0f6141749e7554c71a83d9215ca0415e (diff)
downloadchromium_src-3110e563a36a59145bfa2c20c1b10460b761c1cc.zip
chromium_src-3110e563a36a59145bfa2c20c1b10460b761c1cc.tar.gz
chromium_src-3110e563a36a59145bfa2c20c1b10460b761c1cc.tar.bz2
SafeBrowsing: DatabaseManager owns the V4GetHashProtocolManager
BUG=543161,561867 Committed: https://crrev.com/95bba9fad50442a9ce7ae4fbcc50d1d845d5d399 Cr-Commit-Position: refs/heads/master@{#376088} Review URL: https://codereview.chromium.org/1700943003 Cr-Commit-Position: refs/heads/master@{#376676}
-rw-r--r--chrome/browser/safe_browsing/local_database_manager.cc13
-rw-r--r--chrome/browser/safe_browsing/local_database_manager.h9
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_service.cc54
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_service.h7
-rw-r--r--components/safe_browsing_db/BUILD.gn5
-rw-r--r--components/safe_browsing_db/database_manager.cc19
-rw-r--r--components/safe_browsing_db/database_manager.h19
-rw-r--r--components/safe_browsing_db/remote_database_manager.cc10
-rw-r--r--components/safe_browsing_db/remote_database_manager.h13
9 files changed, 127 insertions, 22 deletions
diff --git a/chrome/browser/safe_browsing/local_database_manager.cc b/chrome/browser/safe_browsing/local_database_manager.cc
index 38395ff..6a02287 100644
--- a/chrome/browser/safe_browsing/local_database_manager.cc
+++ b/chrome/browser/safe_browsing/local_database_manager.cc
@@ -34,6 +34,7 @@
#include "chrome/common/pref_names.h"
#include "components/prefs/pref_service.h"
#include "components/safe_browsing_db/util.h"
+#include "components/safe_browsing_db/v4_get_hash_protocol_manager.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h"
#include "url/url_constants.h"
@@ -270,8 +271,16 @@ void LocalSafeBrowsingDatabaseManager::SafeBrowsingCheck::
}
LocalSafeBrowsingDatabaseManager::LocalSafeBrowsingDatabaseManager(
- const scoped_refptr<SafeBrowsingService>& service)
- : sb_service_(service),
+ const scoped_refptr<SafeBrowsingService>& service) :
+ LocalSafeBrowsingDatabaseManager(service, NULL, V4GetHashProtocolConfig()) {
+}
+
+LocalSafeBrowsingDatabaseManager::LocalSafeBrowsingDatabaseManager(
+ const scoped_refptr<SafeBrowsingService>& service,
+ net::URLRequestContextGetter* request_context_getter,
+ const V4GetHashProtocolConfig& config)
+ : SafeBrowsingDatabaseManager(request_context_getter, config),
+ sb_service_(service),
database_(NULL),
enabled_(false),
enable_download_protection_(false),
diff --git a/chrome/browser/safe_browsing/local_database_manager.h b/chrome/browser/safe_browsing/local_database_manager.h
index c163503..6c543ad 100644
--- a/chrome/browser/safe_browsing/local_database_manager.h
+++ b/chrome/browser/safe_browsing/local_database_manager.h
@@ -41,6 +41,7 @@ class SafeBrowsingService;
class SafeBrowsingDatabase;
class ClientSideDetectionService;
class DownloadProtectionService;
+struct V4GetHashProtocolConfig;
// Implemetation that manages a local database on disk.
//
@@ -100,10 +101,16 @@ class LocalSafeBrowsingDatabaseManager
DISALLOW_COPY_AND_ASSIGN(SafeBrowsingCheck);
};
- // Creates the safe browsing service. Need to initialize before using.
+ // Use this constructor for testing only.
explicit LocalSafeBrowsingDatabaseManager(
const scoped_refptr<SafeBrowsingService>& service);
+ // Creates the safe browsing service. Need to initialize before using.
+ LocalSafeBrowsingDatabaseManager(
+ const scoped_refptr<SafeBrowsingService>& service,
+ net::URLRequestContextGetter* request_context_getter,
+ const V4GetHashProtocolConfig& config);
+
//
// SafeBrowsingDatabaseManager overrides
//
diff --git a/chrome/browser/safe_browsing/safe_browsing_service.cc b/chrome/browser/safe_browsing/safe_browsing_service.cc
index 67f3f2f..18b315a 100644
--- a/chrome/browser/safe_browsing/safe_browsing_service.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_service.cc
@@ -31,6 +31,7 @@
#include "chrome/browser/safe_browsing/download_protection_service.h"
#include "chrome/browser/safe_browsing/ping_manager.h"
#include "chrome/browser/safe_browsing/protocol_manager.h"
+#include "chrome/browser/safe_browsing/protocol_manager_helper.h"
#include "chrome/browser/safe_browsing/ui_manager.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"
@@ -40,10 +41,12 @@
#include "components/prefs/pref_change_registrar.h"
#include "components/prefs/pref_service.h"
#include "components/safe_browsing_db/database_manager.h"
+#include "components/safe_browsing_db/v4_get_hash_protocol_manager.h"
#include "components/user_prefs/tracked/tracked_preference_validation_delegate.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/cookie_store_factory.h"
#include "content/public/browser/notification_service.h"
+#include "google_apis/google_api_keys.h"
#include "net/cookies/cookie_store.h"
#include "net/extras/sqlite/cookie_crypto_delegate.h"
#include "net/url_request/url_request_context.h"
@@ -399,10 +402,11 @@ SafeBrowsingUIManager* SafeBrowsingService::CreateUIManager() {
}
SafeBrowsingDatabaseManager* SafeBrowsingService::CreateDatabaseManager() {
+ V4GetHashProtocolConfig config = GetV4GetHashProtocolConfig();
#if defined(SAFE_BROWSING_DB_LOCAL)
- return new LocalSafeBrowsingDatabaseManager(this);
+ return new LocalSafeBrowsingDatabaseManager(this, NULL, config);
#elif defined(SAFE_BROWSING_DB_REMOTE)
- return new RemoteSafeBrowsingDatabaseManager();
+ return new RemoteSafeBrowsingDatabaseManager(NULL, config);
#else
return NULL;
#endif
@@ -428,37 +432,55 @@ void SafeBrowsingService::RegisterAllDelayedAnalysis() {
SafeBrowsingProtocolConfig SafeBrowsingService::GetProtocolConfig() const {
SafeBrowsingProtocolConfig config;
+ config.client_name = GetProtocolConfigClientName();
+
+ base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess();
+ config.disable_auto_update =
+ cmdline->HasSwitch(switches::kSbDisableAutoUpdate) ||
+ cmdline->HasSwitch(switches::kDisableBackgroundNetworking);
+ config.url_prefix = kSbDefaultURLPrefix;
+ config.backup_connect_error_url_prefix = kSbBackupConnectErrorURLPrefix;
+ config.backup_http_error_url_prefix = kSbBackupHttpErrorURLPrefix;
+ config.backup_network_error_url_prefix = kSbBackupNetworkErrorURLPrefix;
+
+ return config;
+}
+
+V4GetHashProtocolConfig
+SafeBrowsingService::GetV4GetHashProtocolConfig() const {
+ V4GetHashProtocolConfig config;
+ config.client_name = GetProtocolConfigClientName();
+ config.version = SafeBrowsingProtocolManagerHelper::Version();
+ config.key_param = google_apis::GetAPIKey();;
+
+ return config;
+}
+
+std::string SafeBrowsingService::GetProtocolConfigClientName() const {
+ std::string client_name;
// On Windows, get the safe browsing client name from the browser
// distribution classes in installer util. These classes don't yet have
// an analog on non-Windows builds so just keep the name specified here.
#if defined(OS_WIN)
BrowserDistribution* dist = BrowserDistribution::GetDistribution();
- config.client_name = dist->GetSafeBrowsingName();
+ client_name = dist->GetSafeBrowsingName();
#else
#if defined(GOOGLE_CHROME_BUILD)
- config.client_name = "googlechrome";
+ client_name = "googlechrome";
#else
- config.client_name = "chromium";
+ client_name = "chromium";
#endif
// Mark client string to allow server to differentiate mobile.
#if defined(OS_ANDROID)
- config.client_name.append("-a");
+ client_name.append("-a");
#elif defined(OS_IOS)
- config.client_name.append("-i");
+ client_name.append("-i");
#endif
#endif // defined(OS_WIN)
- base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess();
- config.disable_auto_update =
- cmdline->HasSwitch(switches::kSbDisableAutoUpdate) ||
- cmdline->HasSwitch(switches::kDisableBackgroundNetworking);
- config.url_prefix = kSbDefaultURLPrefix;
- config.backup_connect_error_url_prefix = kSbBackupConnectErrorURLPrefix;
- config.backup_http_error_url_prefix = kSbBackupHttpErrorURLPrefix;
- config.backup_network_error_url_prefix = kSbBackupNetworkErrorURLPrefix;
- return config;
+ return client_name;
}
// Any tests that create a DatabaseManager that isn't derived from
diff --git a/chrome/browser/safe_browsing/safe_browsing_service.h b/chrome/browser/safe_browsing/safe_browsing_service.h
index ec8d59c..3c3435d 100644
--- a/chrome/browser/safe_browsing/safe_browsing_service.h
+++ b/chrome/browser/safe_browsing/safe_browsing_service.h
@@ -58,6 +58,7 @@ class SafeBrowsingProtocolManagerDelegate;
class SafeBrowsingServiceFactory;
class SafeBrowsingUIManager;
class SafeBrowsingURLRequestContextGetter;
+struct V4GetHashProtocolConfig;
#if defined(FULL_SAFE_BROWSING)
class IncidentReportingService;
@@ -103,6 +104,12 @@ class SafeBrowsingService
// Create a protocol config struct.
virtual SafeBrowsingProtocolConfig GetProtocolConfig() const;
+ // Create a v4 protocol config struct.
+ virtual V4GetHashProtocolConfig GetV4GetHashProtocolConfig() const;
+
+ // Returns the client_name field for both V3 and V4 protocol manager configs.
+ std::string GetProtocolConfigClientName() const;
+
// Get current enabled status. Must be called on IO thread.
bool enabled() const {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
diff --git a/components/safe_browsing_db/BUILD.gn b/components/safe_browsing_db/BUILD.gn
index ad32884..5a58fe2 100644
--- a/components/safe_browsing_db/BUILD.gn
+++ b/components/safe_browsing_db/BUILD.gn
@@ -49,9 +49,12 @@ source_set("database_manager") {
]
deps = [
":hit_report",
+ ":proto",
":util",
+ ":v4_get_hash_protocol_manager",
"//base:base",
"//content/public/common",
+ "//net",
"//url:url",
]
}
@@ -100,7 +103,9 @@ source_set("remote_database_manager") {
]
deps = [
":database_manager",
+ ":proto",
":safe_browsing_api_handler",
+ ":v4_get_hash_protocol_manager",
"//base:base",
"//components/variations",
"//content/public/browser",
diff --git a/components/safe_browsing_db/database_manager.cc b/components/safe_browsing_db/database_manager.cc
index b818722..6412cf0 100644
--- a/components/safe_browsing_db/database_manager.cc
+++ b/components/safe_browsing_db/database_manager.cc
@@ -4,10 +4,29 @@
#include "components/safe_browsing_db/database_manager.h"
+#include "components/safe_browsing_db/v4_get_hash_protocol_manager.h"
+#include "net/url_request/url_request_context_getter.h"
#include "url/gurl.h"
namespace safe_browsing {
+SafeBrowsingDatabaseManager::SafeBrowsingDatabaseManager()
+ : SafeBrowsingDatabaseManager(NULL, V4GetHashProtocolConfig()) {
+}
+
+SafeBrowsingDatabaseManager::SafeBrowsingDatabaseManager(
+ net::URLRequestContextGetter* request_context_getter,
+ const V4GetHashProtocolConfig& config) {
+ // Instantiate a V4GetHashProtocolManager.
+ if (request_context_getter) {
+ v4_get_hash_protocol_manager_.reset(V4GetHashProtocolManager::Create(
+ request_context_getter, config));
+ }
+}
+
+SafeBrowsingDatabaseManager::~SafeBrowsingDatabaseManager() {
+}
+
void SafeBrowsingDatabaseManager::CheckApiBlacklistUrl(const GURL& url,
Client* client) {
// TODO(kcarattini): Implement this.
diff --git a/components/safe_browsing_db/database_manager.h b/components/safe_browsing_db/database_manager.h
index fd8a276..6ee8cbd 100644
--- a/components/safe_browsing_db/database_manager.h
+++ b/components/safe_browsing_db/database_manager.h
@@ -20,8 +20,15 @@
#include "content/public/common/resource_type.h"
#include "url/gurl.h"
+namespace net {
+class URLRequestContextGetter;
+} // namespace net
+
namespace safe_browsing {
+struct V4GetHashProtocolConfig;
+class V4GetHashProtocolManager;
+
// Base class to either the locally-managed or a remotely-managed database.
class SafeBrowsingDatabaseManager
: public base::RefCountedThreadSafe<SafeBrowsingDatabaseManager> {
@@ -162,9 +169,19 @@ class SafeBrowsingDatabaseManager
virtual void StopOnIOThread(bool shutdown) = 0;
protected:
- virtual ~SafeBrowsingDatabaseManager() {}
+ // Use this constructor for testing only.
+ SafeBrowsingDatabaseManager();
+
+ // Constructs the database manager.
+ SafeBrowsingDatabaseManager(
+ net::URLRequestContextGetter* request_context_getter,
+ const V4GetHashProtocolConfig& config);
+
+ virtual ~SafeBrowsingDatabaseManager();
friend class base::RefCountedThreadSafe<SafeBrowsingDatabaseManager>;
+
+ std::unique_ptr<V4GetHashProtocolManager> v4_get_hash_protocol_manager_;
}; // class SafeBrowsingDatabaseManager
} // namespace safe_browsing
diff --git a/components/safe_browsing_db/remote_database_manager.cc b/components/safe_browsing_db/remote_database_manager.cc
index e699b30..adcb0be 100644
--- a/components/safe_browsing_db/remote_database_manager.cc
+++ b/components/safe_browsing_db/remote_database_manager.cc
@@ -11,6 +11,7 @@
#include "base/strings/string_split.h"
#include "base/timer/elapsed_timer.h"
#include "components/safe_browsing_db/safe_browsing_api_handler.h"
+#include "components/safe_browsing_db/v4_get_hash_protocol_manager.h"
#include "components/variations/variations_associated_data.h"
#include "content/public/browser/browser_thread.h"
@@ -93,7 +94,14 @@ void RemoteSafeBrowsingDatabaseManager::ClientRequest::OnRequestDone(
// TODO(nparker): Add more tests for this class
RemoteSafeBrowsingDatabaseManager::RemoteSafeBrowsingDatabaseManager()
- : enabled_(false) {
+ : RemoteSafeBrowsingDatabaseManager(NULL, V4GetHashProtocolConfig()) {
+}
+
+RemoteSafeBrowsingDatabaseManager::RemoteSafeBrowsingDatabaseManager(
+ net::URLRequestContextGetter* request_context_getter,
+ const V4GetHashProtocolConfig& config)
+ : SafeBrowsingDatabaseManager(request_context_getter, config),
+ enabled_(false) {
// Decide which resource types to check. These two are the minimum.
resource_types_to_check_.insert(content::RESOURCE_TYPE_MAIN_FRAME);
resource_types_to_check_.insert(content::RESOURCE_TYPE_SUB_FRAME);
diff --git a/components/safe_browsing_db/remote_database_manager.h b/components/safe_browsing_db/remote_database_manager.h
index 6b2c764..143902c 100644
--- a/components/safe_browsing_db/remote_database_manager.h
+++ b/components/safe_browsing_db/remote_database_manager.h
@@ -18,15 +18,26 @@
#include "components/safe_browsing_db/database_manager.h"
#include "url/gurl.h"
+namespace net {
+class URLRequestContextGetter;
+}
+
namespace safe_browsing {
+struct V4GetHashProtocolConfig;
+
// An implementation that proxies requests to a service outside of Chromium.
// Does not manage a local database.
class RemoteSafeBrowsingDatabaseManager : public SafeBrowsingDatabaseManager {
public:
+ // Use this constructor for testing only.
+ RemoteSafeBrowsingDatabaseManager();
+
// Construct RemoteSafeBrowsingDatabaseManager.
// Must be initialized by calling StartOnIOThread() before using.
- RemoteSafeBrowsingDatabaseManager();
+ RemoteSafeBrowsingDatabaseManager(
+ net::URLRequestContextGetter* request_context_getter,
+ const V4GetHashProtocolConfig& config);
//
// SafeBrowsingDatabaseManager implementation