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 #include "net/http/http_server_properties_impl.h" | 5 #include "net/http/http_server_properties_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
15 | 15 |
16 namespace net { | 16 namespace net { |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 const uint64 kBrokenAlternateProtocolDelaySecs = 300; | 20 const uint64 kBrokenAlternativeProtocolDelaySecs = 300; |
21 | 21 |
22 } // namespace | 22 } // namespace |
23 | 23 |
24 HttpServerPropertiesImpl::HttpServerPropertiesImpl() | 24 HttpServerPropertiesImpl::HttpServerPropertiesImpl() |
25 : spdy_servers_map_(SpdyServerHostPortMap::NO_AUTO_EVICT), | 25 : spdy_servers_map_(SpdyServerHostPortMap::NO_AUTO_EVICT), |
26 alternate_protocol_map_(AlternateProtocolMap::NO_AUTO_EVICT), | 26 alternative_service_map_(AlternativeServiceMap::NO_AUTO_EVICT), |
27 spdy_settings_map_(SpdySettingsMap::NO_AUTO_EVICT), | 27 spdy_settings_map_(SpdySettingsMap::NO_AUTO_EVICT), |
28 server_network_stats_map_(ServerNetworkStatsMap::NO_AUTO_EVICT), | 28 server_network_stats_map_(ServerNetworkStatsMap::NO_AUTO_EVICT), |
29 alternate_protocol_probability_threshold_(1), | 29 alternate_protocol_probability_threshold_(1), |
30 weak_ptr_factory_(this) { | 30 weak_ptr_factory_(this) { |
31 canonical_suffixes_.push_back(".c.youtube.com"); | 31 canonical_suffixes_.push_back(".c.youtube.com"); |
32 canonical_suffixes_.push_back(".googlevideo.com"); | 32 canonical_suffixes_.push_back(".googlevideo.com"); |
33 canonical_suffixes_.push_back(".googleusercontent.com"); | 33 canonical_suffixes_.push_back(".googleusercontent.com"); |
34 } | 34 } |
35 | 35 |
36 HttpServerPropertiesImpl::~HttpServerPropertiesImpl() { | 36 HttpServerPropertiesImpl::~HttpServerPropertiesImpl() { |
37 } | 37 } |
38 | 38 |
39 void HttpServerPropertiesImpl::InitializeSpdyServers( | 39 void HttpServerPropertiesImpl::InitializeSpdyServers( |
40 std::vector<std::string>* spdy_servers, | 40 std::vector<std::string>* spdy_servers, |
41 bool support_spdy) { | 41 bool support_spdy) { |
42 DCHECK(CalledOnValidThread()); | 42 DCHECK(CalledOnValidThread()); |
43 if (!spdy_servers) | 43 if (!spdy_servers) |
44 return; | 44 return; |
45 // Add the entries from persisted data. | 45 // Add the entries from persisted data. |
46 for (std::vector<std::string>::reverse_iterator it = spdy_servers->rbegin(); | 46 for (std::vector<std::string>::reverse_iterator it = spdy_servers->rbegin(); |
47 it != spdy_servers->rend(); ++it) { | 47 it != spdy_servers->rend(); ++it) { |
48 spdy_servers_map_.Put(*it, support_spdy); | 48 spdy_servers_map_.Put(*it, support_spdy); |
49 } | 49 } |
50 } | 50 } |
51 | 51 |
52 void HttpServerPropertiesImpl::InitializeAlternateProtocolServers( | 52 void HttpServerPropertiesImpl::InitializeAlternativeServiceServers( |
53 AlternateProtocolMap* alternate_protocol_map) { | 53 AlternativeServiceMap* alternative_service_map) { |
54 // Keep all the broken ones since those don't get persisted. | 54 // Keep all the broken ones since those don't get persisted. |
55 for (AlternateProtocolMap::iterator it = alternate_protocol_map_.begin(); | 55 for (AlternativeServiceMap::iterator it = alternative_service_map_.begin(); |
56 it != alternate_protocol_map_.end();) { | 56 it != alternative_service_map_.end();) { |
57 const AlternativeService alternative_service( | 57 if (IsAlternativeServiceBroken(it->second.alternative_service)) { |
58 it->second.protocol, it->first.host(), it->second.port); | |
59 if (IsAlternativeServiceBroken(alternative_service)) { | |
60 ++it; | 58 ++it; |
61 } else { | 59 } else { |
62 it = alternate_protocol_map_.Erase(it); | 60 it = alternative_service_map_.Erase(it); |
63 } | 61 } |
64 } | 62 } |
65 | 63 |
66 // Add the entries from persisted data. | 64 // Add the entries from persisted data. |
67 for (AlternateProtocolMap::reverse_iterator it = | 65 for (AlternativeServiceMap::reverse_iterator it = |
68 alternate_protocol_map->rbegin(); | 66 alternative_service_map->rbegin(); |
69 it != alternate_protocol_map->rend(); ++it) { | 67 it != alternative_service_map->rend(); ++it) { |
70 alternate_protocol_map_.Put(it->first, it->second); | 68 alternative_service_map_.Put(it->first, it->second); |
71 } | 69 } |
72 | 70 |
73 // Attempt to find canonical servers. | 71 // Attempt to find canonical servers. |
74 uint16 canonical_ports[] = { 80, 443 }; | 72 uint16 canonical_ports[] = { 80, 443 }; |
75 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { | 73 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { |
76 std::string canonical_suffix = canonical_suffixes_[i]; | 74 std::string canonical_suffix = canonical_suffixes_[i]; |
77 for (size_t j = 0; j < arraysize(canonical_ports); ++j) { | 75 for (size_t j = 0; j < arraysize(canonical_ports); ++j) { |
78 HostPortPair canonical_host(canonical_suffix, canonical_ports[j]); | 76 HostPortPair canonical_host(canonical_suffix, canonical_ports[j]); |
79 // If we already have a valid canonical server, we're done. | 77 // If we already have a valid canonical server, we're done. |
80 if (ContainsKey(canonical_host_to_origin_map_, canonical_host) && | 78 if (ContainsKey(canonical_host_to_origin_map_, canonical_host) && |
81 (alternate_protocol_map_.Peek(canonical_host_to_origin_map_[ | 79 (alternative_service_map_.Peek( |
82 canonical_host]) != alternate_protocol_map_.end())) { | 80 canonical_host_to_origin_map_[canonical_host]) != |
| 81 alternative_service_map_.end())) { |
83 continue; | 82 continue; |
84 } | 83 } |
85 // Now attempt to find a server which matches this origin and set it as | 84 // Now attempt to find a server which matches this origin and set it as |
86 // canonical . | 85 // canonical. |
87 for (AlternateProtocolMap::const_iterator it = | 86 for (AlternativeServiceMap::const_iterator it = |
88 alternate_protocol_map_.begin(); | 87 alternative_service_map_.begin(); |
89 it != alternate_protocol_map_.end(); ++it) { | 88 it != alternative_service_map_.end(); ++it) { |
90 if (EndsWith(it->first.host(), canonical_suffixes_[i], false)) { | 89 if (EndsWith(it->first.host(), canonical_suffixes_[i], false)) { |
91 canonical_host_to_origin_map_[canonical_host] = it->first; | 90 canonical_host_to_origin_map_[canonical_host] = it->first; |
92 break; | 91 break; |
93 } | 92 } |
94 } | 93 } |
95 } | 94 } |
96 } | 95 } |
97 } | 96 } |
98 | 97 |
99 void HttpServerPropertiesImpl::InitializeSpdySettingsServers( | 98 void HttpServerPropertiesImpl::InitializeSpdySettingsServers( |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 } | 136 } |
138 } | 137 } |
139 | 138 |
140 base::WeakPtr<HttpServerProperties> HttpServerPropertiesImpl::GetWeakPtr() { | 139 base::WeakPtr<HttpServerProperties> HttpServerPropertiesImpl::GetWeakPtr() { |
141 return weak_ptr_factory_.GetWeakPtr(); | 140 return weak_ptr_factory_.GetWeakPtr(); |
142 } | 141 } |
143 | 142 |
144 void HttpServerPropertiesImpl::Clear() { | 143 void HttpServerPropertiesImpl::Clear() { |
145 DCHECK(CalledOnValidThread()); | 144 DCHECK(CalledOnValidThread()); |
146 spdy_servers_map_.Clear(); | 145 spdy_servers_map_.Clear(); |
147 alternate_protocol_map_.Clear(); | 146 alternative_service_map_.Clear(); |
148 canonical_host_to_origin_map_.clear(); | 147 canonical_host_to_origin_map_.clear(); |
149 spdy_settings_map_.Clear(); | 148 spdy_settings_map_.Clear(); |
150 last_quic_address_.clear(); | 149 last_quic_address_.clear(); |
151 server_network_stats_map_.Clear(); | 150 server_network_stats_map_.Clear(); |
152 } | 151 } |
153 | 152 |
154 bool HttpServerPropertiesImpl::SupportsRequestPriority( | 153 bool HttpServerPropertiesImpl::SupportsRequestPriority( |
155 const HostPortPair& host_port_pair) { | 154 const HostPortPair& host_port_pair) { |
156 DCHECK(CalledOnValidThread()); | 155 DCHECK(CalledOnValidThread()); |
157 if (host_port_pair.host().empty()) | 156 if (host_port_pair.host().empty()) |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 std::string canonical_suffix = canonical_suffixes_[i]; | 216 std::string canonical_suffix = canonical_suffixes_[i]; |
218 if (EndsWith(host, canonical_suffixes_[i], false)) { | 217 if (EndsWith(host, canonical_suffixes_[i], false)) { |
219 return canonical_suffix; | 218 return canonical_suffix; |
220 } | 219 } |
221 } | 220 } |
222 return std::string(); | 221 return std::string(); |
223 } | 222 } |
224 | 223 |
225 AlternativeService HttpServerPropertiesImpl::GetAlternativeService( | 224 AlternativeService HttpServerPropertiesImpl::GetAlternativeService( |
226 const HostPortPair& origin) { | 225 const HostPortPair& origin) { |
227 AlternateProtocolMap::const_iterator it = | 226 AlternativeServiceMap::const_iterator it = |
228 GetAlternateProtocolIterator(origin); | 227 alternative_service_map_.Get(origin); |
229 if (it != alternate_protocol_map_.end() && | 228 if (it != alternative_service_map_.end()) { |
230 it->second.probability >= alternate_protocol_probability_threshold_) | 229 if (it->second.probability < alternate_protocol_probability_threshold_) { |
231 return AlternativeService(it->second.protocol, origin.host(), | 230 return AlternativeService(); |
232 it->second.port); | 231 } |
| 232 // Empty hostname defaults to that of origin. |
| 233 if (!it->second.alternative_service.host.empty()) { |
| 234 return it->second.alternative_service; |
| 235 } |
| 236 AlternativeService alternative_service(it->second.alternative_service); |
| 237 alternative_service.host = origin.host(); |
| 238 return alternative_service; |
| 239 } |
233 | 240 |
234 AlternativeService uninitialize_alternative_service; | 241 CanonicalHostMap::const_iterator canonical = GetCanonicalHost(origin); |
235 return uninitialize_alternative_service; | 242 if (canonical == canonical_host_to_origin_map_.end()) { |
| 243 return AlternativeService(); |
| 244 } |
| 245 it = alternative_service_map_.Get(canonical->second); |
| 246 if (it == alternative_service_map_.end()) { |
| 247 return AlternativeService(); |
| 248 } |
| 249 if (it->second.probability < alternate_protocol_probability_threshold_) { |
| 250 return AlternativeService(); |
| 251 } |
| 252 AlternativeService alternative_service(it->second.alternative_service); |
| 253 // Empty hostname: if alternative service for canonical host is not broken... |
| 254 if (alternative_service.host.empty()) { |
| 255 alternative_service.host = canonical->second.host(); |
| 256 } |
| 257 if (IsAlternativeServiceBroken(alternative_service)) { |
| 258 RemoveCanonicalHost(canonical->second); |
| 259 return AlternativeService(); |
| 260 } |
| 261 if (!it->second.alternative_service.host.empty()) { |
| 262 return it->second.alternative_service; |
| 263 } |
| 264 // ...then return alternative service with hostname of origin. |
| 265 alternative_service.host = origin.host(); |
| 266 return alternative_service; |
236 } | 267 } |
237 | 268 |
238 void HttpServerPropertiesImpl::SetAlternativeService( | 269 void HttpServerPropertiesImpl::SetAlternativeService( |
239 const HostPortPair& origin, | 270 const HostPortPair& origin, |
240 const AlternativeService& alternative_service, | 271 const AlternativeService& alternative_service, |
241 double alternative_probability) { | 272 double alternative_probability) { |
242 if (IsAlternativeServiceBroken(alternative_service)) { | 273 AlternativeService complete_alternative_service(alternative_service); |
| 274 if (complete_alternative_service.host.empty()) { |
| 275 complete_alternative_service.host = origin.host(); |
| 276 } |
| 277 if (IsAlternativeServiceBroken(complete_alternative_service)) { |
243 DVLOG(1) << "Ignore alternative service since it is known to be broken."; | 278 DVLOG(1) << "Ignore alternative service since it is known to be broken."; |
244 return; | 279 return; |
245 } | 280 } |
246 | 281 |
247 const AlternateProtocolInfo alternate(alternative_service.port, | 282 const AlternativeServiceInfo alternative_service_info( |
248 alternative_service.protocol, | 283 alternative_service, alternative_probability); |
249 alternative_probability); | 284 AlternativeServiceMap::const_iterator it = |
250 AlternateProtocolMap::const_iterator it = | |
251 GetAlternateProtocolIterator(origin); | 285 GetAlternateProtocolIterator(origin); |
252 if (it != alternate_protocol_map_.end()) { | 286 if (it != alternative_service_map_.end()) { |
253 const AlternateProtocolInfo existing_alternate = it->second; | 287 const AlternativeServiceInfo existing_alternative_service_info = it->second; |
254 | 288 if (existing_alternative_service_info != alternative_service_info) { |
255 if (!existing_alternate.Equals(alternate)) { | 289 LOG(WARNING) << "Changing the alternative service for: " |
256 LOG(WARNING) << "Changing the alternate protocol for: " | 290 << origin.ToString() << " from " |
257 << origin.ToString() | 291 << existing_alternative_service_info.ToString() << " to " |
258 << " from [Port: " << existing_alternate.port | 292 << alternative_service_info.ToString() << "."; |
259 << ", Protocol: " << existing_alternate.protocol | |
260 << ", Probability: " << existing_alternate.probability | |
261 << "] to [Port: " << alternative_service.port | |
262 << ", Protocol: " << alternative_service.protocol | |
263 << ", Probability: " << alternative_probability << "]."; | |
264 } | 293 } |
265 } else { | 294 } else { |
266 if (alternative_probability >= alternate_protocol_probability_threshold_) { | 295 if (alternative_probability >= alternate_protocol_probability_threshold_) { |
267 // TODO(rch): Consider the case where multiple requests are started | 296 // TODO(rch): Consider the case where multiple requests are started |
268 // before the first completes. In this case, only one of the jobs | 297 // before the first completes. In this case, only one of the jobs |
269 // would reach this code, whereas all of them should should have. | 298 // would reach this code, whereas all of them should should have. |
270 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_MAPPING_MISSING); | 299 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_MAPPING_MISSING); |
271 } | 300 } |
272 } | 301 } |
273 | 302 |
274 alternate_protocol_map_.Put(origin, alternate); | 303 alternative_service_map_.Put(origin, alternative_service_info); |
275 | 304 |
276 // If this host ends with a canonical suffix, then set it as the | 305 // If this host ends with a canonical suffix, then set it as the |
277 // canonical host. | 306 // canonical host. |
278 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { | 307 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { |
279 std::string canonical_suffix = canonical_suffixes_[i]; | 308 std::string canonical_suffix = canonical_suffixes_[i]; |
280 if (EndsWith(origin.host(), canonical_suffixes_[i], false)) { | 309 if (EndsWith(origin.host(), canonical_suffixes_[i], false)) { |
281 HostPortPair canonical_host(canonical_suffix, origin.port()); | 310 HostPortPair canonical_host(canonical_suffix, origin.port()); |
282 canonical_host_to_origin_map_[canonical_host] = origin; | 311 canonical_host_to_origin_map_[canonical_host] = origin; |
283 break; | 312 break; |
284 } | 313 } |
285 } | 314 } |
286 } | 315 } |
287 | 316 |
288 void HttpServerPropertiesImpl::MarkAlternativeServiceBroken( | 317 void HttpServerPropertiesImpl::MarkAlternativeServiceBroken( |
289 const AlternativeService& alternative_service) { | 318 const AlternativeService& alternative_service) { |
290 if (alternative_service.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) { | 319 if (alternative_service.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) { |
291 LOG(DFATAL) << "Trying to mark unknown alternate protocol broken."; | 320 LOG(DFATAL) << "Trying to mark unknown alternate protocol broken."; |
292 return; | 321 return; |
293 } | 322 } |
294 int count = ++recently_broken_alternative_services_[alternative_service]; | 323 int count = ++recently_broken_alternative_services_[alternative_service]; |
295 base::TimeDelta delay = | 324 base::TimeDelta delay = |
296 base::TimeDelta::FromSeconds(kBrokenAlternateProtocolDelaySecs); | 325 base::TimeDelta::FromSeconds(kBrokenAlternativeProtocolDelaySecs); |
297 base::TimeTicks when = base::TimeTicks::Now() + delay * (1 << (count - 1)); | 326 base::TimeTicks when = base::TimeTicks::Now() + delay * (1 << (count - 1)); |
298 auto result = broken_alternative_services_.insert( | 327 auto result = broken_alternative_services_.insert( |
299 std::make_pair(alternative_service, when)); | 328 std::make_pair(alternative_service, when)); |
300 // Return if alternative service is already in expiration queue. | 329 // Return if alternative service is already in expiration queue. |
301 if (!result.second) { | 330 if (!result.second) { |
302 return; | 331 return; |
303 } | 332 } |
304 | 333 |
305 // If this is the only entry in the list, schedule an expiration task. | 334 // If this is the only entry in the list, schedule an expiration task. |
306 // Otherwise it will be rescheduled automatically when the pending task runs. | 335 // Otherwise it will be rescheduled automatically when the pending task runs. |
(...skipping 26 matching lines...) Expand all Loading... |
333 if (alternative_service.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) | 362 if (alternative_service.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) |
334 return; | 363 return; |
335 broken_alternative_services_.erase(alternative_service); | 364 broken_alternative_services_.erase(alternative_service); |
336 recently_broken_alternative_services_.erase(alternative_service); | 365 recently_broken_alternative_services_.erase(alternative_service); |
337 } | 366 } |
338 | 367 |
339 void HttpServerPropertiesImpl::ClearAlternativeService( | 368 void HttpServerPropertiesImpl::ClearAlternativeService( |
340 const HostPortPair& origin) { | 369 const HostPortPair& origin) { |
341 RemoveCanonicalHost(origin); | 370 RemoveCanonicalHost(origin); |
342 | 371 |
343 AlternateProtocolMap::iterator it = alternate_protocol_map_.Peek(origin); | 372 AlternativeServiceMap::iterator it = alternative_service_map_.Peek(origin); |
344 if (it == alternate_protocol_map_.end()) { | 373 if (it == alternative_service_map_.end()) { |
345 return; | 374 return; |
346 } | 375 } |
347 const AlternativeService alternative_service( | 376 AlternativeService alternative_service(it->second.alternative_service); |
348 it->second.protocol, it->first.host(), it->second.port); | 377 if (alternative_service.host.empty()) { |
349 alternate_protocol_map_.Erase(it); | 378 alternative_service.host = origin.host(); |
| 379 } |
| 380 alternative_service_map_.Erase(it); |
350 | 381 |
351 // The following is temporary to keep the existing semantics, which is that if | 382 // The following is temporary to keep the existing semantics, which is that if |
352 // there is a broken alternative service in the mapping, then this method | 383 // there is a broken alternative service in the mapping, then this method |
353 // leaves it in a non-broken, but recently broken state. | 384 // leaves it in a non-broken, but recently broken state. |
354 // | 385 // |
355 // TODO(bnc): | 386 // TODO(bnc): |
356 // 1. Verify and document the class invariant that no broken alternative | 387 // 1. Verify and document the class invariant that no broken alternative |
357 // service can be in the mapping. | 388 // service can be in the mapping. |
358 // 2. Remove the rest of this method as it will be moot. | 389 // 2. Remove the rest of this method as it will be moot. |
359 // 3. Provide a SetAlternativeServiceRecentlyBroken if necessary. | |
360 broken_alternative_services_.erase(alternative_service); | 390 broken_alternative_services_.erase(alternative_service); |
361 } | 391 } |
362 | 392 |
363 const AlternateProtocolMap& | 393 const AlternativeServiceMap& HttpServerPropertiesImpl::alternative_service_map() |
364 HttpServerPropertiesImpl::alternate_protocol_map() const { | 394 const { |
365 return alternate_protocol_map_; | 395 return alternative_service_map_; |
366 } | 396 } |
367 | 397 |
368 const SettingsMap& HttpServerPropertiesImpl::GetSpdySettings( | 398 const SettingsMap& HttpServerPropertiesImpl::GetSpdySettings( |
369 const HostPortPair& host_port_pair) { | 399 const HostPortPair& host_port_pair) { |
370 SpdySettingsMap::iterator it = spdy_settings_map_.Get(host_port_pair); | 400 SpdySettingsMap::iterator it = spdy_settings_map_.Get(host_port_pair); |
371 if (it == spdy_settings_map_.end()) { | 401 if (it == spdy_settings_map_.end()) { |
372 CR_DEFINE_STATIC_LOCAL(SettingsMap, kEmptySettingsMap, ()); | 402 CR_DEFINE_STATIC_LOCAL(SettingsMap, kEmptySettingsMap, ()); |
373 return kEmptySettingsMap; | 403 return kEmptySettingsMap; |
374 } | 404 } |
375 return it->second; | 405 return it->second; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 const ServerNetworkStatsMap& | 479 const ServerNetworkStatsMap& |
450 HttpServerPropertiesImpl::server_network_stats_map() const { | 480 HttpServerPropertiesImpl::server_network_stats_map() const { |
451 return server_network_stats_map_; | 481 return server_network_stats_map_; |
452 } | 482 } |
453 | 483 |
454 void HttpServerPropertiesImpl::SetAlternateProtocolProbabilityThreshold( | 484 void HttpServerPropertiesImpl::SetAlternateProtocolProbabilityThreshold( |
455 double threshold) { | 485 double threshold) { |
456 alternate_protocol_probability_threshold_ = threshold; | 486 alternate_protocol_probability_threshold_ = threshold; |
457 } | 487 } |
458 | 488 |
459 AlternateProtocolMap::const_iterator | 489 AlternativeServiceMap::const_iterator |
460 HttpServerPropertiesImpl::GetAlternateProtocolIterator( | 490 HttpServerPropertiesImpl::GetAlternateProtocolIterator( |
461 const HostPortPair& server) { | 491 const HostPortPair& server) { |
462 AlternateProtocolMap::const_iterator it = alternate_protocol_map_.Get(server); | 492 AlternativeServiceMap::const_iterator it = |
463 if (it != alternate_protocol_map_.end()) | 493 alternative_service_map_.Get(server); |
| 494 if (it != alternative_service_map_.end()) |
464 return it; | 495 return it; |
465 | 496 |
466 CanonicalHostMap::const_iterator canonical = GetCanonicalHost(server); | 497 CanonicalHostMap::const_iterator canonical = GetCanonicalHost(server); |
467 if (canonical == canonical_host_to_origin_map_.end()) { | 498 if (canonical == canonical_host_to_origin_map_.end()) { |
468 return alternate_protocol_map_.end(); | 499 return alternative_service_map_.end(); |
469 } | 500 } |
470 | 501 |
471 const HostPortPair canonical_host_port = canonical->second; | 502 const HostPortPair canonical_host_port = canonical->second; |
472 it = alternate_protocol_map_.Get(canonical_host_port); | 503 it = alternative_service_map_.Get(canonical_host_port); |
473 if (it == alternate_protocol_map_.end()) { | 504 if (it == alternative_service_map_.end()) { |
474 return alternate_protocol_map_.end(); | 505 return alternative_service_map_.end(); |
475 } | 506 } |
476 | 507 |
477 const AlternativeService alternative_service( | 508 const AlternativeService alternative_service( |
478 it->second.protocol, canonical_host_port.host(), it->second.port); | 509 it->second.alternative_service.protocol, canonical_host_port.host(), |
| 510 it->second.alternative_service.port); |
479 if (!IsAlternativeServiceBroken(alternative_service)) { | 511 if (!IsAlternativeServiceBroken(alternative_service)) { |
480 return it; | 512 return it; |
481 } | 513 } |
482 | 514 |
483 RemoveCanonicalHost(canonical_host_port); | 515 RemoveCanonicalHost(canonical_host_port); |
484 return alternate_protocol_map_.end(); | 516 return alternative_service_map_.end(); |
485 } | 517 } |
486 | 518 |
487 HttpServerPropertiesImpl::CanonicalHostMap::const_iterator | 519 HttpServerPropertiesImpl::CanonicalHostMap::const_iterator |
488 HttpServerPropertiesImpl::GetCanonicalHost(HostPortPair server) const { | 520 HttpServerPropertiesImpl::GetCanonicalHost(HostPortPair server) const { |
489 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { | 521 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { |
490 std::string canonical_suffix = canonical_suffixes_[i]; | 522 std::string canonical_suffix = canonical_suffixes_[i]; |
491 if (EndsWith(server.host(), canonical_suffixes_[i], false)) { | 523 if (EndsWith(server.host(), canonical_suffixes_[i], false)) { |
492 HostPortPair canonical_host(canonical_suffix, server.port()); | 524 HostPortPair canonical_host(canonical_suffix, server.port()); |
493 return canonical_host_to_origin_map_.find(canonical_host); | 525 return canonical_host_to_origin_map_.find(canonical_host); |
494 } | 526 } |
(...skipping 18 matching lines...) Expand all Loading... |
513 base::TimeTicks now = base::TimeTicks::Now(); | 545 base::TimeTicks now = base::TimeTicks::Now(); |
514 while (!broken_alternative_services_.empty()) { | 546 while (!broken_alternative_services_.empty()) { |
515 BrokenAlternativeServices::iterator it = | 547 BrokenAlternativeServices::iterator it = |
516 broken_alternative_services_.begin(); | 548 broken_alternative_services_.begin(); |
517 if (now < it->second) { | 549 if (now < it->second) { |
518 break; | 550 break; |
519 } | 551 } |
520 | 552 |
521 const AlternativeService alternative_service = it->first; | 553 const AlternativeService alternative_service = it->first; |
522 broken_alternative_services_.erase(it); | 554 broken_alternative_services_.erase(it); |
| 555 // TODO(bnc): Make sure broken alternative services are not in the mapping. |
523 ClearAlternativeService( | 556 ClearAlternativeService( |
524 HostPortPair(alternative_service.host, alternative_service.port)); | 557 HostPortPair(alternative_service.host, alternative_service.port)); |
525 } | 558 } |
526 ScheduleBrokenAlternateProtocolMappingsExpiration(); | 559 ScheduleBrokenAlternateProtocolMappingsExpiration(); |
527 } | 560 } |
528 | 561 |
529 void | 562 void |
530 HttpServerPropertiesImpl::ScheduleBrokenAlternateProtocolMappingsExpiration() { | 563 HttpServerPropertiesImpl::ScheduleBrokenAlternateProtocolMappingsExpiration() { |
531 if (broken_alternative_services_.empty()) { | 564 if (broken_alternative_services_.empty()) { |
532 return; | 565 return; |
533 } | 566 } |
534 base::TimeTicks now = base::TimeTicks::Now(); | 567 base::TimeTicks now = base::TimeTicks::Now(); |
535 base::TimeTicks when = broken_alternative_services_.front().second; | 568 base::TimeTicks when = broken_alternative_services_.front().second; |
536 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); | 569 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); |
537 base::MessageLoop::current()->PostDelayedTask( | 570 base::MessageLoop::current()->PostDelayedTask( |
538 FROM_HERE, | 571 FROM_HERE, |
539 base::Bind( | 572 base::Bind( |
540 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, | 573 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, |
541 weak_ptr_factory_.GetWeakPtr()), | 574 weak_ptr_factory_.GetWeakPtr()), |
542 delay); | 575 delay); |
543 } | 576 } |
544 | 577 |
545 } // namespace net | 578 } // namespace net |
OLD | NEW |