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 <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
11 #include <ostream> | 11 #include <ostream> |
12 #include <string> | 12 #include <string> |
13 #include <tuple> | 13 #include <tuple> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/containers/mru_cache.h" | 16 #include "base/containers/mru_cache.h" |
17 #include "base/macros.h" | 17 #include "base/macros.h" |
18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
19 #include "net/base/host_port_pair.h" | 19 #include "net/base/host_port_pair.h" |
20 #include "net/base/net_export.h" | 20 #include "net/base/net_export.h" |
21 #include "net/quic/core/quic_bandwidth.h" | 21 #include "net/quic/core/quic_bandwidth.h" |
22 #include "net/quic/core/quic_server_id.h" | 22 #include "net/quic/core/quic_server_id.h" |
23 #include "net/quic/core/quic_versions.h" | |
23 #include "net/socket/next_proto.h" | 24 #include "net/socket/next_proto.h" |
24 #include "net/spdy/core/spdy_framer.h" // TODO(willchan): Reconsider this. | 25 #include "net/spdy/core/spdy_framer.h" // TODO(willchan): Reconsider this. |
25 #include "net/spdy/core/spdy_protocol.h" | 26 #include "net/spdy/core/spdy_protocol.h" |
26 #include "url/scheme_host_port.h" | 27 #include "url/scheme_host_port.h" |
27 | 28 |
28 namespace base { | 29 namespace base { |
29 class Value; | 30 class Value; |
30 } | 31 } |
31 | 32 |
32 namespace net { | 33 namespace net { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 std::string host; | 110 std::string host; |
110 uint16_t port; | 111 uint16_t port; |
111 }; | 112 }; |
112 | 113 |
113 NET_EXPORT_PRIVATE std::ostream& operator<<( | 114 NET_EXPORT_PRIVATE std::ostream& operator<<( |
114 std::ostream& os, | 115 std::ostream& os, |
115 const AlternativeService& alternative_service); | 116 const AlternativeService& alternative_service); |
116 | 117 |
117 class NET_EXPORT_PRIVATE AlternativeServiceInfo { | 118 class NET_EXPORT_PRIVATE AlternativeServiceInfo { |
118 public: | 119 public: |
120 static AlternativeServiceInfo CreateHttp2AlternativeServiceInfo( | |
121 const AlternativeService& alternative_service, | |
122 base::Time expiration); | |
123 | |
124 static AlternativeServiceInfo CreateQuicAlternativeServiceInfo( | |
125 const AlternativeService& alternative_service, | |
126 base::Time expiration, | |
127 const QuicVersionVector& advertised_versions); | |
128 | |
119 AlternativeServiceInfo(); | 129 AlternativeServiceInfo(); |
120 | 130 ~AlternativeServiceInfo(); |
121 AlternativeServiceInfo(const AlternativeService& alternative_service, | |
122 base::Time expiration); | |
123 | |
124 AlternativeServiceInfo(NextProto protocol, | |
125 const std::string& host, | |
126 uint16_t port, | |
127 base::Time expiration); | |
128 | 131 |
129 AlternativeServiceInfo( | 132 AlternativeServiceInfo( |
130 const AlternativeServiceInfo& alternative_service_info); | 133 const AlternativeServiceInfo& alternative_service_info); |
134 | |
131 AlternativeServiceInfo& operator=( | 135 AlternativeServiceInfo& operator=( |
132 const AlternativeServiceInfo& alternative_service_info); | 136 const AlternativeServiceInfo& alternative_service_info); |
133 | 137 |
134 bool operator==(const AlternativeServiceInfo& other) const { | 138 bool operator==(const AlternativeServiceInfo& other) const { |
135 return alternative_service_ == other.alternative_service() && | 139 return alternative_service_ == other.alternative_service() && |
136 expiration_ == other.expiration(); | 140 expiration_ == other.expiration() && |
141 advertised_versions_ == other.advertised_versions(); | |
137 } | 142 } |
138 | 143 |
139 bool operator!=(const AlternativeServiceInfo& other) const { | 144 bool operator!=(const AlternativeServiceInfo& other) const { |
140 return !this->operator==(other); | 145 return !this->operator==(other); |
141 } | 146 } |
142 | 147 |
143 std::string ToString() const; | 148 std::string ToString() const; |
144 | 149 |
145 void set_alternative_service(const AlternativeService& alternative_service) { | 150 void set_alternative_service(const AlternativeService& alternative_service) { |
146 alternative_service_ = alternative_service; | 151 alternative_service_ = alternative_service; |
147 } | 152 } |
148 | 153 |
149 void set_protocol(const NextProto& protocol) { | 154 void set_protocol(const NextProto& protocol) { |
150 alternative_service_.protocol = protocol; | 155 alternative_service_.protocol = protocol; |
151 } | 156 } |
152 | 157 |
153 void set_host(const std::string& host) { alternative_service_.host = host; } | 158 void set_host(const std::string& host) { alternative_service_.host = host; } |
154 | 159 |
155 void set_port(uint16_t port) { alternative_service_.port = port; } | 160 void set_port(uint16_t port) { alternative_service_.port = port; } |
156 | 161 |
157 void set_expiration(const base::Time& expiration) { | 162 void set_expiration(const base::Time& expiration) { |
158 expiration_ = expiration; | 163 expiration_ = expiration; |
159 } | 164 } |
160 | 165 |
166 void set_advertised_versions(const QuicVersionVector& advertised_versions) { | |
167 if (alternative_service_.protocol != kProtoQUIC) | |
Bence
2017/06/16 14:43:40
DCHECK_EQ(kProtoQUIC, alternative_service.protocol
Zhongyi Shi
2017/06/20 23:23:37
Although we are expecting this method only be call
Bence
2017/06/21 12:39:25
Good points.
One option is to leave it as it is n
| |
168 return; | |
169 | |
170 advertised_versions_ = advertised_versions; | |
171 std::sort(advertised_versions_.begin(), advertised_versions_.end()); | |
172 } | |
173 | |
161 const AlternativeService& alternative_service() const { | 174 const AlternativeService& alternative_service() const { |
162 return alternative_service_; | 175 return alternative_service_; |
163 } | 176 } |
164 | 177 |
165 base::Time expiration() const { return expiration_; } | 178 base::Time expiration() const { return expiration_; } |
166 | 179 |
180 const QuicVersionVector& advertised_versions() const { | |
181 return advertised_versions_; | |
182 } | |
183 | |
167 private: | 184 private: |
185 AlternativeServiceInfo(const AlternativeService& alternative_service, | |
186 base::Time expiration, | |
187 const QuicVersionVector& advertised_versions); | |
188 | |
168 AlternativeService alternative_service_; | 189 AlternativeService alternative_service_; |
169 base::Time expiration_; | 190 base::Time expiration_; |
191 | |
192 // Lists all the QUIC versions that are advertised by the server and supported | |
193 // by Chrome. If empty, defaults to versions used by the current instance of | |
194 // the netstack. | |
195 // This list MUST be sorted in ascending order. | |
196 QuicVersionVector advertised_versions_; | |
170 }; | 197 }; |
171 | 198 |
172 struct NET_EXPORT SupportsQuic { | 199 struct NET_EXPORT SupportsQuic { |
173 SupportsQuic() : used_quic(false) {} | 200 SupportsQuic() : used_quic(false) {} |
174 SupportsQuic(bool used_quic, const std::string& address) | 201 SupportsQuic(bool used_quic, const std::string& address) |
175 : used_quic(used_quic), | 202 : used_quic(used_quic), |
176 address(address) {} | 203 address(address) {} |
177 | 204 |
178 bool Equals(const SupportsQuic& other) const { | 205 bool Equals(const SupportsQuic& other) const { |
179 return used_quic == other.used_quic && address == other.address; | 206 return used_quic == other.used_quic && address == other.address; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
257 | 284 |
258 // Modify SSLConfig to force HTTP/1.1 if necessary. | 285 // Modify SSLConfig to force HTTP/1.1 if necessary. |
259 virtual void MaybeForceHTTP11(const HostPortPair& server, | 286 virtual void MaybeForceHTTP11(const HostPortPair& server, |
260 SSLConfig* ssl_config) = 0; | 287 SSLConfig* ssl_config) = 0; |
261 | 288 |
262 // Return all alternative services for |origin|, including broken ones. | 289 // Return all alternative services for |origin|, including broken ones. |
263 // Returned alternative services never have empty hostnames. | 290 // Returned alternative services never have empty hostnames. |
264 virtual AlternativeServiceInfoVector GetAlternativeServiceInfos( | 291 virtual AlternativeServiceInfoVector GetAlternativeServiceInfos( |
265 const url::SchemeHostPort& origin) = 0; | 292 const url::SchemeHostPort& origin) = 0; |
266 | 293 |
267 // Set a single alternative service for |origin|. Previous alternative | 294 // Set a single HTTP/2 alternative service for |origin|. Previous |
295 // alternative services for |origin| are discarded. | |
296 // |alternative_service.host| may be empty. | |
297 // Return true if |alternative_service_map_| has changed significantly enough | |
298 // that it should be persisted to disk. | |
299 virtual bool SetHttp2AlternativeService( | |
300 const url::SchemeHostPort& origin, | |
301 const AlternativeService& alternative_service, | |
302 base::Time expiration) = 0; | |
303 | |
304 // Set a single QUIC alternative service for |origin|. Previous alternative | |
268 // services for |origin| are discarded. | 305 // services for |origin| are discarded. |
269 // |alternative_service.host| may be empty. | 306 // |alternative_service.host| may be empty. |
270 // Return true if |alternative_service_map_| has changed significantly enough | 307 // Return true if |alternative_service_map_| has changed significantly enough |
271 // that it should be persisted to disk. | 308 // that it should be persisted to disk. |
272 virtual bool SetAlternativeService( | 309 virtual bool SetQuicAlternativeService( |
273 const url::SchemeHostPort& origin, | 310 const url::SchemeHostPort& origin, |
274 const AlternativeService& alternative_service, | 311 const AlternativeService& alternative_service, |
275 base::Time expiration) = 0; | 312 base::Time expiration, |
313 const QuicVersionVector& advertised_versions) = 0; | |
276 | 314 |
277 // Set alternative services for |origin|. Previous alternative services for | 315 // Set alternative services for |origin|. Previous alternative services for |
278 // |origin| are discarded. | 316 // |origin| are discarded. |
279 // Hostnames in |alternative_service_info_vector| may be empty. | 317 // Hostnames in |alternative_service_info_vector| may be empty. |
280 // |alternative_service_info_vector| may be empty. | 318 // |alternative_service_info_vector| may be empty. |
281 // Return true if |alternative_service_map_| has changed significantly enough | 319 // Return true if |alternative_service_map_| has changed significantly enough |
282 // that it should be persisted to disk. | 320 // that it should be persisted to disk. |
283 virtual bool SetAlternativeServices( | 321 virtual bool SetAlternativeServices( |
284 const url::SchemeHostPort& origin, | 322 const url::SchemeHostPort& origin, |
285 const AlternativeServiceInfoVector& alternative_service_info_vector) = 0; | 323 const AlternativeServiceInfoVector& alternative_service_info_vector) = 0; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
358 // Returns whether HttpServerProperties is initialized. | 396 // Returns whether HttpServerProperties is initialized. |
359 virtual bool IsInitialized() const = 0; | 397 virtual bool IsInitialized() const = 0; |
360 | 398 |
361 private: | 399 private: |
362 DISALLOW_COPY_AND_ASSIGN(HttpServerProperties); | 400 DISALLOW_COPY_AND_ASSIGN(HttpServerProperties); |
363 }; | 401 }; |
364 | 402 |
365 } // namespace net | 403 } // namespace net |
366 | 404 |
367 #endif // NET_HTTP_HTTP_SERVER_PROPERTIES_H_ | 405 #endif // NET_HTTP_HTTP_SERVER_PROPERTIES_H_ |
OLD | NEW |