Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Side by Side Diff: net/http/http_server_properties.h

Issue 1824903002: Change the AlternativeServiceMap with SchemeOriginPair key. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add unittests Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_HTTP_HTTP_SERVER_PROPERTIES_H_ 5 #ifndef NET_HTTP_HTTP_SERVER_PROPERTIES_H_
6 #define NET_HTTP_HTTP_SERVER_PROPERTIES_H_ 6 #define NET_HTTP_HTTP_SERVER_PROPERTIES_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
11 #include <string> 11 #include <string>
12 #include <tuple> 12 #include <tuple>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/containers/mru_cache.h" 15 #include "base/containers/mru_cache.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/weak_ptr.h" 17 #include "base/memory/weak_ptr.h"
18 #include "base/time/time.h" 18 #include "base/time/time.h"
19 #include "net/base/host_port_pair.h" 19 #include "net/base/host_port_pair.h"
20 #include "net/base/net_export.h" 20 #include "net/base/net_export.h"
21 #include "net/quic/quic_bandwidth.h" 21 #include "net/quic/quic_bandwidth.h"
22 #include "net/quic/quic_server_id.h" 22 #include "net/quic/quic_server_id.h"
23 #include "net/socket/next_proto.h" 23 #include "net/socket/next_proto.h"
24 #include "net/spdy/spdy_framer.h" // TODO(willchan): Reconsider this. 24 #include "net/spdy/spdy_framer.h" // TODO(willchan): Reconsider this.
25 #include "net/spdy/spdy_protocol.h" 25 #include "net/spdy/spdy_protocol.h"
26 #include "url/gurl.h"
26 27
27 namespace base { 28 namespace base {
28 class Value; 29 class Value;
29 } 30 }
30 31
31 namespace net { 32 namespace net {
32 33
33 class IPAddress; 34 class IPAddress;
34 struct SSLConfig; 35 struct SSLConfig;
35 36
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 } 200 }
200 201
201 bool operator!=(const ServerNetworkStats& other) const { 202 bool operator!=(const ServerNetworkStats& other) const {
202 return !this->operator==(other); 203 return !this->operator==(other);
203 } 204 }
204 205
205 base::TimeDelta srtt; 206 base::TimeDelta srtt;
206 QuicBandwidth bandwidth_estimate; 207 QuicBandwidth bandwidth_estimate;
207 }; 208 };
208 209
210 class NET_EXPORT SchemeOriginPair {
Ryan Hamilton 2016/03/24 22:23:14 I think we should definitely use url::SchemeHostPo
Zhongyi Shi 2016/04/04 18:58:35 Done.
211 public:
212 SchemeOriginPair();
213 SchemeOriginPair(const std::string& in_scheme,
214 const HostPortPair& in_host_port);
215 // If |in_host| represents an IPv6 address, it should not bracket the address.
216 SchemeOriginPair(const std::string& in_scheme,
217 const std::string& in_host,
218 uint16_t in_port);
219
220 const std::string& scheme() const { return scheme_; }
221
222 const HostPortPair& host_port_pair() const { return host_port_pair_; }
223
224 const std::string& host() const { return host_port_pair_.host(); }
225
226 uint16_t port() const { return host_port_pair_.port(); }
227
228 void set_scheme(const std::string& scheme) { scheme_ = scheme; }
229
230 void set_host(const std::string& host) { host_port_pair_.set_host(host); }
231
232 void set_port(uint16_t port) { host_port_pair_.set_port(port); }
233
234 static SchemeOriginPair FromURL(const GURL& url);
235
236 // Equality test of contents. (Probably another violation of style guide).
237 bool Equals(const SchemeOriginPair& other) const;
238
239 bool IsEmpty() const;
240
241 // Allows SchemeOriginPair to be used as a key in STL.
242 bool operator<(const SchemeOriginPair& other) const;
243
244 private:
245 std::string scheme_;
246 HostPortPair host_port_pair_;
247 };
248
209 typedef std::vector<AlternativeService> AlternativeServiceVector; 249 typedef std::vector<AlternativeService> AlternativeServiceVector;
210 typedef std::vector<AlternativeServiceInfo> AlternativeServiceInfoVector; 250 typedef std::vector<AlternativeServiceInfo> AlternativeServiceInfoVector;
211 typedef base::MRUCache<HostPortPair, AlternativeServiceInfoVector> 251 typedef base::MRUCache<SchemeOriginPair, AlternativeServiceInfoVector>
212 AlternativeServiceMap; 252 AlternativeServiceMap;
213 typedef base::MRUCache<HostPortPair, SettingsMap> SpdySettingsMap; 253 typedef base::MRUCache<HostPortPair, SettingsMap> SpdySettingsMap;
214 typedef base::MRUCache<HostPortPair, ServerNetworkStats> ServerNetworkStatsMap; 254 typedef base::MRUCache<HostPortPair, ServerNetworkStats> ServerNetworkStatsMap;
215 typedef base::MRUCache<QuicServerId, std::string> QuicServerInfoMap; 255 typedef base::MRUCache<QuicServerId, std::string> QuicServerInfoMap;
216 256
217 // Persist 5 QUIC Servers. This is mainly used by cronet. 257 // Persist 5 QUIC Servers. This is mainly used by cronet.
218 const int kMaxQuicServersToPersist = 5; 258 const int kMaxQuicServersToPersist = 5;
219 259
220 extern const char kAlternateProtocolHeader[]; 260 extern const char kAlternateProtocolHeader[];
221 extern const char kAlternativeServiceHeader[]; 261 extern const char kAlternativeServiceHeader[];
(...skipping 13 matching lines...) Expand all
235 virtual ~HttpServerProperties() {} 275 virtual ~HttpServerProperties() {}
236 276
237 // Gets a weak pointer for this object. 277 // Gets a weak pointer for this object.
238 virtual base::WeakPtr<HttpServerProperties> GetWeakPtr() = 0; 278 virtual base::WeakPtr<HttpServerProperties> GetWeakPtr() = 0;
239 279
240 // Deletes all data. 280 // Deletes all data.
241 virtual void Clear() = 0; 281 virtual void Clear() = 0;
242 282
243 // Returns true if |server| supports a network protocol which honors 283 // Returns true if |server| supports a network protocol which honors
244 // request prioritization. 284 // request prioritization.
245 virtual bool SupportsRequestPriority(const HostPortPair& server) = 0; 285 virtual bool SupportsRequestPriority(const SchemeOriginPair& server) = 0;
246 286
247 // Returns the value set by SetSupportsSpdy(). If not set, returns false. 287 // Returns the value set by SetSupportsSpdy(). If not set, returns false.
248 virtual bool GetSupportsSpdy(const HostPortPair& server) = 0; 288 virtual bool GetSupportsSpdy(const HostPortPair& server) = 0;
Ryan Hamilton 2016/03/24 22:23:14 Should these next 6 methods also use a SHP?
Zhongyi Shi 2016/04/04 18:58:35 I don't think so, only SupportsRequestPriority que
249 289
250 // Add |server| into the persistent store. Should only be called from IO 290 // Add |server| into the persistent store. Should only be called from IO
251 // thread. 291 // thread.
252 virtual void SetSupportsSpdy(const HostPortPair& server, 292 virtual void SetSupportsSpdy(const HostPortPair& server,
253 bool support_spdy) = 0; 293 bool support_spdy) = 0;
254 294
255 // Returns true if |server| has required HTTP/1.1 via HTTP/2 error code. 295 // Returns true if |server| has required HTTP/1.1 via HTTP/2 error code.
256 virtual bool RequiresHTTP11(const HostPortPair& server) = 0; 296 virtual bool RequiresHTTP11(const HostPortPair& server) = 0;
257 297
258 // Require HTTP/1.1 on subsequent connections. Not persisted. 298 // Require HTTP/1.1 on subsequent connections. Not persisted.
259 virtual void SetHTTP11Required(const HostPortPair& server) = 0; 299 virtual void SetHTTP11Required(const HostPortPair& server) = 0;
260 300
261 // Modify SSLConfig to force HTTP/1.1. 301 // Modify SSLConfig to force HTTP/1.1.
262 static void ForceHTTP11(SSLConfig* ssl_config); 302 static void ForceHTTP11(SSLConfig* ssl_config);
263 303
264 // Modify SSLConfig to force HTTP/1.1 if necessary. 304 // Modify SSLConfig to force HTTP/1.1 if necessary.
265 virtual void MaybeForceHTTP11(const HostPortPair& server, 305 virtual void MaybeForceHTTP11(const HostPortPair& server,
266 SSLConfig* ssl_config) = 0; 306 SSLConfig* ssl_config) = 0;
267 307
268 // Return all alternative services for |origin| with probability greater than 308 // Return all alternative services for |origin| with probability greater than
269 // or equal to the threshold, including broken ones. 309 // or equal to the threshold, including broken ones.
270 // Returned alternative services never have empty hostnames. 310 // Returned alternative services never have empty hostnames.
271 virtual AlternativeServiceVector GetAlternativeServices( 311 virtual AlternativeServiceVector GetAlternativeServices(
272 const HostPortPair& origin) = 0; 312 const SchemeOriginPair& origin) = 0;
273 313
274 // Set a single alternative service for |origin|. Previous alternative 314 // Set a single alternative service for |origin|. Previous alternative
275 // services for |origin| are discarded. 315 // services for |origin| are discarded.
276 // |alternative_service.host| may be empty. 316 // |alternative_service.host| may be empty.
277 // Return true if |alternative_service_map_| is changed. 317 // Return true if |alternative_service_map_| is changed.
278 virtual bool SetAlternativeService( 318 virtual bool SetAlternativeService(
279 const HostPortPair& origin, 319 const SchemeOriginPair& origin,
280 const AlternativeService& alternative_service, 320 const AlternativeService& alternative_service,
281 double alternative_probability, 321 double alternative_probability,
282 base::Time expiration) = 0; 322 base::Time expiration) = 0;
283 323
284 // Set alternative services for |origin|. Previous alternative services for 324 // Set alternative services for |origin|. Previous alternative services for
285 // |origin| are discarded. 325 // |origin| are discarded.
286 // Hostnames in |alternative_service_info_vector| may be empty. 326 // Hostnames in |alternative_service_info_vector| may be empty.
287 // Return true if |alternative_service_map_| is changed. 327 // Return true if |alternative_service_map_| is changed.
288 virtual bool SetAlternativeServices( 328 virtual bool SetAlternativeServices(
289 const HostPortPair& origin, 329 const SchemeOriginPair& origin,
290 const AlternativeServiceInfoVector& alternative_service_info_vector) = 0; 330 const AlternativeServiceInfoVector& alternative_service_info_vector) = 0;
291 331
292 // Marks |alternative_service| as broken. 332 // Marks |alternative_service| as broken.
293 // |alternative_service.host| must not be empty. 333 // |alternative_service.host| must not be empty.
294 virtual void MarkAlternativeServiceBroken( 334 virtual void MarkAlternativeServiceBroken(
295 const AlternativeService& alternative_service) = 0; 335 const AlternativeService& alternative_service) = 0;
296 336
297 // Marks |alternative_service| as recently broken. 337 // Marks |alternative_service| as recently broken.
298 // |alternative_service.host| must not be empty. 338 // |alternative_service.host| must not be empty.
299 virtual void MarkAlternativeServiceRecentlyBroken( 339 virtual void MarkAlternativeServiceRecentlyBroken(
300 const AlternativeService& alternative_service) = 0; 340 const AlternativeService& alternative_service) = 0;
301 341
302 // Returns true iff |alternative_service| is currently broken. 342 // Returns true iff |alternative_service| is currently broken.
303 // |alternative_service.host| must not be empty. 343 // |alternative_service.host| must not be empty.
304 virtual bool IsAlternativeServiceBroken( 344 virtual bool IsAlternativeServiceBroken(
305 const AlternativeService& alternative_service) const = 0; 345 const AlternativeService& alternative_service) const = 0;
306 346
307 // Returns true iff |alternative_service| was recently broken. 347 // Returns true iff |alternative_service| was recently broken.
308 // |alternative_service.host| must not be empty. 348 // |alternative_service.host| must not be empty.
309 virtual bool WasAlternativeServiceRecentlyBroken( 349 virtual bool WasAlternativeServiceRecentlyBroken(
310 const AlternativeService& alternative_service) = 0; 350 const AlternativeService& alternative_service) = 0;
311 351
312 // Confirms that |alternative_service| is working. 352 // Confirms that |alternative_service| is working.
313 // |alternative_service.host| must not be empty. 353 // |alternative_service.host| must not be empty.
314 virtual void ConfirmAlternativeService( 354 virtual void ConfirmAlternativeService(
315 const AlternativeService& alternative_service) = 0; 355 const AlternativeService& alternative_service) = 0;
316 356
317 // Clear all alternative services for |origin|. 357 // Clear all alternative services for |origin|.
318 virtual void ClearAlternativeServices(const HostPortPair& origin) = 0; 358 virtual void ClearAlternativeServices(const SchemeOriginPair& origin) = 0;
319 359
320 // Returns all alternative service mappings. 360 // Returns all alternative service mappings.
321 // Returned alternative services may have empty hostnames. 361 // Returned alternative services may have empty hostnames.
322 virtual const AlternativeServiceMap& alternative_service_map() const = 0; 362 virtual const AlternativeServiceMap& alternative_service_map() const = 0;
323 363
324 // Returns all alternative service mappings as human readable strings. 364 // Returns all alternative service mappings as human readable strings.
325 // Empty alternative service hostnames will be printed as such. 365 // Empty alternative service hostnames will be printed as such.
326 virtual scoped_ptr<base::Value> GetAlternativeServiceInfoAsValue() const = 0; 366 virtual scoped_ptr<base::Value> GetAlternativeServiceInfoAsValue() const = 0;
327 367
328 // Sets the threshold to be used when evaluating alternative service 368 // Sets the threshold to be used when evaluating alternative service
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 virtual void SetMaxServerConfigsStoredInProperties( 426 virtual void SetMaxServerConfigsStoredInProperties(
387 size_t max_server_configs_stored_in_properties) = 0; 427 size_t max_server_configs_stored_in_properties) = 0;
388 428
389 private: 429 private:
390 DISALLOW_COPY_AND_ASSIGN(HttpServerProperties); 430 DISALLOW_COPY_AND_ASSIGN(HttpServerProperties);
391 }; 431 };
392 432
393 } // namespace net 433 } // namespace net
394 434
395 #endif // NET_HTTP_HTTP_SERVER_PROPERTIES_H_ 435 #endif // NET_HTTP_HTTP_SERVER_PROPERTIES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698