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 AlternativeService alternative_service(it->second.alternative_service); |
| 233 if (alternative_service.host.empty()) { |
| 234 alternative_service.host = origin.host(); |
| 235 } |
| 236 return alternative_service; |
| 237 } |
233 | 238 |
234 AlternativeService uninitialize_alternative_service; | 239 CanonicalHostMap::const_iterator canonical = GetCanonicalHost(origin); |
235 return uninitialize_alternative_service; | 240 if (canonical == canonical_host_to_origin_map_.end()) { |
| 241 return AlternativeService(); |
| 242 } |
| 243 it = alternative_service_map_.Get(canonical->second); |
| 244 if (it == alternative_service_map_.end()) { |
| 245 return AlternativeService(); |
| 246 } |
| 247 if (it->second.probability < alternate_protocol_probability_threshold_) { |
| 248 return AlternativeService(); |
| 249 } |
| 250 AlternativeService alternative_service(it->second.alternative_service); |
| 251 if (alternative_service.host.empty()) { |
| 252 alternative_service.host = canonical->second.host(); |
| 253 } |
| 254 if (IsAlternativeServiceBroken(alternative_service)) { |
| 255 RemoveCanonicalHost(canonical->second); |
| 256 return AlternativeService(); |
| 257 } |
| 258 // Empty hostname: if alternative service for with hostname of canonical host |
| 259 // is not broken, then return alternative service with hostname of origin. |
| 260 if (it->second.alternative_service.host.empty()) { |
| 261 alternative_service.host = origin.host(); |
| 262 } |
| 263 return alternative_service; |
236 } | 264 } |
237 | 265 |
238 void HttpServerPropertiesImpl::SetAlternativeService( | 266 void HttpServerPropertiesImpl::SetAlternativeService( |
239 const HostPortPair& origin, | 267 const HostPortPair& origin, |
240 const AlternativeService& alternative_service, | 268 const AlternativeService& alternative_service, |
241 double alternative_probability) { | 269 double alternative_probability) { |
242 if (IsAlternativeServiceBroken(alternative_service)) { | 270 AlternativeService complete_alternative_service(alternative_service); |
| 271 if (complete_alternative_service.host.empty()) { |
| 272 complete_alternative_service.host = origin.host(); |
| 273 } |
| 274 if (IsAlternativeServiceBroken(complete_alternative_service)) { |
243 DVLOG(1) << "Ignore alternative service since it is known to be broken."; | 275 DVLOG(1) << "Ignore alternative service since it is known to be broken."; |
244 return; | 276 return; |
245 } | 277 } |
246 | 278 |
247 const AlternateProtocolInfo alternate(alternative_service.port, | 279 const AlternativeServiceInfo alternative_service_info( |
248 alternative_service.protocol, | 280 alternative_service, alternative_probability); |
249 alternative_probability); | 281 AlternativeServiceMap::const_iterator it = |
250 AlternateProtocolMap::const_iterator it = | |
251 GetAlternateProtocolIterator(origin); | 282 GetAlternateProtocolIterator(origin); |
252 if (it != alternate_protocol_map_.end()) { | 283 if (it != alternative_service_map_.end()) { |
253 const AlternateProtocolInfo existing_alternate = it->second; | 284 const AlternativeServiceInfo existing_alternative_service_info = it->second; |
254 | 285 if (existing_alternative_service_info != alternative_service_info) { |
255 if (!existing_alternate.Equals(alternate)) { | 286 LOG(WARNING) << "Changing the alternative service for: " |
256 LOG(WARNING) << "Changing the alternate protocol for: " | 287 << origin.ToString() << " from " |
257 << origin.ToString() | 288 << existing_alternative_service_info.ToString() << " to " |
258 << " from [Port: " << existing_alternate.port | 289 << 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 } | 290 } |
265 } else { | 291 } else { |
266 if (alternative_probability >= alternate_protocol_probability_threshold_) { | 292 if (alternative_probability >= alternate_protocol_probability_threshold_) { |
267 // TODO(rch): Consider the case where multiple requests are started | 293 // TODO(rch): Consider the case where multiple requests are started |
268 // before the first completes. In this case, only one of the jobs | 294 // before the first completes. In this case, only one of the jobs |
269 // would reach this code, whereas all of them should should have. | 295 // would reach this code, whereas all of them should should have. |
270 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_MAPPING_MISSING); | 296 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_MAPPING_MISSING); |
271 } | 297 } |
272 } | 298 } |
273 | 299 |
274 alternate_protocol_map_.Put(origin, alternate); | 300 alternative_service_map_.Put(origin, alternative_service_info); |
275 | 301 |
276 // If this host ends with a canonical suffix, then set it as the | 302 // If this host ends with a canonical suffix, then set it as the |
277 // canonical host. | 303 // canonical host. |
278 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { | 304 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { |
279 std::string canonical_suffix = canonical_suffixes_[i]; | 305 std::string canonical_suffix = canonical_suffixes_[i]; |
280 if (EndsWith(origin.host(), canonical_suffixes_[i], false)) { | 306 if (EndsWith(origin.host(), canonical_suffixes_[i], false)) { |
281 HostPortPair canonical_host(canonical_suffix, origin.port()); | 307 HostPortPair canonical_host(canonical_suffix, origin.port()); |
282 canonical_host_to_origin_map_[canonical_host] = origin; | 308 canonical_host_to_origin_map_[canonical_host] = origin; |
283 break; | 309 break; |
284 } | 310 } |
285 } | 311 } |
286 } | 312 } |
287 | 313 |
288 void HttpServerPropertiesImpl::MarkAlternativeServiceBroken( | 314 void HttpServerPropertiesImpl::MarkAlternativeServiceBroken( |
289 const AlternativeService& alternative_service) { | 315 const AlternativeService& alternative_service) { |
290 if (alternative_service.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) { | 316 if (alternative_service.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) { |
291 LOG(DFATAL) << "Trying to mark unknown alternate protocol broken."; | 317 LOG(DFATAL) << "Trying to mark unknown alternate protocol broken."; |
292 return; | 318 return; |
293 } | 319 } |
294 int count = ++recently_broken_alternative_services_[alternative_service]; | 320 int count = ++recently_broken_alternative_services_[alternative_service]; |
295 base::TimeDelta delay = | 321 base::TimeDelta delay = |
296 base::TimeDelta::FromSeconds(kBrokenAlternateProtocolDelaySecs); | 322 base::TimeDelta::FromSeconds(kBrokenAlternativeProtocolDelaySecs); |
297 base::TimeTicks when = base::TimeTicks::Now() + delay * (1 << (count - 1)); | 323 base::TimeTicks when = base::TimeTicks::Now() + delay * (1 << (count - 1)); |
298 auto result = broken_alternative_services_.insert( | 324 auto result = broken_alternative_services_.insert( |
299 std::make_pair(alternative_service, when)); | 325 std::make_pair(alternative_service, when)); |
300 // Return if alternative service is already in expiration queue. | 326 // Return if alternative service is already in expiration queue. |
301 if (!result.second) { | 327 if (!result.second) { |
302 return; | 328 return; |
303 } | 329 } |
304 | 330 |
305 // If this is the only entry in the list, schedule an expiration task. | 331 // 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. | 332 // Otherwise it will be rescheduled automatically when the pending task runs. |
307 if (broken_alternative_services_.size() == 1) { | 333 if (broken_alternative_services_.size() == 1) { |
308 ScheduleBrokenAlternateProtocolMappingsExpiration(); | 334 ScheduleBrokenAlternateProtocolMappingsExpiration(); |
309 } | 335 } |
310 } | 336 } |
311 | 337 |
312 void HttpServerPropertiesImpl::MarkAlternativeServiceRecentlyBroken( | 338 void HttpServerPropertiesImpl::MarkAlternativeServiceRecentlyBroken( |
313 const AlternativeService& alternative_service) { | 339 const AlternativeService& alternative_service) { |
314 if (!ContainsKey(recently_broken_alternative_services_, alternative_service)) | 340 if (!ContainsKey(recently_broken_alternative_services_, alternative_service)) |
315 recently_broken_alternative_services_[alternative_service] = 1; | 341 recently_broken_alternative_services_[alternative_service] = 1; |
316 } | 342 } |
317 | 343 |
318 bool HttpServerPropertiesImpl::IsAlternativeServiceBroken( | 344 bool HttpServerPropertiesImpl::IsAlternativeServiceBroken( |
319 const AlternativeService& alternative_service) { | 345 const AlternativeService& alternative_service) { |
| 346 // Empty host means use host of origin, callers are supposed to substitute. |
| 347 DCHECK(!alternative_service.host.empty()); |
320 return ContainsKey(broken_alternative_services_, alternative_service); | 348 return ContainsKey(broken_alternative_services_, alternative_service); |
321 } | 349 } |
322 | 350 |
323 bool HttpServerPropertiesImpl::WasAlternativeServiceRecentlyBroken( | 351 bool HttpServerPropertiesImpl::WasAlternativeServiceRecentlyBroken( |
324 const AlternativeService& alternative_service) { | 352 const AlternativeService& alternative_service) { |
325 if (alternative_service.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) | 353 if (alternative_service.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) |
326 return false; | 354 return false; |
327 return ContainsKey(recently_broken_alternative_services_, | 355 return ContainsKey(recently_broken_alternative_services_, |
328 alternative_service); | 356 alternative_service); |
329 } | 357 } |
330 | 358 |
331 void HttpServerPropertiesImpl::ConfirmAlternativeService( | 359 void HttpServerPropertiesImpl::ConfirmAlternativeService( |
332 const AlternativeService& alternative_service) { | 360 const AlternativeService& alternative_service) { |
333 if (alternative_service.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) | 361 if (alternative_service.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) |
334 return; | 362 return; |
335 broken_alternative_services_.erase(alternative_service); | 363 broken_alternative_services_.erase(alternative_service); |
336 recently_broken_alternative_services_.erase(alternative_service); | 364 recently_broken_alternative_services_.erase(alternative_service); |
337 } | 365 } |
338 | 366 |
339 void HttpServerPropertiesImpl::ClearAlternativeService( | 367 void HttpServerPropertiesImpl::ClearAlternativeService( |
340 const HostPortPair& origin) { | 368 const HostPortPair& origin) { |
341 RemoveCanonicalHost(origin); | 369 RemoveCanonicalHost(origin); |
342 | 370 |
343 AlternateProtocolMap::iterator it = alternate_protocol_map_.Peek(origin); | 371 AlternativeServiceMap::iterator it = alternative_service_map_.Peek(origin); |
344 if (it == alternate_protocol_map_.end()) { | 372 if (it == alternative_service_map_.end()) { |
345 return; | 373 return; |
346 } | 374 } |
347 const AlternativeService alternative_service( | 375 AlternativeService alternative_service(it->second.alternative_service); |
348 it->second.protocol, it->first.host(), it->second.port); | 376 if (alternative_service.host.empty()) { |
349 alternate_protocol_map_.Erase(it); | 377 alternative_service.host = origin.host(); |
| 378 } |
| 379 alternative_service_map_.Erase(it); |
350 | 380 |
351 // The following is temporary to keep the existing semantics, which is that if | 381 // 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 | 382 // there is a broken alternative service in the mapping, then this method |
353 // leaves it in a non-broken, but recently broken state. | 383 // leaves it in a non-broken, but recently broken state. |
354 // | 384 // |
355 // TODO(bnc): | 385 // TODO(bnc): |
356 // 1. Verify and document the class invariant that no broken alternative | 386 // 1. Verify and document the class invariant that no broken alternative |
357 // service can be in the mapping. | 387 // service can be in the mapping. |
358 // 2. Remove the rest of this method as it will be moot. | 388 // 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); | 389 broken_alternative_services_.erase(alternative_service); |
361 } | 390 } |
362 | 391 |
363 const AlternateProtocolMap& | 392 const AlternativeServiceMap& HttpServerPropertiesImpl::alternative_service_map() |
364 HttpServerPropertiesImpl::alternate_protocol_map() const { | 393 const { |
365 return alternate_protocol_map_; | 394 return alternative_service_map_; |
366 } | 395 } |
367 | 396 |
368 const SettingsMap& HttpServerPropertiesImpl::GetSpdySettings( | 397 const SettingsMap& HttpServerPropertiesImpl::GetSpdySettings( |
369 const HostPortPair& host_port_pair) { | 398 const HostPortPair& host_port_pair) { |
370 SpdySettingsMap::iterator it = spdy_settings_map_.Get(host_port_pair); | 399 SpdySettingsMap::iterator it = spdy_settings_map_.Get(host_port_pair); |
371 if (it == spdy_settings_map_.end()) { | 400 if (it == spdy_settings_map_.end()) { |
372 CR_DEFINE_STATIC_LOCAL(SettingsMap, kEmptySettingsMap, ()); | 401 CR_DEFINE_STATIC_LOCAL(SettingsMap, kEmptySettingsMap, ()); |
373 return kEmptySettingsMap; | 402 return kEmptySettingsMap; |
374 } | 403 } |
375 return it->second; | 404 return it->second; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 const ServerNetworkStatsMap& | 478 const ServerNetworkStatsMap& |
450 HttpServerPropertiesImpl::server_network_stats_map() const { | 479 HttpServerPropertiesImpl::server_network_stats_map() const { |
451 return server_network_stats_map_; | 480 return server_network_stats_map_; |
452 } | 481 } |
453 | 482 |
454 void HttpServerPropertiesImpl::SetAlternateProtocolProbabilityThreshold( | 483 void HttpServerPropertiesImpl::SetAlternateProtocolProbabilityThreshold( |
455 double threshold) { | 484 double threshold) { |
456 alternate_protocol_probability_threshold_ = threshold; | 485 alternate_protocol_probability_threshold_ = threshold; |
457 } | 486 } |
458 | 487 |
459 AlternateProtocolMap::const_iterator | 488 AlternativeServiceMap::const_iterator |
460 HttpServerPropertiesImpl::GetAlternateProtocolIterator( | 489 HttpServerPropertiesImpl::GetAlternateProtocolIterator( |
461 const HostPortPair& server) { | 490 const HostPortPair& server) { |
462 AlternateProtocolMap::const_iterator it = alternate_protocol_map_.Get(server); | 491 AlternativeServiceMap::const_iterator it = |
463 if (it != alternate_protocol_map_.end()) | 492 alternative_service_map_.Get(server); |
| 493 if (it != alternative_service_map_.end()) |
464 return it; | 494 return it; |
465 | 495 |
466 CanonicalHostMap::const_iterator canonical = GetCanonicalHost(server); | 496 CanonicalHostMap::const_iterator canonical = GetCanonicalHost(server); |
467 if (canonical == canonical_host_to_origin_map_.end()) { | 497 if (canonical == canonical_host_to_origin_map_.end()) { |
468 return alternate_protocol_map_.end(); | 498 return alternative_service_map_.end(); |
469 } | 499 } |
470 | 500 |
471 const HostPortPair canonical_host_port = canonical->second; | 501 const HostPortPair canonical_host_port = canonical->second; |
472 it = alternate_protocol_map_.Get(canonical_host_port); | 502 it = alternative_service_map_.Get(canonical_host_port); |
473 if (it == alternate_protocol_map_.end()) { | 503 if (it == alternative_service_map_.end()) { |
474 return alternate_protocol_map_.end(); | 504 return alternative_service_map_.end(); |
475 } | 505 } |
476 | 506 |
477 const AlternativeService alternative_service( | 507 const AlternativeService alternative_service( |
478 it->second.protocol, canonical_host_port.host(), it->second.port); | 508 it->second.alternative_service.protocol, canonical_host_port.host(), |
| 509 it->second.alternative_service.port); |
479 if (!IsAlternativeServiceBroken(alternative_service)) { | 510 if (!IsAlternativeServiceBroken(alternative_service)) { |
480 return it; | 511 return it; |
481 } | 512 } |
482 | 513 |
483 RemoveCanonicalHost(canonical_host_port); | 514 RemoveCanonicalHost(canonical_host_port); |
484 return alternate_protocol_map_.end(); | 515 return alternative_service_map_.end(); |
485 } | 516 } |
486 | 517 |
487 HttpServerPropertiesImpl::CanonicalHostMap::const_iterator | 518 HttpServerPropertiesImpl::CanonicalHostMap::const_iterator |
488 HttpServerPropertiesImpl::GetCanonicalHost(HostPortPair server) const { | 519 HttpServerPropertiesImpl::GetCanonicalHost(HostPortPair server) const { |
489 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { | 520 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { |
490 std::string canonical_suffix = canonical_suffixes_[i]; | 521 std::string canonical_suffix = canonical_suffixes_[i]; |
491 if (EndsWith(server.host(), canonical_suffixes_[i], false)) { | 522 if (EndsWith(server.host(), canonical_suffixes_[i], false)) { |
492 HostPortPair canonical_host(canonical_suffix, server.port()); | 523 HostPortPair canonical_host(canonical_suffix, server.port()); |
493 return canonical_host_to_origin_map_.find(canonical_host); | 524 return canonical_host_to_origin_map_.find(canonical_host); |
494 } | 525 } |
(...skipping 18 matching lines...) Expand all Loading... |
513 base::TimeTicks now = base::TimeTicks::Now(); | 544 base::TimeTicks now = base::TimeTicks::Now(); |
514 while (!broken_alternative_services_.empty()) { | 545 while (!broken_alternative_services_.empty()) { |
515 BrokenAlternativeServices::iterator it = | 546 BrokenAlternativeServices::iterator it = |
516 broken_alternative_services_.begin(); | 547 broken_alternative_services_.begin(); |
517 if (now < it->second) { | 548 if (now < it->second) { |
518 break; | 549 break; |
519 } | 550 } |
520 | 551 |
521 const AlternativeService alternative_service = it->first; | 552 const AlternativeService alternative_service = it->first; |
522 broken_alternative_services_.erase(it); | 553 broken_alternative_services_.erase(it); |
| 554 // TODO(bnc): Make sure broken alternative services are not in the mapping. |
523 ClearAlternativeService( | 555 ClearAlternativeService( |
524 HostPortPair(alternative_service.host, alternative_service.port)); | 556 HostPortPair(alternative_service.host, alternative_service.port)); |
525 } | 557 } |
526 ScheduleBrokenAlternateProtocolMappingsExpiration(); | 558 ScheduleBrokenAlternateProtocolMappingsExpiration(); |
527 } | 559 } |
528 | 560 |
529 void | 561 void |
530 HttpServerPropertiesImpl::ScheduleBrokenAlternateProtocolMappingsExpiration() { | 562 HttpServerPropertiesImpl::ScheduleBrokenAlternateProtocolMappingsExpiration() { |
531 if (broken_alternative_services_.empty()) { | 563 if (broken_alternative_services_.empty()) { |
532 return; | 564 return; |
533 } | 565 } |
534 base::TimeTicks now = base::TimeTicks::Now(); | 566 base::TimeTicks now = base::TimeTicks::Now(); |
535 base::TimeTicks when = broken_alternative_services_.front().second; | 567 base::TimeTicks when = broken_alternative_services_.front().second; |
536 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); | 568 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); |
537 base::MessageLoop::current()->PostDelayedTask( | 569 base::MessageLoop::current()->PostDelayedTask( |
538 FROM_HERE, | 570 FROM_HERE, |
539 base::Bind( | 571 base::Bind( |
540 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, | 572 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, |
541 weak_ptr_factory_.GetWeakPtr()), | 573 weak_ptr_factory_.GetWeakPtr()), |
542 delay); | 574 delay); |
543 } | 575 } |
544 | 576 |
545 } // namespace net | 577 } // namespace net |
OLD | NEW |