Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / net / http / http_server_properties.h
blob718f4c5a4e54dee5b455cd55cd71432423a33350
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
3 // found in the LICENSE file.
5 #ifndef NET_HTTP_HTTP_SERVER_PROPERTIES_H_
6 #define NET_HTTP_HTTP_SERVER_PROPERTIES_H_
8 #include <map>
9 #include <string>
10 #include "base/basictypes.h"
11 #include "base/containers/mru_cache.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/time/time.h"
14 #include "net/base/host_port_pair.h"
15 #include "net/base/net_export.h"
16 #include "net/socket/next_proto.h"
17 #include "net/spdy/spdy_framer.h" // TODO(willchan): Reconsider this.
19 namespace net {
21 enum AlternateProtocolExperiment {
22 // 200 alternate_protocol servers are loaded (persisted 200 MRU servers).
23 ALTERNATE_PROTOCOL_NOT_PART_OF_EXPERIMENT = 0,
24 // 200 alternate_protocol servers are loaded (persisted 1000 MRU servers).
25 ALTERNATE_PROTOCOL_TRUNCATED_200_SERVERS,
26 // 1000 alternate_protocol servers are loaded (persisted 1000 MRU servers).
27 ALTERNATE_PROTOCOL_TRUNCATED_1000_SERVERS,
30 enum AlternateProtocolUsage {
31 // Alternate Protocol was used without racing a normal connection.
32 ALTERNATE_PROTOCOL_USAGE_NO_RACE = 0,
33 // Alternate Protocol was used by winning a race with a normal connection.
34 ALTERNATE_PROTOCOL_USAGE_WON_RACE = 1,
35 // Alternate Protocol was not used by losing a race with a normal connection.
36 ALTERNATE_PROTOCOL_USAGE_LOST_RACE = 2,
37 // Alternate Protocol was not used because no Alternate-Protocol information
38 // was available when the request was issued, but an Alternate-Protocol header
39 // was present in the response.
40 ALTERNATE_PROTOCOL_USAGE_MAPPING_MISSING = 3,
41 // Alternate Protocol was not used because it was marked broken.
42 ALTERNATE_PROTOCOL_USAGE_BROKEN = 4,
43 // Maximum value for the enum.
44 ALTERNATE_PROTOCOL_USAGE_MAX,
47 // Log a histogram to reflect |usage| and |alternate_protocol_experiment|.
48 NET_EXPORT void HistogramAlternateProtocolUsage(
49 AlternateProtocolUsage usage,
50 AlternateProtocolExperiment alternate_protocol_experiment);
52 enum BrokenAlternateProtocolLocation {
53 BROKEN_ALTERNATE_PROTOCOL_LOCATION_HTTP_STREAM_FACTORY_IMPL_JOB = 0,
54 BROKEN_ALTERNATE_PROTOCOL_LOCATION_QUIC_STREAM_FACTORY = 1,
55 BROKEN_ALTERNATE_PROTOCOL_LOCATION_HTTP_STREAM_FACTORY_IMPL_JOB_ALT = 2,
56 BROKEN_ALTERNATE_PROTOCOL_LOCATION_HTTP_STREAM_FACTORY_IMPL_JOB_MAIN = 3,
57 BROKEN_ALTERNATE_PROTOCOL_LOCATION_MAX,
60 // Log a histogram to reflect |location|.
61 NET_EXPORT void HistogramBrokenAlternateProtocolLocation(
62 BrokenAlternateProtocolLocation location);
64 enum AlternateProtocol {
65 DEPRECATED_NPN_SPDY_2 = 0,
66 ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION = DEPRECATED_NPN_SPDY_2,
67 NPN_SPDY_MINIMUM_VERSION = DEPRECATED_NPN_SPDY_2,
68 NPN_SPDY_3,
69 NPN_SPDY_3_1,
70 NPN_SPDY_4, // SPDY4 is HTTP/2.
71 NPN_SPDY_MAXIMUM_VERSION = NPN_SPDY_4,
72 QUIC,
73 ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION = QUIC,
74 ALTERNATE_PROTOCOL_BROKEN, // The alternate protocol is known to be broken.
75 UNINITIALIZED_ALTERNATE_PROTOCOL,
78 // Simply returns whether |protocol| is between
79 // ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION and
80 // ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION (inclusive).
81 NET_EXPORT bool IsAlternateProtocolValid(AlternateProtocol protocol);
83 enum AlternateProtocolSize {
84 NUM_VALID_ALTERNATE_PROTOCOLS =
85 ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION -
86 ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION + 1,
89 NET_EXPORT const char* AlternateProtocolToString(AlternateProtocol protocol);
90 NET_EXPORT AlternateProtocol AlternateProtocolFromString(
91 const std::string& str);
92 NET_EXPORT_PRIVATE AlternateProtocol AlternateProtocolFromNextProto(
93 NextProto next_proto);
95 struct NET_EXPORT AlternateProtocolInfo {
96 AlternateProtocolInfo(uint16 port,
97 AlternateProtocol protocol,
98 double probability)
99 : port(port),
100 protocol(protocol),
101 probability(probability) {}
103 bool Equals(const AlternateProtocolInfo& other) const {
104 return port == other.port &&
105 protocol == other.protocol &&
106 probability == other.probability;
109 std::string ToString() const;
111 uint16 port;
112 AlternateProtocol protocol;
113 double probability;
116 typedef base::MRUCache<
117 HostPortPair, AlternateProtocolInfo> AlternateProtocolMap;
118 typedef base::MRUCache<HostPortPair, SettingsMap> SpdySettingsMap;
120 extern const char kAlternateProtocolHeader[];
122 // The interface for setting/retrieving the HTTP server properties.
123 // Currently, this class manages servers':
124 // * SPDY support (based on NPN results)
125 // * Alternate-Protocol support
126 // * Spdy Settings (like CWND ID field)
127 class NET_EXPORT HttpServerProperties {
128 public:
129 struct NetworkStats {
130 base::TimeDelta srtt;
131 uint64 bandwidth_estimate;
134 HttpServerProperties() {}
135 virtual ~HttpServerProperties() {}
137 // Gets a weak pointer for this object.
138 virtual base::WeakPtr<HttpServerProperties> GetWeakPtr() = 0;
140 // Deletes all data.
141 virtual void Clear() = 0;
143 // Returns true if |server| supports SPDY.
144 virtual bool SupportsSpdy(const HostPortPair& server) = 0;
146 // Add |server| into the persistent store. Should only be called from IO
147 // thread.
148 virtual void SetSupportsSpdy(const HostPortPair& server,
149 bool support_spdy) = 0;
151 // Returns true if |server| has an Alternate-Protocol header.
152 virtual bool HasAlternateProtocol(const HostPortPair& server) = 0;
154 // Returns the Alternate-Protocol and port for |server|.
155 // HasAlternateProtocol(server) must be true.
156 virtual AlternateProtocolInfo GetAlternateProtocol(
157 const HostPortPair& server) = 0;
159 // Sets the Alternate-Protocol for |server|.
160 virtual void SetAlternateProtocol(const HostPortPair& server,
161 uint16 alternate_port,
162 AlternateProtocol alternate_protocol,
163 double probability) = 0;
165 // Sets the Alternate-Protocol for |server| to be BROKEN.
166 virtual void SetBrokenAlternateProtocol(const HostPortPair& server) = 0;
168 // Returns true if Alternate-Protocol for |server| was recently BROKEN.
169 virtual bool WasAlternateProtocolRecentlyBroken(
170 const HostPortPair& server) = 0;
172 // Confirms that Alternate-Protocol for |server| is working.
173 virtual void ConfirmAlternateProtocol(const HostPortPair& server) = 0;
175 // Clears the Alternate-Protocol for |server|.
176 virtual void ClearAlternateProtocol(const HostPortPair& server) = 0;
178 // Returns all Alternate-Protocol mappings.
179 virtual const AlternateProtocolMap& alternate_protocol_map() const = 0;
181 virtual void SetAlternateProtocolExperiment(
182 AlternateProtocolExperiment experiment) = 0;
184 virtual void SetAlternateProtocolProbabilityThreshold(
185 double threshold) = 0;
187 virtual AlternateProtocolExperiment GetAlternateProtocolExperiment()
188 const = 0;
190 // Gets a reference to the SettingsMap stored for a host.
191 // If no settings are stored, returns an empty SettingsMap.
192 virtual const SettingsMap& GetSpdySettings(
193 const HostPortPair& host_port_pair) = 0;
195 // Saves an individual SPDY setting for a host. Returns true if SPDY setting
196 // is to be persisted.
197 virtual bool SetSpdySetting(const HostPortPair& host_port_pair,
198 SpdySettingsIds id,
199 SpdySettingsFlags flags,
200 uint32 value) = 0;
202 // Clears all SPDY settings for a host.
203 virtual void ClearSpdySettings(const HostPortPair& host_port_pair) = 0;
205 // Clears all SPDY settings for all hosts.
206 virtual void ClearAllSpdySettings() = 0;
208 // Returns all persistent SPDY settings.
209 virtual const SpdySettingsMap& spdy_settings_map() const = 0;
211 virtual void SetServerNetworkStats(const HostPortPair& host_port_pair,
212 NetworkStats stats) = 0;
214 virtual const NetworkStats* GetServerNetworkStats(
215 const HostPortPair& host_port_pair) const = 0;
217 private:
218 DISALLOW_COPY_AND_ASSIGN(HttpServerProperties);
221 } // namespace net
223 #endif // NET_HTTP_HTTP_SERVER_PROPERTIES_H_