blob: 6c3829e1be41744fc8dad572b290f7effc284aba [file] [log] [blame]
license.botbf09a502008-08-24 00:55:551// 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.
initial.commit586acc5fe2008-07-26 22:42:524
5#include "net/http/http_network_layer.h"
6
[email protected]0dfc81b2008-08-25 03:44:407#include "base/logging.h"
initial.commit586acc5fe2008-07-26 22:42:528#include "net/http/http_network_session.h"
9#include "net/http/http_network_transaction.h"
[email protected]f7984fc62009-06-22 23:26:4410#include "net/socket/client_socket_factory.h"
initial.commit586acc5fe2008-07-26 22:42:5211
12namespace net {
13
14//-----------------------------------------------------------------------------
15
initial.commit586acc5fe2008-07-26 22:42:5216// static
17HttpTransactionFactory* HttpNetworkLayer::CreateFactory(
[email protected]8a00f00a2009-06-12 00:49:3818 HostResolver* host_resolver,
[email protected]63de95b2008-12-10 04:11:2719 ProxyService* proxy_service) {
20 DCHECK(proxy_service);
initial.commit586acc5fe2008-07-26 22:42:5221
[email protected]c6894572009-06-16 17:10:1022 return new HttpNetworkLayer(ClientSocketFactory::GetDefaultFactory(),
23 host_resolver, proxy_service);
initial.commit586acc5fe2008-07-26 22:42:5224}
25
[email protected]e7f29642009-03-02 22:53:1826// static
27HttpTransactionFactory* HttpNetworkLayer::CreateFactory(
28 HttpNetworkSession* session) {
29 DCHECK(session);
30
31 return new HttpNetworkLayer(session);
32}
33
initial.commit586acc5fe2008-07-26 22:42:5234//-----------------------------------------------------------------------------
35
[email protected]c6894572009-06-16 17:10:1036HttpNetworkLayer::HttpNetworkLayer(ClientSocketFactory* socket_factory,
37 HostResolver* host_resolver,
[email protected]8a00f00a2009-06-12 00:49:3838 ProxyService* proxy_service)
[email protected]c6894572009-06-16 17:10:1039 : socket_factory_(socket_factory),
40 host_resolver_(host_resolver),
[email protected]8a00f00a2009-06-12 00:49:3841 proxy_service_(proxy_service),
42 session_(NULL),
43 suspended_(false) {
[email protected]63de95b2008-12-10 04:11:2744 DCHECK(proxy_service_);
initial.commit586acc5fe2008-07-26 22:42:5245}
46
[email protected]e7f29642009-03-02 22:53:1847HttpNetworkLayer::HttpNetworkLayer(HttpNetworkSession* session)
[email protected]c6894572009-06-16 17:10:1048 : socket_factory_(ClientSocketFactory::GetDefaultFactory()),
49 host_resolver_(NULL),
50 proxy_service_(NULL),
51 session_(session),
52 suspended_(false) {
[email protected]e7f29642009-03-02 22:53:1853 DCHECK(session_.get());
54}
55
initial.commit586acc5fe2008-07-26 22:42:5256HttpNetworkLayer::~HttpNetworkLayer() {
57}
58
59HttpTransaction* HttpNetworkLayer::CreateTransaction() {
60 if (suspended_)
61 return NULL;
62
[email protected]c6894572009-06-16 17:10:1063 return new HttpNetworkTransaction(GetSession(), socket_factory_);
initial.commit586acc5fe2008-07-26 22:42:5264}
65
66HttpCache* HttpNetworkLayer::GetCache() {
67 return NULL;
68}
69
initial.commit586acc5fe2008-07-26 22:42:5270void HttpNetworkLayer::Suspend(bool suspend) {
71 suspended_ = suspend;
72
[email protected]a3b006eea2008-10-22 21:23:0873 if (suspend && session_)
[email protected]e1e06262008-08-06 23:57:0774 session_->connection_pool()->CloseIdleSockets();
initial.commit586acc5fe2008-07-26 22:42:5275}
76
[email protected]e7f29642009-03-02 22:53:1877HttpNetworkSession* HttpNetworkLayer::GetSession() {
78 if (!session_) {
79 DCHECK(proxy_service_);
[email protected]8a00f00a2009-06-12 00:49:3880 session_ = new HttpNetworkSession(host_resolver_, proxy_service_,
[email protected]c6894572009-06-16 17:10:1081 socket_factory_);
[email protected]e7f29642009-03-02 22:53:1882 }
83 return session_;
84}
85
initial.commit586acc5fe2008-07-26 22:42:5286} // namespace net