http_network_layer.h revision c407dc5cd9bdc5668497f21b26b09d988ab439de
1// Copyright (c) 2010 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_LAYER_H_
6#define NET_HTTP_HTTP_NETWORK_LAYER_H_
7
8#include <string>
9
10#include "base/non_thread_safe.h"
11#include "base/ref_counted.h"
12#include "base/scoped_ptr.h"
13#include "net/http/http_transaction_factory.h"
14
15namespace net {
16
17class ClientSocketFactory;
18class HostResolver;
19class HttpAuthHandlerFactory;
20class HttpNetworkDelegate;
21class HttpNetworkSession;
22class NetLog;
23class ProxyInfo;
24class ProxyService;
25class SpdySessionPool;
26class SSLConfigService;
27
28class HttpNetworkLayer : public HttpTransactionFactory, public NonThreadSafe {
29 public:
30  // |socket_factory|, |proxy_service| and |host_resolver| must remain valid for
31  // the lifetime of HttpNetworkLayer.
32  HttpNetworkLayer(ClientSocketFactory* socket_factory,
33                   HostResolver* host_resolver,
34                   ProxyService* proxy_service,
35                   SSLConfigService* ssl_config_service,
36                   HttpAuthHandlerFactory* http_auth_handler_factory,
37                   HttpNetworkDelegate* network_delegate,
38                   NetLog* net_log);
39  // Construct a HttpNetworkLayer with an existing HttpNetworkSession which
40  // contains a valid ProxyService.
41  explicit HttpNetworkLayer(HttpNetworkSession* session);
42  ~HttpNetworkLayer();
43
44  // This function hides the details of how a network layer gets instantiated
45  // and allows other implementations to be substituted.
46  static HttpTransactionFactory* CreateFactory(
47      HostResolver* host_resolver,
48      ProxyService* proxy_service,
49      SSLConfigService* ssl_config_service,
50      HttpAuthHandlerFactory* http_auth_handler_factory,
51      HttpNetworkDelegate* network_delegate,
52      NetLog* net_log);
53  // Create a transaction factory that instantiate a network layer over an
54  // existing network session. Network session contains some valuable
55  // information (e.g. authentication data) that we want to share across
56  // multiple network layers. This method exposes the implementation details
57  // of a network layer, use this method with an existing network layer only
58  // when network session is shared.
59  static HttpTransactionFactory* CreateFactory(HttpNetworkSession* session);
60
61  // HttpTransactionFactory methods:
62  virtual int CreateTransaction(scoped_ptr<HttpTransaction>* trans);
63  virtual HttpCache* GetCache();
64  virtual HttpNetworkSession* GetSession();
65  virtual void Suspend(bool suspend);
66
67  // Enable the spdy protocol.
68  // Without calling this function, SPDY is disabled.  The mode can be:
69  //   ""            : (default) SSL and compression are enabled.
70  //   "no-ssl"      : disables SSL.
71  //   "no-compress" : disables compression.
72  //   "none"        : disables both SSL and compression.
73  static void EnableSpdy(const std::string& mode);
74
75 private:
76  // The factory we will use to create network sockets.
77  ClientSocketFactory* socket_factory_;
78
79  // The host resolver and proxy service that will be used when lazily
80  // creating |session_|.
81  scoped_refptr<HostResolver> host_resolver_;
82  scoped_refptr<ProxyService> proxy_service_;
83
84  // The SSL config service being used for the session.
85  scoped_refptr<SSLConfigService> ssl_config_service_;
86
87  scoped_refptr<HttpNetworkSession> session_;
88  scoped_refptr<SpdySessionPool> spdy_session_pool_;
89
90  HttpAuthHandlerFactory* http_auth_handler_factory_;
91  HttpNetworkDelegate* network_delegate_;
92  NetLog* net_log_;
93
94  bool suspended_;
95  static bool force_spdy_;
96};
97
98}  // namespace net
99
100#endif  // NET_HTTP_HTTP_NETWORK_LAYER_H_
101