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

Side by Side Diff: net/base/registry_controlled_domains/registry_controlled_domain.cc

Issue 2612313003: Optimize SameDomainOrHost via a fast-fail path
Patch Set: Created 3 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // NB: Modelled after Mozilla's code (originally written by Pamela Greene, 5 // NB: Modelled after Mozilla's code (originally written by Pamela Greene,
6 // later modified by others), but almost entirely rewritten for Chrome. 6 // later modified by others), but almost entirely rewritten for Chrome.
7 // (netwerk/dns/src/nsEffectiveTLDService.cpp) 7 // (netwerk/dns/src/nsEffectiveTLDService.cpp)
8 /* ***** BEGIN LICENSE BLOCK ***** 8 /* ***** BEGIN LICENSE BLOCK *****
9 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 9 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
10 * 10 *
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 PrivateRegistryFilter filter) { 314 PrivateRegistryFilter filter) {
315 // Quickly reject cases where either host is empty. 315 // Quickly reject cases where either host is empty.
316 if (host1.empty() || host2.empty()) 316 if (host1.empty() || host2.empty())
317 return false; 317 return false;
318 318
319 // Check for exact host matches, which is faster than looking up the domain 319 // Check for exact host matches, which is faster than looking up the domain
320 // and registry. 320 // and registry.
321 if (host1 == host2) 321 if (host1 == host2)
322 return true; 322 return true;
323 323
324 // Check for a domain and registry match. 324 const base::StringPiece domain1 =
325 const base::StringPiece& domain1 =
326 GetDomainAndRegistryAsStringPiece(host1, filter); 325 GetDomainAndRegistryAsStringPiece(host1, filter);
327 return !domain1.empty() && 326
328 (domain1 == GetDomainAndRegistryAsStringPiece(host2, filter)); 327 // If |domain1| is empty, |host1| either matched no rules in the registry,
328 // or is an IP literal. Since |host2| and |host1| are known to differ,
329 // they can't possibly be same-origin.
330 if (domain1.empty())
331 return false;
332
333 // Fail fast before computing |domain2|, if possible, by checking to see if
334 // |domain1| is a suffix of |host2|. This is a necessary but not sufficient
335 // condition for |domain1| and |domain2| to be equal.
336 if (!base::EndsWith(host2, domain1, base::CompareCase::SENSITIVE))
Ryan Sleevi 2017/01/06 00:38:16 Unclear if you're doing sensitive as an optimizati
337 return false;
338
339 const base::StringPiece domain2 =
340 GetDomainAndRegistryAsStringPiece(host2, filter);
341
342 // We already verified that |domain1| is a suffix of |host2|. And |domain2| is
343 // also a suffix of |host2|, by construction. So if their lengths are equal,
344 // they are identical.
345 return domain2.length() == domain1.length();
329 } 346 }
330 347
331 } // namespace 348 } // namespace
332 349
333 std::string GetDomainAndRegistry(const GURL& gurl, 350 std::string GetDomainAndRegistry(const GURL& gurl,
334 PrivateRegistryFilter filter) { 351 PrivateRegistryFilter filter) {
335 return GetDomainAndRegistryAsStringPiece(gurl.host_piece(), filter) 352 return GetDomainAndRegistryAsStringPiece(gurl.host_piece(), filter)
336 .as_string(); 353 .as_string();
337 } 354 }
338 355
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 452
436 void SetFindDomainGraph(const unsigned char* domains, size_t length) { 453 void SetFindDomainGraph(const unsigned char* domains, size_t length) {
437 CHECK(domains); 454 CHECK(domains);
438 CHECK_NE(length, 0u); 455 CHECK_NE(length, 0u);
439 g_graph = domains; 456 g_graph = domains;
440 g_graph_length = length; 457 g_graph_length = length;
441 } 458 }
442 459
443 } // namespace registry_controlled_domains 460 } // namespace registry_controlled_domains
444 } // namespace net 461 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698