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 struct NET_EXPORT AlternativeService { |
83 NET_EXPORT AlternateProtocol AlternateProtocolFromString( | 85 AlternativeService(AlternateProtocol protocol, |
84 const std::string& str); | 86 const std::string& host, |
85 NET_EXPORT_PRIVATE AlternateProtocol AlternateProtocolFromNextProto( | 87 uint16 port) |
86 NextProto next_proto); | 88 : protocol(protocol), host(host), port(port) {} |
87 | 89 |
| 90 bool operator<(const AlternativeService& other) const { |
| 91 if (protocol != other.protocol) |
| 92 return protocol < other.protocol; |
| 93 if (host != other.host) |
| 94 return host < other.host; |
| 95 return port < other.port; |
| 96 } |
| 97 |
| 98 AlternateProtocol protocol; |
| 99 const std::string host; |
| 100 uint16 port; |
| 101 }; |
| 102 |
| 103 // TODO(bnc): Rename to AlternateServiceInfo. |
88 struct NET_EXPORT AlternateProtocolInfo { | 104 struct NET_EXPORT AlternateProtocolInfo { |
| 105 AlternateProtocolInfo() |
| 106 : port(0), protocol(UNINITIALIZED_ALTERNATE_PROTOCOL), probability(0) {} |
| 107 |
89 AlternateProtocolInfo(uint16 port, | 108 AlternateProtocolInfo(uint16 port, |
90 AlternateProtocol protocol, | 109 AlternateProtocol protocol, |
91 double probability) | 110 double probability) |
92 : port(port), | 111 : port(port), |
93 protocol(protocol), | 112 protocol(protocol), |
94 probability(probability), | 113 probability(probability), |
95 is_broken(false) {} | 114 is_broken(false) {} |
96 | 115 |
97 AlternateProtocolInfo(uint16 port, | 116 AlternateProtocolInfo(uint16 port, |
98 AlternateProtocol protocol, | 117 AlternateProtocol protocol, |
99 double probability, | 118 double probability, |
100 bool is_broken) | 119 bool is_broken) |
101 : port(port), | 120 : port(port), |
102 protocol(protocol), | 121 protocol(protocol), |
103 probability(probability), | 122 probability(probability), |
104 is_broken(is_broken) {} | 123 is_broken(is_broken) {} |
105 | 124 |
106 bool Equals(const AlternateProtocolInfo& other) const { | 125 bool Equals(const AlternateProtocolInfo& other) const { |
107 return port == other.port && | 126 return port == other.port && protocol == other.protocol && |
108 protocol == other.protocol && | 127 probability == other.probability; |
109 probability == other.probability; | 128 } |
| 129 |
| 130 bool EqualsModuloProbability(const AlternateProtocolInfo& other) const { |
| 131 return port == other.port && protocol == other.protocol; |
110 } | 132 } |
111 | 133 |
112 std::string ToString() const; | 134 std::string ToString() const; |
113 | 135 |
114 uint16 port; | 136 uint16 port; |
115 AlternateProtocol protocol; | 137 AlternateProtocol protocol; |
116 double probability; | 138 double probability; |
117 bool is_broken; | 139 bool is_broken; |
118 }; | 140 }; |
119 | 141 |
(...skipping 11 matching lines...) Expand all Loading... |
131 std::string address; | 153 std::string address; |
132 }; | 154 }; |
133 | 155 |
134 struct NET_EXPORT ServerNetworkStats { | 156 struct NET_EXPORT ServerNetworkStats { |
135 ServerNetworkStats() : bandwidth_estimate(QuicBandwidth::Zero()) {} | 157 ServerNetworkStats() : bandwidth_estimate(QuicBandwidth::Zero()) {} |
136 | 158 |
137 base::TimeDelta srtt; | 159 base::TimeDelta srtt; |
138 QuicBandwidth bandwidth_estimate; | 160 QuicBandwidth bandwidth_estimate; |
139 }; | 161 }; |
140 | 162 |
141 typedef base::MRUCache< | 163 // TODO(bnc): Rename to AlternateServices. |
142 HostPortPair, AlternateProtocolInfo> AlternateProtocolMap; | 164 typedef std::vector<AlternateProtocolInfo> AlternateProtocols; |
| 165 // TODO(bnc): Rename to AlternateServicesMap. |
| 166 typedef base::MRUCache<HostPortPair, AlternateProtocols> AlternateProtocolMap; |
143 typedef base::MRUCache<HostPortPair, SettingsMap> SpdySettingsMap; | 167 typedef base::MRUCache<HostPortPair, SettingsMap> SpdySettingsMap; |
144 typedef std::map<HostPortPair, SupportsQuic> SupportsQuicMap; | 168 typedef std::map<HostPortPair, SupportsQuic> SupportsQuicMap; |
145 typedef base::MRUCache<HostPortPair, ServerNetworkStats> ServerNetworkStatsMap; | 169 typedef base::MRUCache<HostPortPair, ServerNetworkStats> ServerNetworkStatsMap; |
146 | 170 |
147 extern const char kAlternateProtocolHeader[]; | 171 extern const char kAlternateProtocolHeader[]; |
148 | 172 |
| 173 NET_EXPORT const char* AlternateProtocolToString(AlternateProtocol protocol); |
| 174 // TODO(bnc): Rename to AlternateServicesToString. |
| 175 NET_EXPORT std::string AlternateProtocolsToString( |
| 176 const AlternateProtocols& services); |
| 177 NET_EXPORT AlternateProtocol |
| 178 AlternateProtocolFromString(const std::string& str); |
| 179 NET_EXPORT_PRIVATE AlternateProtocol |
| 180 AlternateProtocolFromNextProto(NextProto next_proto); |
| 181 |
149 // The interface for setting/retrieving the HTTP server properties. | 182 // The interface for setting/retrieving the HTTP server properties. |
150 // Currently, this class manages servers': | 183 // Currently, this class manages servers': |
151 // * SPDY support (based on NPN results) | 184 // * SPDY support (based on NPN results) |
152 // * Alternate-Protocol support | 185 // * Alternate-Protocol support |
153 // * Spdy Settings (like CWND ID field) | 186 // * Spdy Settings (like CWND ID field) |
154 class NET_EXPORT HttpServerProperties { | 187 class NET_EXPORT HttpServerProperties { |
155 public: | 188 public: |
156 HttpServerProperties() {} | 189 HttpServerProperties() {} |
157 virtual ~HttpServerProperties() {} | 190 virtual ~HttpServerProperties() {} |
158 | 191 |
(...skipping 18 matching lines...) Expand all Loading... |
177 virtual void SetHTTP11Required(const HostPortPair& server) = 0; | 210 virtual void SetHTTP11Required(const HostPortPair& server) = 0; |
178 | 211 |
179 // Modify SSLConfig to force HTTP/1.1. | 212 // Modify SSLConfig to force HTTP/1.1. |
180 static void ForceHTTP11(SSLConfig* ssl_config); | 213 static void ForceHTTP11(SSLConfig* ssl_config); |
181 | 214 |
182 // Modify SSLConfig to force HTTP/1.1 if necessary. | 215 // Modify SSLConfig to force HTTP/1.1 if necessary. |
183 virtual void MaybeForceHTTP11(const HostPortPair& server, | 216 virtual void MaybeForceHTTP11(const HostPortPair& server, |
184 SSLConfig* ssl_config) = 0; | 217 SSLConfig* ssl_config) = 0; |
185 | 218 |
186 // Returns true if |server| has an Alternate-Protocol header. | 219 // Returns true if |server| has an Alternate-Protocol header. |
| 220 // TODO(bnc): Rename to HasAlternateService. |
187 virtual bool HasAlternateProtocol(const HostPortPair& server) = 0; | 221 virtual bool HasAlternateProtocol(const HostPortPair& server) = 0; |
188 | 222 |
189 // Returns the Alternate-Protocol and port for |server|. | 223 // Returns the Alternate-Protocols for |server|. |
190 // HasAlternateProtocol(server) must be true. | 224 // HasAlternateProtocol(server) must be true. |
191 virtual AlternateProtocolInfo GetAlternateProtocol( | 225 virtual const AlternateProtocols& GetAlternateProtocols( |
192 const HostPortPair& server) = 0; | 226 const HostPortPair& server) = 0; |
193 | 227 |
194 // Sets the Alternate-Protocol for |server|. | 228 // Adds an Alternate-Protocol for |server|. |
195 virtual void SetAlternateProtocol(const HostPortPair& server, | 229 // TODO(bnc): Rename to AddAlternateService. |
| 230 virtual void AddAlternateProtocol(const HostPortPair& server, |
196 uint16 alternate_port, | 231 uint16 alternate_port, |
197 AlternateProtocol alternate_protocol, | 232 AlternateProtocol alternate_protocol, |
198 double probability) = 0; | 233 double probability) = 0; |
199 | 234 |
200 // Sets the Alternate-Protocol for |server| to be BROKEN. | 235 // Sets a given Alternate-Protocol for |server| to be BROKEN. |
201 virtual void SetBrokenAlternateProtocol(const HostPortPair& server) = 0; | 236 virtual void SetBrokenAlternateProtocol( |
| 237 const HostPortPair& server, |
| 238 const AlternateProtocolInfo& broken_alternate_protocol) = 0; |
202 | 239 |
203 // Returns true if Alternate-Protocol for |server| was recently BROKEN. | 240 // Returns true if given Alternate-Protocol for |server| was recently BROKEN. |
204 virtual bool WasAlternateProtocolRecentlyBroken( | 241 virtual bool WasAlternateProtocolRecentlyBroken( |
205 const HostPortPair& server) = 0; | 242 const HostPortPair& server, |
| 243 const AlternateProtocolInfo& alternate_protocol) = 0; |
206 | 244 |
207 // Confirms that Alternate-Protocol for |server| is working. | 245 // Confirms that given Alternate-Protocol for |server| is working. |
208 virtual void ConfirmAlternateProtocol(const HostPortPair& server) = 0; | 246 virtual void ConfirmAlternateProtocol( |
| 247 const HostPortPair& server, |
| 248 const AlternateProtocolInfo& alternate_protocol) = 0; |
209 | 249 |
210 // Clears the Alternate-Protocol for |server|. | 250 // Clears all Alternate-Protocols for |server|. |
| 251 // TODO(bnc): Rename to ClearAlternateServices. |
211 virtual void ClearAlternateProtocol(const HostPortPair& server) = 0; | 252 virtual void ClearAlternateProtocol(const HostPortPair& server) = 0; |
212 | 253 |
| 254 // Clears all Alternate-Protocols that are not broken for |server|. |
| 255 // TODO(bnc): Rename to ClearNonBrokenAlternateServices. |
| 256 virtual void ClearNonBrokenAlternateProtocols(const HostPortPair& server) = 0; |
| 257 |
| 258 // Removes an Alternate-Protocol for |server|. |
| 259 // TODO(bnc): Rename to RemoveAlternateService. |
| 260 virtual void RemoveAlternateProtocol( |
| 261 const HostPortPair& server, |
| 262 const AlternateProtocolInfo& alternate_protocol) = 0; |
| 263 |
213 // Returns all Alternate-Protocol mappings. | 264 // Returns all Alternate-Protocol mappings. |
| 265 // TODO(bnc): Rename to alternate_services_map. |
214 virtual const AlternateProtocolMap& alternate_protocol_map() const = 0; | 266 virtual const AlternateProtocolMap& alternate_protocol_map() const = 0; |
215 | 267 |
216 // Sets the threshold to be used when evaluating Alternate-Protocol | 268 // Sets the threshold to be used when evaluating Alternate-Protocol |
217 // advertisments. Only advertisements with a with a probability | 269 // advertisments. Only advertisements with a with a probability |
218 // greater than |threshold| will be honored. |threshold| must be | 270 // greater than |threshold| will be honored. |threshold| must be |
219 // between 0 and 1 inclusive. Hence, a threshold of 0 implies that | 271 // between 0 and 1 inclusive. Hence, a threshold of 0 implies that |
220 // all advertisements will be honored. | 272 // all advertisements will be honored. |
221 virtual void SetAlternateProtocolProbabilityThreshold( | 273 virtual void SetAlternateProtocolProbabilityThreshold( |
222 double threshold) = 0; | 274 double threshold) = 0; |
223 | 275 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 | 312 |
261 virtual const ServerNetworkStatsMap& server_network_stats_map() const = 0; | 313 virtual const ServerNetworkStatsMap& server_network_stats_map() const = 0; |
262 | 314 |
263 private: | 315 private: |
264 DISALLOW_COPY_AND_ASSIGN(HttpServerProperties); | 316 DISALLOW_COPY_AND_ASSIGN(HttpServerProperties); |
265 }; | 317 }; |
266 | 318 |
267 } // namespace net | 319 } // namespace net |
268 | 320 |
269 #endif // NET_HTTP_HTTP_SERVER_PROPERTIES_H_ | 321 #endif // NET_HTTP_HTTP_SERVER_PROPERTIES_H_ |
OLD | NEW |