summaryrefslogtreecommitdiffstats
path: root/net/http/http_network_session.h
blob: a6e10b11262b6468809c8f73c73020e7c806f1d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef NET_HTTP_HTTP_NETWORK_SESSION_H_
#define NET_HTTP_HTTP_NETWORK_SESSION_H_

#include <map>
#include "base/ref_counted.h"
#include "base/scoped_ptr.h"
#include "net/base/host_port_pair.h"
#include "net/base/host_resolver.h"
#include "net/base/ssl_client_auth_cache.h"
#include "net/base/ssl_config_service.h"
#include "net/http/http_alternate_protocols.h"
#include "net/http/http_auth_cache.h"
#include "net/proxy/proxy_service.h"
#include "net/socket/client_socket_pool_histograms.h"
#include "net/socket/socks_client_socket_pool.h"
#include "net/socket/tcp_client_socket_pool.h"
#include "net/spdy/spdy_settings_storage.h"

namespace net {

class ClientSocketFactory;
class HttpAuthHandlerFactory;
class HttpNetworkSessionPeer;
class NetworkChangeNotifier;
class SpdySessionPool;

// This class holds session objects used by HttpNetworkTransaction objects.
class HttpNetworkSession : public base::RefCounted<HttpNetworkSession> {
 public:
  HttpNetworkSession(
      NetworkChangeNotifier* network_change_notifier,
      HostResolver* host_resolver,
      ProxyService* proxy_service,
      ClientSocketFactory* client_socket_factory,
      SSLConfigService* ssl_config_service,
      SpdySessionPool* spdy_session_pool,
      HttpAuthHandlerFactory* http_auth_handler_factory,
      NetLog* net_log);

  HttpAuthCache* auth_cache() { return &auth_cache_; }
  SSLClientAuthCache* ssl_client_auth_cache() {
    return &ssl_client_auth_cache_;
  }

  const HttpAlternateProtocols& alternate_protocols() const {
    return alternate_protocols_;
  }
  HttpAlternateProtocols* mutable_alternate_protocols() {
    return &alternate_protocols_;
  }

  // Access to the SpdySettingsStorage
  const SpdySettingsStorage& spdy_settings() const {
    return spdy_settings_;
  }
  SpdySettingsStorage* mutable_spdy_settings() {
    return &spdy_settings_;
  }

  // TCP sockets come from the tcp_socket_pool().
  const scoped_refptr<TCPClientSocketPool>& tcp_socket_pool() {
    return tcp_socket_pool_;
  }

  const scoped_refptr<SOCKSClientSocketPool>& GetSocketPoolForSOCKSProxy(
      const HostPortPair& socks_proxy);

  const scoped_refptr<TCPClientSocketPool>& GetSocketPoolForHTTPProxy(
      const HostPortPair& http_proxy);

  // SSL sockets come from the socket_factory().
  ClientSocketFactory* socket_factory() { return socket_factory_; }
  HostResolver* host_resolver() { return host_resolver_; }
  ProxyService* proxy_service() { return proxy_service_; }
  SSLConfigService* ssl_config_service() { return ssl_config_service_; }
  const scoped_refptr<SpdySessionPool>& spdy_session_pool() {
    return spdy_session_pool_;
  }
  HttpAuthHandlerFactory* http_auth_handler_factory() {
    return http_auth_handler_factory_;
  }

  static void set_max_sockets_per_group(int socket_count);

  static uint16 fixed_http_port();
  static void set_fixed_http_port(uint16 port);

  static uint16 fixed_https_port();
  static void set_fixed_https_port(uint16 port);

 private:
  typedef std::map<HostPortPair, scoped_refptr<TCPClientSocketPool> >
      HTTPProxySocketPoolMap;
  typedef std::map<HostPortPair, scoped_refptr<SOCKSClientSocketPool> >
      SOCKSSocketPoolMap;

  friend class base::RefCounted<HttpNetworkSession>;
  friend class HttpNetworkSessionPeer;

  ~HttpNetworkSession();

  HttpAuthCache auth_cache_;
  SSLClientAuthCache ssl_client_auth_cache_;
  HttpAlternateProtocols alternate_protocols_;
  NetworkChangeNotifier* const network_change_notifier_;
  scoped_refptr<ClientSocketPoolHistograms> tcp_pool_histograms_;
  scoped_refptr<ClientSocketPoolHistograms> http_proxy_pool_histograms_;
  scoped_refptr<ClientSocketPoolHistograms> tcp_for_socks_pool_histograms_;
  scoped_refptr<ClientSocketPoolHistograms> socks_pool_histograms_;
  scoped_refptr<TCPClientSocketPool> tcp_socket_pool_;
  HTTPProxySocketPoolMap http_proxy_socket_pool_;
  SOCKSSocketPoolMap socks_socket_pool_;
  ClientSocketFactory* socket_factory_;
  scoped_refptr<HostResolver> host_resolver_;
  scoped_refptr<ProxyService> proxy_service_;
  scoped_refptr<SSLConfigService> ssl_config_service_;
  scoped_refptr<SpdySessionPool> spdy_session_pool_;
  HttpAuthHandlerFactory* http_auth_handler_factory_;
  NetLog* net_log_;
  SpdySettingsStorage spdy_settings_;
};

}  // namespace net

#endif  // NET_HTTP_HTTP_NETWORK_SESSION_H_