blob: 1c18438069c56154132d27d0d94ee60b994f7c06 [file] [log] [blame]
[email protected]66761b952010-06-25 21:30:381// Copyright (c) 2010 The Chromium Authors. All rights reserved.
[email protected]aea80602009-09-18 00:55:082// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]dab9c7d2010-02-06 21:44:325#ifndef NET_SPDY_SPDY_SESSION_POOL_H_
6#define NET_SPDY_SPDY_SESSION_POOL_H_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
[email protected]aea80602009-09-18 00:55:088
9#include <map>
10#include <list>
11#include <string>
12
[email protected]367ead42010-02-26 00:15:2113#include "base/basictypes.h"
[email protected]aea80602009-09-18 00:55:0814#include "base/ref_counted.h"
15#include "base/scoped_ptr.h"
[email protected]564b4912010-03-09 16:30:4216#include "net/base/host_port_pair.h"
[email protected]26ef6582010-06-24 02:30:4717#include "net/base/net_errors.h"
[email protected]b846acd2010-06-07 18:13:1018#include "net/base/network_change_notifier.h"
[email protected]5af3c572010-07-20 14:16:2719#include "testing/gtest/include/gtest/gtest_prod.h" // For FRIEND_TEST
[email protected]aea80602009-09-18 00:55:0820
21namespace net {
22
[email protected]b846acd2010-06-07 18:13:1023class BoundNetLog;
[email protected]1f14a912009-12-21 20:32:4424class ClientSocketHandle;
[email protected]aea80602009-09-18 00:55:0825class HttpNetworkSession;
[email protected]955fc2e72010-02-08 20:37:3026class SpdySession;
[email protected]aea80602009-09-18 00:55:0827
[email protected]955fc2e72010-02-08 20:37:3028// This is a very simple pool for open SpdySessions.
[email protected]aea80602009-09-18 00:55:0829// TODO(mbelshe): Make this production ready.
[email protected]b846acd2010-06-07 18:13:1030class SpdySessionPool
31 : public base::RefCounted<SpdySessionPool>,
32 public NetworkChangeNotifier::Observer {
[email protected]aea80602009-09-18 00:55:0833 public:
[email protected]66761b952010-06-25 21:30:3834 SpdySessionPool();
[email protected]aea80602009-09-18 00:55:0835
[email protected]955fc2e72010-02-08 20:37:3036 // Either returns an existing SpdySession or creates a new SpdySession for
[email protected]d1eda932009-11-04 01:03:1037 // use.
[email protected]955fc2e72010-02-08 20:37:3038 scoped_refptr<SpdySession> Get(
[email protected]635909f2010-05-12 18:19:3639 const HostPortPair& host_port_pair, HttpNetworkSession* session,
40 const BoundNetLog& net_log);
[email protected]aea80602009-09-18 00:55:0841
[email protected]4a5e1782010-03-05 20:49:0242 // Set the maximum concurrent sessions per domain.
43 static void set_max_sessions_per_domain(int max) {
44 if (max >= 1)
45 g_max_sessions_per_domain = max;
46 }
47
[email protected]5fe524e2010-02-20 00:43:2248 // Builds a SpdySession from an existing SSL socket. Users should try
49 // calling Get() first to use an existing SpdySession so we don't get
50 // multiple SpdySessions per domain. Note that ownership of |connection| is
[email protected]955fc2e72010-02-08 20:37:3051 // transferred from the caller to the SpdySession.
[email protected]bdbda462010-06-28 17:30:3752 // |certificate_error_code| is used to indicate the certificate error
53 // encountered when connecting the SSL socket. OK means there was no error.
[email protected]9e9e842e2010-07-23 23:09:1554 // For testing, setting is_secure to false allows Spdy to connect with a
55 // pre-existing TCP socket.
[email protected]26ef6582010-06-24 02:30:4756 // Returns OK on success, and the |spdy_session| will be provided.
57 // Returns an error on failure, and |spdy_session| will be NULL.
[email protected]9e9e842e2010-07-23 23:09:1558 net::Error GetSpdySessionFromSocket(
[email protected]367ead42010-02-26 00:15:2159 const HostPortPair& host_port_pair,
[email protected]d1eda932009-11-04 01:03:1060 HttpNetworkSession* session,
[email protected]635909f2010-05-12 18:19:3661 ClientSocketHandle* connection,
[email protected]26ef6582010-06-24 02:30:4762 const BoundNetLog& net_log,
[email protected]bdbda462010-06-28 17:30:3763 int certificate_error_code,
[email protected]9e9e842e2010-07-23 23:09:1564 scoped_refptr<SpdySession>* spdy_session,
65 bool is_secure);
[email protected]aea80602009-09-18 00:55:0866
[email protected]d1eda932009-11-04 01:03:1067 // TODO(willchan): Consider renaming to HasReusableSession, since perhaps we
68 // should be creating a new session.
[email protected]367ead42010-02-26 00:15:2169 bool HasSession(const HostPortPair& host_port_pair)const;
[email protected]d1eda932009-11-04 01:03:1070
[email protected]955fc2e72010-02-08 20:37:3071 // Close all Spdy Sessions; used for debugging.
[email protected]b278eb72010-07-09 20:17:0072 void CloseAllSessions();
[email protected]d1eda932009-11-04 01:03:1073
[email protected]6c6ea172010-07-27 20:04:0374 // Removes a SpdySession from the SpdySessionPool. This should only be called
75 // by SpdySession, because otherwise session->state_ is not set to CLOSED.
[email protected]807c01a2010-04-21 16:57:4576 void Remove(const scoped_refptr<SpdySession>& session);
77
[email protected]b846acd2010-06-07 18:13:1078 // NetworkChangeNotifier::Observer methods:
79
80 // We flush all idle sessions and release references to the active ones so
81 // they won't get re-used. The active ones will either complete successfully
82 // or error out due to the IP address change.
[email protected]66761b952010-06-25 21:30:3883 virtual void OnIPAddressChanged();
[email protected]b846acd2010-06-07 18:13:1084
[email protected]d1eda932009-11-04 01:03:1085 private:
[email protected]955fc2e72010-02-08 20:37:3086 friend class base::RefCounted<SpdySessionPool>;
[email protected]955fc2e72010-02-08 20:37:3087 friend class SpdySessionPoolPeer; // For testing.
[email protected]cb54b3b22010-06-03 16:28:5588 friend class SpdyNetworkTransactionTest; // For testing.
[email protected]5af3c572010-07-20 14:16:2789 FRIEND_TEST(SpdyNetworkTransactionTest, WindowUpdateOverflow);
[email protected]9f7c4fd2009-11-24 18:50:1590
[email protected]955fc2e72010-02-08 20:37:3091 typedef std::list<scoped_refptr<SpdySession> > SpdySessionList;
[email protected]367ead42010-02-26 00:15:2192 typedef std::map<HostPortPair, SpdySessionList*> SpdySessionsMap;
[email protected]d1eda932009-11-04 01:03:1093
[email protected]955fc2e72010-02-08 20:37:3094 virtual ~SpdySessionPool();
[email protected]5389bc72009-11-05 23:34:2495
[email protected]aea80602009-09-18 00:55:0896 // Helper functions for manipulating the lists.
[email protected]367ead42010-02-26 00:15:2197 SpdySessionList* AddSessionList(const HostPortPair& host_port_pair);
98 SpdySessionList* GetSessionList(const HostPortPair& host_port_pair);
99 const SpdySessionList* GetSessionList(
100 const HostPortPair& host_port_pair) const;
101 void RemoveSessionList(const HostPortPair& host_port_pair);
[email protected]b846acd2010-06-07 18:13:10102 // Releases the SpdySessionPool reference to all sessions. Will result in all
103 // idle sessions being deleted, and the active sessions from being reused, so
104 // they will be deleted once all active streams belonging to that session go
105 // away.
[email protected]b278eb72010-07-09 20:17:00106 void ClearSessions();
[email protected]aea80602009-09-18 00:55:08107
108 // This is our weak session pool - one session per domain.
[email protected]955fc2e72010-02-08 20:37:30109 SpdySessionsMap sessions_;
[email protected]d1eda932009-11-04 01:03:10110
[email protected]4a5e1782010-03-05 20:49:02111 static int g_max_sessions_per_domain;
112
[email protected]955fc2e72010-02-08 20:37:30113 DISALLOW_COPY_AND_ASSIGN(SpdySessionPool);
[email protected]aea80602009-09-18 00:55:08114};
115
116} // namespace net
117
[email protected]dab9c7d2010-02-06 21:44:32118#endif // NET_SPDY_SPDY_SESSION_POOL_H_