OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 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_FLIP_FLIP_SESSION_POOL_H_ | 5 #ifndef NET_FLIP_FLIP_SESSION_POOL_H_ |
6 #define NET_FLIP_FLIP_SESSION_POOL_H_ | 6 #define NET_FLIP_FLIP_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/ref_counted.h" | 12 #include "base/ref_counted.h" |
13 #include "base/scoped_ptr.h" | 13 #include "base/scoped_ptr.h" |
14 #include "net/base/host_resolver.h" | 14 #include "net/base/host_resolver.h" |
15 | 15 |
16 namespace net { | 16 namespace net { |
17 | 17 |
| 18 class ClientSocket; |
18 class FlipSession; | 19 class FlipSession; |
19 class HttpNetworkSession; | 20 class HttpNetworkSession; |
20 | 21 |
21 // This is a very simple pool for open FlipSessions. | 22 // This is a very simple pool for open FlipSessions. |
22 // TODO(mbelshe): Make this production ready. | 23 // TODO(mbelshe): Make this production ready. |
23 class FlipSessionPool { | 24 class FlipSessionPool : public base::RefCounted<FlipSessionPool> { |
24 public: | 25 public: |
25 FlipSessionPool() {} | 26 FlipSessionPool(); |
26 virtual ~FlipSessionPool() {} | 27 virtual ~FlipSessionPool(); |
27 | 28 |
28 // Factory for finding open sessions. | 29 // Either returns an existing FlipSession or creates a new FlipSession for |
| 30 // use. |
29 FlipSession* Get(const HostResolver::RequestInfo& info, | 31 FlipSession* Get(const HostResolver::RequestInfo& info, |
30 HttpNetworkSession* session); | 32 HttpNetworkSession* session); |
31 | 33 |
| 34 // Builds a FlipSession from an existing socket. |
| 35 FlipSession* GetFlipSessionFromSocket( |
| 36 const HostResolver::RequestInfo& info, |
| 37 HttpNetworkSession* session, |
| 38 ClientSocket* socket) { |
| 39 // TODO(willchan): Implement this to allow a HttpNetworkTransaction to |
| 40 // upgrade a TCP connection from HTTP to FLIP. |
| 41 return NULL; |
| 42 } |
| 43 |
| 44 // TODO(willchan): Consider renaming to HasReusableSession, since perhaps we |
| 45 // should be creating a new session. |
| 46 bool HasSession(const HostResolver::RequestInfo& info) const; |
| 47 |
32 // Close all Flip Sessions; used for debugging. | 48 // Close all Flip Sessions; used for debugging. |
33 static void CloseAllSessions(); | 49 void CloseAllSessions(); |
34 | 50 |
35 protected: | 51 private: |
36 friend class FlipSession; | 52 friend class FlipSession; // Needed for Remove(). |
| 53 |
| 54 typedef std::list<FlipSession*> FlipSessionList; |
| 55 typedef std::map<std::string, FlipSessionList*> FlipSessionsMap; |
37 | 56 |
38 // Return a FlipSession to the pool. | 57 // Return a FlipSession to the pool. |
39 void Remove(FlipSession* session); | 58 void Remove(FlipSession* session); |
40 | 59 |
41 private: | |
42 typedef std::list<FlipSession*> FlipSessionList; | |
43 typedef std::map<std::string, FlipSessionList*> FlipSessionsMap; | |
44 | |
45 // Helper functions for manipulating the lists. | 60 // Helper functions for manipulating the lists. |
46 FlipSessionList* AddSessionList(std::string domain); | 61 FlipSessionList* AddSessionList(const std::string& domain); |
47 static FlipSessionList* GetSessionList(std::string domain); | 62 FlipSessionList* GetSessionList(const std::string& domain); |
48 static void RemoveSessionList(std::string domain); | 63 const FlipSessionList* GetSessionList(const std::string& domain) const; |
| 64 void RemoveSessionList(const std::string& domain); |
49 | 65 |
50 // This is our weak session pool - one session per domain. | 66 // This is our weak session pool - one session per domain. |
51 static scoped_ptr<FlipSessionsMap> sessions_; | 67 FlipSessionsMap sessions_; |
| 68 |
| 69 DISALLOW_COPY_AND_ASSIGN(FlipSessionPool); |
52 }; | 70 }; |
53 | 71 |
54 } // namespace net | 72 } // namespace net |
55 | 73 |
56 #endif // NET_FLIP_FLIP_SESSION_POOL_H_ | 74 #endif // NET_FLIP_FLIP_SESSION_POOL_H_ |
57 | |
OLD | NEW |