| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // HttpAlternateProtocols is an in-memory data structure used for keeping track | 5 // HttpAlternateProtocols is an in-memory data structure used for keeping track |
| 6 // of which HTTP HostPortPairs have an alternate protocol that can be used | 6 // of which HTTP HostPortPairs have an alternate protocol that can be used |
| 7 // instead of HTTP on a different port. | 7 // instead of HTTP on a different port. |
| 8 | 8 |
| 9 #ifndef NET_HTTP_HTTP_ALTERNATE_PROTOCOLS_H_ | 9 #ifndef NET_HTTP_HTTP_ALTERNATE_PROTOCOLS_H_ |
| 10 #define NET_HTTP_HTTP_ALTERNATE_PROTOCOLS_H_ | 10 #define NET_HTTP_HTTP_ALTERNATE_PROTOCOLS_H_ |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 NUM_ALTERNATE_PROTOCOLS, | 27 NUM_ALTERNATE_PROTOCOLS, |
| 28 BROKEN, // The alternate protocol is known to be broken. | 28 BROKEN, // The alternate protocol is known to be broken. |
| 29 UNINITIALIZED, | 29 UNINITIALIZED, |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 struct PortProtocolPair { | 32 struct PortProtocolPair { |
| 33 bool Equals(const PortProtocolPair& other) const { | 33 bool Equals(const PortProtocolPair& other) const { |
| 34 return port == other.port && protocol == other.protocol; | 34 return port == other.port && protocol == other.protocol; |
| 35 } | 35 } |
| 36 | 36 |
| 37 std::string ToString() const; |
| 38 |
| 37 uint16 port; | 39 uint16 port; |
| 38 Protocol protocol; | 40 Protocol protocol; |
| 39 }; | 41 }; |
| 40 | 42 |
| 43 typedef std::map<HostPortPair, PortProtocolPair> ProtocolMap; |
| 44 |
| 41 static const char kHeader[]; | 45 static const char kHeader[]; |
| 42 static const char* const kProtocolStrings[NUM_ALTERNATE_PROTOCOLS]; | 46 static const char* const kProtocolStrings[NUM_ALTERNATE_PROTOCOLS]; |
| 43 | 47 |
| 44 HttpAlternateProtocols(); | 48 HttpAlternateProtocols(); |
| 45 ~HttpAlternateProtocols(); | 49 ~HttpAlternateProtocols(); |
| 46 | 50 |
| 47 // Reports whether or not we have received Alternate-Protocol for | 51 // Reports whether or not we have received Alternate-Protocol for |
| 48 // |http_host_port_pair|. | 52 // |http_host_port_pair|. |
| 49 bool HasAlternateProtocolFor(const HostPortPair& http_host_port_pair) const; | 53 bool HasAlternateProtocolFor(const HostPortPair& http_host_port_pair) const; |
| 50 bool HasAlternateProtocolFor(const std::string& host, uint16 port) const; | 54 bool HasAlternateProtocolFor(const std::string& host, uint16 port) const; |
| 51 | 55 |
| 52 PortProtocolPair GetAlternateProtocolFor( | 56 PortProtocolPair GetAlternateProtocolFor( |
| 53 const HostPortPair& http_host_port_pair) const; | 57 const HostPortPair& http_host_port_pair) const; |
| 54 PortProtocolPair GetAlternateProtocolFor( | 58 PortProtocolPair GetAlternateProtocolFor( |
| 55 const std::string& host, uint16 port) const; | 59 const std::string& host, uint16 port) const; |
| 56 | 60 |
| 57 // SetAlternateProtocolFor() will ignore the request if the alternate protocol | 61 // SetAlternateProtocolFor() will ignore the request if the alternate protocol |
| 58 // has already been marked broken via MarkBrokenAlternateProtocolFor(). | 62 // has already been marked broken via MarkBrokenAlternateProtocolFor(). |
| 59 void SetAlternateProtocolFor(const HostPortPair& http_host_port_pair, | 63 void SetAlternateProtocolFor(const HostPortPair& http_host_port_pair, |
| 60 uint16 alternate_port, | 64 uint16 alternate_port, |
| 61 Protocol alternate_protocol); | 65 Protocol alternate_protocol); |
| 62 | 66 |
| 63 // Marks the alternate protocol as broken. Once marked broken, any further | 67 // Marks the alternate protocol as broken. Once marked broken, any further |
| 64 // attempts to set the alternate protocol for |http_host_port_pair| will fail. | 68 // attempts to set the alternate protocol for |http_host_port_pair| will fail. |
| 65 void MarkBrokenAlternateProtocolFor(const HostPortPair& http_host_port_pair); | 69 void MarkBrokenAlternateProtocolFor(const HostPortPair& http_host_port_pair); |
| 66 | 70 |
| 71 const ProtocolMap& protocol_map() const { return protocol_map_; } |
| 72 |
| 67 // Debugging to simulate presence of an AlternateProtocol. | 73 // Debugging to simulate presence of an AlternateProtocol. |
| 68 // If we don't have an alternate protocol in the map for any given host/port | 74 // If we don't have an alternate protocol in the map for any given host/port |
| 69 // pair, force this ProtocolPortPair. | 75 // pair, force this ProtocolPortPair. |
| 70 static void ForceAlternateProtocol(const PortProtocolPair& pair); | 76 static void ForceAlternateProtocol(const PortProtocolPair& pair); |
| 71 static void DisableForcedAlternateProtocol(); | 77 static void DisableForcedAlternateProtocol(); |
| 72 | 78 |
| 73 private: | 79 private: |
| 74 typedef std::map<HostPortPair, PortProtocolPair> ProtocolMap; | 80 ProtocolMap protocol_map_; |
| 75 | 81 |
| 76 ProtocolMap protocol_map_; | 82 static const char* ProtocolToString(Protocol protocol); |
| 77 | 83 |
| 78 // The forced alternate protocol. If not-null, there is a protocol being | 84 // The forced alternate protocol. If not-null, there is a protocol being |
| 79 // forced. | 85 // forced. |
| 80 static PortProtocolPair* forced_alternate_protocol_; | 86 static PortProtocolPair* forced_alternate_protocol_; |
| 81 | 87 |
| 82 DISALLOW_COPY_AND_ASSIGN(HttpAlternateProtocols); | 88 DISALLOW_COPY_AND_ASSIGN(HttpAlternateProtocols); |
| 83 }; | 89 }; |
| 84 | 90 |
| 85 } // namespace net | 91 } // namespace net |
| 86 | 92 |
| 87 #endif // NET_HTTP_HTTP_ALTERNATE_PROTOCOLS_H_ | 93 #endif // NET_HTTP_HTTP_ALTERNATE_PROTOCOLS_H_ |
| OLD | NEW |