OLD | NEW |
1 // Copyright (c) 2009 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 #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 <map> | 8 #include <map> |
9 #include <list> | 9 #include <list> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/ref_counted.h" | 13 #include "base/ref_counted.h" |
14 #include "base/scoped_ptr.h" | 14 #include "base/scoped_ptr.h" |
15 #include "net/base/host_port_pair.h" | 15 #include "net/base/host_port_pair.h" |
16 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
17 #include "net/base/network_change_notifier.h" | 17 #include "net/base/network_change_notifier.h" |
18 | 18 |
19 namespace net { | 19 namespace net { |
20 | 20 |
21 class BoundNetLog; | 21 class BoundNetLog; |
22 class ClientSocketHandle; | 22 class ClientSocketHandle; |
23 class HttpNetworkSession; | 23 class HttpNetworkSession; |
24 class NetworkChangeNotifier; | |
25 class SpdySession; | 24 class SpdySession; |
26 | 25 |
27 // This is a very simple pool for open SpdySessions. | 26 // This is a very simple pool for open SpdySessions. |
28 // TODO(mbelshe): Make this production ready. | 27 // TODO(mbelshe): Make this production ready. |
29 class SpdySessionPool | 28 class SpdySessionPool |
30 : public base::RefCounted<SpdySessionPool>, | 29 : public base::RefCounted<SpdySessionPool>, |
31 public NetworkChangeNotifier::Observer { | 30 public NetworkChangeNotifier::Observer { |
32 public: | 31 public: |
33 explicit SpdySessionPool(NetworkChangeNotifier* notifier); | 32 SpdySessionPool(); |
34 | 33 |
35 // Either returns an existing SpdySession or creates a new SpdySession for | 34 // Either returns an existing SpdySession or creates a new SpdySession for |
36 // use. | 35 // use. |
37 scoped_refptr<SpdySession> Get( | 36 scoped_refptr<SpdySession> Get( |
38 const HostPortPair& host_port_pair, HttpNetworkSession* session, | 37 const HostPortPair& host_port_pair, HttpNetworkSession* session, |
39 const BoundNetLog& net_log); | 38 const BoundNetLog& net_log); |
40 | 39 |
41 // Set the maximum concurrent sessions per domain. | 40 // Set the maximum concurrent sessions per domain. |
42 static void set_max_sessions_per_domain(int max) { | 41 static void set_max_sessions_per_domain(int max) { |
43 if (max >= 1) | 42 if (max >= 1) |
(...skipping 21 matching lines...) Expand all Loading... |
65 void CloseAllSessions() { RemoveAllSessions(true); } | 64 void CloseAllSessions() { RemoveAllSessions(true); } |
66 | 65 |
67 // Removes a SpdySession from the SpdySessionPool. | 66 // Removes a SpdySession from the SpdySessionPool. |
68 void Remove(const scoped_refptr<SpdySession>& session); | 67 void Remove(const scoped_refptr<SpdySession>& session); |
69 | 68 |
70 // NetworkChangeNotifier::Observer methods: | 69 // NetworkChangeNotifier::Observer methods: |
71 | 70 |
72 // We flush all idle sessions and release references to the active ones so | 71 // We flush all idle sessions and release references to the active ones so |
73 // they won't get re-used. The active ones will either complete successfully | 72 // they won't get re-used. The active ones will either complete successfully |
74 // or error out due to the IP address change. | 73 // or error out due to the IP address change. |
75 virtual void OnIPAddressChanged() { ClearSessions(); } | 74 virtual void OnIPAddressChanged(); |
76 | 75 |
77 private: | 76 private: |
78 friend class base::RefCounted<SpdySessionPool>; | 77 friend class base::RefCounted<SpdySessionPool>; |
79 friend class SpdySessionPoolPeer; // For testing. | 78 friend class SpdySessionPoolPeer; // For testing. |
80 friend class SpdyNetworkTransactionTest; // For testing. | 79 friend class SpdyNetworkTransactionTest; // For testing. |
81 | 80 |
82 typedef std::list<scoped_refptr<SpdySession> > SpdySessionList; | 81 typedef std::list<scoped_refptr<SpdySession> > SpdySessionList; |
83 typedef std::map<HostPortPair, SpdySessionList*> SpdySessionsMap; | 82 typedef std::map<HostPortPair, SpdySessionList*> SpdySessionsMap; |
84 | 83 |
85 virtual ~SpdySessionPool(); | 84 virtual ~SpdySessionPool(); |
86 | 85 |
87 // Helper functions for manipulating the lists. | 86 // Helper functions for manipulating the lists. |
88 SpdySessionList* AddSessionList(const HostPortPair& host_port_pair); | 87 SpdySessionList* AddSessionList(const HostPortPair& host_port_pair); |
89 SpdySessionList* GetSessionList(const HostPortPair& host_port_pair); | 88 SpdySessionList* GetSessionList(const HostPortPair& host_port_pair); |
90 const SpdySessionList* GetSessionList( | 89 const SpdySessionList* GetSessionList( |
91 const HostPortPair& host_port_pair) const; | 90 const HostPortPair& host_port_pair) const; |
92 void RemoveSessionList(const HostPortPair& host_port_pair); | 91 void RemoveSessionList(const HostPortPair& host_port_pair); |
93 // Releases the SpdySessionPool reference to all sessions. Will result in all | 92 // Releases the SpdySessionPool reference to all sessions. Will result in all |
94 // idle sessions being deleted, and the active sessions from being reused, so | 93 // idle sessions being deleted, and the active sessions from being reused, so |
95 // they will be deleted once all active streams belonging to that session go | 94 // they will be deleted once all active streams belonging to that session go |
96 // away. | 95 // away. |
97 void ClearSessions() { RemoveAllSessions(false); } | 96 void ClearSessions() { RemoveAllSessions(false); } |
98 void RemoveAllSessions(bool close); | 97 void RemoveAllSessions(bool close); |
99 | 98 |
100 // This is our weak session pool - one session per domain. | 99 // This is our weak session pool - one session per domain. |
101 SpdySessionsMap sessions_; | 100 SpdySessionsMap sessions_; |
102 | 101 |
103 NetworkChangeNotifier* const network_change_notifier_; | |
104 | |
105 static int g_max_sessions_per_domain; | 102 static int g_max_sessions_per_domain; |
106 | 103 |
107 DISALLOW_COPY_AND_ASSIGN(SpdySessionPool); | 104 DISALLOW_COPY_AND_ASSIGN(SpdySessionPool); |
108 }; | 105 }; |
109 | 106 |
110 } // namespace net | 107 } // namespace net |
111 | 108 |
112 #endif // NET_SPDY_SPDY_SESSION_POOL_H_ | 109 #endif // NET_SPDY_SPDY_SESSION_POOL_H_ |
OLD | NEW |