| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/quic/quic_server_id.h" | 5 #include "net/quic/quic_server_id.h" |
| 6 #include "base/logging.h" |
| 6 | 7 |
| 7 #include "net/base/host_port_pair.h" | 8 #include "net/base/host_port_pair.h" |
| 8 #include "net/base/port_util.h" | 9 #include "net/base/port_util.h" |
| 9 #include "url/gurl.h" | 10 #include "url/gurl.h" |
| 10 | 11 |
| 11 using std::string; | 12 using std::string; |
| 12 | 13 |
| 13 namespace net { | 14 namespace net { |
| 14 | 15 |
| 15 QuicServerId::QuicServerId() | 16 QuicServerId::QuicServerId() : privacy_mode_(PRIVACY_MODE_DISABLED) {} |
| 16 : is_https_(false), privacy_mode_(PRIVACY_MODE_DISABLED) { | |
| 17 } | |
| 18 | 17 |
| 19 QuicServerId::QuicServerId(const HostPortPair& host_port_pair, | 18 QuicServerId::QuicServerId(const HostPortPair& host_port_pair, |
| 20 bool is_https, | |
| 21 PrivacyMode privacy_mode) | 19 PrivacyMode privacy_mode) |
| 22 : host_port_pair_(host_port_pair), | 20 : host_port_pair_(host_port_pair), |
| 23 is_https_(is_https), | |
| 24 privacy_mode_(privacy_mode) {} | 21 privacy_mode_(privacy_mode) {} |
| 25 | 22 |
| 26 QuicServerId::QuicServerId(const string& host, | 23 QuicServerId::QuicServerId(const string& host, uint16 port) |
| 27 uint16 port, | |
| 28 bool is_https) | |
| 29 : host_port_pair_(host, port), | 24 : host_port_pair_(host, port), |
| 30 is_https_(is_https), | |
| 31 privacy_mode_(PRIVACY_MODE_DISABLED) {} | 25 privacy_mode_(PRIVACY_MODE_DISABLED) {} |
| 32 | 26 |
| 33 QuicServerId::QuicServerId(const string& host, | 27 QuicServerId::QuicServerId(const string& host, |
| 34 uint16 port, | 28 uint16 port, |
| 35 bool is_https, | |
| 36 PrivacyMode privacy_mode) | 29 PrivacyMode privacy_mode) |
| 37 : host_port_pair_(host, port), | 30 : host_port_pair_(host, port), |
| 38 is_https_(is_https), | |
| 39 privacy_mode_(privacy_mode) {} | 31 privacy_mode_(privacy_mode) {} |
| 40 | 32 |
| 41 QuicServerId::~QuicServerId() {} | 33 QuicServerId::~QuicServerId() {} |
| 42 | 34 |
| 43 bool QuicServerId::operator<(const QuicServerId& other) const { | 35 bool QuicServerId::operator<(const QuicServerId& other) const { |
| 44 if (!host_port_pair_.Equals(other.host_port_pair_)) { | 36 if (!host_port_pair_.Equals(other.host_port_pair_)) { |
| 45 return host_port_pair_ < other.host_port_pair_; | 37 return host_port_pair_ < other.host_port_pair_; |
| 46 } | 38 } |
| 47 if (is_https_ != other.is_https_) { | |
| 48 return is_https_ < other.is_https_; | |
| 49 } | |
| 50 return privacy_mode_ < other.privacy_mode_; | 39 return privacy_mode_ < other.privacy_mode_; |
| 51 } | 40 } |
| 52 | 41 |
| 53 bool QuicServerId::operator==(const QuicServerId& other) const { | 42 bool QuicServerId::operator==(const QuicServerId& other) const { |
| 54 return is_https_ == other.is_https_ && | 43 return privacy_mode_ == other.privacy_mode_ && |
| 55 privacy_mode_ == other.privacy_mode_ && | 44 host_port_pair_.Equals(other.host_port_pair_); |
| 56 host_port_pair_.Equals(other.host_port_pair_); | |
| 57 } | 45 } |
| 58 | 46 |
| 59 // static | 47 // static |
| 60 QuicServerId QuicServerId::FromString(const std::string& str) { | 48 QuicServerId QuicServerId::FromString(const std::string& str) { |
| 61 GURL url(str); | 49 GURL url(str); |
| 62 if (!url.is_valid()) | 50 if (!url.is_valid()) |
| 63 return QuicServerId(); | 51 return QuicServerId(); |
| 64 return QuicServerId( | 52 return QuicServerId( |
| 65 HostPortPair::FromURL(url), url.scheme() == "https", | 53 HostPortPair::FromURL(url), |
| 66 url.path() == "/private" ? PRIVACY_MODE_ENABLED : PRIVACY_MODE_DISABLED); | 54 url.path() == "/private" ? PRIVACY_MODE_ENABLED : PRIVACY_MODE_DISABLED); |
| 67 } | 55 } |
| 68 | 56 |
| 69 string QuicServerId::ToString() const { | 57 string QuicServerId::ToString() const { |
| 70 return (is_https_ ? "https://" : "http://") + host_port_pair_.ToString() + | 58 return "https://" + host_port_pair_.ToString() + |
| 71 (privacy_mode_ == PRIVACY_MODE_ENABLED ? "/private" : ""); | 59 (privacy_mode_ == PRIVACY_MODE_ENABLED ? "/private" : ""); |
| 72 } | 60 } |
| 73 | 61 |
| 74 } // namespace net | 62 } // namespace net |
| OLD | NEW |