Chromium Code Reviews| 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 #ifndef NET_HTTP_HTTP_SERVER_PROPERTIES_H_ | 5 #ifndef NET_HTTP_HTTP_SERVER_PROPERTIES_H_ |
| 6 #define NET_HTTP_HTTP_SERVER_PROPERTIES_H_ | 6 #define NET_HTTP_HTTP_SERVER_PROPERTIES_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | |
| 11 | |
| 10 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 11 #include "base/containers/mru_cache.h" | 13 #include "base/containers/mru_cache.h" |
| 12 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 13 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 14 #include "net/base/host_port_pair.h" | 16 #include "net/base/host_port_pair.h" |
| 15 #include "net/base/net_export.h" | 17 #include "net/base/net_export.h" |
| 16 #include "net/socket/next_proto.h" | 18 #include "net/socket/next_proto.h" |
| 17 #include "net/spdy/spdy_framer.h" // TODO(willchan): Reconsider this. | 19 #include "net/spdy/spdy_framer.h" // TODO(willchan): Reconsider this. |
| 18 #include "net/spdy/spdy_protocol.h" | 20 #include "net/spdy/spdy_protocol.h" |
| 19 | 21 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 // ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION and | 71 // ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION and |
| 70 // ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION (inclusive). | 72 // ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION (inclusive). |
| 71 NET_EXPORT bool IsAlternateProtocolValid(AlternateProtocol protocol); | 73 NET_EXPORT bool IsAlternateProtocolValid(AlternateProtocol protocol); |
| 72 | 74 |
| 73 enum AlternateProtocolSize { | 75 enum AlternateProtocolSize { |
| 74 NUM_VALID_ALTERNATE_PROTOCOLS = | 76 NUM_VALID_ALTERNATE_PROTOCOLS = |
| 75 ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION - | 77 ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION - |
| 76 ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION + 1, | 78 ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION + 1, |
| 77 }; | 79 }; |
| 78 | 80 |
| 79 NET_EXPORT const char* AlternateProtocolToString(AlternateProtocol protocol); | 81 // TODO(bnc): Rename to AlternateServiceInfo. |
| 80 NET_EXPORT AlternateProtocol AlternateProtocolFromString( | 82 struct NET_EXPORT AlternateProtocolInfo { |
| 81 const std::string& str); | 83 AlternateProtocolInfo() |
| 82 NET_EXPORT_PRIVATE AlternateProtocol AlternateProtocolFromNextProto( | 84 : port(), protocol(UNINITIALIZED_ALTERNATE_PROTOCOL), probability() {} |
| 83 NextProto next_proto); | |
| 84 | 85 |
| 85 struct NET_EXPORT AlternateProtocolInfo { | |
| 86 AlternateProtocolInfo(uint16 port, | 86 AlternateProtocolInfo(uint16 port, |
| 87 AlternateProtocol protocol, | 87 AlternateProtocol protocol, |
| 88 double probability) | 88 double probability) |
| 89 : port(port), | 89 : port(port), |
| 90 protocol(protocol), | 90 protocol(protocol), |
| 91 probability(probability) {} | 91 probability(probability) {} |
| 92 | 92 |
| 93 bool Equals(const AlternateProtocolInfo& other) const { | 93 bool Equals(const AlternateProtocolInfo& other) const { |
| 94 return port == other.port && | 94 return port == other.port && |
| 95 protocol == other.protocol && | 95 protocol == other.protocol && |
| 96 probability == other.probability; | 96 probability == other.probability; |
| 97 } | 97 } |
| 98 | 98 |
| 99 bool EqualsModuloProbabilityAndProtocol( | |
| 100 const AlternateProtocolInfo& other) const { | |
| 101 return port == other.port; | |
|
Ryan Hamilton
2014/11/03 19:00:30
I'm surprised that this only checks the port. Is t
Bence
2014/11/03 22:32:25
Yes, I use it in AlternateProtocols to identify du
Ryan Hamilton
2014/11/04 18:56:22
Ah right! There are still no hosts. Gotcha.
| |
| 102 } | |
| 103 | |
| 99 std::string ToString() const; | 104 std::string ToString() const; |
| 100 | 105 |
| 101 uint16 port; | 106 uint16 port; |
| 102 AlternateProtocol protocol; | 107 AlternateProtocol protocol; |
| 103 double probability; | 108 double probability; |
| 104 }; | 109 }; |
| 105 | 110 |
| 106 struct NET_EXPORT SupportsQuic { | 111 struct NET_EXPORT SupportsQuic { |
| 107 SupportsQuic() : used_quic(false) {} | 112 SupportsQuic() : used_quic(false) {} |
| 108 SupportsQuic(bool used_quic, const std::string& address) | 113 SupportsQuic(bool used_quic, const std::string& address) |
| 109 : used_quic(used_quic), | 114 : used_quic(used_quic), |
| 110 address(address) {} | 115 address(address) {} |
| 111 | 116 |
| 112 bool Equals(const SupportsQuic& other) const { | 117 bool Equals(const SupportsQuic& other) const { |
| 113 return used_quic == other.used_quic && address == other.address; | 118 return used_quic == other.used_quic && address == other.address; |
| 114 } | 119 } |
| 115 | 120 |
| 116 bool used_quic; | 121 bool used_quic; |
| 117 std::string address; | 122 std::string address; |
| 118 }; | 123 }; |
| 119 | 124 |
| 120 typedef base::MRUCache< | 125 // TODO(bnc): Rename to AlternateServices. |
| 121 HostPortPair, AlternateProtocolInfo> AlternateProtocolMap; | 126 typedef std::vector<AlternateProtocolInfo> AlternateProtocols; |
| 127 // TODO(bnc): Rename to AlternateServicesMap. | |
| 128 typedef base::MRUCache<HostPortPair, AlternateProtocols> AlternateProtocolMap; | |
| 122 typedef base::MRUCache<HostPortPair, SettingsMap> SpdySettingsMap; | 129 typedef base::MRUCache<HostPortPair, SettingsMap> SpdySettingsMap; |
| 123 typedef std::map<HostPortPair, SupportsQuic> SupportsQuicMap; | 130 typedef std::map<HostPortPair, SupportsQuic> SupportsQuicMap; |
| 124 | 131 |
| 125 extern const char kAlternateProtocolHeader[]; | 132 extern const char kAlternateProtocolHeader[]; |
| 126 | 133 |
| 134 NET_EXPORT const char* AlternateProtocolToString(AlternateProtocol protocol); | |
| 135 // TODO(bnc): Rename to AlternateServicesToString. | |
| 136 NET_EXPORT std::string AlternateProtocolsToString(AlternateProtocols services); | |
| 137 NET_EXPORT AlternateProtocol | |
| 138 AlternateProtocolFromString(const std::string& str); | |
| 139 NET_EXPORT_PRIVATE AlternateProtocol | |
| 140 AlternateProtocolFromNextProto(NextProto next_proto); | |
| 141 | |
| 127 // The interface for setting/retrieving the HTTP server properties. | 142 // The interface for setting/retrieving the HTTP server properties. |
| 128 // Currently, this class manages servers': | 143 // Currently, this class manages servers': |
| 129 // * SPDY support (based on NPN results) | 144 // * SPDY support (based on NPN results) |
| 130 // * Alternate-Protocol support | 145 // * Alternate-Protocol support |
| 131 // * Spdy Settings (like CWND ID field) | 146 // * Spdy Settings (like CWND ID field) |
| 132 class NET_EXPORT HttpServerProperties { | 147 class NET_EXPORT HttpServerProperties { |
| 133 public: | 148 public: |
| 134 struct NetworkStats { | 149 struct NetworkStats { |
| 135 base::TimeDelta srtt; | 150 base::TimeDelta srtt; |
| 136 uint64 bandwidth_estimate; | 151 uint64 bandwidth_estimate; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 147 | 162 |
| 148 // Returns true if |server| supports SPDY. | 163 // Returns true if |server| supports SPDY. |
| 149 virtual bool SupportsSpdy(const HostPortPair& server) = 0; | 164 virtual bool SupportsSpdy(const HostPortPair& server) = 0; |
| 150 | 165 |
| 151 // Add |server| into the persistent store. Should only be called from IO | 166 // Add |server| into the persistent store. Should only be called from IO |
| 152 // thread. | 167 // thread. |
| 153 virtual void SetSupportsSpdy(const HostPortPair& server, | 168 virtual void SetSupportsSpdy(const HostPortPair& server, |
| 154 bool support_spdy) = 0; | 169 bool support_spdy) = 0; |
| 155 | 170 |
| 156 // Returns true if |server| has an Alternate-Protocol header. | 171 // Returns true if |server| has an Alternate-Protocol header. |
| 172 // TODO(bnc): Rename to HasAlternateService. | |
| 157 virtual bool HasAlternateProtocol(const HostPortPair& server) = 0; | 173 virtual bool HasAlternateProtocol(const HostPortPair& server) = 0; |
| 158 | 174 |
| 159 // Returns the Alternate-Protocol and port for |server|. | 175 // Returns the Alternate-Protocols for |server|. |
| 160 // HasAlternateProtocol(server) must be true. | 176 // HasAlternateProtocol(server) must be true. |
| 161 virtual AlternateProtocolInfo GetAlternateProtocol( | 177 virtual AlternateProtocols GetAlternateProtocol( |
|
Ryan Hamilton
2014/11/03 19:00:30
Seems like it might be a good idea for this to ret
Ryan Hamilton
2014/11/03 19:00:30
Since this returns multiple protocols, should the
Bence
2014/11/03 22:32:25
Done.
Bence
2014/11/03 22:32:25
Done.
| |
| 162 const HostPortPair& server) = 0; | 178 const HostPortPair& server) = 0; |
| 163 | 179 |
| 164 // Sets the Alternate-Protocol for |server|. | 180 // Adds an Alternate-Protocol for |server|. |
| 165 virtual void SetAlternateProtocol(const HostPortPair& server, | 181 // TODO(bnc): Rename to AddAlternateService. |
| 182 virtual void AddAlternateProtocol(const HostPortPair& server, | |
| 166 uint16 alternate_port, | 183 uint16 alternate_port, |
| 167 AlternateProtocol alternate_protocol, | 184 AlternateProtocol alternate_protocol, |
| 168 double probability) = 0; | 185 double probability) = 0; |
| 169 | 186 |
| 170 // Sets the Alternate-Protocol for |server| to be BROKEN. | 187 // Sets a given Alternate-Protocol for |server| to be BROKEN. |
| 171 virtual void SetBrokenAlternateProtocol(const HostPortPair& server) = 0; | 188 virtual void SetBrokenAlternateProtocol( |
| 189 const HostPortPair& server, | |
| 190 const AlternateProtocolInfo& broken_alternate_protocol) = 0; | |
|
Ryan Hamilton
2014/11/03 19:00:30
Does this only need to take the protocol, or does
Bence
2014/11/03 22:32:26
Since a server might advertise multiple alternate
Ryan Hamilton
2014/11/04 18:56:22
Argh! I misread AlternateProtocolInfo as the proto
| |
| 172 | 191 |
| 173 // Returns true if Alternate-Protocol for |server| was recently BROKEN. | 192 // Returns true if given Alternate-Protocol for |server| was recently BROKEN. |
| 174 virtual bool WasAlternateProtocolRecentlyBroken( | 193 virtual bool WasAlternateProtocolRecentlyBroken( |
| 175 const HostPortPair& server) = 0; | 194 const HostPortPair& server, |
| 195 const AlternateProtocolInfo& alternate_protocol) = 0; | |
| 176 | 196 |
| 177 // Confirms that Alternate-Protocol for |server| is working. | 197 // Confirms that given Alternate-Protocol for |server| is working. |
| 178 virtual void ConfirmAlternateProtocol(const HostPortPair& server) = 0; | 198 virtual void ConfirmAlternateProtocol( |
| 199 const HostPortPair& server, | |
| 200 const AlternateProtocolInfo& alternate_protocol) = 0; | |
| 179 | 201 |
| 180 // Clears the Alternate-Protocol for |server|. | 202 // Clears all Alternate-Protocols for |server|. |
| 203 // TODO(bnc): Rename to ClearAlternateServices. | |
| 181 virtual void ClearAlternateProtocol(const HostPortPair& server) = 0; | 204 virtual void ClearAlternateProtocol(const HostPortPair& server) = 0; |
| 182 | 205 |
| 206 // Removes an Alternate-Protocol for |server|. | |
| 207 // TODO(bnc): Rename to RemoveAlternateService. | |
| 208 virtual void RemoveAlternateProtocol( | |
| 209 const HostPortPair& server, | |
| 210 const AlternateProtocolInfo& alternate_protocol) = 0; | |
| 211 | |
| 183 // Returns all Alternate-Protocol mappings. | 212 // Returns all Alternate-Protocol mappings. |
| 213 // TODO(bnc): Rename to alternate_services_map. | |
| 184 virtual const AlternateProtocolMap& alternate_protocol_map() const = 0; | 214 virtual const AlternateProtocolMap& alternate_protocol_map() const = 0; |
| 185 | 215 |
| 186 // Sets the threshold to be used when evaluating Alternate-Protocol | 216 // Sets the threshold to be used when evaluating Alternate-Protocol |
| 187 // advertisments. Only advertisements with a with a probability | 217 // advertisments. Only advertisements with a with a probability |
| 188 // greater than |threshold| will be honored. |threshold| must be | 218 // greater than |threshold| will be honored. |threshold| must be |
| 189 // between 0 and 1 inclusive. Hence, a threshold of 0 implies that | 219 // between 0 and 1 inclusive. Hence, a threshold of 0 implies that |
| 190 // all advertisements will be honored. | 220 // all advertisements will be honored. |
| 191 virtual void SetAlternateProtocolProbabilityThreshold( | 221 virtual void SetAlternateProtocolProbabilityThreshold( |
| 192 double threshold) = 0; | 222 double threshold) = 0; |
| 193 | 223 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 228 virtual const NetworkStats* GetServerNetworkStats( | 258 virtual const NetworkStats* GetServerNetworkStats( |
| 229 const HostPortPair& host_port_pair) const = 0; | 259 const HostPortPair& host_port_pair) const = 0; |
| 230 | 260 |
| 231 private: | 261 private: |
| 232 DISALLOW_COPY_AND_ASSIGN(HttpServerProperties); | 262 DISALLOW_COPY_AND_ASSIGN(HttpServerProperties); |
| 233 }; | 263 }; |
| 234 | 264 |
| 235 } // namespace net | 265 } // namespace net |
| 236 | 266 |
| 237 #endif // NET_HTTP_HTTP_SERVER_PROPERTIES_H_ | 267 #endif // NET_HTTP_HTTP_SERVER_PROPERTIES_H_ |
| OLD | NEW |