OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/http/http_network_layer.h" | 5 #include "net/http/http_network_layer.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "net/base/client_socket_factory.h" | 8 #include "net/base/client_socket_factory.h" |
9 #include "net/http/http_network_session.h" | 9 #include "net/http/http_network_session.h" |
10 #include "net/http/http_network_transaction.h" | 10 #include "net/http/http_network_transaction.h" |
11 | 11 |
12 namespace net { | 12 namespace net { |
13 | 13 |
14 //----------------------------------------------------------------------------- | 14 //----------------------------------------------------------------------------- |
15 | 15 |
16 // static | 16 // static |
17 HttpTransactionFactory* HttpNetworkLayer::CreateFactory( | 17 HttpTransactionFactory* HttpNetworkLayer::CreateFactory( |
18 ProxyService* proxy_service) { | 18 ProxyService* proxy_service) { |
19 DCHECK(proxy_service); | 19 DCHECK(proxy_service); |
20 | 20 |
21 return new HttpNetworkLayer(proxy_service); | 21 return new HttpNetworkLayer(proxy_service); |
22 } | 22 } |
23 | 23 |
| 24 // static |
| 25 HttpTransactionFactory* HttpNetworkLayer::CreateFactory( |
| 26 HttpNetworkSession* session) { |
| 27 DCHECK(session); |
| 28 |
| 29 return new HttpNetworkLayer(session); |
| 30 } |
| 31 |
24 //----------------------------------------------------------------------------- | 32 //----------------------------------------------------------------------------- |
25 | 33 |
26 HttpNetworkLayer::HttpNetworkLayer(ProxyService* proxy_service) | 34 HttpNetworkLayer::HttpNetworkLayer(ProxyService* proxy_service) |
27 : proxy_service_(proxy_service), suspended_(false) { | 35 : proxy_service_(proxy_service), session_(NULL), suspended_(false) { |
28 DCHECK(proxy_service_); | 36 DCHECK(proxy_service_); |
29 } | 37 } |
30 | 38 |
| 39 HttpNetworkLayer::HttpNetworkLayer(HttpNetworkSession* session) |
| 40 : proxy_service_(NULL), session_(session), suspended_(false) { |
| 41 DCHECK(session_.get()); |
| 42 } |
| 43 |
31 HttpNetworkLayer::~HttpNetworkLayer() { | 44 HttpNetworkLayer::~HttpNetworkLayer() { |
32 } | 45 } |
33 | 46 |
34 HttpTransaction* HttpNetworkLayer::CreateTransaction() { | 47 HttpTransaction* HttpNetworkLayer::CreateTransaction() { |
35 if (suspended_) | 48 if (suspended_) |
36 return NULL; | 49 return NULL; |
37 | 50 |
38 if (!session_) | |
39 session_ = new HttpNetworkSession(proxy_service_); | |
40 | |
41 return new HttpNetworkTransaction( | 51 return new HttpNetworkTransaction( |
42 session_, ClientSocketFactory::GetDefaultFactory()); | 52 GetSession(), ClientSocketFactory::GetDefaultFactory()); |
43 } | 53 } |
44 | 54 |
45 HttpCache* HttpNetworkLayer::GetCache() { | 55 HttpCache* HttpNetworkLayer::GetCache() { |
46 return NULL; | 56 return NULL; |
47 } | 57 } |
48 | 58 |
49 void HttpNetworkLayer::Suspend(bool suspend) { | 59 void HttpNetworkLayer::Suspend(bool suspend) { |
50 suspended_ = suspend; | 60 suspended_ = suspend; |
51 | 61 |
52 if (suspend && session_) | 62 if (suspend && session_) |
53 session_->connection_pool()->CloseIdleSockets(); | 63 session_->connection_pool()->CloseIdleSockets(); |
54 } | 64 } |
55 | 65 |
| 66 HttpNetworkSession* HttpNetworkLayer::GetSession() { |
| 67 if (session_) { |
| 68 DCHECK(proxy_service_); |
| 69 session_ = new HttpNetworkSession(proxy_service_); |
| 70 } |
| 71 return session_; |
| 72 } |
| 73 |
56 } // namespace net | 74 } // namespace net |
57 | 75 |
OLD | NEW |