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

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: 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
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(enable_ip_based_pooling = false) call
Ryan Hamilton 2017/03/14 22:20:20 nit: I'd just remove "enable... = " from this, or
Bence 2017/03/15 10:05:26 Done.
81 // would return true (or just returned true).
Ryan Hamilton 2017/03/14 22:20:20 nit: I'd remove the "(or just returned true)" clau
Bence 2017/03/15 10:05:26 Done.
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 template <class T, class U>
Ryan Hamilton 2017/03/14 22:20:20 I'm sure it's obvious, but why does this need to b
Bence 2017/03/15 10:05:27 Good question. It totally wasn't obvious to me, a
195 class Iterator {
196 public:
197 Iterator();
198 Iterator(const Iterator& other);
199 void operator=(const Iterator& other);
200 ~Iterator();
201
202 bool operator==(const Iterator& other) const;
203 bool operator!=(const Iterator& other) const;
204 T& operator->();
205 Iterator& operator++();
206
207 private:
208 friend SpdySessionPool::AvailableSessionMap;
Bence 2017/03/15 10:05:26 I still need this friend to allow AvailableSession
209
210 Iterator(T iterator, bool ip_pooled, U* session_map);
211
212 T iterator_;
213 bool ip_pooled_;
214 U* session_map_;
215 };
216
217 AvailableSessionMap();
218 AvailableSessionMap(const AvailableSessionMap&) = delete;
219 void operator=(const AvailableSessionMap&) = delete;
220 ~AvailableSessionMap();
221
222 const_iterator begin() const;
223 const_iterator end() const;
224 iterator begin();
225 iterator end();
226 bool empty() const;
227
228 // If both IP pooled and non IP pooled entries exist,
229 // then return the non IP pooled one.
230 iterator find(const key_type& key);
231
232 // |value| must not be in the map (this is unlike std::map::insert).
233 void insert(const value_type& value, bool ip_pooled);
234
235 // |key| must exist (this is unlike std::map::erase).
236 void erase(const key_type& key, bool ip_pooled);
237
238 private:
239 friend iterator;
240 friend const_iterator;
241
242 MapType non_ip_pooled_sessions_;
243 MapType ip_pooled_sessions_;
244 };
245
165 typedef std::set<SpdySession*> SessionSet; 246 typedef std::set<SpdySession*> SessionSet;
166 typedef std::vector<base::WeakPtr<SpdySession> > WeakSessionList; 247 typedef std::vector<base::WeakPtr<SpdySession> > WeakSessionList;
167 typedef std::map<SpdySessionKey, base::WeakPtr<SpdySession> >
168 AvailableSessionMap;
169 typedef std::map<IPEndPoint, SpdySessionKey> AliasMap; 248 typedef std::map<IPEndPoint, SpdySessionKey> AliasMap;
170 typedef std::map<GURL, WeakSessionList> UnclaimedPushedStreamMap; 249 typedef std::map<GURL, WeakSessionList> UnclaimedPushedStreamMap;
171 250
172 // Returns true iff |session| is in |available_sessions_|. 251 // Returns true iff |session| is in |available_sessions_|.
173 bool IsSessionAvailable(const base::WeakPtr<SpdySession>& session) const; 252 bool IsSessionAvailable(const base::WeakPtr<SpdySession>& session) const;
174 253
175 // Map the given key to the given session. There must not already be 254 // Map the given key to the given session. There must not already be
176 // a mapping for |key|. 255 // a mapping for |key| in the bucket defined by |ip_pooled|.
177 void MapKeyToAvailableSession(const SpdySessionKey& key, 256 void MapKeyToAvailableSession(const SpdySessionKey& key,
178 const base::WeakPtr<SpdySession>& session); 257 const base::WeakPtr<SpdySession>& session,
258 bool ip_pooled);
179 259
180 // Returns an iterator into |available_sessions_| for the given key,
181 // which may be equal to |available_sessions_.end()|.
182 AvailableSessionMap::iterator LookupAvailableSessionByKey( 260 AvailableSessionMap::iterator LookupAvailableSessionByKey(
183 const SpdySessionKey& key); 261 const SpdySessionKey& key);
184 262
185 // Remove the mapping of the given key, which must exist. 263 // Remove the mapping of |key| from the bucket defined by |ip_pooled|,
186 void UnmapKey(const SpdySessionKey& key); 264 // which must exist.
265 void UnmapKey(const SpdySessionKey& key, bool ip_pooled);
187 266
188 // Remove all aliases for |key| from the aliases table. 267 // Remove all aliases for |key| from the aliases table.
189 void RemoveAliases(const SpdySessionKey& key); 268 void RemoveAliases(const SpdySessionKey& key);
190 269
191 // Get a copy of the current sessions as a list of WeakPtrs. Used by 270 // Get a copy of the current sessions as a list of WeakPtrs. Used by
192 // CloseCurrentSessionsHelper() below. 271 // CloseCurrentSessionsHelper() below.
193 WeakSessionList GetCurrentSessions() const; 272 WeakSessionList GetCurrentSessions() const;
194 273
195 // Close only the currently existing SpdySessions with |error|. Let 274 // Close only the currently existing SpdySessions with |error|. Let
196 // any new ones created while this method is running continue to 275 // any new ones created while this method is running continue to
197 // live. If |idle_only| is true only idle sessions are closed. 276 // live. If |idle_only| is true only idle sessions are closed.
198 void CloseCurrentSessionsHelper( 277 void CloseCurrentSessionsHelper(
199 Error error, 278 Error error,
200 const std::string& description, 279 const std::string& description,
201 bool idle_only); 280 bool idle_only);
202 281
203 HttpServerProperties* http_server_properties_; 282 HttpServerProperties* http_server_properties_;
204 283
205 TransportSecurityState* transport_security_state_; 284 TransportSecurityState* transport_security_state_;
206 285
207 // The set of all sessions. This is a superset of the sessions in 286 // The set of all sessions. This is a superset of the sessions in
208 // |available_sessions_|. 287 // |available_sessions_|.
209 // 288 //
210 // |sessions_| owns all its SpdySession objects. 289 // |sessions_| owns all its SpdySession objects.
211 SessionSet sessions_; 290 SessionSet sessions_;
212 291
213 // This is a map of available sessions by key. A session may appear 292 // 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. 293 // pooled sessions stored separately.
215 AvailableSessionMap available_sessions_; 294 AvailableSessionMap available_sessions_;
216 295
217 // A map of IPEndPoint aliases for sessions. 296 // A map of IPEndPoint aliases for sessions.
218 AliasMap aliases_; 297 AliasMap aliases_;
219 298
220 // A map of all SpdySessions owned by |this| that have an unclaimed pushed 299 // A map of all SpdySessions owned by |this| that have an unclaimed pushed
221 // streams for a GURL. Might contain invalid WeakPtr's. 300 // streams for a GURL. Might contain invalid WeakPtr's.
222 // A single SpdySession can only have at most one pushed stream for each GURL, 301 // 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 302 // but it is possible that multiple SpdySessions have pushed streams for the
224 // same GURL. 303 // same GURL.
(...skipping 21 matching lines...) Expand all
246 // resources from origins that are different from those of their associated 325 // resources from origins that are different from those of their associated
247 // streams. May be nullptr. 326 // streams. May be nullptr.
248 ProxyDelegate* proxy_delegate_; 327 ProxyDelegate* proxy_delegate_;
249 328
250 DISALLOW_COPY_AND_ASSIGN(SpdySessionPool); 329 DISALLOW_COPY_AND_ASSIGN(SpdySessionPool);
251 }; 330 };
252 331
253 } // namespace net 332 } // namespace net
254 333
255 #endif // NET_SPDY_SPDY_SESSION_POOL_H_ 334 #endif // NET_SPDY_SPDY_SESSION_POOL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698