| OLD | NEW |
| 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 #ifndef NET_BASE_HOST_PORT_PAIR_H_ | 5 #ifndef NET_BASE_HOST_PORT_PAIR_H_ |
| 6 #define NET_BASE_HOST_PORT_PAIR_H_ | 6 #define NET_BASE_HOST_PORT_PAIR_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "net/base/net_export.h" | 10 #include "net/base/net_export.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 if (port_ != other.port_) | 37 if (port_ != other.port_) |
| 38 return port_ < other.port_; | 38 return port_ < other.port_; |
| 39 return host_ < other.host_; | 39 return host_ < other.host_; |
| 40 } | 40 } |
| 41 | 41 |
| 42 // Equality test of contents. (Probably another violation of style guide). | 42 // Equality test of contents. (Probably another violation of style guide). |
| 43 bool Equals(const HostPortPair& other) const { | 43 bool Equals(const HostPortPair& other) const { |
| 44 return host_ == other.host_ && port_ == other.port_; | 44 return host_ == other.host_ && port_ == other.port_; |
| 45 } | 45 } |
| 46 | 46 |
| 47 bool IsEmpty() const { | 47 bool IsEmpty() const { return host_.empty() && port_ == 0; } |
| 48 return host_.empty() && port_ == 0; | |
| 49 } | |
| 50 | 48 |
| 51 const std::string& host() const { | 49 const std::string& host() const { return host_; } |
| 52 return host_; | |
| 53 } | |
| 54 | 50 |
| 55 uint16 port() const { | 51 uint16 port() const { return port_; } |
| 56 return port_; | |
| 57 } | |
| 58 | 52 |
| 59 void set_host(const std::string& in_host) { | 53 void set_host(const std::string& in_host) { host_ = in_host; } |
| 60 host_ = in_host; | |
| 61 } | |
| 62 | 54 |
| 63 void set_port(uint16 in_port) { | 55 void set_port(uint16 in_port) { port_ = in_port; } |
| 64 port_ = in_port; | |
| 65 } | |
| 66 | 56 |
| 67 // ToString() will convert the HostPortPair to "host:port". If |host_| is an | 57 // ToString() will convert the HostPortPair to "host:port". If |host_| is an |
| 68 // IPv6 literal, it will add brackets around |host_|. | 58 // IPv6 literal, it will add brackets around |host_|. |
| 69 std::string ToString() const; | 59 std::string ToString() const; |
| 70 | 60 |
| 71 // Returns |host_|, adding IPv6 brackets if needed. | 61 // Returns |host_|, adding IPv6 brackets if needed. |
| 72 std::string HostForURL() const; | 62 std::string HostForURL() const; |
| 73 | 63 |
| 74 private: | 64 private: |
| 75 // If |host_| represents an IPv6 address, this string will not contain | 65 // If |host_| represents an IPv6 address, this string will not contain |
| 76 // brackets around the address. | 66 // brackets around the address. |
| 77 std::string host_; | 67 std::string host_; |
| 78 uint16 port_; | 68 uint16 port_; |
| 79 }; | 69 }; |
| 80 | 70 |
| 81 } // namespace net | 71 } // namespace net |
| 82 | 72 |
| 83 #endif // NET_BASE_HOST_PORT_PAIR_H_ | 73 #endif // NET_BASE_HOST_PORT_PAIR_H_ |
| OLD | NEW |