1 // Copyright 2018 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "net/quic/quic_session_key.h"
6 
7 #include "base/feature_list.h"
8 #include "net/base/features.h"
9 
10 namespace net {
11 
12 QuicSessionKey::QuicSessionKey() = default;
13 
QuicSessionKey(const HostPortPair & host_port_pair,PrivacyMode privacy_mode,const SocketTag & socket_tag,const NetworkIsolationKey & network_isolation_key,bool disable_secure_dns)14 QuicSessionKey::QuicSessionKey(const HostPortPair& host_port_pair,
15                                PrivacyMode privacy_mode,
16                                const SocketTag& socket_tag,
17                                const NetworkIsolationKey& network_isolation_key,
18                                bool disable_secure_dns)
19     : QuicSessionKey(host_port_pair.host(),
20                      host_port_pair.port(),
21                      privacy_mode,
22                      socket_tag,
23                      network_isolation_key,
24                      disable_secure_dns) {}
25 
QuicSessionKey(const std::string & host,uint16_t port,PrivacyMode privacy_mode,const SocketTag & socket_tag,const NetworkIsolationKey & network_isolation_key,bool disable_secure_dns)26 QuicSessionKey::QuicSessionKey(const std::string& host,
27                                uint16_t port,
28                                PrivacyMode privacy_mode,
29                                const SocketTag& socket_tag,
30                                const NetworkIsolationKey& network_isolation_key,
31                                bool disable_secure_dns)
32     : QuicSessionKey(
33           quic::QuicServerId(host, port, privacy_mode == PRIVACY_MODE_ENABLED),
34           socket_tag,
35           network_isolation_key,
36           disable_secure_dns) {}
37 
QuicSessionKey(const quic::QuicServerId & server_id,const SocketTag & socket_tag,const NetworkIsolationKey & network_isolation_key,bool disable_secure_dns)38 QuicSessionKey::QuicSessionKey(const quic::QuicServerId& server_id,
39                                const SocketTag& socket_tag,
40                                const NetworkIsolationKey& network_isolation_key,
41                                bool disable_secure_dns)
42     : server_id_(server_id),
43       socket_tag_(socket_tag),
44       network_isolation_key_(
45           base::FeatureList::IsEnabled(
46               features::kPartitionConnectionsByNetworkIsolationKey)
47               ? network_isolation_key
48               : NetworkIsolationKey()),
49       disable_secure_dns_(disable_secure_dns) {}
50 
51 QuicSessionKey::QuicSessionKey(const QuicSessionKey& other) = default;
52 
operator <(const QuicSessionKey & other) const53 bool QuicSessionKey::operator<(const QuicSessionKey& other) const {
54   return std::tie(server_id_, socket_tag_, network_isolation_key_,
55                   disable_secure_dns_) <
56          std::tie(other.server_id_, other.socket_tag_,
57                   other.network_isolation_key_, other.disable_secure_dns_);
58 }
operator ==(const QuicSessionKey & other) const59 bool QuicSessionKey::operator==(const QuicSessionKey& other) const {
60   return server_id_ == other.server_id_ && socket_tag_ == other.socket_tag_ &&
61          network_isolation_key_ == other.network_isolation_key_ &&
62          disable_secure_dns_ == other.disable_secure_dns_;
63 }
64 
EstimateMemoryUsage() const65 size_t QuicSessionKey::EstimateMemoryUsage() const {
66   return server_id_.EstimateMemoryUsage();
67 }
68 
69 }  // namespace net
70