Home | History | Annotate | Download | only in http
      1 // Copyright (c) 2006-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_HTTP_HTTP_NETWORK_SESSION_H_
      6 #define NET_HTTP_HTTP_NETWORK_SESSION_H_
      7 
      8 #include "base/ref_counted.h"
      9 #include "net/base/host_resolver.h"
     10 #include "net/base/ssl_client_auth_cache.h"
     11 #include "net/base/ssl_config_service.h"
     12 #include "net/http/http_auth_cache.h"
     13 #include "net/proxy/proxy_service.h"
     14 #include "net/socket/tcp_client_socket_pool.h"
     15 
     16 namespace net {
     17 
     18 class ClientSocketFactory;
     19 class FlipSessionPool;
     20 class NetworkChangeNotifier;
     21 
     22 // This class holds session objects used by HttpNetworkTransaction objects.
     23 class HttpNetworkSession : public base::RefCounted<HttpNetworkSession> {
     24  public:
     25   HttpNetworkSession(
     26       NetworkChangeNotifier* network_change_notifier,
     27       HostResolver* host_resolver,
     28       ProxyService* proxy_service,
     29       ClientSocketFactory* client_socket_factory,
     30       SSLConfigService* ssl_config_service,
     31       FlipSessionPool* flip_session_pool);
     32 
     33   HttpAuthCache* auth_cache() { return &auth_cache_; }
     34   SSLClientAuthCache* ssl_client_auth_cache() {
     35     return &ssl_client_auth_cache_;
     36   }
     37 
     38   // TCP sockets come from the tcp_socket_pool().
     39   TCPClientSocketPool* tcp_socket_pool() { return tcp_socket_pool_; }
     40   // SSL sockets come frmo the socket_factory().
     41   ClientSocketFactory* socket_factory() { return socket_factory_; }
     42   HostResolver* host_resolver() { return host_resolver_; }
     43   ProxyService* proxy_service() { return proxy_service_; }
     44   SSLConfigService* ssl_config_service() { return ssl_config_service_; }
     45   const scoped_refptr<FlipSessionPool>& flip_session_pool() {
     46     return flip_session_pool_;
     47   }
     48 
     49   // Replace the current socket pool with a new one.  This effectively
     50   // abandons the current pool.  This is only used for debugging.
     51   void ReplaceTCPSocketPool();
     52 
     53   static void set_max_sockets_per_group(int socket_count);
     54 
     55   static uint16 fixed_http_port() { return g_fixed_http_port; }
     56   static void set_fixed_http_port(uint16 port) { g_fixed_http_port = port; }
     57 
     58   static uint16 fixed_https_port() { return g_fixed_https_port; }
     59   static void set_fixed_https_port(uint16 port) { g_fixed_https_port = port; }
     60 
     61  private:
     62   friend class base::RefCounted<HttpNetworkSession>;
     63   FRIEND_TEST(HttpNetworkTransactionTest, GroupNameForProxyConnections);
     64 
     65   ~HttpNetworkSession();
     66 
     67   // Total limit of sockets. Not a constant to allow experiments.
     68   static int max_sockets_;
     69 
     70   // Default to allow up to 6 connections per host. Experiment and tuning may
     71   // try other values (greater than 0).  Too large may cause many problems, such
     72   // as home routers blocking the connections!?!?
     73   static int max_sockets_per_group_;
     74 
     75   static uint16 g_fixed_http_port;
     76   static uint16 g_fixed_https_port;
     77 
     78   HttpAuthCache auth_cache_;
     79   SSLClientAuthCache ssl_client_auth_cache_;
     80   NetworkChangeNotifier* const network_change_notifier_;
     81   scoped_refptr<TCPClientSocketPool> tcp_socket_pool_;
     82   ClientSocketFactory* socket_factory_;
     83   scoped_refptr<HostResolver> host_resolver_;
     84   scoped_refptr<ProxyService> proxy_service_;
     85   scoped_refptr<SSLConfigService> ssl_config_service_;
     86   scoped_refptr<FlipSessionPool> flip_session_pool_;
     87 };
     88 
     89 }  // namespace net
     90 
     91 #endif  // NET_HTTP_HTTP_NETWORK_SESSION_H_
     92