diff options
author | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-22 22:20:35 +0000 |
---|---|---|
committer | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-22 22:20:35 +0000 |
commit | 2fbaecf27edd63f4f760581b798a99dcdf78a5eb (patch) | |
tree | a974662967015c83e63ccd7944aac2d2dc784b8f /net/proxy | |
parent | a063c102fd36f61f4a0a01447f4b01ace4ffccdf (diff) | |
download | chromium_src-2fbaecf27edd63f4f760581b798a99dcdf78a5eb.zip chromium_src-2fbaecf27edd63f4f760581b798a99dcdf78a5eb.tar.gz chromium_src-2fbaecf27edd63f4f760581b798a99dcdf78a5eb.tar.bz2 |
Net: Get rid of ProxyServer::host_and_port() and friends.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/3032017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@53403 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/proxy')
-rw-r--r-- | net/proxy/proxy_server.cc | 52 | ||||
-rw-r--r-- | net/proxy/proxy_server.h | 30 | ||||
-rw-r--r-- | net/proxy/proxy_server_unittest.cc | 24 |
3 files changed, 29 insertions, 77 deletions
diff --git a/net/proxy/proxy_server.cc b/net/proxy/proxy_server.cc index b78c347..792a47d 100644 --- a/net/proxy/proxy_server.cc +++ b/net/proxy/proxy_server.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -60,39 +60,25 @@ ProxyServer::Scheme GetSchemeFromURI(std::string::const_iterator begin, return ProxyServer::SCHEME_INVALID; } -} // namespace - -std::string ProxyServer::HostNoBrackets() const { - // Doesn't make sense to call this if the URI scheme doesn't - // have concept of a host. - DCHECK(is_valid() && !is_direct()); - +std::string HostNoBrackets(const std::string& host) { // Remove brackets from an RFC 2732-style IPv6 literal address. - const std::string::size_type len = host_.size(); - if (len != 0 && host_[0] == '[' && host_[len - 1] == ']') - return host_.substr(1, len - 2); - return host_; + const std::string::size_type len = host.size(); + if (len >= 2 && host[0] == '[' && host[len - 1] == ']') + return host.substr(1, len - 2); + return host; } -int ProxyServer::port() const { - // Doesn't make sense to call this if the URI scheme doesn't - // have concept of a port. - DCHECK(is_valid() && !is_direct()); - return port_; -} +} // namespace -std::string ProxyServer::host_and_port() const { - // Doesn't make sense to call this if the URI scheme doesn't - // have concept of a host. - DCHECK(is_valid() && !is_direct()); - return host_ + ":" + IntToString(port_); +ProxyServer::ProxyServer(Scheme scheme, const std::string& host, int port) + : scheme_(scheme), host_port_pair_(HostNoBrackets(host), port) { } -HostPortPair ProxyServer::host_port_pair() const { +const HostPortPair& ProxyServer::host_port_pair() const { // Doesn't make sense to call this if the URI scheme doesn't // have concept of a host. DCHECK(is_valid() && !is_direct()); - return HostPortPair(host_, port_); + return host_port_pair_; } // static @@ -131,13 +117,13 @@ std::string ProxyServer::ToURI() const { return "direct://"; case SCHEME_HTTP: // Leave off "http://" since it is our default scheme. - return host_and_port(); + return host_port_pair().ToString(); case SCHEME_SOCKS4: - return std::string("socks4://") + host_and_port(); + return std::string("socks4://") + host_port_pair().ToString(); case SCHEME_SOCKS5: - return std::string("socks5://") + host_and_port(); + return std::string("socks5://") + host_port_pair().ToString(); case SCHEME_HTTPS: - return std::string("https://") + host_and_port(); + return std::string("https://") + host_port_pair().ToString(); default: // Got called with an invalid scheme. NOTREACHED(); @@ -180,14 +166,14 @@ std::string ProxyServer::ToPacString() const { case SCHEME_DIRECT: return "DIRECT"; case SCHEME_HTTP: - return std::string("PROXY ") + host_and_port(); + return std::string("PROXY ") + host_port_pair().ToString(); case SCHEME_SOCKS4: // For compatibility send SOCKS instead of SOCKS4. - return std::string("SOCKS ") + host_and_port(); + return std::string("SOCKS ") + host_port_pair().ToString(); case SCHEME_SOCKS5: - return std::string("SOCKS5 ") + host_and_port(); + return std::string("SOCKS5 ") + host_port_pair().ToString(); case SCHEME_HTTPS: - return std::string("HTTPS ") + host_and_port(); + return std::string("HTTPS ") + host_port_pair().ToString(); default: // Got called with an invalid scheme. NOTREACHED(); diff --git a/net/proxy/proxy_server.h b/net/proxy/proxy_server.h index 3d5593c..ea06188 100644 --- a/net/proxy/proxy_server.h +++ b/net/proxy/proxy_server.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -35,12 +35,12 @@ class ProxyServer { // Default copy-constructor and assignment operator are OK! // Constructs an invalid ProxyServer. - ProxyServer() : scheme_(SCHEME_INVALID), port_(-1) {} + ProxyServer() : scheme_(SCHEME_INVALID) {} + // TODO(thestig) Replace |host| and |port| with HostPortPair. // If |host| is an IPv6 literal address, it must include the square // brackets. - ProxyServer(Scheme scheme, const std::string& host, int port) - : scheme_(scheme), host_(host), port_(port) {} + ProxyServer(Scheme scheme, const std::string& host, int port); bool is_valid() const { return scheme_ != SCHEME_INVALID; } @@ -61,21 +61,7 @@ class ProxyServer { return scheme_ == SCHEME_SOCKS4 || scheme_ == SCHEME_SOCKS5; } - // Gets the host portion of the proxy server. If the host portion is an - // IPv6 literal address, the return value does not include the square - // brackets ([]) used to separate it from the port portion. - std::string HostNoBrackets() const; - - // Gets the port portion of the proxy server. - int port() const; - - // Returns the <host>":"<port> string for the proxy server. - // TODO(willchan): Remove in favor of host_port_pair(). - std::string host_and_port() const; - - // TODO(willchan): Change to const HostPortPair& after refactoring |host_| and - // |port_| here. - HostPortPair host_port_pair() const; + const HostPortPair& host_port_pair() const; // Parses from an input with format: // [<scheme>"://"]<server>[":"<port>] @@ -145,8 +131,7 @@ class ProxyServer { bool operator==(const ProxyServer& other) const { return scheme_ == other.scheme_ && - host_ == other.host_ && - port_ == other.port_; + host_port_pair_.Equals(other.host_port_pair_); } private: @@ -158,8 +143,7 @@ class ProxyServer { std::string::const_iterator host_and_port_end); Scheme scheme_; - std::string host_; - int port_; + HostPortPair host_port_pair_; }; } // namespace net diff --git a/net/proxy/proxy_server_unittest.cc b/net/proxy/proxy_server_unittest.cc index f91ad66..04f0770 100644 --- a/net/proxy/proxy_server_unittest.cc +++ b/net/proxy/proxy_server_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -16,7 +16,6 @@ TEST(ProxyServerTest, FromURI) { net::ProxyServer::Scheme expected_scheme; const char* expected_host; int expected_port; - const char* expected_host_and_port; const char* expected_pac_string; } tests[] = { // HTTP proxy URIs: @@ -26,7 +25,6 @@ TEST(ProxyServerTest, FromURI) { net::ProxyServer::SCHEME_HTTP, "foopy", 10, - "foopy:10", "PROXY foopy:10" }, { @@ -35,7 +33,6 @@ TEST(ProxyServerTest, FromURI) { net::ProxyServer::SCHEME_HTTP, "foopy", 80, - "foopy:80", "PROXY foopy:80" }, { @@ -44,7 +41,6 @@ TEST(ProxyServerTest, FromURI) { net::ProxyServer::SCHEME_HTTP, "foopy", 10, - "foopy:10", "PROXY foopy:10" }, @@ -55,7 +51,6 @@ TEST(ProxyServerTest, FromURI) { net::ProxyServer::SCHEME_HTTP, "FEDC:BA98:7654:3210:FEDC:BA98:7654:3210", 10, - "[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:10", "PROXY [FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:10" }, { @@ -64,7 +59,6 @@ TEST(ProxyServerTest, FromURI) { net::ProxyServer::SCHEME_HTTP, "3ffe:2a00:100:7031::1", 80, - "[3ffe:2a00:100:7031::1]:80", "PROXY [3ffe:2a00:100:7031::1]:80" }, { @@ -73,7 +67,6 @@ TEST(ProxyServerTest, FromURI) { net::ProxyServer::SCHEME_HTTP, "::192.9.5.5", 80, - "[::192.9.5.5]:80", "PROXY [::192.9.5.5]:80" }, { @@ -82,7 +75,6 @@ TEST(ProxyServerTest, FromURI) { net::ProxyServer::SCHEME_HTTP, "::FFFF:129.144.52.38", 80, - "[::FFFF:129.144.52.38]:80", "PROXY [::FFFF:129.144.52.38]:80" }, @@ -93,7 +85,6 @@ TEST(ProxyServerTest, FromURI) { net::ProxyServer::SCHEME_SOCKS4, "foopy", 1080, - "foopy:1080", "SOCKS foopy:1080" }, { @@ -102,7 +93,6 @@ TEST(ProxyServerTest, FromURI) { net::ProxyServer::SCHEME_SOCKS4, "foopy", 10, - "foopy:10", "SOCKS foopy:10" }, @@ -113,7 +103,6 @@ TEST(ProxyServerTest, FromURI) { net::ProxyServer::SCHEME_SOCKS5, "foopy", 1080, - "foopy:1080", "SOCKS5 foopy:1080" }, { @@ -122,7 +111,6 @@ TEST(ProxyServerTest, FromURI) { net::ProxyServer::SCHEME_SOCKS5, "foopy", 10, - "foopy:10", "SOCKS5 foopy:10" }, @@ -133,7 +121,6 @@ TEST(ProxyServerTest, FromURI) { net::ProxyServer::SCHEME_SOCKS4, "foopy", 1080, - "foopy:1080", "SOCKS foopy:1080" }, { @@ -142,7 +129,6 @@ TEST(ProxyServerTest, FromURI) { net::ProxyServer::SCHEME_SOCKS4, "foopy", 10, - "foopy:10", "SOCKS foopy:10" }, @@ -153,7 +139,6 @@ TEST(ProxyServerTest, FromURI) { net::ProxyServer::SCHEME_HTTPS, "foopy", 443, - "foopy:443", "HTTPS foopy:443" }, { @@ -162,7 +147,6 @@ TEST(ProxyServerTest, FromURI) { net::ProxyServer::SCHEME_HTTPS, "foopy", 10, - "foopy:10", "HTTPS foopy:10" }, { @@ -171,7 +155,6 @@ TEST(ProxyServerTest, FromURI) { net::ProxyServer::SCHEME_HTTPS, "1.2.3.4", 10, - "1.2.3.4:10", "HTTPS 1.2.3.4:10" }, }; @@ -184,9 +167,8 @@ TEST(ProxyServerTest, FromURI) { EXPECT_FALSE(uri.is_direct()); EXPECT_EQ(tests[i].expected_uri, uri.ToURI()); EXPECT_EQ(tests[i].expected_scheme, uri.scheme()); - EXPECT_EQ(tests[i].expected_host, uri.HostNoBrackets()); - EXPECT_EQ(tests[i].expected_port, uri.port()); - EXPECT_EQ(tests[i].expected_host_and_port, uri.host_and_port()); + EXPECT_EQ(tests[i].expected_host, uri.host_port_pair().host()); + EXPECT_EQ(tests[i].expected_port, uri.host_port_pair().port()); EXPECT_EQ(tests[i].expected_pac_string, uri.ToPacString()); } } |