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

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_util.cc

Issue 337723004: [Safe browsing] Clean up code to scan hash results for threats. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/safe_browsing/safe_browsing_util.h" 5 #include "chrome/browser/safe_browsing/safe_browsing_util.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 std::vector<std::string> hosts, paths; 458 std::vector<std::string> hosts, paths;
459 GenerateHostsToCheck(url, &hosts); 459 GenerateHostsToCheck(url, &hosts);
460 GeneratePathsToCheck(url, &paths); 460 GeneratePathsToCheck(url, &paths);
461 for (size_t h = 0; h < hosts.size(); ++h) { 461 for (size_t h = 0; h < hosts.size(); ++h) {
462 for (size_t p = 0; p < paths.size(); ++p) { 462 for (size_t p = 0; p < paths.size(); ++p) {
463 urls->push_back(hosts[h] + paths[p]); 463 urls->push_back(hosts[h] + paths[p]);
464 } 464 }
465 } 465 }
466 } 466 }
467 467
468 int GetHashIndex(const SBFullHash& hash,
469 const std::vector<SBFullHashResult>& full_hashes) {
470 for (size_t i = 0; i < full_hashes.size(); ++i) {
471 if (SBFullHashEqual(hash, full_hashes[i].hash))
472 return static_cast<int>(i);
473 }
474 return -1;
475 }
476
477 int GetUrlHashIndex(const GURL& url,
478 const std::vector<SBFullHashResult>& full_hashes) {
479 if (full_hashes.empty())
480 return -1;
481
482 std::vector<std::string> patterns;
483 GeneratePatternsToCheck(url, &patterns);
484
485 for (size_t i = 0; i < patterns.size(); ++i) {
486 SBFullHash key = SBFullHashForString(patterns[i]);
487 int index = GetHashIndex(key, full_hashes);
488 if (index != -1)
489 return index;
490 }
491 return -1;
492 }
493
494 GURL GeneratePhishingReportUrl(const std::string& report_page, 468 GURL GeneratePhishingReportUrl(const std::string& report_page,
495 const std::string& url_to_report, 469 const std::string& url_to_report,
496 bool is_client_side_detection) { 470 bool is_client_side_detection) {
497 const std::string current_esc = net::EscapeQueryParamValue(url_to_report, 471 const std::string current_esc = net::EscapeQueryParamValue(url_to_report,
498 true); 472 true);
499 473
500 #if defined(OS_WIN) 474 #if defined(OS_WIN)
501 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 475 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
502 std::string client_name(dist->GetSafeBrowsingName()); 476 std::string client_name(dist->GetSafeBrowsingName());
503 #else 477 #else
(...skipping 15 matching lines...) Expand all
519 memcpy(hash_out.full_hash, hash_in.data(), crypto::kSHA256Length); 493 memcpy(hash_out.full_hash, hash_in.data(), crypto::kSHA256Length);
520 return hash_out; 494 return hash_out;
521 } 495 }
522 496
523 std::string SBFullHashToString(const SBFullHash& hash) { 497 std::string SBFullHashToString(const SBFullHash& hash) {
524 DCHECK_EQ(crypto::kSHA256Length, sizeof(hash.full_hash)); 498 DCHECK_EQ(crypto::kSHA256Length, sizeof(hash.full_hash));
525 return std::string(hash.full_hash, sizeof(hash.full_hash)); 499 return std::string(hash.full_hash, sizeof(hash.full_hash));
526 } 500 }
527 501
528 } // namespace safe_browsing_util 502 } // namespace safe_browsing_util
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_util.h ('k') | chrome/browser/safe_browsing/safe_browsing_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698