| 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 #include "net/base/host_port_pair.h" | 5 #include "net/base/host_port_pair.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 if (!ParseInt32(key_port[1], ParseIntFormat::NON_NEGATIVE, &port)) | 42 if (!ParseInt32(key_port[1], ParseIntFormat::NON_NEGATIVE, &port)) |
| 43 return HostPortPair(); | 43 return HostPortPair(); |
| 44 if (!IsPortValid(port)) | 44 if (!IsPortValid(port)) |
| 45 return HostPortPair(); | 45 return HostPortPair(); |
| 46 HostPortPair host_port_pair; | 46 HostPortPair host_port_pair; |
| 47 host_port_pair.set_host(key_port[0].as_string()); | 47 host_port_pair.set_host(key_port[0].as_string()); |
| 48 host_port_pair.set_port(static_cast<uint16_t>(port)); | 48 host_port_pair.set_port(static_cast<uint16_t>(port)); |
| 49 return host_port_pair; | 49 return host_port_pair; |
| 50 } | 50 } |
| 51 | 51 |
| 52 size_t HostPortPair::EstimateMemoryUsage(const HostPortPair& pair) { | |
| 53 return base::trace_event::EstimateMemoryUsage(pair.host()); | |
| 54 } | |
| 55 | |
| 56 std::string HostPortPair::ToString() const { | 52 std::string HostPortPair::ToString() const { |
| 57 std::string ret(HostForURL()); | 53 std::string ret(HostForURL()); |
| 58 ret += ':'; | 54 ret += ':'; |
| 59 ret += base::UintToString(port_); | 55 ret += base::UintToString(port_); |
| 60 return ret; | 56 return ret; |
| 61 } | 57 } |
| 62 | 58 |
| 63 std::string HostPortPair::HostForURL() const { | 59 std::string HostPortPair::HostForURL() const { |
| 64 // TODO(rtenneti): Add support for |host| to have '\0'. | 60 // TODO(rtenneti): Add support for |host| to have '\0'. |
| 65 if (host_.find('\0') != std::string::npos) { | 61 if (host_.find('\0') != std::string::npos) { |
| 66 std::string host_for_log(host_); | 62 std::string host_for_log(host_); |
| 67 size_t nullpos; | 63 size_t nullpos; |
| 68 while ((nullpos = host_for_log.find('\0')) != std::string::npos) { | 64 while ((nullpos = host_for_log.find('\0')) != std::string::npos) { |
| 69 host_for_log.replace(nullpos, 1, "%00"); | 65 host_for_log.replace(nullpos, 1, "%00"); |
| 70 } | 66 } |
| 71 LOG(DFATAL) << "Host has a null char: " << host_for_log; | 67 LOG(DFATAL) << "Host has a null char: " << host_for_log; |
| 72 } | 68 } |
| 73 // Check to see if the host is an IPv6 address. If so, added brackets. | 69 // Check to see if the host is an IPv6 address. If so, added brackets. |
| 74 if (host_.find(':') != std::string::npos) { | 70 if (host_.find(':') != std::string::npos) { |
| 75 DCHECK_NE(host_[0], '['); | 71 DCHECK_NE(host_[0], '['); |
| 76 return base::StringPrintf("[%s]", host_.c_str()); | 72 return base::StringPrintf("[%s]", host_.c_str()); |
| 77 } | 73 } |
| 78 | 74 |
| 79 return host_; | 75 return host_; |
| 80 } | 76 } |
| 81 | 77 |
| 78 size_t HostPortPair::EstimateMemoryUsage() const { |
| 79 return base::trace_event::EstimateMemoryUsage(host_); |
| 80 } |
| 81 |
| 82 } // namespace net | 82 } // namespace net |
| OLD | NEW |