OLD | NEW |
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 <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
| 10 #include <vector> |
| 11 |
10 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
11 #include "base/containers/mru_cache.h" | 13 #include "base/containers/mru_cache.h" |
12 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
13 #include "base/time/time.h" | 15 #include "base/time/time.h" |
14 #include "net/base/host_port_pair.h" | 16 #include "net/base/host_port_pair.h" |
15 #include "net/base/net_export.h" | 17 #include "net/base/net_export.h" |
16 #include "net/quic/quic_bandwidth.h" | 18 #include "net/quic/quic_bandwidth.h" |
17 #include "net/socket/next_proto.h" | 19 #include "net/socket/next_proto.h" |
18 #include "net/spdy/spdy_framer.h" // TODO(willchan): Reconsider this. | 20 #include "net/spdy/spdy_framer.h" // TODO(willchan): Reconsider this. |
19 #include "net/spdy/spdy_protocol.h" | 21 #include "net/spdy/spdy_protocol.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 // ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION and | 74 // ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION and |
73 // ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION (inclusive). | 75 // ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION (inclusive). |
74 NET_EXPORT bool IsAlternateProtocolValid(AlternateProtocol protocol); | 76 NET_EXPORT bool IsAlternateProtocolValid(AlternateProtocol protocol); |
75 | 77 |
76 enum AlternateProtocolSize { | 78 enum AlternateProtocolSize { |
77 NUM_VALID_ALTERNATE_PROTOCOLS = | 79 NUM_VALID_ALTERNATE_PROTOCOLS = |
78 ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION - | 80 ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION - |
79 ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION + 1, | 81 ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION + 1, |
80 }; | 82 }; |
81 | 83 |
82 NET_EXPORT const char* AlternateProtocolToString(AlternateProtocol protocol); | 84 // TODO(bnc): Rename to AlternativeServiceInfo. |
83 NET_EXPORT AlternateProtocol AlternateProtocolFromString( | 85 struct NET_EXPORT AlternateProtocolInfo { |
84 const std::string& str); | 86 AlternateProtocolInfo() |
85 NET_EXPORT_PRIVATE AlternateProtocol AlternateProtocolFromNextProto( | 87 : port(0), protocol(UNINITIALIZED_ALTERNATE_PROTOCOL), probability(0) {} |
86 NextProto next_proto); | |
87 | 88 |
88 struct NET_EXPORT AlternateProtocolInfo { | |
89 AlternateProtocolInfo(uint16 port, | 89 AlternateProtocolInfo(uint16 port, |
90 AlternateProtocol protocol, | 90 AlternateProtocol protocol, |
91 double probability) | 91 double probability) |
92 : port(port), | 92 : port(port), |
93 protocol(protocol), | 93 protocol(protocol), |
94 probability(probability), | 94 probability(probability), |
95 is_broken(false) {} | 95 is_broken(false) {} |
96 | 96 |
97 AlternateProtocolInfo(uint16 port, | 97 AlternateProtocolInfo(uint16 port, |
98 AlternateProtocol protocol, | 98 AlternateProtocol protocol, |
99 double probability, | 99 double probability, |
100 bool is_broken) | 100 bool is_broken) |
101 : port(port), | 101 : port(port), |
102 protocol(protocol), | 102 protocol(protocol), |
103 probability(probability), | 103 probability(probability), |
104 is_broken(is_broken) {} | 104 is_broken(is_broken) {} |
105 | 105 |
106 bool Equals(const AlternateProtocolInfo& other) const { | 106 bool Equals(const AlternateProtocolInfo& other) const { |
107 return port == other.port && | 107 return port == other.port && protocol == other.protocol && |
108 protocol == other.protocol && | 108 probability == other.probability; |
109 probability == other.probability; | 109 } |
| 110 |
| 111 bool EqualsModuloProbability(const AlternateProtocolInfo& other) const { |
| 112 return port == other.port && protocol == other.protocol; |
110 } | 113 } |
111 | 114 |
112 std::string ToString() const; | 115 std::string ToString() const; |
113 | 116 |
114 uint16 port; | 117 uint16 port; |
115 AlternateProtocol protocol; | 118 AlternateProtocol protocol; |
116 double probability; | 119 double probability; |
117 bool is_broken; | 120 bool is_broken; |
118 }; | 121 }; |
119 | 122 |
(...skipping 11 matching lines...) Expand all Loading... |
131 std::string address; | 134 std::string address; |
132 }; | 135 }; |
133 | 136 |
134 struct NET_EXPORT ServerNetworkStats { | 137 struct NET_EXPORT ServerNetworkStats { |
135 ServerNetworkStats() : bandwidth_estimate(QuicBandwidth::Zero()) {} | 138 ServerNetworkStats() : bandwidth_estimate(QuicBandwidth::Zero()) {} |
136 | 139 |
137 base::TimeDelta srtt; | 140 base::TimeDelta srtt; |
138 QuicBandwidth bandwidth_estimate; | 141 QuicBandwidth bandwidth_estimate; |
139 }; | 142 }; |
140 | 143 |
141 typedef base::MRUCache< | 144 // TODO(bnc): Rename to AlternativeServices. |
142 HostPortPair, AlternateProtocolInfo> AlternateProtocolMap; | 145 typedef std::vector<AlternateProtocolInfo> AlternateProtocols; |
| 146 // TODO(bnc): Rename to AlternativeServicesMap. |
| 147 typedef base::MRUCache<HostPortPair, AlternateProtocols> AlternateProtocolMap; |
143 typedef base::MRUCache<HostPortPair, SettingsMap> SpdySettingsMap; | 148 typedef base::MRUCache<HostPortPair, SettingsMap> SpdySettingsMap; |
144 typedef std::map<HostPortPair, SupportsQuic> SupportsQuicMap; | 149 typedef std::map<HostPortPair, SupportsQuic> SupportsQuicMap; |
145 typedef base::MRUCache<HostPortPair, ServerNetworkStats> ServerNetworkStatsMap; | 150 typedef base::MRUCache<HostPortPair, ServerNetworkStats> ServerNetworkStatsMap; |
146 | 151 |
147 extern const char kAlternateProtocolHeader[]; | 152 extern const char kAlternateProtocolHeader[]; |
148 | 153 |
| 154 NET_EXPORT const char* AlternateProtocolToString(AlternateProtocol protocol); |
| 155 // TODO(bnc): Rename to AlternativeServicesToString. |
| 156 NET_EXPORT std::string AlternateProtocolsToString( |
| 157 const AlternateProtocols& services); |
| 158 NET_EXPORT AlternateProtocol |
| 159 AlternateProtocolFromString(const std::string& str); |
| 160 NET_EXPORT_PRIVATE AlternateProtocol |
| 161 AlternateProtocolFromNextProto(NextProto next_proto); |
| 162 |
149 // The interface for setting/retrieving the HTTP server properties. | 163 // The interface for setting/retrieving the HTTP server properties. |
150 // Currently, this class manages servers': | 164 // Currently, this class manages servers': |
151 // * SPDY support (based on NPN results) | 165 // * SPDY support (based on NPN results) |
152 // * Alternate-Protocol support | 166 // * Alternate-Protocol support |
153 // * Spdy Settings (like CWND ID field) | 167 // * Spdy Settings (like CWND ID field) |
154 class NET_EXPORT HttpServerProperties { | 168 class NET_EXPORT HttpServerProperties { |
155 public: | 169 public: |
156 HttpServerProperties() {} | 170 HttpServerProperties() {} |
157 virtual ~HttpServerProperties() {} | 171 virtual ~HttpServerProperties() {} |
158 | 172 |
(...skipping 17 matching lines...) Expand all Loading... |
176 // Require HTTP/1.1 on subsequent connections. Not persisted. | 190 // Require HTTP/1.1 on subsequent connections. Not persisted. |
177 virtual void SetHTTP11Required(const HostPortPair& server) = 0; | 191 virtual void SetHTTP11Required(const HostPortPair& server) = 0; |
178 | 192 |
179 // Modify SSLConfig to force HTTP/1.1. | 193 // Modify SSLConfig to force HTTP/1.1. |
180 static void ForceHTTP11(SSLConfig* ssl_config); | 194 static void ForceHTTP11(SSLConfig* ssl_config); |
181 | 195 |
182 // Modify SSLConfig to force HTTP/1.1 if necessary. | 196 // Modify SSLConfig to force HTTP/1.1 if necessary. |
183 virtual void MaybeForceHTTP11(const HostPortPair& server, | 197 virtual void MaybeForceHTTP11(const HostPortPair& server, |
184 SSLConfig* ssl_config) = 0; | 198 SSLConfig* ssl_config) = 0; |
185 | 199 |
186 // Returns true if |server| has an Alternate-Protocol header. | 200 // Returns true iff |server| has a non-broken AlternateProtocol with |
| 201 // probability exceeding threshold, or if AlternateProtocol is forced. |
| 202 // TODO(bnc): Rename to HasAlternativeService. |
187 virtual bool HasAlternateProtocol(const HostPortPair& server) = 0; | 203 virtual bool HasAlternateProtocol(const HostPortPair& server) = 0; |
188 | 204 |
189 // Returns the Alternate-Protocol and port for |server|. | 205 // Returns the first non-broken AlternateProtocol with probability exceeding |
190 // HasAlternateProtocol(server) must be true. | 206 // threshold for |server|, or forced AlternateProtocol, or one with |
| 207 // UNINITIALIZED_ALTERNATE_PROTOCOL. |
| 208 // TODO(bnc): Rename to GetAlternativeService. |
191 virtual AlternateProtocolInfo GetAlternateProtocol( | 209 virtual AlternateProtocolInfo GetAlternateProtocol( |
192 const HostPortPair& server) = 0; | 210 const HostPortPair& server) = 0; |
193 | 211 |
194 // Sets the Alternate-Protocol for |server|. | 212 // Adds an Alternate-Protocol for |server|. |
195 virtual void SetAlternateProtocol(const HostPortPair& server, | 213 // TODO(bnc): Rename to AddAlternativeService. |
| 214 virtual void AddAlternateProtocol(const HostPortPair& server, |
196 uint16 alternate_port, | 215 uint16 alternate_port, |
197 AlternateProtocol alternate_protocol, | 216 AlternateProtocol alternate_protocol, |
198 double probability) = 0; | 217 double probability) = 0; |
199 | 218 |
200 // Sets the Alternate-Protocol for |server| to be BROKEN. | 219 // Sets a given Alternate-Protocol for |server| to be broken. |
201 virtual void SetBrokenAlternateProtocol(const HostPortPair& server) = 0; | 220 virtual void SetBrokenAlternateProtocol( |
| 221 const HostPortPair& server, |
| 222 const AlternateProtocolInfo& broken_alternate_protocol) = 0; |
202 | 223 |
203 // Returns true if Alternate-Protocol for |server| was recently BROKEN. | 224 // Returns true if given Alternate-Protocol for |server| was recently broken. |
204 virtual bool WasAlternateProtocolRecentlyBroken( | 225 virtual bool WasAlternateProtocolRecentlyBroken( |
205 const HostPortPair& server) = 0; | 226 const HostPortPair& server, |
| 227 const AlternateProtocolInfo& alternate_protocol) = 0; |
206 | 228 |
207 // Confirms that Alternate-Protocol for |server| is working. | 229 // Confirms that given Alternate-Protocol for |server| is working. |
208 virtual void ConfirmAlternateProtocol(const HostPortPair& server) = 0; | 230 virtual void ConfirmAlternateProtocol( |
| 231 const HostPortPair& server, |
| 232 const AlternateProtocolInfo& alternate_protocol) = 0; |
209 | 233 |
210 // Clears the Alternate-Protocol for |server|. | 234 // Clears all Alternate-Protocols for |server|. |
| 235 // TODO(bnc): Rename to ClearAlternativeServices. |
211 virtual void ClearAlternateProtocol(const HostPortPair& server) = 0; | 236 virtual void ClearAlternateProtocol(const HostPortPair& server) = 0; |
212 | 237 |
| 238 // Clears all Alternate-Protocols that are not broken for |server|. |
| 239 // TODO(bnc): Rename to ClearNonBrokenAlternativeServices. |
| 240 virtual void ClearNonBrokenAlternateProtocols(const HostPortPair& server) = 0; |
| 241 |
| 242 // Removes an Alternate-Protocol for |server|. |
| 243 // TODO(bnc): Rename to RemoveAlternativeService. |
| 244 virtual void RemoveAlternateProtocol( |
| 245 const HostPortPair& server, |
| 246 const AlternateProtocolInfo& alternate_protocol) = 0; |
| 247 |
213 // Returns all Alternate-Protocol mappings. | 248 // Returns all Alternate-Protocol mappings. |
| 249 // TODO(bnc): Rename to alternative_services_map. |
214 virtual const AlternateProtocolMap& alternate_protocol_map() const = 0; | 250 virtual const AlternateProtocolMap& alternate_protocol_map() const = 0; |
215 | 251 |
216 // Sets the threshold to be used when evaluating Alternate-Protocol | 252 // Sets the threshold to be used when evaluating Alternate-Protocol |
217 // advertisments. Only advertisements with a with a probability | 253 // advertisments. Only advertisements with a with a probability |
218 // greater than |threshold| will be honored. |threshold| must be | 254 // greater than |threshold| will be honored. |threshold| must be |
219 // between 0 and 1 inclusive. Hence, a threshold of 0 implies that | 255 // between 0 and 1 inclusive. Hence, a threshold of 0 implies that |
220 // all advertisements will be honored. | 256 // all advertisements will be honored. |
221 virtual void SetAlternateProtocolProbabilityThreshold( | 257 virtual void SetAlternateProtocolProbabilityThreshold( |
222 double threshold) = 0; | 258 double threshold) = 0; |
223 | 259 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 | 296 |
261 virtual const ServerNetworkStatsMap& server_network_stats_map() const = 0; | 297 virtual const ServerNetworkStatsMap& server_network_stats_map() const = 0; |
262 | 298 |
263 private: | 299 private: |
264 DISALLOW_COPY_AND_ASSIGN(HttpServerProperties); | 300 DISALLOW_COPY_AND_ASSIGN(HttpServerProperties); |
265 }; | 301 }; |
266 | 302 |
267 } // namespace net | 303 } // namespace net |
268 | 304 |
269 #endif // NET_HTTP_HTTP_SERVER_PROPERTIES_H_ | 305 #endif // NET_HTTP_HTTP_SERVER_PROPERTIES_H_ |
OLD | NEW |