blob: fc3be5c780ffb8378d013476cb8a74a7aa11be1f [file] [log] [blame]
[email protected]aea80602009-09-18 00:55:081// 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
16namespace net {
17
[email protected]d1eda932009-11-04 01:03:1018class ClientSocket;
[email protected]aea80602009-09-18 00:55:0819class FlipSession;
20class HttpNetworkSession;
21
22// This is a very simple pool for open FlipSessions.
23// TODO(mbelshe): Make this production ready.
[email protected]d1eda932009-11-04 01:03:1024class FlipSessionPool : public base::RefCounted<FlipSessionPool> {
[email protected]aea80602009-09-18 00:55:0825 public:
[email protected]d1eda932009-11-04 01:03:1026 FlipSessionPool();
[email protected]aea80602009-09-18 00:55:0827
[email protected]d1eda932009-11-04 01:03:1028 // Either returns an existing FlipSession or creates a new FlipSession for
29 // use.
[email protected]9f7c4fd2009-11-24 18:50:1530 scoped_refptr<FlipSession> Get(
31 const HostResolver::RequestInfo& info, HttpNetworkSession* session);
[email protected]aea80602009-09-18 00:55:0832
[email protected]d1eda932009-11-04 01:03:1033 // Builds a FlipSession from an existing socket.
[email protected]9f7c4fd2009-11-24 18:50:1534 // 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]d1eda932009-11-04 01:03:1037 const HostResolver::RequestInfo& info,
38 HttpNetworkSession* session,
[email protected]9f7c4fd2009-11-24 18:50:1539 ClientSocket* socket);
[email protected]aea80602009-09-18 00:55:0840
[email protected]d1eda932009-11-04 01:03:1041 // 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]5389bc72009-11-05 23:34:2449 friend class base::RefCounted<FlipSessionPool>;
[email protected]d1eda932009-11-04 01:03:1050 friend class FlipSession; // Needed for Remove().
[email protected]9f7c4fd2009-11-24 18:50:1551 friend class FlipSessionPoolPeer; // For testing.
52
53 typedef std::list<scoped_refptr<FlipSession> > FlipSessionList;
54 typedef std::map<std::string, FlipSessionList*> FlipSessionsMap;
[email protected]d1eda932009-11-04 01:03:1055
[email protected]5389bc72009-11-05 23:34:2456 virtual ~FlipSessionPool();
57
[email protected]9f7c4fd2009-11-24 18:50:1558 // Removes a FlipSession from the FlipSessionPool.
59 void Remove(const scoped_refptr<FlipSession>& session);
[email protected]aea80602009-09-18 00:55:0860
[email protected]aea80602009-09-18 00:55:0861 // Helper functions for manipulating the lists.
[email protected]d1eda932009-11-04 01:03:1062 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]aea80602009-09-18 00:55:0866
67 // This is our weak session pool - one session per domain.
[email protected]d1eda932009-11-04 01:03:1068 FlipSessionsMap sessions_;
69
70 DISALLOW_COPY_AND_ASSIGN(FlipSessionPool);
[email protected]aea80602009-09-18 00:55:0871};
72
73} // namespace net
74
75#endif // NET_FLIP_FLIP_SESSION_POOL_H_