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