| 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" |
| 11 | 11 |
| 12 class GURL; | 12 class GURL; |
| 13 | 13 |
| 14 namespace net { | 14 namespace net { |
| 15 | 15 |
| 16 class IPEndPoint; | 16 class IPEndPoint; |
| 17 | 17 |
| 18 class NET_EXPORT HostPortPair { | 18 class NET_EXPORT HostPortPair { |
| 19 public: | 19 public: |
| 20 HostPortPair(); | 20 HostPortPair(); |
| 21 // If |in_host| represents an IPv6 address, it should not bracket the address. | 21 // If |in_host| represents an IPv6 address, it should not bracket the address. |
| 22 HostPortPair(const std::string& in_host, uint16 in_port); | 22 HostPortPair(const std::string& in_host, uint16_t in_port); |
| 23 | 23 |
| 24 // Creates a HostPortPair for the origin of |url|. | 24 // Creates a HostPortPair for the origin of |url|. |
| 25 static HostPortPair FromURL(const GURL& url); | 25 static HostPortPair FromURL(const GURL& url); |
| 26 | 26 |
| 27 // Creates a HostPortPair from an IPEndPoint. | 27 // Creates a HostPortPair from an IPEndPoint. |
| 28 static HostPortPair FromIPEndPoint(const IPEndPoint& ipe); | 28 static HostPortPair FromIPEndPoint(const IPEndPoint& ipe); |
| 29 | 29 |
| 30 // Creates a HostPortPair from a string formatted in same manner as | 30 // Creates a HostPortPair from a string formatted in same manner as |
| 31 // ToString(). | 31 // ToString(). |
| 32 static HostPortPair FromString(const std::string& str); | 32 static HostPortPair FromString(const std::string& str); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 45 } | 45 } |
| 46 | 46 |
| 47 bool IsEmpty() const { | 47 bool IsEmpty() const { |
| 48 return host_.empty() && port_ == 0; | 48 return host_.empty() && port_ == 0; |
| 49 } | 49 } |
| 50 | 50 |
| 51 const std::string& host() const { | 51 const std::string& host() const { |
| 52 return host_; | 52 return host_; |
| 53 } | 53 } |
| 54 | 54 |
| 55 uint16 port() const { | 55 uint16_t port() const { return port_; } |
| 56 return port_; | |
| 57 } | |
| 58 | 56 |
| 59 void set_host(const std::string& in_host) { | 57 void set_host(const std::string& in_host) { |
| 60 host_ = in_host; | 58 host_ = in_host; |
| 61 } | 59 } |
| 62 | 60 |
| 63 void set_port(uint16 in_port) { | 61 void set_port(uint16_t in_port) { port_ = in_port; } |
| 64 port_ = in_port; | |
| 65 } | |
| 66 | 62 |
| 67 // ToString() will convert the HostPortPair to "host:port". If |host_| is an | 63 // ToString() will convert the HostPortPair to "host:port". If |host_| is an |
| 68 // IPv6 literal, it will add brackets around |host_|. | 64 // IPv6 literal, it will add brackets around |host_|. |
| 69 std::string ToString() const; | 65 std::string ToString() const; |
| 70 | 66 |
| 71 // Returns |host_|, adding IPv6 brackets if needed. | 67 // Returns |host_|, adding IPv6 brackets if needed. |
| 72 std::string HostForURL() const; | 68 std::string HostForURL() const; |
| 73 | 69 |
| 74 private: | 70 private: |
| 75 // If |host_| represents an IPv6 address, this string will not contain | 71 // If |host_| represents an IPv6 address, this string will not contain |
| 76 // brackets around the address. | 72 // brackets around the address. |
| 77 std::string host_; | 73 std::string host_; |
| 78 uint16 port_; | 74 uint16_t port_; |
| 79 }; | 75 }; |
| 80 | 76 |
| 81 } // namespace net | 77 } // namespace net |
| 82 | 78 |
| 83 #endif // NET_BASE_HOST_PORT_PAIR_H_ | 79 #endif // NET_BASE_HOST_PORT_PAIR_H_ |
| OLD | NEW |