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() {} |
Ryan Hamilton
2014/11/04 18:56:22
Can you explicitly specify 0 for the numeric initi
Bence
2014/11/04 21:55:50
Done.
| |
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; | |
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( | |
137 const AlternateProtocols& services); | |
138 NET_EXPORT AlternateProtocol | |
139 AlternateProtocolFromString(const std::string& str); | |
140 NET_EXPORT_PRIVATE AlternateProtocol | |
141 AlternateProtocolFromNextProto(NextProto next_proto); | |
142 | |
127 // The interface for setting/retrieving the HTTP server properties. | 143 // The interface for setting/retrieving the HTTP server properties. |
128 // Currently, this class manages servers': | 144 // Currently, this class manages servers': |
129 // * SPDY support (based on NPN results) | 145 // * SPDY support (based on NPN results) |
130 // * Alternate-Protocol support | 146 // * Alternate-Protocol support |
131 // * Spdy Settings (like CWND ID field) | 147 // * Spdy Settings (like CWND ID field) |
132 class NET_EXPORT HttpServerProperties { | 148 class NET_EXPORT HttpServerProperties { |
133 public: | 149 public: |
134 struct NetworkStats { | 150 struct NetworkStats { |
135 base::TimeDelta srtt; | 151 base::TimeDelta srtt; |
136 uint64 bandwidth_estimate; | 152 uint64 bandwidth_estimate; |
(...skipping 10 matching lines...) Expand all Loading... | |
147 | 163 |
148 // Returns true if |server| supports SPDY. | 164 // Returns true if |server| supports SPDY. |
149 virtual bool SupportsSpdy(const HostPortPair& server) = 0; | 165 virtual bool SupportsSpdy(const HostPortPair& server) = 0; |
150 | 166 |
151 // Add |server| into the persistent store. Should only be called from IO | 167 // Add |server| into the persistent store. Should only be called from IO |
152 // thread. | 168 // thread. |
153 virtual void SetSupportsSpdy(const HostPortPair& server, | 169 virtual void SetSupportsSpdy(const HostPortPair& server, |
154 bool support_spdy) = 0; | 170 bool support_spdy) = 0; |
155 | 171 |
156 // Returns true if |server| has an Alternate-Protocol header. | 172 // Returns true if |server| has an Alternate-Protocol header. |
173 // TODO(bnc): Rename to HasAlternateService. | |
157 virtual bool HasAlternateProtocol(const HostPortPair& server) = 0; | 174 virtual bool HasAlternateProtocol(const HostPortPair& server) = 0; |
158 | 175 |
159 // Returns the Alternate-Protocol and port for |server|. | 176 // Returns the Alternate-Protocols for |server|. |
160 // HasAlternateProtocol(server) must be true. | 177 // HasAlternateProtocol(server) must be true. |
161 virtual AlternateProtocolInfo GetAlternateProtocol( | 178 virtual const AlternateProtocols& GetAlternateProtocols( |
162 const HostPortPair& server) = 0; | 179 const HostPortPair& server) = 0; |
163 | 180 |
164 // Sets the Alternate-Protocol for |server|. | 181 // Adds an Alternate-Protocol for |server|. |
165 virtual void SetAlternateProtocol(const HostPortPair& server, | 182 // TODO(bnc): Rename to AddAlternateService. |
183 virtual void AddAlternateProtocol(const HostPortPair& server, | |
166 uint16 alternate_port, | 184 uint16 alternate_port, |
167 AlternateProtocol alternate_protocol, | 185 AlternateProtocol alternate_protocol, |
168 double probability) = 0; | 186 double probability) = 0; |
169 | 187 |
170 // Sets the Alternate-Protocol for |server| to be BROKEN. | 188 // Sets a given Alternate-Protocol for |server| to be BROKEN. |
171 virtual void SetBrokenAlternateProtocol(const HostPortPair& server) = 0; | 189 virtual void SetBrokenAlternateProtocol( |
190 const HostPortPair& server, | |
191 const AlternateProtocolInfo& broken_alternate_protocol) = 0; | |
172 | 192 |
173 // Returns true if Alternate-Protocol for |server| was recently BROKEN. | 193 // Returns true if given Alternate-Protocol for |server| was recently BROKEN. |
174 virtual bool WasAlternateProtocolRecentlyBroken( | 194 virtual bool WasAlternateProtocolRecentlyBroken( |
175 const HostPortPair& server) = 0; | 195 const HostPortPair& server, |
196 const AlternateProtocolInfo& alternate_protocol) = 0; | |
176 | 197 |
177 // Confirms that Alternate-Protocol for |server| is working. | 198 // Confirms that given Alternate-Protocol for |server| is working. |
178 virtual void ConfirmAlternateProtocol(const HostPortPair& server) = 0; | 199 virtual void ConfirmAlternateProtocol( |
200 const HostPortPair& server, | |
201 const AlternateProtocolInfo& alternate_protocol) = 0; | |
179 | 202 |
180 // Clears the Alternate-Protocol for |server|. | 203 // Clears all Alternate-Protocols for |server|. |
204 // TODO(bnc): Rename to ClearAlternateServices. | |
181 virtual void ClearAlternateProtocol(const HostPortPair& server) = 0; | 205 virtual void ClearAlternateProtocol(const HostPortPair& server) = 0; |
182 | 206 |
207 // Removes an Alternate-Protocol for |server|. | |
208 // TODO(bnc): Rename to RemoveAlternateService. | |
209 virtual void RemoveAlternateProtocol( | |
210 const HostPortPair& server, | |
211 const AlternateProtocolInfo& alternate_protocol) = 0; | |
212 | |
183 // Returns all Alternate-Protocol mappings. | 213 // Returns all Alternate-Protocol mappings. |
214 // TODO(bnc): Rename to alternate_services_map. | |
184 virtual const AlternateProtocolMap& alternate_protocol_map() const = 0; | 215 virtual const AlternateProtocolMap& alternate_protocol_map() const = 0; |
185 | 216 |
186 // Sets the threshold to be used when evaluating Alternate-Protocol | 217 // Sets the threshold to be used when evaluating Alternate-Protocol |
187 // advertisments. Only advertisements with a with a probability | 218 // advertisments. Only advertisements with a with a probability |
188 // greater than |threshold| will be honored. |threshold| must be | 219 // greater than |threshold| will be honored. |threshold| must be |
189 // between 0 and 1 inclusive. Hence, a threshold of 0 implies that | 220 // between 0 and 1 inclusive. Hence, a threshold of 0 implies that |
190 // all advertisements will be honored. | 221 // all advertisements will be honored. |
191 virtual void SetAlternateProtocolProbabilityThreshold( | 222 virtual void SetAlternateProtocolProbabilityThreshold( |
192 double threshold) = 0; | 223 double threshold) = 0; |
193 | 224 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
228 virtual const NetworkStats* GetServerNetworkStats( | 259 virtual const NetworkStats* GetServerNetworkStats( |
229 const HostPortPair& host_port_pair) const = 0; | 260 const HostPortPair& host_port_pair) const = 0; |
230 | 261 |
231 private: | 262 private: |
232 DISALLOW_COPY_AND_ASSIGN(HttpServerProperties); | 263 DISALLOW_COPY_AND_ASSIGN(HttpServerProperties); |
233 }; | 264 }; |
234 | 265 |
235 } // namespace net | 266 } // namespace net |
236 | 267 |
237 #endif // NET_HTTP_HTTP_SERVER_PROPERTIES_H_ | 268 #endif // NET_HTTP_HTTP_SERVER_PROPERTIES_H_ |
OLD | NEW |