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