Chromium Code Reviews| 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..fa39ba9c8ec61f42d9649e90810a1dfc9ff3861b 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" |
| @@ -17,6 +18,7 @@ |
| #include "base/timer/timer.h" |
| #include "chrome/browser/safe_browsing/protocol_parser.h" |
| #include "chrome/common/env_vars.h" |
| +#include "components/safe_browsing_db/safebrowsing.pb.h" |
| #include "components/safe_browsing_db/util.h" |
| #include "components/variations/variations_associated_data.h" |
| #include "google_apis/google_api_keys.h" |
| @@ -193,6 +195,10 @@ SafeBrowsingProtocolManager::~SafeBrowsingProtocolManager() { |
| STLDeleteContainerPairFirstPointers(hash_requests_.begin(), |
| hash_requests_.end()); |
| hash_requests_.clear(); |
| + |
| + STLDeleteContainerPairFirstPointers(hash_api_requests_.begin(), |
| + hash_api_requests_.end()); |
| + hash_api_requests_.clear(); |
| } |
| // We can only have one update or chunk request outstanding, but there may be |
| @@ -228,6 +234,50 @@ void SafeBrowsingProtocolManager::GetFullHash( |
| fetcher->Start(); |
| } |
| +std::string SafeBrowsingProtocolManager::GetHashWithApisRequest( |
|
Nathan Parker
2015/12/27 01:10:17
This could be non-"Apis
-specific by passing the t
kcarattini
2015/12/28 00:05:46
Done.
|
| + const std::vector<SBPrefix>& prefixes) { |
| + // 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(API_ABUSE); |
| + 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::GetFullHashWithApis( |
|
Nathan Parker
2015/12/27 01:10:17
Same here. This function could call a generic Pve
kcarattini
2015/12/28 00:05:46
Done.
|
| + const std::vector<SBPrefix>& prefixes, |
| + FullHashCallback callback) { |
| + DCHECK(CalledOnValidThread()); |
| + // TODO(kcarattini): Implement backoff behavior. |
| + |
| + std::string req_base64 = GetHashWithApisRequest(prefixes); |
| + GURL gethash_url = GetHashWithApisUrl(req_base64); |
| + |
| + net::URLFetcher* fetcher = |
| + net::URLFetcher::Create(url_fetcher_id_++, gethash_url, |
| + net::URLFetcher::POST, this) |
| + .release(); |
| + hash_api_requests_[fetcher] = FullHashDetails(callback, |
| + false /* is_download */); |
| + |
| + fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE); |
| + fetcher->SetRequestContext(request_context_getter_.get()); |
| + fetcher->Start(); |
| +} |
| + |
| void SafeBrowsingProtocolManager::GetNextUpdate() { |
| DCHECK(CalledOnValidThread()); |
| if (request_.get() || request_type_ != NO_REQUEST) |
| @@ -758,6 +808,15 @@ GURL SafeBrowsingProtocolManager::GetHashUrl(bool is_extended_reporting) const { |
| return GURL(url); |
| } |
| +// The API hash call uses the pver4 Safe Browsing server. |
| +GURL SafeBrowsingProtocolManager::GetHashWithApisUrl( |
|
Nathan Parker
2015/12/27 01:10:17
This is not "Apis" specific -- we could call it Ge
kcarattini
2015/12/28 00:05:46
Done.
|
| + 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; |