[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 1 | // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 | // Use of this source code is governed by a BSD-style license that can be | ||||
3 | // found in the LICENSE file. | ||||
4 | |||||
5 | #ifndef NET_FLIP_FLIP_SESSION_POOL_H_ | ||||
6 | #define NET_FLIP_FLIP_SESSION_POOL_H_ | ||||
7 | |||||
8 | #include <map> | ||||
9 | #include <list> | ||||
10 | #include <string> | ||||
11 | |||||
12 | #include "base/ref_counted.h" | ||||
13 | #include "base/scoped_ptr.h" | ||||
14 | #include "net/base/host_resolver.h" | ||||
15 | |||||
16 | namespace net { | ||||
17 | |||||
[email protected] | d1eda93 | 2009-11-04 01:03:10 | [diff] [blame] | 18 | class ClientSocket; |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 19 | class FlipSession; |
20 | class HttpNetworkSession; | ||||
21 | |||||
22 | // This is a very simple pool for open FlipSessions. | ||||
23 | // TODO(mbelshe): Make this production ready. | ||||
[email protected] | d1eda93 | 2009-11-04 01:03:10 | [diff] [blame] | 24 | class FlipSessionPool : public base::RefCounted<FlipSessionPool> { |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 25 | public: |
[email protected] | d1eda93 | 2009-11-04 01:03:10 | [diff] [blame] | 26 | FlipSessionPool(); |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 27 | |
[email protected] | d1eda93 | 2009-11-04 01:03:10 | [diff] [blame] | 28 | // Either returns an existing FlipSession or creates a new FlipSession for |
29 | // use. | ||||
[email protected] | 9f7c4fd | 2009-11-24 18:50:15 | [diff] [blame^] | 30 | scoped_refptr<FlipSession> Get( |
31 | const HostResolver::RequestInfo& info, HttpNetworkSession* session); | ||||
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 32 | |
[email protected] | d1eda93 | 2009-11-04 01:03:10 | [diff] [blame] | 33 | // Builds a FlipSession from an existing socket. |
[email protected] | 9f7c4fd | 2009-11-24 18:50:15 | [diff] [blame^] | 34 | // TODO(willchan): Implement this to allow a HttpNetworkTransaction to |
35 | // upgrade a TCP connection from HTTP to FLIP. | ||||
36 | scoped_refptr<FlipSession> GetFlipSessionFromSocket( | ||||
[email protected] | d1eda93 | 2009-11-04 01:03:10 | [diff] [blame] | 37 | const HostResolver::RequestInfo& info, |
38 | HttpNetworkSession* session, | ||||
[email protected] | 9f7c4fd | 2009-11-24 18:50:15 | [diff] [blame^] | 39 | ClientSocket* socket); |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 40 | |
[email protected] | d1eda93 | 2009-11-04 01:03:10 | [diff] [blame] | 41 | // TODO(willchan): Consider renaming to HasReusableSession, since perhaps we |
42 | // should be creating a new session. | ||||
43 | bool HasSession(const HostResolver::RequestInfo& info) const; | ||||
44 | |||||
45 | // Close all Flip Sessions; used for debugging. | ||||
46 | void CloseAllSessions(); | ||||
47 | |||||
48 | private: | ||||
[email protected] | 5389bc7 | 2009-11-05 23:34:24 | [diff] [blame] | 49 | friend class base::RefCounted<FlipSessionPool>; |
[email protected] | d1eda93 | 2009-11-04 01:03:10 | [diff] [blame] | 50 | friend class FlipSession; // Needed for Remove(). |
[email protected] | 9f7c4fd | 2009-11-24 18:50:15 | [diff] [blame^] | 51 | friend class FlipSessionPoolPeer; // For testing. |
52 | |||||
53 | typedef std::list<scoped_refptr<FlipSession> > FlipSessionList; | ||||
54 | typedef std::map<std::string, FlipSessionList*> FlipSessionsMap; | ||||
[email protected] | d1eda93 | 2009-11-04 01:03:10 | [diff] [blame] | 55 | |
[email protected] | 5389bc7 | 2009-11-05 23:34:24 | [diff] [blame] | 56 | virtual ~FlipSessionPool(); |
57 | |||||
[email protected] | 9f7c4fd | 2009-11-24 18:50:15 | [diff] [blame^] | 58 | // Removes a FlipSession from the FlipSessionPool. |
59 | void Remove(const scoped_refptr<FlipSession>& session); | ||||
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 60 | |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 61 | // Helper functions for manipulating the lists. |
[email protected] | d1eda93 | 2009-11-04 01:03:10 | [diff] [blame] | 62 | FlipSessionList* AddSessionList(const std::string& domain); |
63 | FlipSessionList* GetSessionList(const std::string& domain); | ||||
64 | const FlipSessionList* GetSessionList(const std::string& domain) const; | ||||
65 | void RemoveSessionList(const std::string& domain); | ||||
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 66 | |
67 | // This is our weak session pool - one session per domain. | ||||
[email protected] | d1eda93 | 2009-11-04 01:03:10 | [diff] [blame] | 68 | FlipSessionsMap sessions_; |
69 | |||||
70 | DISALLOW_COPY_AND_ASSIGN(FlipSessionPool); | ||||
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 71 | }; |
72 | |||||
73 | } // namespace net | ||||
74 | |||||
75 | #endif // NET_FLIP_FLIP_SESSION_POOL_H_ |