summaryrefslogtreecommitdiffstats
path: root/net/base
diff options
context:
space:
mode:
authorthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-22 22:20:35 +0000
committerthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-22 22:20:35 +0000
commit2fbaecf27edd63f4f760581b798a99dcdf78a5eb (patch)
treea974662967015c83e63ccd7944aac2d2dc784b8f /net/base
parenta063c102fd36f61f4a0a01447f4b01ace4ffccdf (diff)
downloadchromium_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/base')
-rw-r--r--net/base/host_mapping_rules.cc8
-rw-r--r--net/base/host_mapping_rules.h4
-rw-r--r--net/base/host_mapping_rules_unittest.cc16
-rw-r--r--net/base/host_port_pair.cc12
-rw-r--r--net/base/host_port_pair.h41
-rw-r--r--net/base/mapped_host_resolver.cc4
6 files changed, 52 insertions, 33 deletions
diff --git a/net/base/host_mapping_rules.cc b/net/base/host_mapping_rules.cc
index 3296b0e..ab560a7 100644
--- a/net/base/host_mapping_rules.cc
+++ b/net/base/host_mapping_rules.cc
@@ -19,7 +19,7 @@ bool HostMappingRules::RewriteHost(HostPortPair* host_port) const {
for (ExclusionRuleList::const_iterator it = exclusion_rules_.begin();
it != exclusion_rules_.end(); ++it) {
const ExclusionRule& rule = *it;
- if (MatchPatternASCII(host_port->host, rule.hostname_pattern))
+ if (MatchPatternASCII(host_port->host(), rule.hostname_pattern))
return false;
}
@@ -28,12 +28,12 @@ bool HostMappingRules::RewriteHost(HostPortPair* host_port) const {
it != map_rules_.end(); ++it) {
const MapRule& rule = *it;
- if (!MatchPatternASCII(host_port->host, rule.hostname_pattern))
+ if (!MatchPatternASCII(host_port->host(), rule.hostname_pattern))
continue; // This rule doesn't apply.
- host_port->host = rule.replacement_hostname;
+ host_port->set_host(rule.replacement_hostname);
if (rule.replacement_port != -1)
- host_port->port = rule.replacement_port;
+ host_port->set_port(rule.replacement_port);
return true;
}
diff --git a/net/base/host_mapping_rules.h b/net/base/host_mapping_rules.h
index a754a47..e9b3484 100644
--- a/net/base/host_mapping_rules.h
+++ b/net/base/host_mapping_rules.h
@@ -11,12 +11,12 @@
namespace net {
-struct HostPortPair;
+class HostPortPair;
class HostMappingRules {
public:
HostMappingRules();
-
+
// Modifies |*host_port| based on the current rules. Returns true if the
// RequestInfo was modified, false otherwise.
bool RewriteHost(HostPortPair* host_port) const;
diff --git a/net/base/host_mapping_rules_unittest.cc b/net/base/host_mapping_rules_unittest.cc
index 0cea821..09e7f45 100644
--- a/net/base/host_mapping_rules_unittest.cc
+++ b/net/base/host_mapping_rules_unittest.cc
@@ -18,23 +18,23 @@ TEST(HostMappingRulesTest, SetRulesFromString) {
HostPortPair host_port("test", 1234);
EXPECT_FALSE(rules.RewriteHost(&host_port));
- EXPECT_EQ("test", host_port.host);
- EXPECT_EQ(1234u, host_port.port);
+ EXPECT_EQ("test", host_port.host());
+ EXPECT_EQ(1234u, host_port.port());
host_port = HostPortPair("chrome.net", 80);
EXPECT_TRUE(rules.RewriteHost(&host_port));
- EXPECT_EQ("bar", host_port.host);
- EXPECT_EQ(60u, host_port.port);
+ EXPECT_EQ("bar", host_port.host());
+ EXPECT_EQ(60u, host_port.port());
host_port = HostPortPair("crack.com", 80);
EXPECT_TRUE(rules.RewriteHost(&host_port));
- EXPECT_EQ("baz", host_port.host);
- EXPECT_EQ(80u, host_port.port);
+ EXPECT_EQ("baz", host_port.host());
+ EXPECT_EQ(80u, host_port.port());
host_port = HostPortPair("wtf.foo.com", 666);
EXPECT_FALSE(rules.RewriteHost(&host_port));
- EXPECT_EQ("wtf.foo.com", host_port.host);
- EXPECT_EQ(666u, host_port.port);
+ EXPECT_EQ("wtf.foo.com", host_port.host());
+ EXPECT_EQ(666u, host_port.port());
}
// Parsing bad rules should silently discard the rule (and never crash).
diff --git a/net/base/host_port_pair.cc b/net/base/host_port_pair.cc
index d4e7d4e..645d958 100644
--- a/net/base/host_port_pair.cc
+++ b/net/base/host_port_pair.cc
@@ -7,15 +7,17 @@
namespace net {
-HostPortPair::HostPortPair() : port(0) {}
+HostPortPair::HostPortPair() : port_(0) {}
HostPortPair::HostPortPair(const std::string& in_host, uint16 in_port)
- : host(in_host), port(in_port) {}
+ : host_(in_host), port_(in_port) {}
std::string HostPortPair::ToString() const {
// Check to see if the host is an IPv6 address. If so, added brackets.
- if (host.find(':') != std::string::npos)
- return StringPrintf("[%s]:%u", host.c_str(), port);
- return StringPrintf("%s:%u", host.c_str(), port);
+ if (host_.find(':') != std::string::npos) {
+ DCHECK_NE(host_[0], '[');
+ return StringPrintf("[%s]:%u", host_.c_str(), port_);
+ }
+ return StringPrintf("%s:%u", host_.c_str(), port_);
}
} // namespace net
diff --git a/net/base/host_port_pair.h b/net/base/host_port_pair.h
index 78f74ea..7c1d33f 100644
--- a/net/base/host_port_pair.h
+++ b/net/base/host_port_pair.h
@@ -10,33 +10,50 @@
namespace net {
-struct HostPortPair {
+class HostPortPair {
+ public:
HostPortPair();
// If |in_host| represents an IPv6 address, it should not bracket the address.
HostPortPair(const std::string& in_host, uint16 in_port);
// TODO(willchan): Define a functor instead.
// Comparator function so this can be placed in a std::map.
- // TODO(jar): Violation of style guide, and should be removed.
bool operator<(const HostPortPair& other) const {
- if (port != other.port)
- return port < other.port;
- return host < other.host;
+ if (port_ != other.port_)
+ return port_ < other.port_;
+ return host_ < other.host_;
}
// Equality test of contents. (Probably another violation of style guide).
bool Equals(const HostPortPair& other) const {
- return host == other.host && port == other.port;
+ return host_ == other.host_ && port_ == other.port_;
}
- // ToString() will convert the HostPortPair to "host:port". If |host| is an
- // IPv6 literal, it will add brackets around |host|.
+ const std::string& host() const {
+ return host_;
+ }
+
+ uint16 port() const {
+ return port_;
+ }
+
+ void set_host(const std::string& in_host) {
+ host_ = in_host;
+ }
+
+ void set_port(uint16 in_port) {
+ port_ = in_port;
+ }
+
+ // ToString() will convert the HostPortPair to "host:port". If |host_| is an
+ // IPv6 literal, it will add brackets around |host_|.
std::string ToString() const;
- // If |host| represents an IPv6 address, this string will not contain brackets
- // around the address.
- std::string host;
- uint16 port;
+ private:
+ // If |host_| represents an IPv6 address, this string will not contain
+ // brackets around the address.
+ std::string host_;
+ uint16 port_;
};
} // namespace net
diff --git a/net/base/mapped_host_resolver.cc b/net/base/mapped_host_resolver.cc
index b401917..0349232 100644
--- a/net/base/mapped_host_resolver.cc
+++ b/net/base/mapped_host_resolver.cc
@@ -24,8 +24,8 @@ int MappedHostResolver::Resolve(const RequestInfo& info,
RequestInfo modified_info = info;
HostPortPair host_port(info.hostname(), info.port());
if (rules_.RewriteHost(&host_port)) {
- modified_info.set_hostname(host_port.host);
- modified_info.set_port(host_port.port);
+ modified_info.set_hostname(host_port.host());
+ modified_info.set_port(host_port.port());
}
return impl_->Resolve(modified_info, addresses, callback, out_req, net_log);
}