| Index: url/scheme_host_port.cc
|
| diff --git a/url/scheme_host_port.cc b/url/scheme_host_port.cc
|
| index b9599865dd9f4e58ef7ffc63802efbad0aa313f4..94da494cff44ef8ddd0f2d0ec02a295122d41e37 100644
|
| --- a/url/scheme_host_port.cc
|
| +++ b/url/scheme_host_port.cc
|
| @@ -49,7 +49,8 @@ bool IsCanonicalHost(const base::StringPiece& host) {
|
|
|
| bool IsValidInput(const base::StringPiece& scheme,
|
| const base::StringPiece& host,
|
| - uint16_t port) {
|
| + uint16_t port,
|
| + bool is_canonicalized) {
|
| SchemeType scheme_type = SCHEME_WITH_PORT;
|
| bool is_standard = GetStandardSchemeType(
|
| scheme.data(),
|
| @@ -72,7 +73,10 @@ bool IsValidInput(const base::StringPiece& scheme,
|
| if (host.empty() || port == 0)
|
| return false;
|
|
|
| - if (!IsCanonicalHost(host))
|
| + // Don't do an expensive canonicalization if the host is already
|
| + // canonicalized.
|
| + DCHECK(!is_canonicalized || IsCanonicalHost(host));
|
| + if (!is_canonicalized && !IsCanonicalHost(host))
|
| return false;
|
|
|
| return true;
|
| @@ -84,7 +88,10 @@ bool IsValidInput(const base::StringPiece& scheme,
|
| return false;
|
| }
|
|
|
| - if (!IsCanonicalHost(host))
|
| + // Don't do an expensive canonicalization if the host is already
|
| + // canonicalized.
|
| + DCHECK(!is_canonicalized || IsCanonicalHost(host));
|
| + if (!is_canonicalized && !IsCanonicalHost(host))
|
| return false;
|
|
|
| return true;
|
| @@ -105,9 +112,10 @@ SchemeHostPort::SchemeHostPort() : port_(0) {
|
|
|
| SchemeHostPort::SchemeHostPort(base::StringPiece scheme,
|
| base::StringPiece host,
|
| - uint16_t port)
|
| + uint16_t port,
|
| + bool is_canonicalized)
|
| : port_(0) {
|
| - if (!IsValidInput(scheme, host, port))
|
| + if (!IsValidInput(scheme, host, port, is_canonicalized))
|
| return;
|
|
|
| scheme.CopyToString(&scheme_);
|
| @@ -115,6 +123,11 @@ SchemeHostPort::SchemeHostPort(base::StringPiece scheme,
|
| port_ = port;
|
| }
|
|
|
| +SchemeHostPort::SchemeHostPort(base::StringPiece scheme,
|
| + base::StringPiece host,
|
| + uint16_t port)
|
| + : SchemeHostPort(scheme, host, port, false /* is_canonicalized */) {}
|
| +
|
| SchemeHostPort::SchemeHostPort(const GURL& url) : port_(0) {
|
| if (!url.is_valid())
|
| return;
|
| @@ -127,7 +140,7 @@ SchemeHostPort::SchemeHostPort(const GURL& url) : port_(0) {
|
| if (port == PORT_UNSPECIFIED)
|
| port = 0;
|
|
|
| - if (!IsValidInput(scheme, host, port))
|
| + if (!IsValidInput(scheme, host, port, true /* is_canonicalized */))
|
| return;
|
|
|
| scheme.CopyToString(&scheme_);
|
|
|