OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/string_util.h" | 8 #include "base/string_util.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 #include "net/socket/client_socket_factory.h" | 11 #include "net/socket/client_socket_factory.h" |
12 #include "net/spdy/spdy_framer.h" | 12 #include "net/spdy/spdy_framer.h" |
13 #include "net/spdy/spdy_network_transaction.h" | 13 #include "net/spdy/spdy_network_transaction.h" |
14 #include "net/spdy/spdy_session.h" | 14 #include "net/spdy/spdy_session.h" |
| 15 #include "net/spdy/spdy_session_pool.h" |
15 | 16 |
16 namespace net { | 17 namespace net { |
17 | 18 |
18 //----------------------------------------------------------------------------- | 19 //----------------------------------------------------------------------------- |
19 | 20 |
20 // static | 21 // static |
21 HttpTransactionFactory* HttpNetworkLayer::CreateFactory( | 22 HttpTransactionFactory* HttpNetworkLayer::CreateFactory( |
22 NetworkChangeNotifier* network_change_notifier, | 23 NetworkChangeNotifier* network_change_notifier, |
23 HostResolver* host_resolver, | 24 HostResolver* host_resolver, |
24 ProxyService* proxy_service, | 25 ProxyService* proxy_service, |
(...skipping 24 matching lines...) Expand all Loading... |
49 HostResolver* host_resolver, | 50 HostResolver* host_resolver, |
50 ProxyService* proxy_service, | 51 ProxyService* proxy_service, |
51 SSLConfigService* ssl_config_service, | 52 SSLConfigService* ssl_config_service, |
52 HttpAuthHandlerFactory* http_auth_handler_factory) | 53 HttpAuthHandlerFactory* http_auth_handler_factory) |
53 : socket_factory_(socket_factory), | 54 : socket_factory_(socket_factory), |
54 network_change_notifier_(network_change_notifier), | 55 network_change_notifier_(network_change_notifier), |
55 host_resolver_(host_resolver), | 56 host_resolver_(host_resolver), |
56 proxy_service_(proxy_service), | 57 proxy_service_(proxy_service), |
57 ssl_config_service_(ssl_config_service), | 58 ssl_config_service_(ssl_config_service), |
58 session_(NULL), | 59 session_(NULL), |
| 60 spdy_session_pool_(NULL), |
59 http_auth_handler_factory_(http_auth_handler_factory), | 61 http_auth_handler_factory_(http_auth_handler_factory), |
60 suspended_(false) { | 62 suspended_(false) { |
61 DCHECK(proxy_service_); | 63 DCHECK(proxy_service_); |
62 DCHECK(ssl_config_service_.get()); | 64 DCHECK(ssl_config_service_.get()); |
63 } | 65 } |
64 | 66 |
65 HttpNetworkLayer::HttpNetworkLayer(HttpNetworkSession* session) | 67 HttpNetworkLayer::HttpNetworkLayer(HttpNetworkSession* session) |
66 : socket_factory_(ClientSocketFactory::GetDefaultFactory()), | 68 : socket_factory_(ClientSocketFactory::GetDefaultFactory()), |
67 network_change_notifier_(NULL), | 69 network_change_notifier_(NULL), |
68 ssl_config_service_(NULL), | 70 ssl_config_service_(NULL), |
69 session_(session), | 71 session_(session), |
| 72 spdy_session_pool_(session->spdy_session_pool()), |
70 http_auth_handler_factory_(NULL), | 73 http_auth_handler_factory_(NULL), |
71 suspended_(false) { | 74 suspended_(false) { |
72 DCHECK(session_.get()); | 75 DCHECK(session_.get()); |
73 } | 76 } |
74 | 77 |
75 HttpNetworkLayer::~HttpNetworkLayer() { | 78 HttpNetworkLayer::~HttpNetworkLayer() { |
76 } | 79 } |
77 | 80 |
78 int HttpNetworkLayer::CreateTransaction(scoped_ptr<HttpTransaction>* trans) { | 81 int HttpNetworkLayer::CreateTransaction(scoped_ptr<HttpTransaction>* trans) { |
79 if (suspended_) | 82 if (suspended_) |
80 return ERR_NETWORK_IO_SUSPENDED; | 83 return ERR_NETWORK_IO_SUSPENDED; |
81 | 84 |
82 if (force_spdy_) | 85 if (force_spdy_) |
83 trans->reset(new SpdyNetworkTransaction(GetSession())); | 86 trans->reset(new SpdyNetworkTransaction(GetSession())); |
84 else | 87 else |
85 trans->reset(new HttpNetworkTransaction(GetSession())); | 88 trans->reset(new HttpNetworkTransaction(GetSession())); |
86 return OK; | 89 return OK; |
87 } | 90 } |
88 | 91 |
89 HttpCache* HttpNetworkLayer::GetCache() { | 92 HttpCache* HttpNetworkLayer::GetCache() { |
90 return NULL; | 93 return NULL; |
91 } | 94 } |
92 | 95 |
93 void HttpNetworkLayer::Suspend(bool suspend) { | 96 void HttpNetworkLayer::Suspend(bool suspend) { |
94 suspended_ = suspend; | 97 suspended_ = suspend; |
95 | 98 |
96 if (suspend && session_) | 99 if (suspend && session_) |
97 session_->Flush(); | 100 session_->tcp_socket_pool()->CloseIdleSockets(); |
98 } | 101 } |
99 | 102 |
100 HttpNetworkSession* HttpNetworkLayer::GetSession() { | 103 HttpNetworkSession* HttpNetworkLayer::GetSession() { |
101 if (!session_) { | 104 if (!session_) { |
102 DCHECK(proxy_service_); | 105 DCHECK(proxy_service_); |
| 106 SpdySessionPool* spdy_pool = new SpdySessionPool; |
103 session_ = new HttpNetworkSession( | 107 session_ = new HttpNetworkSession( |
104 network_change_notifier_, host_resolver_, proxy_service_, | 108 network_change_notifier_, host_resolver_, proxy_service_, |
105 socket_factory_, ssl_config_service_, | 109 socket_factory_, ssl_config_service_, spdy_pool, |
106 http_auth_handler_factory_); | 110 http_auth_handler_factory_); |
107 // These were just temps for lazy-initializing HttpNetworkSession. | 111 // These were just temps for lazy-initializing HttpNetworkSession. |
108 network_change_notifier_ = NULL; | 112 network_change_notifier_ = NULL; |
109 host_resolver_ = NULL; | 113 host_resolver_ = NULL; |
110 proxy_service_ = NULL; | 114 proxy_service_ = NULL; |
111 socket_factory_ = NULL; | 115 socket_factory_ = NULL; |
112 http_auth_handler_factory_ = NULL; | 116 http_auth_handler_factory_ = NULL; |
113 } | 117 } |
114 return session_; | 118 return session_; |
115 } | 119 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 force_spdy_ = false; | 151 force_spdy_ = false; |
148 } else if (option.empty() && it == spdy_options.begin()) { | 152 } else if (option.empty() && it == spdy_options.begin()) { |
149 continue; | 153 continue; |
150 } else { | 154 } else { |
151 LOG(DFATAL) << "Unrecognized spdy option: " << option; | 155 LOG(DFATAL) << "Unrecognized spdy option: " << option; |
152 } | 156 } |
153 } | 157 } |
154 } | 158 } |
155 | 159 |
156 } // namespace net | 160 } // namespace net |
OLD | NEW |