Index: chrome/browser/safe_browsing/remote_database_manager.cc |
diff --git a/chrome/browser/safe_browsing/remote_database_manager.cc b/chrome/browser/safe_browsing/remote_database_manager.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9ee7359802f6cb7e27d0ce04db5280397d6eed06 |
--- /dev/null |
+++ b/chrome/browser/safe_browsing/remote_database_manager.cc |
@@ -0,0 +1,151 @@ |
+// Copyright (c) 2015 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/remote_database_manager.h" |
+ |
+#include <vector> |
+ |
+#include "chrome/browser/safe_browsing/android_safe_browsing_api_handler.h" |
+#include "content/public/browser/browser_thread.h" |
+ |
+using content::BrowserThread; |
+ |
+// TODO(nparker): Add tests for this class once implemented. |
+RemoteSafeBrowsingDatabaseManager::RemoteSafeBrowsingDatabaseManager() |
+ : enabled_(false), |
+ api_handler_(new AndroidSafeBrowsingAPIHandler()), |
+ weak_ptr_factory_(this) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::UI); |
+ VLOG(1) << "RemoteSafeBrowsing selected."; |
+ // TODO(nparker): Implement the initialization glue. |
+ // Check flag to see if this is enabled. |
+ // Ask AndroidSafeBrowsingAPIHandler if Java API is correct version. |
+} |
+ |
+RemoteSafeBrowsingDatabaseManager::~RemoteSafeBrowsingDatabaseManager() { |
+ DCHECK(!enabled_); |
+} |
+ |
+bool RemoteSafeBrowsingDatabaseManager::CanCheckUrl(const GURL& url) const { |
+ return url.SchemeIs(url::kHttpsScheme) || url.SchemeIs(url::kHttpScheme) || |
+ url.SchemeIs(url::kFtpScheme); |
+} |
+ |
+bool RemoteSafeBrowsingDatabaseManager::CheckDownloadUrl( |
+ const std::vector<GURL>& url_chain, |
+ Client* client) { |
+ DCHECK(false) << "Not available in this implementation."; |
mattm
2015/04/29 22:59:59
how about just make these NOTREACHED?
Nathan Parker
2015/05/04 21:17:19
Done.
|
+ return true; |
+} |
+ |
+bool RemoteSafeBrowsingDatabaseManager::CheckExtensionIDs( |
+ const std::set<std::string>& extension_ids, |
+ Client* client) { |
+ DCHECK(false) << "Not available in this implementation."; |
+ return true; |
+} |
+ |
+bool RemoteSafeBrowsingDatabaseManager::MatchMalwareIP( |
+ const std::string& ip_address) { |
+ DCHECK(false) << "Not available in this implementation."; |
+ return false; |
+} |
+ |
+bool RemoteSafeBrowsingDatabaseManager::MatchCsdWhitelistUrl(const GURL& url) { |
+ DCHECK(false) << "Not available in this implementation."; |
+ return true; |
+} |
+ |
+bool RemoteSafeBrowsingDatabaseManager::MatchDownloadWhitelistUrl( |
+ const GURL& url) { |
+ DCHECK(false) << "Not available in this implementation."; |
+ return true; |
+} |
+ |
+bool RemoteSafeBrowsingDatabaseManager::MatchDownloadWhitelistString( |
+ const std::string& str) { |
+ DCHECK(false) << "Not available in this implementation."; |
+ return true; |
+} |
+ |
+bool RemoteSafeBrowsingDatabaseManager::MatchInclusionWhitelistUrl( |
+ const GURL& url) { |
+ DCHECK(false) << "Not available in this implementation."; |
+ return true; |
+} |
+ |
+bool RemoteSafeBrowsingDatabaseManager::IsMalwareKillSwitchOn() { |
+ DCHECK(false) << "Not available in this implementation."; |
+ return true; |
+} |
+ |
+bool RemoteSafeBrowsingDatabaseManager::IsCsdWhitelistKillSwitchOn() { |
+ DCHECK(false) << "Not available in this implementation."; |
+ return true; |
+} |
+ |
+bool RemoteSafeBrowsingDatabaseManager::CheckBrowseUrl(const GURL& url, |
+ Client* client) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::IO); |
+ if (!enabled_) |
+ return true; |
+ |
+ if (!CanCheckUrl(url)) |
+ return true; // Safe, continue right away. |
+ |
+ ClientRequest* req = new ClientRequest(); |
+ req->db_manager = weak_ptr_factory_.GetWeakPtr(); |
+ req->url = url; |
+ req->client = client; |
+ |
+ VLOG(1) << "Checking URL " << url; |
+ DCHECK(api_handler_->StartRequest(req)) << "Request failed to start"; |
mattm
2015/04/29 22:59:59
don't put real code in a DCHECK
Nathan Parker
2015/05/04 21:17:19
Indeed. Fixed.
|
+ current_requests_.insert(req); |
+ |
+ // Defer the resource load. |
+ return false; |
+} |
+ |
+void RemoteSafeBrowsingDatabaseManager::CancelCheck(Client* client) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::IO); |
+ DCHECK(enabled_); |
+ std::vector<ClientRequest*> to_delete; |
mattm
2015/04/29 22:59:59
Doesn't actually delete here. Maybe to_remove?
Nathan Parker
2015/05/04 21:17:19
I've refactored this since it's now a vector of sc
|
+ for (auto req : current_requests_) { |
+ if (req->client == client) { |
+ // This will indicate to the api_handler that the request is canceled. |
+ req->client = NULL; |
+ to_delete.push_back(req); |
+ VLOG(1) << "Canceling check for URL " << req->url; |
+ } |
+ } |
+ // There should be exactly one active request per client. Old requests |
+ // from this client may still be pending, but they will have their client |
+ // field cleared previously when canceled. |
+ DCHECK(to_delete.size() == 1); |
+ for (auto req : to_delete) { |
+ current_requests_.erase(req); |
+ } |
+} |
+ |
+void RemoteSafeBrowsingDatabaseManager::StartOnIOThread() { |
+ VLOG(1) << "RemoteSafeBrowsing starting"; |
+ enabled_ = true; |
+} |
+ |
+void RemoteSafeBrowsingDatabaseManager::StopOnIOThread(bool shutdown) { |
+ // |shutdown| is not used. |
+ DCHECK_CURRENTLY_ON(BrowserThread::IO); |
+ VLOG(1) << "RemoteSafeBrowsing stopping"; |
+ |
+ // Call back any remaining clients. |
+ for (auto req : current_requests_) { |
+ if (req->client) { |
+ VLOG(1) << "Stopping: Canceling req for URL " << req->url; |
+ req->client->OnCheckBrowseUrlResult(req->url, SB_THREAT_TYPE_SAFE, ""); |
+ req->client = NULL; |
+ } |
+ } |
+ enabled_ = false; |
+} |
+ |