| 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 <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 // Creates a HostPortPair for the origin of |url|. | 27 // Creates a HostPortPair for the origin of |url|. |
| 28 static HostPortPair FromURL(const GURL& url); | 28 static HostPortPair FromURL(const GURL& url); |
| 29 | 29 |
| 30 // Creates a HostPortPair from an IPEndPoint. | 30 // Creates a HostPortPair from an IPEndPoint. |
| 31 static HostPortPair FromIPEndPoint(const IPEndPoint& ipe); | 31 static HostPortPair FromIPEndPoint(const IPEndPoint& ipe); |
| 32 | 32 |
| 33 // Creates a HostPortPair from a string formatted in same manner as | 33 // Creates a HostPortPair from a string formatted in same manner as |
| 34 // ToString(). | 34 // ToString(). |
| 35 static HostPortPair FromString(const std::string& str); | 35 static HostPortPair FromString(const std::string& str); |
| 36 | 36 |
| 37 // Returns the estimate of dynamically allocated memory in bytes. | |
| 38 static size_t EstimateMemoryUsage(const HostPortPair& pair); | |
| 39 | |
| 40 // TODO(willchan): Define a functor instead. | 37 // TODO(willchan): Define a functor instead. |
| 41 // Comparator function so this can be placed in a std::map. | 38 // Comparator function so this can be placed in a std::map. |
| 42 bool operator<(const HostPortPair& other) const { | 39 bool operator<(const HostPortPair& other) const { |
| 43 return std::tie(port_, host_) < std::tie(other.port_, other.host_); | 40 return std::tie(port_, host_) < std::tie(other.port_, other.host_); |
| 44 } | 41 } |
| 45 | 42 |
| 46 // Equality test of contents. (Probably another violation of style guide). | 43 // Equality test of contents. (Probably another violation of style guide). |
| 47 bool Equals(const HostPortPair& other) const { | 44 bool Equals(const HostPortPair& other) const { |
| 48 return host_ == other.host_ && port_ == other.port_; | 45 return host_ == other.host_ && port_ == other.port_; |
| 49 } | 46 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 64 | 61 |
| 65 void set_port(uint16_t in_port) { port_ = in_port; } | 62 void set_port(uint16_t in_port) { port_ = in_port; } |
| 66 | 63 |
| 67 // ToString() will convert the HostPortPair to "host:port". If |host_| is an | 64 // ToString() will convert the HostPortPair to "host:port". If |host_| is an |
| 68 // IPv6 literal, it will add brackets around |host_|. | 65 // IPv6 literal, it will add brackets around |host_|. |
| 69 std::string ToString() const; | 66 std::string ToString() const; |
| 70 | 67 |
| 71 // Returns |host_|, adding IPv6 brackets if needed. | 68 // Returns |host_|, adding IPv6 brackets if needed. |
| 72 std::string HostForURL() const; | 69 std::string HostForURL() const; |
| 73 | 70 |
| 71 // Returns the estimate of dynamically allocated memory in bytes. |
| 72 size_t EstimateMemoryUsage() const; |
| 73 |
| 74 private: | 74 private: |
| 75 // If |host_| represents an IPv6 address, this string will not contain | 75 // If |host_| represents an IPv6 address, this string will not contain |
| 76 // brackets around the address. | 76 // brackets around the address. |
| 77 std::string host_; | 77 std::string host_; |
| 78 uint16_t port_; | 78 uint16_t port_; |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 } // namespace net | 81 } // namespace net |
| 82 | 82 |
| 83 #endif // NET_BASE_HOST_PORT_PAIR_H_ | 83 #endif // NET_BASE_HOST_PORT_PAIR_H_ |
| OLD | NEW |