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

Side by Side Diff: components/google/core/browser/google_util.cc

Issue 2495773003: Fast path for google_util::IsValidHostName (Closed)
Patch Set: Created 4 years, 1 month 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/google/core/browser/google_util.h" 5 #include "components/google/core/browser/google_util.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 bool IsPathHomePageBase(base::StringPiece path) { 43 bool IsPathHomePageBase(base::StringPiece path) {
44 return (path == "/") || (path == "/webhp"); 44 return (path == "/") || (path == "/webhp");
45 } 45 }
46 46
47 // True if the given canonical |host| is "[www.]<domain_in_lower_case>.<TLD>" 47 // True if the given canonical |host| is "[www.]<domain_in_lower_case>.<TLD>"
48 // with a valid TLD. If |subdomain_permission| is ALLOW_SUBDOMAIN, we check 48 // with a valid TLD. If |subdomain_permission| is ALLOW_SUBDOMAIN, we check
49 // against host "*.<domain_in_lower_case>.<TLD>" instead. 49 // against host "*.<domain_in_lower_case>.<TLD>" instead.
50 bool IsValidHostName(base::StringPiece host, 50 bool IsValidHostName(base::StringPiece host,
51 base::StringPiece domain_in_lower_case, 51 base::StringPiece domain_in_lower_case,
52 SubdomainPermission subdomain_permission) { 52 SubdomainPermission subdomain_permission) {
53 // Fast path to avoid searching the registry set.
54 if (host.find(domain_in_lower_case) == base::StringPiece::npos)
55 return false;
53 size_t tld_length = 56 size_t tld_length =
54 net::registry_controlled_domains::GetCanonicalHostRegistryLength( 57 net::registry_controlled_domains::GetCanonicalHostRegistryLength(
55 host, net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, 58 host, net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES,
56 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); 59 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES);
57 if ((tld_length == 0) || (tld_length == std::string::npos)) 60 if ((tld_length == 0) || (tld_length == std::string::npos))
58 return false; 61 return false;
59 62
60 // Removes the tld and the preceding dot. 63 // Removes the tld and the preceding dot.
61 base::StringPiece host_minus_tld = 64 base::StringPiece host_minus_tld =
62 host.substr(0, host.length() - tld_length - 1); 65 host.substr(0, host.length() - tld_length - 1);
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 } 230 }
228 231
229 bool IsYoutubeDomainUrl(const GURL& url, 232 bool IsYoutubeDomainUrl(const GURL& url,
230 SubdomainPermission subdomain_permission, 233 SubdomainPermission subdomain_permission,
231 PortPermission port_permission) { 234 PortPermission port_permission) {
232 return IsValidURL(url, port_permission) && 235 return IsValidURL(url, port_permission) &&
233 IsValidHostName(url.host_piece(), "youtube", subdomain_permission); 236 IsValidHostName(url.host_piece(), "youtube", subdomain_permission);
234 } 237 }
235 238
236 } // namespace google_util 239 } // namespace google_util
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