Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/safe_browsing_db/v4_get_hash_protocol_manager.h" | 5 #include "components/safe_browsing_db/v4_get_hash_protocol_manager.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/base64url.h" | 9 #include "base/base64url.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 291 RecordParseGetHashResult(UNEXPECTED_THREAT_TYPE_ERROR); | 291 RecordParseGetHashResult(UNEXPECTED_THREAT_TYPE_ERROR); |
| 292 return false; | 292 return false; |
| 293 } | 293 } |
| 294 | 294 |
| 295 full_hashes->push_back(result); | 295 full_hashes->push_back(result); |
| 296 } | 296 } |
| 297 return true; | 297 return true; |
| 298 } | 298 } |
| 299 | 299 |
| 300 void V4GetHashProtocolManager::GetFullHashes( | 300 void V4GetHashProtocolManager::GetFullHashes( |
| 301 const base::hash_set<HashPrefix>& prefixes, | |
| 302 const PlatformTypeSet& platforms, | |
| 303 const ThreatEntryTypeSet& threat_entry_types, | |
| 304 const ThreatTypeSet& threat_types, | |
| 305 FullHashCallback callback) { | |
|
Scott Hess - ex-Googler
2016/08/23 20:25:46
I think these are in the opposite order from the h
| |
| 306 DCHECK(CalledOnValidThread()); | |
| 307 DCHECK(!prefixes.empty()); | |
| 308 DCHECK(!platforms.empty()); | |
| 309 DCHECK(!threat_entry_types.empty()); | |
| 310 DCHECK(!threat_types.empty()); | |
| 311 | |
| 312 // TODO(vakh): The following code currently relies on the PVer3 | |
| 313 // implementation but should not. This will be fixed after | |
| 314 // http://crbug.com/616647 is fixed. | |
| 315 std::vector<SBPrefix> pver3_prefixes; | |
| 316 for (const auto& prefix : prefixes) { | |
| 317 // This code assumes 4-byte hash prefixes but PVer4 prefixes can be longer. | |
| 318 SBPrefix pver3_prefix = | |
| 319 prefix[0] | prefix[1] << 8 | prefix[2] << 16 | prefix[3] << 24; | |
| 320 pver3_prefixes.push_back(pver3_prefix); | |
| 321 } | |
| 322 std::vector<PlatformType> platforms_list(platforms.begin(), platforms.end()); | |
| 323 | |
| 324 GetFullHashes(pver3_prefixes, platforms_list, *(threat_types.begin()), | |
| 325 callback); | |
|
Scott Hess - ex-Googler
2016/08/23 20:25:46
I'm a tiny bit nervous about DCHECK(!thread_types.
| |
| 326 } | |
| 327 | |
| 328 void V4GetHashProtocolManager::GetFullHashes( | |
| 301 const std::vector<SBPrefix>& prefixes, | 329 const std::vector<SBPrefix>& prefixes, |
| 302 const std::vector<PlatformType>& platforms, | 330 const std::vector<PlatformType>& platforms, |
| 303 ThreatType threat_type, | 331 ThreatType threat_type, |
| 304 FullHashCallback callback) { | 332 FullHashCallback callback) { |
| 305 DCHECK(CalledOnValidThread()); | 333 DCHECK(CalledOnValidThread()); |
| 306 // We need to wait the minimum waiting duration, and if we are in backoff, | 334 // We need to wait the minimum waiting duration, and if we are in backoff, |
| 307 // we need to check if we're past the next allowed time. If we are, we can | 335 // we need to check if we're past the next allowed time. If we are, we can |
| 308 // proceed with the request. If not, we are required to return empty results | 336 // proceed with the request. If not, we are required to return empty results |
| 309 // (i.e. treat the page as safe). | 337 // (i.e. treat the page as safe). |
| 310 if (clock_->Now() <= next_gethash_time_) { | 338 if (clock_->Now() <= next_gethash_time_) { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 409 | 437 |
| 410 void V4GetHashProtocolManager::GetHashUrlAndHeaders( | 438 void V4GetHashProtocolManager::GetHashUrlAndHeaders( |
| 411 const std::string& req_base64, | 439 const std::string& req_base64, |
| 412 GURL* gurl, | 440 GURL* gurl, |
| 413 net::HttpRequestHeaders* headers) const { | 441 net::HttpRequestHeaders* headers) const { |
| 414 V4ProtocolManagerUtil::GetRequestUrlAndHeaders(req_base64, "fullHashes:find", | 442 V4ProtocolManagerUtil::GetRequestUrlAndHeaders(req_base64, "fullHashes:find", |
| 415 config_, gurl, headers); | 443 config_, gurl, headers); |
| 416 } | 444 } |
| 417 | 445 |
| 418 } // namespace safe_browsing | 446 } // namespace safe_browsing |
| OLD | NEW |