media: Specify WebRTC owners in media OWNERS file.
[chromium-blink-merge.git] / net / http / http_server_properties.h
bloba73b4eb17cd868b7cc99d1d119259d4301f3b2d0
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/quic/quic_bandwidth.h"
17 #include "net/socket/next_proto.h"
18 #include "net/spdy/spdy_framer.h" // TODO(willchan): Reconsider this.
19 #include "net/spdy/spdy_protocol.h"
21 namespace net {
23 struct SSLConfig;
25 enum AlternateProtocolUsage {
26 // Alternate Protocol was used without racing a normal connection.
27 ALTERNATE_PROTOCOL_USAGE_NO_RACE = 0,
28 // Alternate Protocol was used by winning a race with a normal connection.
29 ALTERNATE_PROTOCOL_USAGE_WON_RACE = 1,
30 // Alternate Protocol was not used by losing a race with a normal connection.
31 ALTERNATE_PROTOCOL_USAGE_LOST_RACE = 2,
32 // Alternate Protocol was not used because no Alternate-Protocol information
33 // was available when the request was issued, but an Alternate-Protocol header
34 // was present in the response.
35 ALTERNATE_PROTOCOL_USAGE_MAPPING_MISSING = 3,
36 // Alternate Protocol was not used because it was marked broken.
37 ALTERNATE_PROTOCOL_USAGE_BROKEN = 4,
38 // Maximum value for the enum.
39 ALTERNATE_PROTOCOL_USAGE_MAX,
42 // Log a histogram to reflect |usage|.
43 NET_EXPORT void HistogramAlternateProtocolUsage(AlternateProtocolUsage usage);
45 enum BrokenAlternateProtocolLocation {
46 BROKEN_ALTERNATE_PROTOCOL_LOCATION_HTTP_STREAM_FACTORY_IMPL_JOB = 0,
47 BROKEN_ALTERNATE_PROTOCOL_LOCATION_QUIC_STREAM_FACTORY = 1,
48 BROKEN_ALTERNATE_PROTOCOL_LOCATION_HTTP_STREAM_FACTORY_IMPL_JOB_ALT = 2,
49 BROKEN_ALTERNATE_PROTOCOL_LOCATION_HTTP_STREAM_FACTORY_IMPL_JOB_MAIN = 3,
50 BROKEN_ALTERNATE_PROTOCOL_LOCATION_MAX,
53 // Log a histogram to reflect |location|.
54 NET_EXPORT void HistogramBrokenAlternateProtocolLocation(
55 BrokenAlternateProtocolLocation location);
57 enum AlternateProtocol {
58 DEPRECATED_NPN_SPDY_2 = 0,
59 ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION = DEPRECATED_NPN_SPDY_2,
60 NPN_SPDY_MINIMUM_VERSION = DEPRECATED_NPN_SPDY_2,
61 NPN_SPDY_3,
62 NPN_SPDY_3_1,
63 NPN_SPDY_4_14, // HTTP/2 draft-14
64 NPN_SPDY_4_15, // HTTP/2 draft-15
65 NPN_SPDY_MAXIMUM_VERSION = NPN_SPDY_4_15,
66 QUIC,
67 ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION = QUIC,
68 UNINITIALIZED_ALTERNATE_PROTOCOL,
71 // Simply returns whether |protocol| is between
72 // ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION and
73 // ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION (inclusive).
74 NET_EXPORT bool IsAlternateProtocolValid(AlternateProtocol protocol);
76 enum AlternateProtocolSize {
77 NUM_VALID_ALTERNATE_PROTOCOLS =
78 ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION -
79 ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION + 1,
82 NET_EXPORT const char* AlternateProtocolToString(AlternateProtocol protocol);
83 NET_EXPORT AlternateProtocol AlternateProtocolFromString(
84 const std::string& str);
85 NET_EXPORT_PRIVATE AlternateProtocol AlternateProtocolFromNextProto(
86 NextProto next_proto);
88 struct NET_EXPORT AlternateProtocolInfo {
89 AlternateProtocolInfo()
90 : port(0),
91 protocol(UNINITIALIZED_ALTERNATE_PROTOCOL),
92 probability(0),
93 is_broken(false) {}
95 AlternateProtocolInfo(uint16 port,
96 AlternateProtocol protocol,
97 double probability)
98 : port(port),
99 protocol(protocol),
100 probability(probability),
101 is_broken(false) {}
103 AlternateProtocolInfo(uint16 port,
104 AlternateProtocol protocol,
105 double probability,
106 bool is_broken)
107 : port(port),
108 protocol(protocol),
109 probability(probability),
110 is_broken(is_broken) {}
112 bool Equals(const AlternateProtocolInfo& other) const {
113 return port == other.port &&
114 protocol == other.protocol &&
115 probability == other.probability;
118 std::string ToString() const;
120 uint16 port;
121 AlternateProtocol protocol;
122 double probability;
123 bool is_broken;
126 struct NET_EXPORT SupportsQuic {
127 SupportsQuic() : used_quic(false) {}
128 SupportsQuic(bool used_quic, const std::string& address)
129 : used_quic(used_quic),
130 address(address) {}
132 bool Equals(const SupportsQuic& other) const {
133 return used_quic == other.used_quic && address == other.address;
136 bool used_quic;
137 std::string address;
140 struct NET_EXPORT ServerNetworkStats {
141 ServerNetworkStats() : bandwidth_estimate(QuicBandwidth::Zero()) {}
143 base::TimeDelta srtt;
144 QuicBandwidth bandwidth_estimate;
147 typedef base::MRUCache<
148 HostPortPair, AlternateProtocolInfo> AlternateProtocolMap;
149 typedef base::MRUCache<HostPortPair, SettingsMap> SpdySettingsMap;
150 typedef std::map<HostPortPair, SupportsQuic> SupportsQuicMap;
151 typedef base::MRUCache<HostPortPair, ServerNetworkStats> ServerNetworkStatsMap;
153 extern const char kAlternateProtocolHeader[];
155 // The interface for setting/retrieving the HTTP server properties.
156 // Currently, this class manages servers':
157 // * SPDY support (based on NPN results)
158 // * Alternate-Protocol support
159 // * Spdy Settings (like CWND ID field)
160 class NET_EXPORT HttpServerProperties {
161 public:
162 HttpServerProperties() {}
163 virtual ~HttpServerProperties() {}
165 // Gets a weak pointer for this object.
166 virtual base::WeakPtr<HttpServerProperties> GetWeakPtr() = 0;
168 // Deletes all data.
169 virtual void Clear() = 0;
171 // Returns true if |server| supports a network protocol which honors
172 // request prioritization.
173 virtual bool SupportsRequestPriority(const HostPortPair& server) = 0;
175 // Add |server| into the persistent store. Should only be called from IO
176 // thread.
177 virtual void SetSupportsSpdy(const HostPortPair& server,
178 bool support_spdy) = 0;
180 // Returns true if |server| has required HTTP/1.1 via HTTP/2 error code.
181 virtual bool RequiresHTTP11(const HostPortPair& server) = 0;
183 // Require HTTP/1.1 on subsequent connections. Not persisted.
184 virtual void SetHTTP11Required(const HostPortPair& server) = 0;
186 // Modify SSLConfig to force HTTP/1.1.
187 static void ForceHTTP11(SSLConfig* ssl_config);
189 // Modify SSLConfig to force HTTP/1.1 if necessary.
190 virtual void MaybeForceHTTP11(const HostPortPair& server,
191 SSLConfig* ssl_config) = 0;
193 // Returns the AlternateProtocol for |server| if it has probability equal to
194 // or exceeding threshold, or else the forced AlternateProtocol if there is
195 // one, or else one with UNINITIALIZED_ALTERNATE_PROTOCOL.
196 virtual AlternateProtocolInfo GetAlternateProtocol(
197 const HostPortPair& server) = 0;
199 // Sets the Alternate-Protocol for |server|.
200 virtual void SetAlternateProtocol(const HostPortPair& server,
201 uint16 alternate_port,
202 AlternateProtocol alternate_protocol,
203 double probability) = 0;
205 // Sets the Alternate-Protocol for |server| to be BROKEN.
206 virtual void SetBrokenAlternateProtocol(const HostPortPair& server) = 0;
208 // Returns true if Alternate-Protocol for |server| was recently BROKEN.
209 virtual bool WasAlternateProtocolRecentlyBroken(
210 const HostPortPair& server) = 0;
212 // Confirms that Alternate-Protocol for |server| is working.
213 virtual void ConfirmAlternateProtocol(const HostPortPair& server) = 0;
215 // Clears the Alternate-Protocol for |server|.
216 virtual void ClearAlternateProtocol(const HostPortPair& server) = 0;
218 // Returns all Alternate-Protocol mappings.
219 virtual const AlternateProtocolMap& alternate_protocol_map() const = 0;
221 // Sets the threshold to be used when evaluating Alternate-Protocol
222 // advertisments. Only advertisements with a with a probability
223 // greater than |threshold| will be honored. |threshold| must be
224 // between 0 and 1 inclusive. Hence, a threshold of 0 implies that
225 // all advertisements will be honored.
226 virtual void SetAlternateProtocolProbabilityThreshold(
227 double threshold) = 0;
229 // Gets a reference to the SettingsMap stored for a host.
230 // If no settings are stored, returns an empty SettingsMap.
231 virtual const SettingsMap& GetSpdySettings(
232 const HostPortPair& host_port_pair) = 0;
234 // Saves an individual SPDY setting for a host. Returns true if SPDY setting
235 // is to be persisted.
236 virtual bool SetSpdySetting(const HostPortPair& host_port_pair,
237 SpdySettingsIds id,
238 SpdySettingsFlags flags,
239 uint32 value) = 0;
241 // Clears all SPDY settings for a host.
242 virtual void ClearSpdySettings(const HostPortPair& host_port_pair) = 0;
244 // Clears all SPDY settings for all hosts.
245 virtual void ClearAllSpdySettings() = 0;
247 // Returns all persistent SPDY settings.
248 virtual const SpdySettingsMap& spdy_settings_map() const = 0;
250 // TODO(rtenneti): Make SupportsQuic a global (instead of per host_port_pair).
251 virtual SupportsQuic GetSupportsQuic(
252 const HostPortPair& host_port_pair) const = 0;
254 virtual void SetSupportsQuic(const HostPortPair& host_port_pair,
255 bool used_quic,
256 const std::string& address) = 0;
258 virtual const SupportsQuicMap& supports_quic_map() const = 0;
260 virtual void SetServerNetworkStats(const HostPortPair& host_port_pair,
261 ServerNetworkStats stats) = 0;
263 virtual const ServerNetworkStats* GetServerNetworkStats(
264 const HostPortPair& host_port_pair) = 0;
266 virtual const ServerNetworkStatsMap& server_network_stats_map() const = 0;
268 private:
269 DISALLOW_COPY_AND_ASSIGN(HttpServerProperties);
272 } // namespace net
274 #endif // NET_HTTP_HTTP_SERVER_PROPERTIES_H_