Chromium Code Reviews| Index: net/http/http_alternate_protocols.cc |
| =================================================================== |
| --- net/http/http_alternate_protocols.cc (revision 57015) |
| +++ net/http/http_alternate_protocols.cc (working copy) |
| @@ -15,12 +15,17 @@ |
| "npn-spdy/2", |
| }; |
| +// static |
| +HttpAlternateProtocols::PortProtocolPair* |
| + HttpAlternateProtocols::forced_alternate_protocol_ = NULL; |
| + |
| HttpAlternateProtocols::HttpAlternateProtocols() {} |
| HttpAlternateProtocols::~HttpAlternateProtocols() {} |
| bool HttpAlternateProtocols::HasAlternateProtocolFor( |
| const HostPortPair& http_host_port_pair) const { |
| - return ContainsKey(protocol_map_, http_host_port_pair); |
| + return ContainsKey(protocol_map_, http_host_port_pair) || |
| + forced_alternate_protocol_; |
| } |
| bool HttpAlternateProtocols::HasAlternateProtocolFor( |
| @@ -32,8 +37,16 @@ |
| HttpAlternateProtocols::PortProtocolPair |
| HttpAlternateProtocols::GetAlternateProtocolFor( |
| const HostPortPair& http_host_port_pair) const { |
| - DCHECK(ContainsKey(protocol_map_, http_host_port_pair)); |
| - return protocol_map_.find(http_host_port_pair)->second; |
| + DCHECK(HasAlternateProtocolFor(http_host_port_pair)); |
| + |
| + // First check the map. |
| + ProtocolMap::const_iterator it = protocol_map_.find(http_host_port_pair); |
| + if (it != protocol_map_.end()) |
| + return it->second; |
| + |
| + // We must be forcing an alternate. |
| + DCHECK(forced_alternate_protocol_); |
| + return *forced_alternate_protocol_; |
| } |
| HttpAlternateProtocols::PortProtocolPair |
| @@ -83,4 +96,17 @@ |
| protocol_map_[http_host_port_pair].protocol = BROKEN; |
| } |
| +// static |
| +void HttpAlternateProtocols::ForceAlternateProtocol( |
| + const PortProtocolPair& pair) { |
| + // Note: we're going to leak this. |
|
willchan no longer on Chromium
2010/08/22 16:27:33
Call delete forced_alternate_protocol_ here, in ca
|
| + forced_alternate_protocol_ = new PortProtocolPair(pair); |
| +} |
| + |
| +// static |
| +void HttpAlternateProtocols::DisableForcedAlternateProtocol() { |
| + delete forced_alternate_protocol_; |
| + forced_alternate_protocol_ = NULL; |
| +} |
| + |
| } // namespace net |