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" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 return; | 42 return; |
43 // Add the entries from persisted data. | 43 // Add the entries from persisted data. |
44 for (std::vector<std::string>::reverse_iterator it = spdy_servers->rbegin(); | 44 for (std::vector<std::string>::reverse_iterator it = spdy_servers->rbegin(); |
45 it != spdy_servers->rend(); ++it) { | 45 it != spdy_servers->rend(); ++it) { |
46 spdy_servers_map_.Put(*it, support_spdy); | 46 spdy_servers_map_.Put(*it, support_spdy); |
47 } | 47 } |
48 } | 48 } |
49 | 49 |
50 void HttpServerPropertiesImpl::InitializeAlternateProtocolServers( | 50 void HttpServerPropertiesImpl::InitializeAlternateProtocolServers( |
51 AlternateProtocolMap* alternate_protocol_map) { | 51 AlternateProtocolMap* alternate_protocol_map) { |
52 // Keep all the ALTERNATE_PROTOCOL_BROKEN ones since those don't | 52 // Keep all the broken ones since those don't get persisted. |
53 // get persisted. | |
54 for (AlternateProtocolMap::iterator it = alternate_protocol_map_.begin(); | 53 for (AlternateProtocolMap::iterator it = alternate_protocol_map_.begin(); |
55 it != alternate_protocol_map_.end();) { | 54 it != alternate_protocol_map_.end();) { |
56 AlternateProtocolMap::iterator old_it = it; | 55 AlternateProtocolMap::iterator old_it = it; |
57 ++it; | 56 ++it; |
58 if (old_it->second.protocol != ALTERNATE_PROTOCOL_BROKEN) { | 57 if (!old_it->second.is_broken) { |
59 alternate_protocol_map_.Erase(old_it); | 58 alternate_protocol_map_.Erase(old_it); |
60 } | 59 } |
61 } | 60 } |
62 | 61 |
63 // Add the entries from persisted data. | 62 // Add the entries from persisted data. |
64 for (AlternateProtocolMap::reverse_iterator it = | 63 for (AlternateProtocolMap::reverse_iterator it = |
65 alternate_protocol_map->rbegin(); | 64 alternate_protocol_map->rbegin(); |
66 it != alternate_protocol_map->rend(); ++it) { | 65 it != alternate_protocol_map->rend(); ++it) { |
67 alternate_protocol_map_.Put(it->first, it->second); | 66 alternate_protocol_map_.Put(it->first, it->second); |
68 } | 67 } |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 // We must be forcing an alternate. | 243 // We must be forcing an alternate. |
245 DCHECK(g_forced_alternate_protocol); | 244 DCHECK(g_forced_alternate_protocol); |
246 return *g_forced_alternate_protocol; | 245 return *g_forced_alternate_protocol; |
247 } | 246 } |
248 | 247 |
249 void HttpServerPropertiesImpl::SetAlternateProtocol( | 248 void HttpServerPropertiesImpl::SetAlternateProtocol( |
250 const HostPortPair& server, | 249 const HostPortPair& server, |
251 uint16 alternate_port, | 250 uint16 alternate_port, |
252 AlternateProtocol alternate_protocol, | 251 AlternateProtocol alternate_protocol, |
253 double alternate_probability) { | 252 double alternate_probability) { |
254 if (alternate_protocol == ALTERNATE_PROTOCOL_BROKEN) { | |
255 LOG(DFATAL) << "Call SetBrokenAlternateProtocol() instead."; | |
256 return; | |
257 } | |
258 | 253 |
259 AlternateProtocolInfo alternate(alternate_port, | 254 AlternateProtocolInfo alternate(alternate_port, |
260 alternate_protocol, | 255 alternate_protocol, |
261 alternate_probability); | 256 alternate_probability); |
262 if (HasAlternateProtocol(server)) { | 257 if (HasAlternateProtocol(server)) { |
263 const AlternateProtocolInfo existing_alternate = | 258 const AlternateProtocolInfo existing_alternate = |
264 GetAlternateProtocol(server); | 259 GetAlternateProtocol(server); |
265 | 260 |
266 if (existing_alternate.protocol == ALTERNATE_PROTOCOL_BROKEN) { | 261 if (existing_alternate.is_broken) { |
267 DVLOG(1) << "Ignore alternate protocol since it's known to be broken."; | 262 DVLOG(1) << "Ignore alternate protocol since it's known to be broken."; |
268 return; | 263 return; |
269 } | 264 } |
270 | 265 |
271 if (alternate_protocol != ALTERNATE_PROTOCOL_BROKEN && | 266 if (!existing_alternate.Equals(alternate)) { |
272 !existing_alternate.Equals(alternate)) { | |
273 LOG(WARNING) << "Changing the alternate protocol for: " | 267 LOG(WARNING) << "Changing the alternate protocol for: " |
274 << server.ToString() | 268 << server.ToString() |
275 << " from [Port: " << existing_alternate.port | 269 << " from [Port: " << existing_alternate.port |
276 << ", Protocol: " << existing_alternate.protocol | 270 << ", Protocol: " << existing_alternate.protocol |
277 << ", Probability: " << existing_alternate.probability | 271 << ", Probability: " << existing_alternate.probability |
278 << "] to [Port: " << alternate_port | 272 << "] to [Port: " << alternate_port |
279 << ", Protocol: " << alternate_protocol | 273 << ", Protocol: " << alternate_protocol |
280 << ", Probability: " << alternate_probability | 274 << ", Probability: " << alternate_probability |
281 << "]."; | 275 << "]."; |
282 } | 276 } |
(...skipping 16 matching lines...) Expand all Loading... |
299 HostPortPair canonical_host(canonical_suffix, server.port()); | 293 HostPortPair canonical_host(canonical_suffix, server.port()); |
300 canonical_host_to_origin_map_[canonical_host] = server; | 294 canonical_host_to_origin_map_[canonical_host] = server; |
301 break; | 295 break; |
302 } | 296 } |
303 } | 297 } |
304 } | 298 } |
305 | 299 |
306 void HttpServerPropertiesImpl::SetBrokenAlternateProtocol( | 300 void HttpServerPropertiesImpl::SetBrokenAlternateProtocol( |
307 const HostPortPair& server) { | 301 const HostPortPair& server) { |
308 AlternateProtocolMap::iterator it = alternate_protocol_map_.Get(server); | 302 AlternateProtocolMap::iterator it = alternate_protocol_map_.Get(server); |
309 if (it != alternate_protocol_map_.end()) { | 303 if (it == alternate_protocol_map_.end()) { |
310 it->second.protocol = ALTERNATE_PROTOCOL_BROKEN; | 304 LOG(DFATAL) << "Trying to mark unknown alternate protocol broken."; |
311 } else { | 305 return; |
312 AlternateProtocolInfo alternate(server.port(), | |
313 ALTERNATE_PROTOCOL_BROKEN, | |
314 1); | |
315 alternate_protocol_map_.Put(server, alternate); | |
316 } | 306 } |
| 307 it->second.is_broken = true; |
317 int count = ++broken_alternate_protocol_map_[server]; | 308 int count = ++broken_alternate_protocol_map_[server]; |
318 base::TimeDelta delay = | 309 base::TimeDelta delay = |
319 base::TimeDelta::FromSeconds(kBrokenAlternateProtocolDelaySecs); | 310 base::TimeDelta::FromSeconds(kBrokenAlternateProtocolDelaySecs); |
320 BrokenAlternateProtocolEntry entry; | 311 BrokenAlternateProtocolEntry entry; |
321 entry.server = server; | 312 entry.server = server; |
322 entry.when = base::TimeTicks::Now() + delay * (1 << (count - 1)); | 313 entry.when = base::TimeTicks::Now() + delay * (1 << (count - 1)); |
323 broken_alternate_protocol_list_.push_back(entry); | 314 broken_alternate_protocol_list_.push_back(entry); |
324 | 315 |
325 // Do not leave this host as canonical so that we don't infer the other | 316 // Do not leave this host as canonical so that we don't infer the other |
326 // hosts are also broken without testing them first. | 317 // hosts are also broken without testing them first. |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); | 491 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); |
501 base::MessageLoop::current()->PostDelayedTask( | 492 base::MessageLoop::current()->PostDelayedTask( |
502 FROM_HERE, | 493 FROM_HERE, |
503 base::Bind( | 494 base::Bind( |
504 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, | 495 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, |
505 weak_ptr_factory_.GetWeakPtr()), | 496 weak_ptr_factory_.GetWeakPtr()), |
506 delay); | 497 delay); |
507 } | 498 } |
508 | 499 |
509 } // namespace net | 500 } // namespace net |
OLD | NEW |