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

Unified Diff: chrome/browser/safe_browsing/protocol_manager.cc

Issue 1543153002: Add a GetFullHashWithApis method to Protocol Manager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make v4 generic Created 5 years 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: chrome/browser/safe_browsing/protocol_manager.cc
diff --git a/chrome/browser/safe_browsing/protocol_manager.cc b/chrome/browser/safe_browsing/protocol_manager.cc
index e746763c7b99f505bc0fe58d20cf5e651e4ab2ed..9716a0880aa2f2de226b98d70c22042e4989aa9b 100644
--- a/chrome/browser/safe_browsing/protocol_manager.cc
+++ b/chrome/browser/safe_browsing/protocol_manager.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/safe_browsing/protocol_manager.h"
+#include "base/base64.h"
#include "base/environment.h"
#include "base/logging.h"
#include "base/metrics/histogram_macros.h"
@@ -193,6 +194,10 @@ SafeBrowsingProtocolManager::~SafeBrowsingProtocolManager() {
STLDeleteContainerPairFirstPointers(hash_requests_.begin(),
hash_requests_.end());
hash_requests_.clear();
+
+ STLDeleteContainerPairFirstPointers(v4_hash_requests_.begin(),
+ v4_hash_requests_.end());
+ v4_hash_requests_.clear();
}
// We can only have one update or chunk request outstanding, but there may be
@@ -228,6 +233,58 @@ void SafeBrowsingProtocolManager::GetFullHash(
fetcher->Start();
}
+std::string SafeBrowsingProtocolManager::GetV4HashRequest(
+ const std::vector<SBPrefix>& prefixes,
+ ThreatType threat_type) {
+ // Build the request. Client info and client states are not added to the
+ // request protocol buffer. Client info is passed as params in the url.
+ FindFullHashesRequest req;
+ ThreatInfo* info = req.mutable_threat_info();
+ info->add_threat_types(threat_type);
+ info->add_platform_types(CHROME_PLATFORM);
+ info->add_threat_entry_types(URL_EXPRESSION);
+ for (const SBPrefix& prefix : prefixes) {
+ std::string hash;
+ hash.append(reinterpret_cast<const char*>(&prefix), sizeof(SBPrefix));
+ info->add_threat_entries()->set_hash(hash);
+ }
+
+ // Serialize and Base64 encode.
+ std::string req_data, req_base64;
+ req.SerializeToString(&req_data);
+ base::Base64Encode(req_data, &req_base64);
+
+ return req_base64;
+}
+
+void SafeBrowsingProtocolManager::GetV4FullHash(
awoz 2015/12/28 15:57:31 nit: This function name should reflect the fact th
kcarattini 2015/12/29 00:12:47 Done.
+ const std::vector<SBPrefix>& prefixes,
+ ThreatType threat_type,
+ FullHashCallback callback) {
+ DCHECK(CalledOnValidThread());
+ // TODO(kcarattini): Implement backoff behavior.
+
+ std::string req_base64 = GetV4HashRequest(prefixes, threat_type);
+ GURL gethash_url = GetV4HashUrl(req_base64);
+
+ net::URLFetcher* fetcher =
+ net::URLFetcher::Create(url_fetcher_id_++, gethash_url,
+ net::URLFetcher::POST, this)
+ .release();
+ v4_hash_requests_[fetcher] = FullHashDetails(callback,
awoz 2015/12/28 15:57:32 Maybe a TODO to implement a new response processor
kcarattini 2015/12/29 00:12:47 Done.
+ false /* is_download */);
awoz 2015/12/28 15:57:32 nit: indent off
kcarattini 2015/12/29 00:12:47 Done.
+
+ fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE);
+ fetcher->SetRequestContext(request_context_getter_.get());
+ fetcher->Start();
+}
+
+void SafeBrowsingProtocolManager::GetFullHashWithApis(
+ const std::vector<SBPrefix>& prefixes,
+ FullHashCallback callback) {
+ GetV4FullHash(prefixes, API_ABUSE, callback);
+}
+
void SafeBrowsingProtocolManager::GetNextUpdate() {
DCHECK(CalledOnValidThread());
if (request_.get() || request_type_ != NO_REQUEST)
@@ -758,6 +815,15 @@ GURL SafeBrowsingProtocolManager::GetHashUrl(bool is_extended_reporting) const {
return GURL(url);
}
+// The API hash call uses the pver4 Safe Browsing server.
+GURL SafeBrowsingProtocolManager::GetV4HashUrl(
+ const std::string& request_base64) const {
+ std::string url = SafeBrowsingProtocolManagerHelper::ComposePver4Url(
+ "https://safebrowsing.googleapis.com/v4", "encodedFullHashes",
+ request_base64, client_name_, version_);
+ return GURL(url);
+}
+
GURL SafeBrowsingProtocolManager::NextChunkUrl(const std::string& url) const {
DCHECK(CalledOnValidThread());
std::string next_url;
« no previous file with comments | « chrome/browser/safe_browsing/protocol_manager.h ('k') | chrome/browser/safe_browsing/protocol_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698