Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(986)

Side by Side Diff: net/spdy/spdy_session_pool.h

Issue 2749123002: ABANDONED Allow SpdySessionPool to find/create SpdySession with IP pooling disabled. (Closed)
Patch Set: Re: #7. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/spdy/spdy_network_transaction_unittest.cc ('k') | net/spdy/spdy_session_pool.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_SPDY_SPDY_SESSION_POOL_H_ 5 #ifndef NET_SPDY_SPDY_SESSION_POOL_H_
6 #define NET_SPDY_SPDY_SESSION_POOL_H_ 6 #define NET_SPDY_SPDY_SESSION_POOL_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <iterator>
10 #include <map> 11 #include <map>
11 #include <memory> 12 #include <memory>
12 #include <set> 13 #include <set>
13 #include <string> 14 #include <string>
14 #include <vector> 15 #include <vector>
15 16
16 #include "base/macros.h" 17 #include "base/macros.h"
17 #include "base/memory/ref_counted.h" 18 #include "base/memory/ref_counted.h"
18 #include "base/memory/weak_ptr.h" 19 #include "base/memory/weak_ptr.h"
19 #include "net/base/host_port_pair.h" 20 #include "net/base/host_port_pair.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 ~SpdySessionPool() override; 66 ~SpdySessionPool() override;
66 67
67 // In the functions below, a session is "available" if this pool has 68 // In the functions below, a session is "available" if this pool has
68 // a reference to it and there is some SpdySessionKey for which 69 // a reference to it and there is some SpdySessionKey for which
69 // FindAvailableSession() will return it. A session is "unavailable" 70 // FindAvailableSession() will return it. A session is "unavailable"
70 // if this pool has a reference to it but it won't be returned by 71 // if this pool has a reference to it but it won't be returned by
71 // FindAvailableSession() for any SpdySessionKey; for example, this 72 // FindAvailableSession() for any SpdySessionKey; for example, this
72 // can happen when a session receives a GOAWAY frame and is still 73 // can happen when a session receives a GOAWAY frame and is still
73 // processing existing streams. 74 // processing existing streams.
74 75
75 // Create a new SPDY session from an existing socket. There must 76 // Create a new SPDY session from an existing socket. There must not already
76 // not already be a session for the given key. 77 // be a non IP pooled session for |key|. However, a session originally opened
78 // with a different key may be marked as an available IP pooled session for
79 // |key|. In other words, CreateAvailableSessionFromSocket() must not be
80 // called if a FindAvailableSession() call with |enable_ip_based_pooling|
81 // argument false would return true.
77 // 82 //
78 // |is_secure| can be false for testing or when SPDY is configured 83 // |is_secure| can be false for testing or when SPDY is configured
79 // to work with non-secure sockets. 84 // to work with non-secure sockets.
80 // 85 //
81 // Returns the new SpdySession. Note that the SpdySession begins reading from 86 // Returns the new SpdySession. Note that the SpdySession begins reading from
82 // |connection| on a subsequent event loop iteration, so it may be closed 87 // |connection| on a subsequent event loop iteration, so it may be closed
83 // immediately afterwards if the first read of |connection| fails. 88 // immediately afterwards if the first read of |connection| fails.
84 base::WeakPtr<SpdySession> CreateAvailableSessionFromSocket( 89 base::WeakPtr<SpdySession> CreateAvailableSessionFromSocket(
85 const SpdySessionKey& key, 90 const SpdySessionKey& key,
86 std::unique_ptr<ClientSocketHandle> connection, 91 std::unique_ptr<ClientSocketHandle> connection,
87 const NetLogWithSource& net_log, 92 const NetLogWithSource& net_log,
88 bool is_secure); 93 bool is_secure);
89 94
90 // Return an available session for |key| that has an unclaimed push stream for 95 // If |url| is not empty and there is a session for |key| that has an
91 // |url| if such exists and |url| is not empty, or else an available session 96 // unclaimed push stream for |url|, return it. Otherwise if there is an
92 // for |key| if such exists, or else nullptr. 97 // available session for |key|, return it. Otherwise if there is a session to
98 // use based on IP address, mark it as available for |key| and return it.
99 // Otherwise return nullptr.
93 base::WeakPtr<SpdySession> FindAvailableSession( 100 base::WeakPtr<SpdySession> FindAvailableSession(
94 const SpdySessionKey& key, 101 const SpdySessionKey& key,
95 const GURL& url, 102 const GURL& url,
103 bool enable_ip_based_pooling,
96 const NetLogWithSource& net_log); 104 const NetLogWithSource& net_log);
97 105
98 // Remove all mappings and aliases for the given session, which must 106 // Remove all mappings and aliases for the given session, which must
99 // still be available. Except for in tests, this must be called by 107 // still be available. Except for in tests, this must be called by
100 // the given session itself. 108 // the given session itself.
101 void MakeSessionUnavailable( 109 void MakeSessionUnavailable(
102 const base::WeakPtr<SpdySession>& available_session); 110 const base::WeakPtr<SpdySession>& available_session);
103 111
104 // Removes an unavailable session from the pool. Except for in 112 // Removes an unavailable session from the pool. Except for in
105 // tests, this must be called by the given session itself. 113 // tests, this must be called by the given session itself.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 // We perform the same flushing as described above when certificate database 163 // We perform the same flushing as described above when certificate database
156 // is changed. 164 // is changed.
157 void OnCertDBChanged() override; 165 void OnCertDBChanged() override;
158 166
159 void DumpMemoryStats(base::trace_event::ProcessMemoryDump* pmd, 167 void DumpMemoryStats(base::trace_event::ProcessMemoryDump* pmd,
160 const std::string& parent_dump_absolute_name) const; 168 const std::string& parent_dump_absolute_name) const;
161 169
162 private: 170 private:
163 friend class SpdySessionPoolPeer; // For testing. 171 friend class SpdySessionPoolPeer; // For testing.
164 172
173 // A container class that wraps two maps: non IP pooled sessions and IP pooled
174 // sessions, both keyed off SpdySessionKey. Every non IP pooled session is
175 // keyed by its own SpdySessionKey, but the same session can occur multiple
176 // times under different keys in the IP pooled map.
177 // Every key can have up to one non IP pooled session and up to one IP pooled
178 // session, possibly simultaneously: for example, if FindAvailableSession() is
179 // called with IP pooling enabled, then later
180 // CreateAvailableSessionFromSocket() is called with the same key to open a
181 // non IP pooled session.
182 class AvailableSessionMap {
183 public:
184 template <class T, class U>
185 class Iterator;
186
187 using MapType = std::map<SpdySessionKey, base::WeakPtr<SpdySession>>;
188 using key_type = MapType::key_type;
189 using value_type = MapType::value_type;
190 using iterator = Iterator<MapType::iterator, AvailableSessionMap>;
191 using const_iterator =
192 Iterator<MapType::const_iterator, const AvailableSessionMap>;
193
194 // Iterator first iterates through the elements of
195 // |non_ip_pooled_sessions_|, then the elements of |ip_pooled_sessions_|.
196 template <class T, class U>
197 class Iterator {
198 public:
199 Iterator();
200 Iterator(const Iterator& other);
201 void operator=(const Iterator& other);
202 ~Iterator();
203
204 static Iterator begin(U* session_map);
205 static Iterator end(U* session_map);
206
207 bool operator==(const Iterator& other) const;
208 bool operator!=(const Iterator& other) const;
209 T& operator->();
210 Iterator& operator++();
211
212 private:
213 friend AvailableSessionMap;
214
215 Iterator(T iterator, bool ip_pooled, U* session_map);
216
217 T iterator_;
218 bool ip_pooled_;
219 U* session_map_;
220 };
221
222 AvailableSessionMap();
223 AvailableSessionMap(const AvailableSessionMap&) = delete;
224 void operator=(const AvailableSessionMap&) = delete;
225 ~AvailableSessionMap();
226
227 iterator begin();
228 iterator end();
229 const_iterator begin() const;
230 const_iterator end() const;
231 bool empty() const;
232
233 // If both IP pooled and non IP pooled entries exist,
234 // then return the non IP pooled one.
235 iterator find(const key_type& key);
236
237 // |value| must not be in the map (this is unlike std::map::insert).
238 void insert(const value_type& value, bool ip_pooled);
239
240 // |key| must exist (this is unlike std::map::erase).
241 void erase(const key_type& key, bool ip_pooled);
242
243 private:
244 friend iterator;
245 friend const_iterator;
246
247 MapType non_ip_pooled_sessions_;
248 MapType ip_pooled_sessions_;
249 };
250
165 typedef std::set<SpdySession*> SessionSet; 251 typedef std::set<SpdySession*> SessionSet;
166 typedef std::vector<base::WeakPtr<SpdySession> > WeakSessionList; 252 typedef std::vector<base::WeakPtr<SpdySession> > WeakSessionList;
167 typedef std::map<SpdySessionKey, base::WeakPtr<SpdySession> >
168 AvailableSessionMap;
169 typedef std::map<IPEndPoint, SpdySessionKey> AliasMap; 253 typedef std::map<IPEndPoint, SpdySessionKey> AliasMap;
170 typedef std::map<GURL, WeakSessionList> UnclaimedPushedStreamMap; 254 typedef std::map<GURL, WeakSessionList> UnclaimedPushedStreamMap;
171 255
172 // Returns true iff |session| is in |available_sessions_|. 256 // Returns true iff |session| is in |available_sessions_|.
173 bool IsSessionAvailable(const base::WeakPtr<SpdySession>& session) const; 257 bool IsSessionAvailable(const base::WeakPtr<SpdySession>& session) const;
174 258
175 // Map the given key to the given session. There must not already be 259 // Map the given key to the given session. There must not already be
176 // a mapping for |key|. 260 // a mapping for |key| in the bucket defined by |ip_pooled|.
177 void MapKeyToAvailableSession(const SpdySessionKey& key, 261 void MapKeyToAvailableSession(const SpdySessionKey& key,
178 const base::WeakPtr<SpdySession>& session); 262 const base::WeakPtr<SpdySession>& session,
263 bool ip_pooled);
179 264
180 // Returns an iterator into |available_sessions_| for the given key,
181 // which may be equal to |available_sessions_.end()|.
182 AvailableSessionMap::iterator LookupAvailableSessionByKey( 265 AvailableSessionMap::iterator LookupAvailableSessionByKey(
183 const SpdySessionKey& key); 266 const SpdySessionKey& key);
184 267
185 // Remove the mapping of the given key, which must exist. 268 // Remove the mapping of |key| from the bucket defined by |ip_pooled|,
186 void UnmapKey(const SpdySessionKey& key); 269 // which must exist.
270 void UnmapKey(const SpdySessionKey& key, bool ip_pooled);
187 271
188 // Remove all aliases for |key| from the aliases table. 272 // Remove all aliases for |key| from the aliases table.
189 void RemoveAliases(const SpdySessionKey& key); 273 void RemoveAliases(const SpdySessionKey& key);
190 274
191 // Get a copy of the current sessions as a list of WeakPtrs. Used by 275 // Get a copy of the current sessions as a list of WeakPtrs. Used by
192 // CloseCurrentSessionsHelper() below. 276 // CloseCurrentSessionsHelper() below.
193 WeakSessionList GetCurrentSessions() const; 277 WeakSessionList GetCurrentSessions() const;
194 278
195 // Close only the currently existing SpdySessions with |error|. Let 279 // Close only the currently existing SpdySessions with |error|. Let
196 // any new ones created while this method is running continue to 280 // any new ones created while this method is running continue to
197 // live. If |idle_only| is true only idle sessions are closed. 281 // live. If |idle_only| is true only idle sessions are closed.
198 void CloseCurrentSessionsHelper( 282 void CloseCurrentSessionsHelper(
199 Error error, 283 Error error,
200 const std::string& description, 284 const std::string& description,
201 bool idle_only); 285 bool idle_only);
202 286
203 HttpServerProperties* http_server_properties_; 287 HttpServerProperties* http_server_properties_;
204 288
205 TransportSecurityState* transport_security_state_; 289 TransportSecurityState* transport_security_state_;
206 290
207 // The set of all sessions. This is a superset of the sessions in 291 // The set of all sessions. This is a superset of the sessions in
208 // |available_sessions_|. 292 // |available_sessions_|.
209 // 293 //
210 // |sessions_| owns all its SpdySession objects. 294 // |sessions_| owns all its SpdySession objects.
211 SessionSet sessions_; 295 SessionSet sessions_;
212 296
213 // This is a map of available sessions by key. A session may appear 297 // This is a container of available sessions by key, with IP pooled and non IP
214 // more than once in this map if it has aliases. 298 // pooled sessions stored separately.
215 AvailableSessionMap available_sessions_; 299 AvailableSessionMap available_sessions_;
216 300
217 // A map of IPEndPoint aliases for sessions. 301 // A map of IPEndPoint aliases for sessions.
218 AliasMap aliases_; 302 AliasMap aliases_;
219 303
220 // A map of all SpdySessions owned by |this| that have an unclaimed pushed 304 // A map of all SpdySessions owned by |this| that have an unclaimed pushed
221 // streams for a GURL. Might contain invalid WeakPtr's. 305 // streams for a GURL. Might contain invalid WeakPtr's.
222 // A single SpdySession can only have at most one pushed stream for each GURL, 306 // A single SpdySession can only have at most one pushed stream for each GURL,
223 // but it is possible that multiple SpdySessions have pushed streams for the 307 // but it is possible that multiple SpdySessions have pushed streams for the
224 // same GURL. 308 // same GURL.
(...skipping 21 matching lines...) Expand all
246 // resources from origins that are different from those of their associated 330 // resources from origins that are different from those of their associated
247 // streams. May be nullptr. 331 // streams. May be nullptr.
248 ProxyDelegate* proxy_delegate_; 332 ProxyDelegate* proxy_delegate_;
249 333
250 DISALLOW_COPY_AND_ASSIGN(SpdySessionPool); 334 DISALLOW_COPY_AND_ASSIGN(SpdySessionPool);
251 }; 335 };
252 336
253 } // namespace net 337 } // namespace net
254 338
255 #endif // NET_SPDY_SPDY_SESSION_POOL_H_ 339 #endif // NET_SPDY_SPDY_SESSION_POOL_H_
OLDNEW
« no previous file with comments | « net/spdy/spdy_network_transaction_unittest.cc ('k') | net/spdy/spdy_session_pool.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698