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