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

Side by Side Diff: components/safe_browsing_db/util.cc

Issue 1569673002: [NOT FOR LANDING] Detailed loading traces Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 9 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
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 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/util.h" 5 #include "components/safe_browsing_db/util.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/trace_event/trace_event.h"
9 #include "base/macros.h" 10 #include "base/macros.h"
10 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
11 #include "base/trace_event/trace_event.h" 12 #include "base/trace_event/trace_event.h"
12 #include "crypto/sha2.h" 13 #include "crypto/sha2.h"
13 #include "net/base/escape.h" 14 #include "net/base/escape.h"
14 #include "url/gurl.h" 15 #include "url/gurl.h"
15 #include "url/url_util.h" 16 #include "url/url_util.h"
16 17
17 namespace safe_browsing { 18 namespace safe_browsing {
18 19
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 } 311 }
311 if (canonicalized_query && final_parsed.query.len > 0) { 312 if (canonicalized_query && final_parsed.query.len > 0) {
312 *canonicalized_query = escaped_canon_url_str.substr( 313 *canonicalized_query = escaped_canon_url_str.substr(
313 final_parsed.query.begin, final_parsed.query.len); 314 final_parsed.query.begin, final_parsed.query.len);
314 } 315 }
315 } 316 }
316 317
317 void UrlToFullHashes(const GURL& url, 318 void UrlToFullHashes(const GURL& url,
318 bool include_whitelist_hashes, 319 bool include_whitelist_hashes,
319 std::vector<SBFullHash>* full_hashes) { 320 std::vector<SBFullHash>* full_hashes) {
321 TRACE_EVENT0("toplevel", "UrlToFullHashes");
320 // Include this function in traces because it's not cheap so it should be 322 // Include this function in traces because it's not cheap so it should be
321 // called sparingly. 323 // called sparingly.
322 TRACE_EVENT2("loader", "safe_browsing::UrlToFullHashes", "url", url.spec(), 324 TRACE_EVENT2("loader", "safe_browsing::UrlToFullHashes", "url", url.spec(),
323 "include_whitelist_hashes", include_whitelist_hashes); 325 "include_whitelist_hashes", include_whitelist_hashes);
324 std::vector<std::string> hosts; 326 std::vector<std::string> hosts;
325 if (url.HostIsIPAddress()) { 327 if (url.HostIsIPAddress()) {
326 hosts.push_back(url.host()); 328 hosts.push_back(url.host());
327 } else { 329 } else {
328 GenerateHostsToCheck(url, &hosts); 330 GenerateHostsToCheck(url, &hosts);
329 } 331 }
(...skipping 12 matching lines...) Expand all
342 if (include_whitelist_hashes && path.size() > 1 && 344 if (include_whitelist_hashes && path.size() > 1 &&
343 path[path.size() - 1] == '/') { 345 path[path.size() - 1] == '/') {
344 full_hashes->push_back(SBFullHashForString( 346 full_hashes->push_back(SBFullHashForString(
345 host + path.substr(0, path.size() - 1))); 347 host + path.substr(0, path.size() - 1)));
346 } 348 }
347 } 349 }
348 } 350 }
349 } 351 }
350 352
351 void GenerateHostsToCheck(const GURL& url, std::vector<std::string>* hosts) { 353 void GenerateHostsToCheck(const GURL& url, std::vector<std::string>* hosts) {
354 TRACE_EVENT0("toplevel", "GenerateHostsToCheck");
355
352 hosts->clear(); 356 hosts->clear();
353 357
354 std::string canon_host; 358 std::string canon_host;
355 CanonicalizeUrl(url, &canon_host, NULL, NULL); 359 CanonicalizeUrl(url, &canon_host, NULL, NULL);
356 360
357 const std::string host = canon_host; // const sidesteps GCC bugs below! 361 const std::string host = canon_host; // const sidesteps GCC bugs below!
358 if (host.empty()) 362 if (host.empty())
359 return; 363 return;
360 364
361 // Per the Safe Browsing Protocol v2 spec, we try the host, and also up to 4 365 // Per the Safe Browsing Protocol v2 spec, we try the host, and also up to 4
(...skipping 17 matching lines...) Expand all
379 if (skipped_last_component) 383 if (skipped_last_component)
380 hosts->push_back(std::string(i.base(), host.end())); 384 hosts->push_back(std::string(i.base(), host.end()));
381 else 385 else
382 skipped_last_component = true; 386 skipped_last_component = true;
383 } 387 }
384 } 388 }
385 hosts->push_back(host); 389 hosts->push_back(host);
386 } 390 }
387 391
388 void GeneratePathsToCheck(const GURL& url, std::vector<std::string>* paths) { 392 void GeneratePathsToCheck(const GURL& url, std::vector<std::string>* paths) {
393 TRACE_EVENT0("toplevel", "GeneratePathsToCheck");
394
389 paths->clear(); 395 paths->clear();
390 396
391 std::string canon_path; 397 std::string canon_path;
392 std::string canon_query; 398 std::string canon_query;
393 CanonicalizeUrl(url, NULL, &canon_path, &canon_query); 399 CanonicalizeUrl(url, NULL, &canon_path, &canon_query);
394 400
395 const std::string path = canon_path; // const sidesteps GCC bugs below! 401 const std::string path = canon_path; // const sidesteps GCC bugs below!
396 const std::string query = canon_query; 402 const std::string query = canon_query;
397 if (path.empty()) 403 if (path.empty())
398 return; 404 return;
(...skipping 22 matching lines...) Expand all
421 GenerateHostsToCheck(url, &hosts); 427 GenerateHostsToCheck(url, &hosts);
422 GeneratePathsToCheck(url, &paths); 428 GeneratePathsToCheck(url, &paths);
423 for (size_t h = 0; h < hosts.size(); ++h) { 429 for (size_t h = 0; h < hosts.size(); ++h) {
424 for (size_t p = 0; p < paths.size(); ++p) { 430 for (size_t p = 0; p < paths.size(); ++p) {
425 urls->push_back(hosts[h] + paths[p]); 431 urls->push_back(hosts[h] + paths[p]);
426 } 432 }
427 } 433 }
428 } 434 }
429 435
430 } // namespace safe_browsing 436 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « components/safe_browsing_db/remote_database_manager.cc ('k') | content/browser/devtools/devtools_netlog_observer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698