[email protected] | 39c48fc | 2012-03-12 18:42:12 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | db96a88 | 2011-10-09 02:01:54 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef NET_HTTP_HTTP_SERVER_PROPERTIES_H_ |
| 6 | #define NET_HTTP_HTTP_SERVER_PROPERTIES_H_ |
| 7 | |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 8 | #include <stddef.h> |
| 9 | #include <stdint.h> |
| 10 | |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11 | #include <map> |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 12 | #include <memory> |
| 13 | #include <set> |
[email protected] | db96a88 | 2011-10-09 02:01:54 | [diff] [blame] | 14 | #include <string> |
jsbell | cea42a5 | 2015-11-30 23:50:25 | [diff] [blame] | 15 | #include <tuple> |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 16 | #include <vector> |
| 17 | |
Matt Menke | dce5056 | 2017-12-19 22:12:20 | [diff] [blame] | 18 | #include "base/callback.h" |
[email protected] | 9801e370 | 2014-03-07 09:33:55 | [diff] [blame] | 19 | #include "base/containers/mru_cache.h" |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 20 | #include "base/macros.h" |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 21 | #include "base/memory/weak_ptr.h" |
Matt Menke | 5e7dcd3 | 2019-08-09 22:25:21 | [diff] [blame] | 22 | #include "base/optional.h" |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 23 | #include "base/threading/thread_checker.h" |
[email protected] | 3b8cf7f | 2014-01-27 22:08:51 | [diff] [blame] | 24 | #include "base/time/time.h" |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 25 | #include "base/timer/timer.h" |
| 26 | #include "base/values.h" |
| 27 | #include "net/base/host_port_pair.h" |
| 28 | #include "net/base/ip_address.h" |
[email protected] | db96a88 | 2011-10-09 02:01:54 | [diff] [blame] | 29 | #include "net/base/net_export.h" |
Matt Menke | 1be93d2 | 2019-08-20 16:57:58 | [diff] [blame] | 30 | #include "net/base/network_isolation_key.h" |
Matt Menke | 2890796e | 2019-08-02 16:55:23 | [diff] [blame] | 31 | #include "net/http/alternative_service.h" |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 32 | #include "net/http/broken_alternative_services.h" |
| 33 | #include "net/http/http_server_properties.h" |
Victor Vasiliev | 6bb59d2 | 2019-03-08 21:34:51 | [diff] [blame] | 34 | #include "net/third_party/quiche/src/quic/core/quic_bandwidth.h" |
| 35 | #include "net/third_party/quiche/src/quic/core/quic_server_id.h" |
| 36 | #include "net/third_party/quiche/src/quic/core/quic_versions.h" |
Victor Vasiliev | 27cc771 | 2019-01-24 11:50:14 | [diff] [blame] | 37 | #include "net/third_party/quiche/src/spdy/core/spdy_framer.h" // TODO(willchan): Reconsider this. |
| 38 | #include "net/third_party/quiche/src/spdy/core/spdy_protocol.h" |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 39 | #include "url/scheme_host_port.h" |
[email protected] | db96a88 | 2011-10-09 02:01:54 | [diff] [blame] | 40 | |
bnc | 8ba74a178 | 2015-04-14 17:42:08 | [diff] [blame] | 41 | namespace base { |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 42 | class Clock; |
| 43 | class TickClock; |
bnc | 8ba74a178 | 2015-04-14 17:42:08 | [diff] [blame] | 44 | class Value; |
| 45 | } |
| 46 | |
[email protected] | db96a88 | 2011-10-09 02:01:54 | [diff] [blame] | 47 | namespace net { |
| 48 | |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 49 | class HttpServerPropertiesManager; |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 50 | class IPAddress; |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 51 | class NetLog; |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 52 | struct SSLConfig; |
| 53 | |
rtenneti | 1c863aa | 2014-09-25 18:39:33 | [diff] [blame] | 54 | struct NET_EXPORT SupportsQuic { |
| 55 | SupportsQuic() : used_quic(false) {} |
| 56 | SupportsQuic(bool used_quic, const std::string& address) |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 57 | : used_quic(used_quic), address(address) {} |
rtenneti | 1c863aa | 2014-09-25 18:39:33 | [diff] [blame] | 58 | |
| 59 | bool Equals(const SupportsQuic& other) const { |
| 60 | return used_quic == other.used_quic && address == other.address; |
| 61 | } |
| 62 | |
| 63 | bool used_quic; |
| 64 | std::string address; |
| 65 | }; |
| 66 | |
rtenneti | 338cd36a | 2015-01-06 00:20:07 | [diff] [blame] | 67 | struct NET_EXPORT ServerNetworkStats { |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 68 | ServerNetworkStats() : bandwidth_estimate(quic::QuicBandwidth::Zero()) {} |
rtenneti | 338cd36a | 2015-01-06 00:20:07 | [diff] [blame] | 69 | |
rtenneti | cce34d5 | 2015-06-05 23:36:29 | [diff] [blame] | 70 | bool operator==(const ServerNetworkStats& other) const { |
| 71 | return srtt == other.srtt && bandwidth_estimate == other.bandwidth_estimate; |
| 72 | } |
| 73 | |
| 74 | bool operator!=(const ServerNetworkStats& other) const { |
| 75 | return !this->operator==(other); |
| 76 | } |
| 77 | |
rtenneti | 338cd36a | 2015-01-06 00:20:07 | [diff] [blame] | 78 | base::TimeDelta srtt; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 79 | quic::QuicBandwidth bandwidth_estimate; |
rtenneti | 338cd36a | 2015-01-06 00:20:07 | [diff] [blame] | 80 | }; |
| 81 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 82 | typedef std::vector<AlternativeService> AlternativeServiceVector; |
Yixin Wang | 4a227aa2 | 2017-11-30 21:33:01 | [diff] [blame] | 83 | |
Yixin Wang | 4a227aa2 | 2017-11-30 21:33:01 | [diff] [blame] | 84 | // Store at most 200 MRU RecentlyBrokenAlternativeServices in memory and disk. |
Matt Menke | 2890796e | 2019-08-02 16:55:23 | [diff] [blame] | 85 | // This ideally would be with the other constants in HttpServerProperties, but |
| 86 | // has to go here instead of prevent a circular dependency. |
Yixin Wang | 4a227aa2 | 2017-11-30 21:33:01 | [diff] [blame] | 87 | const int kMaxRecentlyBrokenAlternativeServiceEntries = 200; |
| 88 | |
| 89 | // Store at most 5 MRU QUIC servers by default. This is mainly used by cronet. |
| 90 | const int kDefaultMaxQuicServerEntries = 5; |
| 91 | |
[email protected] | db96a88 | 2011-10-09 02:01:54 | [diff] [blame] | 92 | // The interface for setting/retrieving the HTTP server properties. |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 93 | // Currently, this class manages servers': |
Bence Béky | ffb237f | 2017-06-29 12:17:39 | [diff] [blame] | 94 | // * HTTP/2 support; |
| 95 | // * Alternative Service support; |
rtenneti | cd2aaa15b | 2015-10-10 20:29:33 | [diff] [blame] | 96 | // * QUIC data (like ServerNetworkStats and QuicServerInfo). |
| 97 | // |
Matt Menke | fe1f1c8 | 2019-08-20 17:49:11 | [diff] [blame] | 98 | // Optionally retrieves and saves properties from/to disk. This class is not |
| 99 | // threadsafe. |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 100 | class NET_EXPORT HttpServerProperties |
| 101 | : public BrokenAlternativeServices::Delegate { |
[email protected] | db96a88 | 2011-10-09 02:01:54 | [diff] [blame] | 102 | public: |
Matt Menke | 5e7dcd3 | 2019-08-09 22:25:21 | [diff] [blame] | 103 | // Store at most 500 MRU ServerInfos in memory and disk. |
| 104 | static const int kMaxServerInfoEntries = 500; |
| 105 | |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 106 | // Provides an interface to interact with persistent preferences storage |
| 107 | // implemented by the embedder. The prefs are assumed not to have been loaded |
| 108 | // before HttpServerPropertiesManager construction. |
| 109 | class NET_EXPORT PrefDelegate { |
| 110 | public: |
| 111 | virtual ~PrefDelegate(); |
| 112 | |
| 113 | // Returns the branch of the preferences system for the server properties. |
| 114 | // Returns nullptr if the pref system has no data for the server properties. |
| 115 | virtual const base::DictionaryValue* GetServerProperties() const = 0; |
| 116 | |
| 117 | // Sets the server properties to the given value. If |callback| is |
| 118 | // non-empty, flushes data to persistent storage and invokes |callback| |
| 119 | // asynchronously when complete. |
| 120 | virtual void SetServerProperties(const base::DictionaryValue& value, |
| 121 | base::OnceClosure callback) = 0; |
| 122 | |
| 123 | // Starts listening for prefs to be loaded. If prefs are already loaded, |
| 124 | // |pref_loaded_callback| will be invoked asynchronously. Callback will be |
| 125 | // invoked even if prefs fail to load. Will only be called once by the |
| 126 | // HttpServerPropertiesManager. |
| 127 | virtual void WaitForPrefLoad(base::OnceClosure pref_loaded_callback) = 0; |
| 128 | }; |
| 129 | |
Matt Menke | f2ee07c | 2019-08-29 02:10:36 | [diff] [blame] | 130 | // Contains metadata about a particular server. Note that all methods that |
| 131 | // take a "SchemeHostPort" expect schemes of ws and wss to be mapped to http |
| 132 | // and https, respectively. See GetNormalizedSchemeHostPort(). |
Matt Menke | 5e7dcd3 | 2019-08-09 22:25:21 | [diff] [blame] | 133 | struct NET_EXPORT ServerInfo { |
| 134 | ServerInfo(); |
| 135 | ServerInfo(const ServerInfo& server_info); |
| 136 | ServerInfo(ServerInfo&& server_info); |
| 137 | ~ServerInfo(); |
| 138 | |
Matt Menke | fe9b596 | 2019-08-14 20:56:14 | [diff] [blame] | 139 | // Returns true if no fields are populated. |
| 140 | bool empty() const; |
| 141 | |
Matt Menke | 1be93d2 | 2019-08-20 16:57:58 | [diff] [blame] | 142 | // Used in tests. |
| 143 | bool operator==(const ServerInfo& other) const; |
| 144 | |
Matt Menke | 5e7dcd3 | 2019-08-09 22:25:21 | [diff] [blame] | 145 | // IMPORTANT: When adding a field here, be sure to update |
| 146 | // HttpServerProperties::OnServerInfoLoaded() as well as |
| 147 | // HttpServerPropertiesManager to correctly load/save the from/to the pref |
| 148 | // store. |
| 149 | |
| 150 | // Whether or not a server is known to support H2/SPDY. False indicates |
| 151 | // known lack of support, true indicates known support, and not set |
| 152 | // indicates unknown. The difference between false and not set only matters |
| 153 | // when loading from disk, when an initialized false value will take |
| 154 | // priority over a not set value. |
| 155 | base::Optional<bool> supports_spdy; |
| 156 | |
Matt Menke | f2ee07c | 2019-08-29 02:10:36 | [diff] [blame] | 157 | // True if the server has previously indicated it required HTTP/1.1. Unlike |
| 158 | // other fields, not persisted to disk. |
| 159 | base::Optional<bool> requires_http11; |
| 160 | |
Matt Menke | fe9b596 | 2019-08-14 20:56:14 | [diff] [blame] | 161 | base::Optional<AlternativeServiceInfoVector> alternative_services; |
Matt Menke | 86878a6 | 2019-08-14 21:01:11 | [diff] [blame] | 162 | base::Optional<ServerNetworkStats> server_network_stats; |
Matt Menke | 5e7dcd3 | 2019-08-09 22:25:21 | [diff] [blame] | 163 | }; |
| 164 | |
Matt Menke | 1be93d2 | 2019-08-20 16:57:58 | [diff] [blame] | 165 | struct NET_EXPORT ServerInfoMapKey { |
| 166 | // If |use_network_isolation_key| is false, an empty NetworkIsolationKey is |
Matt Menke | d9b24f0 | 2019-09-26 17:07:17 | [diff] [blame] | 167 | // used instead of |network_isolation_key|. Note that |server| can be passed |
| 168 | // in via std::move(), since most callsites can pass a recently created |
| 169 | // SchemeHostPort. |
| 170 | ServerInfoMapKey(url::SchemeHostPort server, |
Matt Menke | 1be93d2 | 2019-08-20 16:57:58 | [diff] [blame] | 171 | const NetworkIsolationKey& network_isolation_key, |
| 172 | bool use_network_isolation_key); |
| 173 | ~ServerInfoMapKey(); |
| 174 | |
| 175 | bool operator<(const ServerInfoMapKey& other) const; |
| 176 | |
Matt Menke | d9b24f0 | 2019-09-26 17:07:17 | [diff] [blame] | 177 | // IMPORTANT: The constructor normalizes the scheme so that "ws" is replaced |
| 178 | // by "http" and "wss" by "https", so this should never be compared directly |
| 179 | // with values passed into to HttpServerProperties methods. |
Matt Menke | 1be93d2 | 2019-08-20 16:57:58 | [diff] [blame] | 180 | url::SchemeHostPort server; |
Matt Menke | d9b24f0 | 2019-09-26 17:07:17 | [diff] [blame] | 181 | |
Matt Menke | 1be93d2 | 2019-08-20 16:57:58 | [diff] [blame] | 182 | NetworkIsolationKey network_isolation_key; |
| 183 | }; |
| 184 | |
Matt Menke | 5e7dcd3 | 2019-08-09 22:25:21 | [diff] [blame] | 185 | class NET_EXPORT ServerInfoMap |
Matt Menke | 1be93d2 | 2019-08-20 16:57:58 | [diff] [blame] | 186 | : public base::MRUCache<ServerInfoMapKey, ServerInfo> { |
Matt Menke | 5e7dcd3 | 2019-08-09 22:25:21 | [diff] [blame] | 187 | public: |
| 188 | ServerInfoMap(); |
| 189 | |
| 190 | // If there's an entry corresponding to |key|, brings that entry to the |
| 191 | // front and returns an iterator to it. Otherwise, inserts an empty |
| 192 | // ServerInfo using |key|, and returns an iterator to it. |
Matt Menke | 1be93d2 | 2019-08-20 16:57:58 | [diff] [blame] | 193 | iterator GetOrPut(const ServerInfoMapKey& key); |
Matt Menke | 5e7dcd3 | 2019-08-09 22:25:21 | [diff] [blame] | 194 | |
Matt Menke | fe9b596 | 2019-08-14 20:56:14 | [diff] [blame] | 195 | // Erases the ServerInfo identified by |server_info_it| if no fields have |
| 196 | // data. The iterator must point to an entry in the map. Regardless of |
| 197 | // whether the entry is removed or not, returns iterator for the next entry. |
| 198 | iterator EraseIfEmpty(iterator server_info_it); |
| 199 | |
Matt Menke | 5e7dcd3 | 2019-08-09 22:25:21 | [diff] [blame] | 200 | private: |
| 201 | DISALLOW_COPY_AND_ASSIGN(ServerInfoMap); |
| 202 | }; |
| 203 | |
Matt Menke | 0142bc0 | 2019-09-13 20:17:45 | [diff] [blame] | 204 | struct NET_EXPORT QuicServerInfoMapKey { |
| 205 | // If |use_network_isolation_key| is false, an empty NetworkIsolationKey is |
| 206 | // used instead of |network_isolation_key|. |
| 207 | QuicServerInfoMapKey(const quic::QuicServerId& server_id, |
| 208 | const NetworkIsolationKey& network_isolation_key, |
| 209 | bool use_network_isolation_key); |
| 210 | ~QuicServerInfoMapKey(); |
| 211 | |
| 212 | bool operator<(const QuicServerInfoMapKey& other) const; |
| 213 | |
| 214 | // Used in tests. |
| 215 | bool operator==(const QuicServerInfoMapKey& other) const; |
| 216 | |
| 217 | quic::QuicServerId server_id; |
| 218 | NetworkIsolationKey network_isolation_key; |
| 219 | }; |
| 220 | |
| 221 | // Max number of quic servers to store is not hardcoded and can be set. |
| 222 | // Because of this, QuicServerInfoMap will not be a subclass of MRUCache. |
| 223 | // Separate from ServerInfoMap because the key includes privacy mode (Since |
| 224 | // this is analogous to the SSL session cache, which has separate caches for |
| 225 | // privacy mode), and each entry can be quite large, so it has its own size |
| 226 | // limit, which is much smaller than the ServerInfoMap's limit. |
| 227 | typedef base::MRUCache<QuicServerInfoMapKey, std::string> QuicServerInfoMap; |
| 228 | |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 229 | // If a |pref_delegate| is specified, it will be used to read/write the |
| 230 | // properties to a pref file. Writes are rate limited to improve performance. |
| 231 | // |
| 232 | // |tick_clock| is used for setting expiration times and scheduling the |
| 233 | // expiration of broken alternative services. If null, default clock will be |
| 234 | // used. |
| 235 | // |
| 236 | // |clock| is used for converting base::TimeTicks to base::Time for |
| 237 | // wherever base::Time is preferable. |
| 238 | HttpServerProperties(std::unique_ptr<PrefDelegate> pref_delegate = nullptr, |
| 239 | NetLog* net_log = nullptr, |
| 240 | const base::TickClock* tick_clock = nullptr, |
| 241 | base::Clock* clock = nullptr); |
| 242 | |
| 243 | ~HttpServerProperties() override; |
[email protected] | db96a88 | 2011-10-09 02:01:54 | [diff] [blame] | 244 | |
Matt Menke | dce5056 | 2017-12-19 22:12:20 | [diff] [blame] | 245 | // Deletes all data. If |callback| is non-null, flushes data to disk |
| 246 | // and invokes the callback asynchronously once changes have been written to |
| 247 | // disk. |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 248 | void Clear(base::OnceClosure callback); |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 249 | |
Matt Menke | fe1f1c8 | 2019-08-20 17:49:11 | [diff] [blame] | 250 | // Returns true if |server|, in the context of |network_isolation_key|, has |
| 251 | // previously supported a network protocol which honors request |
| 252 | // prioritization. |
| 253 | // |
rdsmith | c31e060 | 2016-08-30 06:27:23 | [diff] [blame] | 254 | // Note that this also implies that the server supports request |
| 255 | // multiplexing, since priorities imply a relationship between |
| 256 | // multiple requests. |
Matt Menke | fe1f1c8 | 2019-08-20 17:49:11 | [diff] [blame] | 257 | bool SupportsRequestPriority( |
| 258 | const url::SchemeHostPort& server, |
| 259 | const net::NetworkIsolationKey& network_isolation_key); |
[email protected] | db96a88 | 2011-10-09 02:01:54 | [diff] [blame] | 260 | |
rtenneti | e267d6a | 2015-06-05 21:55:23 | [diff] [blame] | 261 | // Returns the value set by SetSupportsSpdy(). If not set, returns false. |
Matt Menke | fe1f1c8 | 2019-08-20 17:49:11 | [diff] [blame] | 262 | bool GetSupportsSpdy(const url::SchemeHostPort& server, |
| 263 | const net::NetworkIsolationKey& network_isolation_key); |
rtenneti | e267d6a | 2015-06-05 21:55:23 | [diff] [blame] | 264 | |
Matt Menke | fe1f1c8 | 2019-08-20 17:49:11 | [diff] [blame] | 265 | // Records whether |server| supports H2 or not. Information is restricted to |
| 266 | // the context of |network_isolation_key|, to prevent cross-site information |
| 267 | // leakage. |
| 268 | void SetSupportsSpdy(const url::SchemeHostPort& server, |
| 269 | const net::NetworkIsolationKey& network_isolation_key, |
| 270 | bool supports_spdy); |
[email protected] | db96a88 | 2011-10-09 02:01:54 | [diff] [blame] | 271 | |
Matt Menke | f2ee07c | 2019-08-29 02:10:36 | [diff] [blame] | 272 | // Returns true if |server| has required HTTP/1.1 via HTTP/2 error code, in |
| 273 | // the context of |network_isolation_key|. |
| 274 | bool RequiresHTTP11(const url::SchemeHostPort& server, |
| 275 | const net::NetworkIsolationKey& network_isolation_key); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 276 | |
Matt Menke | f2ee07c | 2019-08-29 02:10:36 | [diff] [blame] | 277 | // Require HTTP/1.1 on subsequent connections, in the context of |
| 278 | // |network_isolation_key|. Not persisted. |
| 279 | void SetHTTP11Required(const url::SchemeHostPort& server, |
| 280 | const net::NetworkIsolationKey& network_isolation_key); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 281 | |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 282 | // Modify SSLConfig to force HTTP/1.1 if necessary. |
Matt Menke | f2ee07c | 2019-08-29 02:10:36 | [diff] [blame] | 283 | void MaybeForceHTTP11(const url::SchemeHostPort& server, |
| 284 | const net::NetworkIsolationKey& network_isolation_key, |
| 285 | SSLConfig* ssl_config); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 286 | |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 287 | // Return all alternative services for |origin|, learned in the context of |
| 288 | // |network_isolation_key|, including broken ones. Returned alternative |
| 289 | // services never have empty hostnames. |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 290 | AlternativeServiceInfoVector GetAlternativeServiceInfos( |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 291 | const url::SchemeHostPort& origin, |
| 292 | const net::NetworkIsolationKey& network_isolation_key); |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 293 | |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 294 | // Set a single HTTP/2 alternative service for |origin|. Previous |
| 295 | // alternative services for |origin| are discarded. |
| 296 | // |alternative_service.host| may be empty. |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 297 | void SetHttp2AlternativeService( |
| 298 | const url::SchemeHostPort& origin, |
| 299 | const NetworkIsolationKey& network_isolation_key, |
| 300 | const AlternativeService& alternative_service, |
| 301 | base::Time expiration); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 302 | |
| 303 | // Set a single QUIC alternative service for |origin|. Previous alternative |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 304 | // services for |origin| are discarded. |
| 305 | // |alternative_service.host| may be empty. |
Matt Menke | 2f63ef69 | 2019-08-02 22:48:03 | [diff] [blame] | 306 | void SetQuicAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 307 | const url::SchemeHostPort& origin, |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 308 | const NetworkIsolationKey& network_isolation_key, |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 309 | const AlternativeService& alternative_service, |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 310 | base::Time expiration, |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 311 | const quic::ParsedQuicVersionVector& advertised_versions); |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 312 | |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 313 | // Set alternative services for |origin|, learned in the context of |
| 314 | // |network_isolation_key|. Previous alternative services for |origin| are |
| 315 | // discarded. Hostnames in |alternative_service_info_vector| may be empty. |
bnc | 4b91d83 | 2016-07-27 23:36:12 | [diff] [blame] | 316 | // |alternative_service_info_vector| may be empty. |
Matt Menke | 2f63ef69 | 2019-08-02 22:48:03 | [diff] [blame] | 317 | void SetAlternativeServices( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 318 | const url::SchemeHostPort& origin, |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 319 | const net::NetworkIsolationKey& network_isolation_key, |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 320 | const AlternativeServiceInfoVector& alternative_service_info_vector); |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 321 | |
Matt Menke | 977f0279 | 2019-09-10 16:23:09 | [diff] [blame] | 322 | // Marks |alternative_service| as broken in the context of |
| 323 | // |network_isolation_key|. |alternative_service.host| must not be empty. |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 324 | void MarkAlternativeServiceBroken( |
Matt Menke | 977f0279 | 2019-09-10 16:23:09 | [diff] [blame] | 325 | const AlternativeService& alternative_service, |
Matt Menke | b32ba512 | 2019-09-10 19:17:05 | [diff] [blame] | 326 | const net::NetworkIsolationKey& network_isolation_key); |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 327 | |
Matt Menke | 977f0279 | 2019-09-10 16:23:09 | [diff] [blame] | 328 | // Marks |alternative_service| as broken in the context of |
| 329 | // |network_isolation_key| until the default network changes. |
Zhongyi Shi | 826b1d2 | 2018-08-28 21:45:15 | [diff] [blame] | 330 | // |alternative_service.host| must not be empty. |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 331 | void MarkAlternativeServiceBrokenUntilDefaultNetworkChanges( |
Matt Menke | 977f0279 | 2019-09-10 16:23:09 | [diff] [blame] | 332 | const AlternativeService& alternative_service, |
Matt Menke | b32ba512 | 2019-09-10 19:17:05 | [diff] [blame] | 333 | const net::NetworkIsolationKey& network_isolation_key); |
Zhongyi Shi | 826b1d2 | 2018-08-28 21:45:15 | [diff] [blame] | 334 | |
Matt Menke | 977f0279 | 2019-09-10 16:23:09 | [diff] [blame] | 335 | // Marks |alternative_service| as recently broken in the context of |
| 336 | // |network_isolation_key|. |alternative_service.host| must not be empty. |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 337 | void MarkAlternativeServiceRecentlyBroken( |
Matt Menke | 977f0279 | 2019-09-10 16:23:09 | [diff] [blame] | 338 | const AlternativeService& alternative_service, |
Matt Menke | b32ba512 | 2019-09-10 19:17:05 | [diff] [blame] | 339 | const net::NetworkIsolationKey& network_isolation_key); |
bnc | d1e0aa2 | 2015-03-13 10:14:31 | [diff] [blame] | 340 | |
Matt Menke | 977f0279 | 2019-09-10 16:23:09 | [diff] [blame] | 341 | // Returns true iff |alternative_service| is currently broken in the context |
| 342 | // of |network_isolation_key|. |alternative_service.host| must not be empty. |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 343 | bool IsAlternativeServiceBroken( |
Matt Menke | 977f0279 | 2019-09-10 16:23:09 | [diff] [blame] | 344 | const AlternativeService& alternative_service, |
Matt Menke | b32ba512 | 2019-09-10 19:17:05 | [diff] [blame] | 345 | const net::NetworkIsolationKey& network_isolation_key) const; |
bnc | 8445b300 | 2015-03-13 01:57:09 | [diff] [blame] | 346 | |
Matt Menke | 977f0279 | 2019-09-10 16:23:09 | [diff] [blame] | 347 | // Returns true iff |alternative_service| was recently broken in the context |
| 348 | // of |network_isolation_key|. |alternative_service.host| must not be empty. |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 349 | bool WasAlternativeServiceRecentlyBroken( |
Matt Menke | 977f0279 | 2019-09-10 16:23:09 | [diff] [blame] | 350 | const AlternativeService& alternative_service, |
Matt Menke | b32ba512 | 2019-09-10 19:17:05 | [diff] [blame] | 351 | const net::NetworkIsolationKey& network_isolation_key); |
[email protected] | f5716e3 | 2014-04-18 00:44:16 | [diff] [blame] | 352 | |
Matt Menke | 977f0279 | 2019-09-10 16:23:09 | [diff] [blame] | 353 | // Confirms that |alternative_service| is working in the context of |
| 354 | // |network_isolation_key|. |alternative_service.host| must not be empty. |
| 355 | void ConfirmAlternativeService( |
| 356 | const AlternativeService& alternative_service, |
Matt Menke | b32ba512 | 2019-09-10 19:17:05 | [diff] [blame] | 357 | const net::NetworkIsolationKey& network_isolation_key); |
[email protected] | f5716e3 | 2014-04-18 00:44:16 | [diff] [blame] | 358 | |
Zhongyi Shi | 826b1d2 | 2018-08-28 21:45:15 | [diff] [blame] | 359 | // Called when the default network changes. |
| 360 | // Clears all the alternative services that were marked broken until the |
| 361 | // default network changed. |
Matt Menke | 2f63ef69 | 2019-08-02 22:48:03 | [diff] [blame] | 362 | void OnDefaultNetworkChanged(); |
Zhongyi Shi | 826b1d2 | 2018-08-28 21:45:15 | [diff] [blame] | 363 | |
bnc | 8ba74a178 | 2015-04-14 17:42:08 | [diff] [blame] | 364 | // Returns all alternative service mappings as human readable strings. |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 365 | // Empty alternative service hostnames will be printed as such. |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 366 | std::unique_ptr<base::Value> GetAlternativeServiceInfoAsValue() const; |
bnc | 8ba74a178 | 2015-04-14 17:42:08 | [diff] [blame] | 367 | |
Matt Menke | b566c39 | 2019-09-11 23:22:43 | [diff] [blame] | 368 | // Tracks the last local address when QUIC was known to work. The address |
| 369 | // cannot be set to an empty address - use |
| 370 | // ClearLastLocalAddressWhenQuicWorked() if it needs to be cleared. |
| 371 | bool WasLastLocalAddressWhenQuicWorked(const IPAddress& local_address) const; |
| 372 | bool HasLastLocalAddressWhenQuicWorked() const; |
| 373 | void SetLastLocalAddressWhenQuicWorked( |
| 374 | IPAddress last_local_address_when_quic_worked); |
| 375 | void ClearLastLocalAddressWhenQuicWorked(); |
rtenneti | 1c863aa | 2014-09-25 18:39:33 | [diff] [blame] | 376 | |
rch | ac7f35e | 2017-03-15 20:42:30 | [diff] [blame] | 377 | // Sets |stats| for |server|. |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 378 | void SetServerNetworkStats(const url::SchemeHostPort& server, |
Matt Menke | 19475f7 | 2019-08-21 18:57:44 | [diff] [blame] | 379 | const NetworkIsolationKey& network_isolation_key, |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 380 | ServerNetworkStats stats); |
[email protected] | 3b8cf7f | 2014-01-27 22:08:51 | [diff] [blame] | 381 | |
rch | ac7f35e | 2017-03-15 20:42:30 | [diff] [blame] | 382 | // Clears any stats for |server|. |
Matt Menke | 19475f7 | 2019-08-21 18:57:44 | [diff] [blame] | 383 | void ClearServerNetworkStats( |
| 384 | const url::SchemeHostPort& server, |
| 385 | const NetworkIsolationKey& network_isolation_key); |
rch | ac7f35e | 2017-03-15 20:42:30 | [diff] [blame] | 386 | |
| 387 | // Returns any stats for |server| or nullptr if there are none. |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 388 | const ServerNetworkStats* GetServerNetworkStats( |
Matt Menke | 19475f7 | 2019-08-21 18:57:44 | [diff] [blame] | 389 | const url::SchemeHostPort& server, |
| 390 | const NetworkIsolationKey& network_isolation_key); |
rtenneti | 338cd36a | 2015-01-06 00:20:07 | [diff] [blame] | 391 | |
Matt Menke | 0142bc0 | 2019-09-13 20:17:45 | [diff] [blame] | 392 | // Save QuicServerInfo (in std::string form) for the given |server_id|, in the |
| 393 | // context of |network_isolation_key|. |
Matt Menke | 2f63ef69 | 2019-08-02 22:48:03 | [diff] [blame] | 394 | void SetQuicServerInfo(const quic::QuicServerId& server_id, |
Matt Menke | 0142bc0 | 2019-09-13 20:17:45 | [diff] [blame] | 395 | const NetworkIsolationKey& network_isolation_key, |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 396 | const std::string& server_info); |
rtenneti | 8b673f7 | 2015-10-08 23:45:37 | [diff] [blame] | 397 | |
Matt Menke | 0142bc0 | 2019-09-13 20:17:45 | [diff] [blame] | 398 | // Get QuicServerInfo (in std::string form) for the given |server_id|, in the |
| 399 | // context of |network_isolation_key|. |
| 400 | const std::string* GetQuicServerInfo( |
| 401 | const quic::QuicServerId& server_id, |
| 402 | const NetworkIsolationKey& network_isolation_key); |
rtenneti | 8b673f7 | 2015-10-08 23:45:37 | [diff] [blame] | 403 | |
| 404 | // Returns all persistent QuicServerInfo objects. |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 405 | const QuicServerInfoMap& quic_server_info_map() const; |
rtenneti | 8b673f7 | 2015-10-08 23:45:37 | [diff] [blame] | 406 | |
rtenneti | 6971c17 | 2016-01-15 20:12:10 | [diff] [blame] | 407 | // Returns the number of server configs (QuicServerInfo objects) persisted. |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 408 | size_t max_server_configs_stored_in_properties() const; |
rtenneti | 6971c17 | 2016-01-15 20:12:10 | [diff] [blame] | 409 | |
| 410 | // Sets the number of server configs (QuicServerInfo objects) to be persisted. |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 411 | void SetMaxServerConfigsStoredInProperties( |
| 412 | size_t max_server_configs_stored_in_properties); |
rtenneti | 6971c17 | 2016-01-15 20:12:10 | [diff] [blame] | 413 | |
xunjieli | 1df4de1 | 2017-02-09 17:21:19 | [diff] [blame] | 414 | // Returns whether HttpServerProperties is initialized. |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 415 | bool IsInitialized() const; |
| 416 | |
| 417 | // BrokenAlternativeServices::Delegate method. |
| 418 | void OnExpireBrokenAlternativeService( |
Matt Menke | 9d0e995 | 2019-09-10 16:09:38 | [diff] [blame] | 419 | const AlternativeService& expired_alternative_service, |
| 420 | const NetworkIsolationKey& network_isolation_key) override; |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 421 | |
| 422 | static base::TimeDelta GetUpdatePrefsDelayForTesting(); |
| 423 | |
| 424 | // Test-only routines that call the methods used to load the specified |
| 425 | // field(s) from a prefs file. Unlike OnPrefsLoaded(), these may be invoked |
| 426 | // multiple times. |
Matt Menke | 5e7dcd3 | 2019-08-09 22:25:21 | [diff] [blame] | 427 | void OnServerInfoLoadedForTesting( |
| 428 | std::unique_ptr<ServerInfoMap> server_info_map) { |
| 429 | OnServerInfoLoaded(std::move(server_info_map)); |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 430 | } |
Matt Menke | b566c39 | 2019-09-11 23:22:43 | [diff] [blame] | 431 | void OnLastLocalAddressWhenQuicWorkedForTesting( |
| 432 | const IPAddress& last_local_address_when_quic_worked) { |
| 433 | OnLastLocalAddressWhenQuicWorkedLoaded(last_local_address_when_quic_worked); |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 434 | } |
| 435 | void OnQuicServerInfoMapLoadedForTesting( |
| 436 | std::unique_ptr<QuicServerInfoMap> quic_server_info_map) { |
| 437 | OnQuicServerInfoMapLoaded(std::move(quic_server_info_map)); |
| 438 | } |
| 439 | void OnBrokenAndRecentlyBrokenAlternativeServicesLoadedForTesting( |
| 440 | std::unique_ptr<BrokenAlternativeServiceList> |
| 441 | broken_alternative_service_list, |
| 442 | std::unique_ptr<RecentlyBrokenAlternativeServices> |
| 443 | recently_broken_alternative_services) { |
| 444 | OnBrokenAndRecentlyBrokenAlternativeServicesLoaded( |
| 445 | std::move(broken_alternative_service_list), |
| 446 | std::move(recently_broken_alternative_services)); |
| 447 | } |
| 448 | |
| 449 | const std::string* GetCanonicalSuffixForTesting( |
| 450 | const std::string& host) const { |
| 451 | return GetCanonicalSuffix(host); |
| 452 | } |
| 453 | |
Matt Menke | 5e7dcd3 | 2019-08-09 22:25:21 | [diff] [blame] | 454 | const ServerInfoMap& server_info_map_for_testing() const { |
| 455 | return server_info_map_; |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | // TODO(mmenke): Look into removing this. |
| 459 | HttpServerPropertiesManager* properties_manager_for_testing() { |
| 460 | return properties_manager_.get(); |
| 461 | } |
xunjieli | 1df4de1 | 2017-02-09 17:21:19 | [diff] [blame] | 462 | |
[email protected] | db96a88 | 2011-10-09 02:01:54 | [diff] [blame] | 463 | private: |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 464 | // TODO (wangyix): modify HttpServerProperties unit tests so this |
| 465 | // friendness is no longer required. |
| 466 | friend class HttpServerPropertiesPeer; |
| 467 | |
Matt Menke | 0142bc0 | 2019-09-13 20:17:45 | [diff] [blame] | 468 | typedef base::flat_map<ServerInfoMapKey, url::SchemeHostPort> CanonicalMap; |
| 469 | typedef base::flat_map<QuicServerInfoMapKey, quic::QuicServerId> |
| 470 | QuicCanonicalMap; |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 471 | typedef std::vector<std::string> CanonicalSuffixList; |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 472 | |
Matt Menke | d9b24f0 | 2019-09-26 17:07:17 | [diff] [blame] | 473 | // Internal implementations of public methods. SchemeHostPort argument must be |
| 474 | // normalized before calling (ws/wss replaced with http/https). Use wrapped |
| 475 | // functions instead of putting the normalization in the public functions to |
| 476 | // reduce chance of regression - normalization in ServerInfoMapKey's |
| 477 | // constructor would leave |server.scheme| as wrong if not access through the |
| 478 | // key, and explicit normalization to create |normalized_server| means the one |
| 479 | // with the incorrect scheme would still be available. |
| 480 | bool GetSupportsSpdyInternal( |
| 481 | url::SchemeHostPort server, |
| 482 | const net::NetworkIsolationKey& network_isolation_key); |
| 483 | void SetSupportsSpdyInternal( |
| 484 | url::SchemeHostPort server, |
| 485 | const net::NetworkIsolationKey& network_isolation_key, |
| 486 | bool supports_spdy); |
| 487 | bool RequiresHTTP11Internal( |
| 488 | url::SchemeHostPort server, |
| 489 | const net::NetworkIsolationKey& network_isolation_key); |
| 490 | void SetHTTP11RequiredInternal( |
| 491 | url::SchemeHostPort server, |
| 492 | const net::NetworkIsolationKey& network_isolation_key); |
| 493 | void MaybeForceHTTP11Internal( |
| 494 | url::SchemeHostPort server, |
| 495 | const net::NetworkIsolationKey& network_isolation_key, |
| 496 | SSLConfig* ssl_config); |
| 497 | AlternativeServiceInfoVector GetAlternativeServiceInfosInternal( |
| 498 | const url::SchemeHostPort& origin, |
| 499 | const net::NetworkIsolationKey& network_isolation_key); |
| 500 | void SetAlternativeServicesInternal( |
| 501 | const url::SchemeHostPort& origin, |
| 502 | const net::NetworkIsolationKey& network_isolation_key, |
| 503 | const AlternativeServiceInfoVector& alternative_service_info_vector); |
| 504 | void SetServerNetworkStatsInternal( |
| 505 | url::SchemeHostPort server, |
| 506 | const NetworkIsolationKey& network_isolation_key, |
| 507 | ServerNetworkStats stats); |
| 508 | void ClearServerNetworkStatsInternal( |
| 509 | url::SchemeHostPort server, |
| 510 | const NetworkIsolationKey& network_isolation_key); |
| 511 | const ServerNetworkStats* GetServerNetworkStatsInternal( |
| 512 | url::SchemeHostPort server, |
| 513 | const NetworkIsolationKey& network_isolation_key); |
| 514 | |
Matt Menke | 0142bc0 | 2019-09-13 20:17:45 | [diff] [blame] | 515 | // Helper functions to use the passed in parameters and |
| 516 | // |use_network_isolation_key_| to create a [Quic]ServerInfoMapKey. |
Matt Menke | 1be93d2 | 2019-08-20 16:57:58 | [diff] [blame] | 517 | ServerInfoMapKey CreateServerInfoKey( |
| 518 | const url::SchemeHostPort& server, |
Matt Menke | 04a5a08 | 2019-08-21 15:07:07 | [diff] [blame] | 519 | const NetworkIsolationKey& network_isolation_key) const; |
Matt Menke | 0142bc0 | 2019-09-13 20:17:45 | [diff] [blame] | 520 | QuicServerInfoMapKey CreateQuicServerInfoKey( |
| 521 | const quic::QuicServerId& server_id, |
| 522 | const NetworkIsolationKey& network_isolation_key) const; |
Matt Menke | 1be93d2 | 2019-08-20 16:57:58 | [diff] [blame] | 523 | |
Matt Menke | 04a5a08 | 2019-08-21 15:07:07 | [diff] [blame] | 524 | // Return the iterator for |server| in the context of |network_isolation_key|, |
| 525 | // or for its canonical host, or end. Skips over ServerInfos without |
| 526 | // |alternative_service_info| populated. |
Matt Menke | fe9b596 | 2019-08-14 20:56:14 | [diff] [blame] | 527 | ServerInfoMap::const_iterator GetIteratorWithAlternativeServiceInfo( |
Matt Menke | 04a5a08 | 2019-08-21 15:07:07 | [diff] [blame] | 528 | const url::SchemeHostPort& server, |
| 529 | const net::NetworkIsolationKey& network_isolation_key); |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 530 | |
Matt Menke | 04a5a08 | 2019-08-21 15:07:07 | [diff] [blame] | 531 | // Return the canonical host for |server| in the context of |
| 532 | // |network_isolation_key|, or end if none exists. |
Matt Menke | 0142bc0 | 2019-09-13 20:17:45 | [diff] [blame] | 533 | CanonicalMap::const_iterator GetCanonicalAltSvcHost( |
Matt Menke | 04a5a08 | 2019-08-21 15:07:07 | [diff] [blame] | 534 | const url::SchemeHostPort& server, |
| 535 | const net::NetworkIsolationKey& network_isolation_key) const; |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 536 | |
| 537 | // Return the canonical host with the same canonical suffix as |server|. |
| 538 | // The returned canonical host can be used to search for server info in |
| 539 | // |quic_server_info_map_|. Return 'end' the host doesn't exist. |
Matt Menke | 0142bc0 | 2019-09-13 20:17:45 | [diff] [blame] | 540 | QuicCanonicalMap::const_iterator GetCanonicalServerInfoHost( |
| 541 | const QuicServerInfoMapKey& key) const; |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 542 | |
Matt Menke | 04a5a08 | 2019-08-21 15:07:07 | [diff] [blame] | 543 | // Remove the canonical alt-svc host for |server| with |
| 544 | // |network_isolation_key|. |
| 545 | void RemoveAltSvcCanonicalHost( |
| 546 | const url::SchemeHostPort& server, |
| 547 | const NetworkIsolationKey& network_isolation_key); |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 548 | |
| 549 | // Update |canonical_server_info_map_| with the new canonical host. |
Matt Menke | 0142bc0 | 2019-09-13 20:17:45 | [diff] [blame] | 550 | // The |key| should have the corresponding server info associated with it |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 551 | // in |quic_server_info_map_|. If |canonical_server_info_map_| doesn't |
Matt Menke | 0142bc0 | 2019-09-13 20:17:45 | [diff] [blame] | 552 | // have an entry associated with |key|, the method will add one. |
| 553 | void UpdateCanonicalServerInfoMap(const QuicServerInfoMapKey& key); |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 554 | |
| 555 | // Returns the canonical host suffix for |host|, or nullptr if none |
| 556 | // exists. |
| 557 | const std::string* GetCanonicalSuffix(const std::string& host) const; |
| 558 | |
Matt Menke | b566c39 | 2019-09-11 23:22:43 | [diff] [blame] | 559 | void OnPrefsLoaded(std::unique_ptr<ServerInfoMap> server_info_map, |
| 560 | const IPAddress& last_local_address_when_quic_worked, |
| 561 | std::unique_ptr<QuicServerInfoMap> quic_server_info_map, |
| 562 | std::unique_ptr<BrokenAlternativeServiceList> |
| 563 | broken_alternative_service_list, |
| 564 | std::unique_ptr<RecentlyBrokenAlternativeServices> |
| 565 | recently_broken_alternative_services); |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 566 | |
| 567 | // These methods are called by OnPrefsLoaded to handle merging properties |
| 568 | // loaded from prefs with what has been learned while waiting for prefs to |
| 569 | // load. |
Matt Menke | 5e7dcd3 | 2019-08-09 22:25:21 | [diff] [blame] | 570 | void OnServerInfoLoaded(std::unique_ptr<ServerInfoMap> server_info_map); |
Matt Menke | b566c39 | 2019-09-11 23:22:43 | [diff] [blame] | 571 | void OnLastLocalAddressWhenQuicWorkedLoaded( |
| 572 | const IPAddress& last_local_address_when_quic_worked); |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 573 | void OnQuicServerInfoMapLoaded( |
| 574 | std::unique_ptr<QuicServerInfoMap> quic_server_info_map); |
| 575 | void OnBrokenAndRecentlyBrokenAlternativeServicesLoaded( |
| 576 | std::unique_ptr<BrokenAlternativeServiceList> |
| 577 | broken_alternative_service_list, |
| 578 | std::unique_ptr<RecentlyBrokenAlternativeServices> |
| 579 | recently_broken_alternative_services); |
| 580 | |
| 581 | // Queue a delayed call to WriteProperties(). If |is_initialized_| is false, |
| 582 | // or |properties_manager_| is nullptr, or there's already a queued call to |
| 583 | // WriteProperties(), does nothing. |
| 584 | void MaybeQueueWriteProperties(); |
| 585 | |
| 586 | // Writes cached state to |properties_manager_|, which must not be null. |
| 587 | // Invokes |callback| on completion, if non-null. |
| 588 | void WriteProperties(base::OnceClosure callback) const; |
| 589 | |
| 590 | const base::TickClock* tick_clock_; // Unowned |
| 591 | base::Clock* clock_; // Unowned |
| 592 | |
Matt Menke | 1be93d2 | 2019-08-20 16:57:58 | [diff] [blame] | 593 | // Cached value of kPartitionHttpServerPropertiesByNetworkIsolationKey |
| 594 | // feature. Cached to improve performance. |
| 595 | const bool use_network_isolation_key_; |
| 596 | |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 597 | // Set to true once initial properties have been retrieved from disk by |
| 598 | // |properties_manager_|. Always true if |properties_manager_| is nullptr. |
| 599 | bool is_initialized_; |
| 600 | |
Matt Menke | 723f1029 | 2019-08-02 21:13:10 | [diff] [blame] | 601 | // Queue a write when resources finish loading. Set to true when |
| 602 | // MaybeQueueWriteProperties() is invoked while still waiting on |
| 603 | // initialization to complete. |
| 604 | bool queue_write_on_load_; |
| 605 | |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 606 | // Used to load/save properties from/to preferences. May be nullptr. |
| 607 | std::unique_ptr<HttpServerPropertiesManager> properties_manager_; |
| 608 | |
Matt Menke | 5e7dcd3 | 2019-08-09 22:25:21 | [diff] [blame] | 609 | ServerInfoMap server_info_map_; |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 610 | |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 611 | BrokenAlternativeServices broken_alternative_services_; |
| 612 | |
Matt Menke | b566c39 | 2019-09-11 23:22:43 | [diff] [blame] | 613 | IPAddress last_local_address_when_quic_worked_; |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 614 | // Contains a map of servers which could share the same alternate protocol. |
Matt Menke | 0142bc0 | 2019-09-13 20:17:45 | [diff] [blame] | 615 | // Map from a Canonical scheme/host/port/NIK (host is some postfix of host |
| 616 | // names) to an actual origin, which has a plausible alternate protocol |
| 617 | // mapping. |
| 618 | CanonicalMap canonical_alt_svc_map_; |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 619 | |
| 620 | // Contains list of suffixes (for example ".c.youtube.com", |
| 621 | // ".googlevideo.com", ".googleusercontent.com") of canonical hostnames. |
| 622 | const CanonicalSuffixList canonical_suffixes_; |
| 623 | |
| 624 | QuicServerInfoMap quic_server_info_map_; |
| 625 | |
| 626 | // Maps canonical suffixes to host names that have the same canonical suffix |
| 627 | // and have a corresponding entry in |quic_server_info_map_|. The map can be |
| 628 | // used to quickly look for server info for hosts that share the same |
| 629 | // canonical suffix but don't have exact match in |quic_server_info_map_|. The |
| 630 | // map exists solely to improve the search performance. It only contains |
| 631 | // derived data that can be recalculated by traversing |
| 632 | // |quic_server_info_map_|. |
Matt Menke | 0142bc0 | 2019-09-13 20:17:45 | [diff] [blame] | 633 | QuicCanonicalMap canonical_server_info_map_; |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 634 | |
| 635 | size_t max_server_configs_stored_in_properties_; |
| 636 | |
| 637 | // Used to post calls to WriteProperties(). |
| 638 | base::OneShotTimer prefs_update_timer_; |
| 639 | |
| 640 | THREAD_CHECKER(thread_checker_); |
| 641 | |
[email protected] | db96a88 | 2011-10-09 02:01:54 | [diff] [blame] | 642 | DISALLOW_COPY_AND_ASSIGN(HttpServerProperties); |
| 643 | }; |
| 644 | |
| 645 | } // namespace net |
| 646 | |
| 647 | #endif // NET_HTTP_HTTP_SERVER_PROPERTIES_H_ |