license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 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. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 4 | |
| 5 | #include "net/http/http_network_layer.h" |
| 6 | |
[email protected] | 0dfc81b | 2008-08-25 03:44:40 | [diff] [blame] | 7 | #include "base/logging.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 8 | #include "net/http/http_network_session.h" |
| 9 | #include "net/http/http_network_transaction.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame^] | 10 | #include "net/socket/client_socket_factory.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 11 | |
| 12 | namespace net { |
| 13 | |
| 14 | //----------------------------------------------------------------------------- |
| 15 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 16 | // static |
| 17 | HttpTransactionFactory* HttpNetworkLayer::CreateFactory( |
[email protected] | 8a00f00a | 2009-06-12 00:49:38 | [diff] [blame] | 18 | HostResolver* host_resolver, |
[email protected] | 63de95b | 2008-12-10 04:11:27 | [diff] [blame] | 19 | ProxyService* proxy_service) { |
| 20 | DCHECK(proxy_service); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 21 | |
[email protected] | c689457 | 2009-06-16 17:10:10 | [diff] [blame] | 22 | return new HttpNetworkLayer(ClientSocketFactory::GetDefaultFactory(), |
| 23 | host_resolver, proxy_service); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 24 | } |
| 25 | |
[email protected] | e7f2964 | 2009-03-02 22:53:18 | [diff] [blame] | 26 | // static |
| 27 | HttpTransactionFactory* HttpNetworkLayer::CreateFactory( |
| 28 | HttpNetworkSession* session) { |
| 29 | DCHECK(session); |
| 30 | |
| 31 | return new HttpNetworkLayer(session); |
| 32 | } |
| 33 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 34 | //----------------------------------------------------------------------------- |
| 35 | |
[email protected] | c689457 | 2009-06-16 17:10:10 | [diff] [blame] | 36 | HttpNetworkLayer::HttpNetworkLayer(ClientSocketFactory* socket_factory, |
| 37 | HostResolver* host_resolver, |
[email protected] | 8a00f00a | 2009-06-12 00:49:38 | [diff] [blame] | 38 | ProxyService* proxy_service) |
[email protected] | c689457 | 2009-06-16 17:10:10 | [diff] [blame] | 39 | : socket_factory_(socket_factory), |
| 40 | host_resolver_(host_resolver), |
[email protected] | 8a00f00a | 2009-06-12 00:49:38 | [diff] [blame] | 41 | proxy_service_(proxy_service), |
| 42 | session_(NULL), |
| 43 | suspended_(false) { |
[email protected] | 63de95b | 2008-12-10 04:11:27 | [diff] [blame] | 44 | DCHECK(proxy_service_); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 45 | } |
| 46 | |
[email protected] | e7f2964 | 2009-03-02 22:53:18 | [diff] [blame] | 47 | HttpNetworkLayer::HttpNetworkLayer(HttpNetworkSession* session) |
[email protected] | c689457 | 2009-06-16 17:10:10 | [diff] [blame] | 48 | : socket_factory_(ClientSocketFactory::GetDefaultFactory()), |
| 49 | host_resolver_(NULL), |
| 50 | proxy_service_(NULL), |
| 51 | session_(session), |
| 52 | suspended_(false) { |
[email protected] | e7f2964 | 2009-03-02 22:53:18 | [diff] [blame] | 53 | DCHECK(session_.get()); |
| 54 | } |
| 55 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 56 | HttpNetworkLayer::~HttpNetworkLayer() { |
| 57 | } |
| 58 | |
| 59 | HttpTransaction* HttpNetworkLayer::CreateTransaction() { |
| 60 | if (suspended_) |
| 61 | return NULL; |
| 62 | |
[email protected] | c689457 | 2009-06-16 17:10:10 | [diff] [blame] | 63 | return new HttpNetworkTransaction(GetSession(), socket_factory_); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | HttpCache* HttpNetworkLayer::GetCache() { |
| 67 | return NULL; |
| 68 | } |
| 69 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 70 | void HttpNetworkLayer::Suspend(bool suspend) { |
| 71 | suspended_ = suspend; |
| 72 | |
[email protected] | a3b006eea | 2008-10-22 21:23:08 | [diff] [blame] | 73 | if (suspend && session_) |
[email protected] | e1e0626 | 2008-08-06 23:57:07 | [diff] [blame] | 74 | session_->connection_pool()->CloseIdleSockets(); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 75 | } |
| 76 | |
[email protected] | e7f2964 | 2009-03-02 22:53:18 | [diff] [blame] | 77 | HttpNetworkSession* HttpNetworkLayer::GetSession() { |
| 78 | if (!session_) { |
| 79 | DCHECK(proxy_service_); |
[email protected] | 8a00f00a | 2009-06-12 00:49:38 | [diff] [blame] | 80 | session_ = new HttpNetworkSession(host_resolver_, proxy_service_, |
[email protected] | c689457 | 2009-06-16 17:10:10 | [diff] [blame] | 81 | socket_factory_); |
[email protected] | e7f2964 | 2009-03-02 22:53:18 | [diff] [blame] | 82 | } |
| 83 | return session_; |
| 84 | } |
| 85 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 86 | } // namespace net |