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] | db36938c | 2009-08-19 21:48:42 | [diff] [blame^] | 19 | ProxyService* proxy_service, |
| 20 | SSLConfigService* ssl_config_service) { |
[email protected] | 63de95b | 2008-12-10 04:11:27 | [diff] [blame] | 21 | DCHECK(proxy_service); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 22 | |
[email protected] | c689457 | 2009-06-16 17:10:10 | [diff] [blame] | 23 | return new HttpNetworkLayer(ClientSocketFactory::GetDefaultFactory(), |
[email protected] | db36938c | 2009-08-19 21:48:42 | [diff] [blame^] | 24 | host_resolver, proxy_service, ssl_config_service); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 25 | } |
| 26 | |
[email protected] | e7f2964 | 2009-03-02 22:53:18 | [diff] [blame] | 27 | // static |
| 28 | HttpTransactionFactory* HttpNetworkLayer::CreateFactory( |
| 29 | HttpNetworkSession* session) { |
| 30 | DCHECK(session); |
| 31 | |
| 32 | return new HttpNetworkLayer(session); |
| 33 | } |
| 34 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 35 | //----------------------------------------------------------------------------- |
| 36 | |
[email protected] | c689457 | 2009-06-16 17:10:10 | [diff] [blame] | 37 | HttpNetworkLayer::HttpNetworkLayer(ClientSocketFactory* socket_factory, |
| 38 | HostResolver* host_resolver, |
[email protected] | db36938c | 2009-08-19 21:48:42 | [diff] [blame^] | 39 | ProxyService* proxy_service, |
| 40 | SSLConfigService* ssl_config_service) |
[email protected] | c689457 | 2009-06-16 17:10:10 | [diff] [blame] | 41 | : socket_factory_(socket_factory), |
| 42 | host_resolver_(host_resolver), |
[email protected] | 8a00f00a | 2009-06-12 00:49:38 | [diff] [blame] | 43 | proxy_service_(proxy_service), |
[email protected] | db36938c | 2009-08-19 21:48:42 | [diff] [blame^] | 44 | ssl_config_service_(ssl_config_service), |
[email protected] | 8a00f00a | 2009-06-12 00:49:38 | [diff] [blame] | 45 | session_(NULL), |
| 46 | suspended_(false) { |
[email protected] | 63de95b | 2008-12-10 04:11:27 | [diff] [blame] | 47 | DCHECK(proxy_service_); |
[email protected] | db36938c | 2009-08-19 21:48:42 | [diff] [blame^] | 48 | DCHECK(ssl_config_service_.get()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 49 | } |
| 50 | |
[email protected] | e7f2964 | 2009-03-02 22:53:18 | [diff] [blame] | 51 | HttpNetworkLayer::HttpNetworkLayer(HttpNetworkSession* session) |
[email protected] | c689457 | 2009-06-16 17:10:10 | [diff] [blame] | 52 | : socket_factory_(ClientSocketFactory::GetDefaultFactory()), |
[email protected] | db36938c | 2009-08-19 21:48:42 | [diff] [blame^] | 53 | ssl_config_service_(NULL), |
[email protected] | c689457 | 2009-06-16 17:10:10 | [diff] [blame] | 54 | session_(session), |
| 55 | suspended_(false) { |
[email protected] | e7f2964 | 2009-03-02 22:53:18 | [diff] [blame] | 56 | DCHECK(session_.get()); |
| 57 | } |
| 58 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 59 | HttpNetworkLayer::~HttpNetworkLayer() { |
| 60 | } |
| 61 | |
| 62 | HttpTransaction* HttpNetworkLayer::CreateTransaction() { |
| 63 | if (suspended_) |
| 64 | return NULL; |
| 65 | |
[email protected] | c689457 | 2009-06-16 17:10:10 | [diff] [blame] | 66 | return new HttpNetworkTransaction(GetSession(), socket_factory_); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | HttpCache* HttpNetworkLayer::GetCache() { |
| 70 | return NULL; |
| 71 | } |
| 72 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 73 | void HttpNetworkLayer::Suspend(bool suspend) { |
| 74 | suspended_ = suspend; |
| 75 | |
[email protected] | a3b006eea | 2008-10-22 21:23:08 | [diff] [blame] | 76 | if (suspend && session_) |
[email protected] | a937a06d | 2009-08-19 21:19:24 | [diff] [blame] | 77 | session_->tcp_socket_pool()->CloseIdleSockets(); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 78 | } |
| 79 | |
[email protected] | e7f2964 | 2009-03-02 22:53:18 | [diff] [blame] | 80 | HttpNetworkSession* HttpNetworkLayer::GetSession() { |
| 81 | if (!session_) { |
| 82 | DCHECK(proxy_service_); |
[email protected] | 8a00f00a | 2009-06-12 00:49:38 | [diff] [blame] | 83 | session_ = new HttpNetworkSession(host_resolver_, proxy_service_, |
[email protected] | db36938c | 2009-08-19 21:48:42 | [diff] [blame^] | 84 | socket_factory_, ssl_config_service_); |
[email protected] | 80d6524d | 2009-08-18 03:58:09 | [diff] [blame] | 85 | // These were just temps for lazy-initializing HttpNetworkSession. |
| 86 | host_resolver_ = NULL; |
| 87 | proxy_service_ = NULL; |
[email protected] | e7f2964 | 2009-03-02 22:53:18 | [diff] [blame] | 88 | } |
| 89 | return session_; |
| 90 | } |
| 91 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 92 | } // namespace net |