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

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

Issue 992733002: Remove //net (except for Android test stuff) and sdch (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 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
« no previous file with comments | « net/http/http_security_headers_unittest.cc ('k') | net/http/http_server_properties.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #ifndef NET_HTTP_HTTP_SERVER_PROPERTIES_H_
6 #define NET_HTTP_HTTP_SERVER_PROPERTIES_H_
7
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/base/net_util.h"
17 #include "net/quic/quic_bandwidth.h"
18 #include "net/socket/next_proto.h"
19 #include "net/spdy/spdy_framer.h" // TODO(willchan): Reconsider this.
20 #include "net/spdy/spdy_protocol.h"
21
22 namespace net {
23
24 struct SSLConfig;
25
26 enum AlternateProtocolUsage {
27 // Alternate Protocol was used without racing a normal connection.
28 ALTERNATE_PROTOCOL_USAGE_NO_RACE = 0,
29 // Alternate Protocol was used by winning a race with a normal connection.
30 ALTERNATE_PROTOCOL_USAGE_WON_RACE = 1,
31 // Alternate Protocol was not used by losing a race with a normal connection.
32 ALTERNATE_PROTOCOL_USAGE_LOST_RACE = 2,
33 // Alternate Protocol was not used because no Alternate-Protocol information
34 // was available when the request was issued, but an Alternate-Protocol header
35 // was present in the response.
36 ALTERNATE_PROTOCOL_USAGE_MAPPING_MISSING = 3,
37 // Alternate Protocol was not used because it was marked broken.
38 ALTERNATE_PROTOCOL_USAGE_BROKEN = 4,
39 // Maximum value for the enum.
40 ALTERNATE_PROTOCOL_USAGE_MAX,
41 };
42
43 // Log a histogram to reflect |usage|.
44 NET_EXPORT void HistogramAlternateProtocolUsage(AlternateProtocolUsage usage);
45
46 enum BrokenAlternateProtocolLocation {
47 BROKEN_ALTERNATE_PROTOCOL_LOCATION_HTTP_STREAM_FACTORY_IMPL_JOB = 0,
48 BROKEN_ALTERNATE_PROTOCOL_LOCATION_QUIC_STREAM_FACTORY = 1,
49 BROKEN_ALTERNATE_PROTOCOL_LOCATION_HTTP_STREAM_FACTORY_IMPL_JOB_ALT = 2,
50 BROKEN_ALTERNATE_PROTOCOL_LOCATION_HTTP_STREAM_FACTORY_IMPL_JOB_MAIN = 3,
51 BROKEN_ALTERNATE_PROTOCOL_LOCATION_MAX,
52 };
53
54 // Log a histogram to reflect |location|.
55 NET_EXPORT void HistogramBrokenAlternateProtocolLocation(
56 BrokenAlternateProtocolLocation location);
57
58 enum AlternateProtocol {
59 DEPRECATED_NPN_SPDY_2 = 0,
60 ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION = DEPRECATED_NPN_SPDY_2,
61 NPN_SPDY_MINIMUM_VERSION = DEPRECATED_NPN_SPDY_2,
62 NPN_SPDY_3,
63 NPN_SPDY_3_1,
64 NPN_SPDY_4_14, // HTTP/2 draft-14
65 NPN_SPDY_4_15, // HTTP/2 draft-15
66 NPN_SPDY_MAXIMUM_VERSION = NPN_SPDY_4_15,
67 QUIC,
68 ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION = QUIC,
69 UNINITIALIZED_ALTERNATE_PROTOCOL,
70 };
71
72 // Simply returns whether |protocol| is between
73 // ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION and
74 // ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION (inclusive).
75 NET_EXPORT bool IsAlternateProtocolValid(AlternateProtocol protocol);
76
77 enum AlternateProtocolSize {
78 NUM_VALID_ALTERNATE_PROTOCOLS =
79 ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION -
80 ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION + 1,
81 };
82
83 NET_EXPORT const char* AlternateProtocolToString(AlternateProtocol protocol);
84 NET_EXPORT AlternateProtocol AlternateProtocolFromString(
85 const std::string& str);
86 NET_EXPORT_PRIVATE AlternateProtocol AlternateProtocolFromNextProto(
87 NextProto next_proto);
88
89 struct NET_EXPORT AlternateProtocolInfo {
90 AlternateProtocolInfo()
91 : port(0),
92 protocol(UNINITIALIZED_ALTERNATE_PROTOCOL),
93 probability(0),
94 is_broken(false) {}
95
96 AlternateProtocolInfo(uint16 port,
97 AlternateProtocol protocol,
98 double probability)
99 : port(port),
100 protocol(protocol),
101 probability(probability),
102 is_broken(false) {}
103
104 AlternateProtocolInfo(uint16 port,
105 AlternateProtocol protocol,
106 double probability,
107 bool is_broken)
108 : port(port),
109 protocol(protocol),
110 probability(probability),
111 is_broken(is_broken) {}
112
113 bool Equals(const AlternateProtocolInfo& other) const {
114 return port == other.port &&
115 protocol == other.protocol &&
116 probability == other.probability;
117 }
118
119 std::string ToString() const;
120
121 uint16 port;
122 AlternateProtocol protocol;
123 double probability;
124 bool is_broken;
125 };
126
127 struct NET_EXPORT SupportsQuic {
128 SupportsQuic() : used_quic(false) {}
129 SupportsQuic(bool used_quic, const std::string& address)
130 : used_quic(used_quic),
131 address(address) {}
132
133 bool Equals(const SupportsQuic& other) const {
134 return used_quic == other.used_quic && address == other.address;
135 }
136
137 bool used_quic;
138 std::string address;
139 };
140
141 struct NET_EXPORT ServerNetworkStats {
142 ServerNetworkStats() : bandwidth_estimate(QuicBandwidth::Zero()) {}
143
144 base::TimeDelta srtt;
145 QuicBandwidth bandwidth_estimate;
146 };
147
148 typedef base::MRUCache<
149 HostPortPair, AlternateProtocolInfo> AlternateProtocolMap;
150 typedef base::MRUCache<HostPortPair, SettingsMap> SpdySettingsMap;
151 typedef base::MRUCache<HostPortPair, ServerNetworkStats> ServerNetworkStatsMap;
152
153 extern const char kAlternateProtocolHeader[];
154
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() {}
164
165 // Gets a weak pointer for this object.
166 virtual base::WeakPtr<HttpServerProperties> GetWeakPtr() = 0;
167
168 // Deletes all data.
169 virtual void Clear() = 0;
170
171 // Returns true if |server| supports a network protocol which honors
172 // request prioritization.
173 virtual bool SupportsRequestPriority(const HostPortPair& server) = 0;
174
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;
179
180 // Returns true if |server| has required HTTP/1.1 via HTTP/2 error code.
181 virtual bool RequiresHTTP11(const HostPortPair& server) = 0;
182
183 // Require HTTP/1.1 on subsequent connections. Not persisted.
184 virtual void SetHTTP11Required(const HostPortPair& server) = 0;
185
186 // Modify SSLConfig to force HTTP/1.1.
187 static void ForceHTTP11(SSLConfig* ssl_config);
188
189 // Modify SSLConfig to force HTTP/1.1 if necessary.
190 virtual void MaybeForceHTTP11(const HostPortPair& server,
191 SSLConfig* ssl_config) = 0;
192
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;
198
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;
204
205 // Sets the Alternate-Protocol for |server| to be BROKEN.
206 virtual void SetBrokenAlternateProtocol(const HostPortPair& server) = 0;
207
208 // Returns true if Alternate-Protocol for |server| was recently BROKEN.
209 virtual bool WasAlternateProtocolRecentlyBroken(
210 const HostPortPair& server) = 0;
211
212 // Confirms that Alternate-Protocol for |server| is working.
213 virtual void ConfirmAlternateProtocol(const HostPortPair& server) = 0;
214
215 // Clears the Alternate-Protocol for |server|.
216 virtual void ClearAlternateProtocol(const HostPortPair& server) = 0;
217
218 // Returns all Alternate-Protocol mappings.
219 virtual const AlternateProtocolMap& alternate_protocol_map() const = 0;
220
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;
228
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;
233
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;
240
241 // Clears all SPDY settings for a host.
242 virtual void ClearSpdySettings(const HostPortPair& host_port_pair) = 0;
243
244 // Clears all SPDY settings for all hosts.
245 virtual void ClearAllSpdySettings() = 0;
246
247 // Returns all persistent SPDY settings.
248 virtual const SpdySettingsMap& spdy_settings_map() const = 0;
249
250 virtual bool GetSupportsQuic(IPAddressNumber* last_address) const = 0;
251
252 virtual void SetSupportsQuic(bool used_quic,
253 const IPAddressNumber& last_address) = 0;
254
255 virtual void SetServerNetworkStats(const HostPortPair& host_port_pair,
256 ServerNetworkStats stats) = 0;
257
258 virtual const ServerNetworkStats* GetServerNetworkStats(
259 const HostPortPair& host_port_pair) = 0;
260
261 virtual const ServerNetworkStatsMap& server_network_stats_map() const = 0;
262
263 private:
264 DISALLOW_COPY_AND_ASSIGN(HttpServerProperties);
265 };
266
267 } // namespace net
268
269 #endif // NET_HTTP_HTTP_SERVER_PROPERTIES_H_
OLDNEW
« no previous file with comments | « net/http/http_security_headers_unittest.cc ('k') | net/http/http_server_properties.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698