summaryrefslogtreecommitdiffstats
path: root/net/http/http_network_layer.h
blob: bd3cb686e37fb4f6a6119a8d8796f4842b0cc3f1 (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
// Copyright (c) 2006-2008 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_LAYER_H_
#define NET_HTTP_HTTP_NETWORK_LAYER_H_

#include "base/ref_counted.h"
#include "base/scoped_ptr.h"
#include "net/http/http_transaction_factory.h"

namespace net {

class ClientSocketFactory;
class HostResolver;
class HttpNetworkSession;
class ProxyInfo;
class ProxyService;

class HttpNetworkLayer : public HttpTransactionFactory {
 public:
  // |socket_factory|, |proxy_service| and |host_resolver| must remain valid
  // for the lifetime of HttpNetworkLayer.
  HttpNetworkLayer(ClientSocketFactory* socket_factory,
                   HostResolver* host_resolver, ProxyService* proxy_service);
  // Construct a HttpNetworkLayer with an existing HttpNetworkSession which
  // contains a valid ProxyService.
  explicit HttpNetworkLayer(HttpNetworkSession* session);
  ~HttpNetworkLayer();

  // This function hides the details of how a network layer gets instantiated
  // and allows other implementations to be substituted.
  static HttpTransactionFactory* CreateFactory(HostResolver* host_resolver,
                                               ProxyService* proxy_service);
  // Create a transaction factory that instantiate a network layer over an
  // existing network session. Network session contains some valuable
  // information (e.g. authentication data) that we want to share across
  // multiple network layers. This method exposes the implementation details
  // of a network layer, use this method with an existing network layer only
  // when network session is shared.
  static HttpTransactionFactory* CreateFactory(HttpNetworkSession* session);

  // HttpTransactionFactory methods:
  virtual HttpTransaction* CreateTransaction();
  virtual HttpCache* GetCache();
  virtual void Suspend(bool suspend);

  HttpNetworkSession* GetSession();

 private:
  // The factory we will use to create network sockets.
  ClientSocketFactory* socket_factory_;

  // The host resolver and proxy service that will used when lazily
  // creating |session_|.
  scoped_refptr<HostResolver> host_resolver_;
  scoped_refptr<ProxyService> proxy_service_;

  scoped_refptr<HttpNetworkSession> session_;
  bool suspended_;
};

}  // namespace net

#endif  // NET_HTTP_HTTP_NETWORK_LAYER_H_