OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "android_webview/browser/net/aw_url_request_context_getter.h" | 5 #include "android_webview/browser/net/aw_url_request_context_getter.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "android_webview/browser/aw_content_browser_client.h" | 9 #include "android_webview/browser/aw_content_browser_client.h" |
10 #include "android_webview/browser/aw_request_interceptor.h" | 10 #include "android_webview/browser/aw_request_interceptor.h" |
11 #include "android_webview/browser/net/aw_network_delegate.h" | 11 #include "android_webview/browser/net/aw_network_delegate.h" |
12 #include "android_webview/browser/net/aw_url_request_job_factory.h" | 12 #include "android_webview/browser/net/aw_url_request_job_factory.h" |
13 #include "android_webview/browser/net/init_native_callback.h" | 13 #include "android_webview/browser/net/init_native_callback.h" |
14 #include "android_webview/common/aw_switches.h" | 14 #include "android_webview/common/aw_switches.h" |
15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
17 #include "base/threading/sequenced_worker_pool.h" | 17 #include "base/threading/sequenced_worker_pool.h" |
18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
19 #include "content/public/browser/content_browser_client.h" | 19 #include "content/public/browser/content_browser_client.h" |
20 #include "content/public/browser/cookie_store_factory.h" | 20 #include "content/public/browser/cookie_store_factory.h" |
21 #include "content/public/common/content_client.h" | 21 #include "content/public/common/content_client.h" |
22 #include "content/public/common/content_switches.h" | 22 #include "content/public/common/content_switches.h" |
23 #include "content/public/common/url_constants.h" | 23 #include "content/public/common/url_constants.h" |
24 #include "net/base/cache_type.h" | 24 #include "net/base/cache_type.h" |
25 #include "net/cookies/cookie_store.h" | 25 #include "net/cookies/cookie_store.h" |
26 #include "net/dns/mapped_host_resolver.h" | 26 #include "net/dns/mapped_host_resolver.h" |
27 #include "net/http/http_cache.h" | 27 #include "net/http/http_cache.h" |
| 28 #include "net/http/http_stream_factory.h" |
28 #include "net/proxy/proxy_service.h" | 29 #include "net/proxy/proxy_service.h" |
29 #include "net/url_request/data_protocol_handler.h" | 30 #include "net/url_request/data_protocol_handler.h" |
30 #include "net/url_request/file_protocol_handler.h" | 31 #include "net/url_request/file_protocol_handler.h" |
31 #include "net/url_request/protocol_intercept_job_factory.h" | 32 #include "net/url_request/protocol_intercept_job_factory.h" |
32 #include "net/url_request/url_request_context_builder.h" | 33 #include "net/url_request/url_request_context_builder.h" |
33 #include "net/url_request/url_request_context.h" | 34 #include "net/url_request/url_request_context.h" |
34 | 35 |
35 using content::BrowserThread; | 36 using content::BrowserThread; |
36 | 37 |
37 namespace android_webview { | 38 namespace android_webview { |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 // TODO(mnaganov): Fix URLRequestContextBuilder to use proper threads. | 190 // TODO(mnaganov): Fix URLRequestContextBuilder to use proper threads. |
190 net::HttpNetworkSession::Params network_session_params; | 191 net::HttpNetworkSession::Params network_session_params; |
191 | 192 |
192 net::BackendType cache_type = net::CACHE_BACKEND_SIMPLE; | 193 net::BackendType cache_type = net::CACHE_BACKEND_SIMPLE; |
193 if (CommandLine::ForCurrentProcess()->HasSwitch( | 194 if (CommandLine::ForCurrentProcess()->HasSwitch( |
194 switches::kDisableSimpleCache)) { | 195 switches::kDisableSimpleCache)) { |
195 cache_type = net::CACHE_BACKEND_BLOCKFILE; | 196 cache_type = net::CACHE_BACKEND_BLOCKFILE; |
196 } | 197 } |
197 PopulateNetworkSessionParams(url_request_context_.get(), | 198 PopulateNetworkSessionParams(url_request_context_.get(), |
198 &network_session_params); | 199 &network_session_params); |
| 200 |
199 net::HttpCache* main_cache = new net::HttpCache( | 201 net::HttpCache* main_cache = new net::HttpCache( |
200 network_session_params, | 202 network_session_params, |
201 new net::HttpCache::DefaultBackend( | 203 new net::HttpCache::DefaultBackend( |
202 net::DISK_CACHE, | 204 net::DISK_CACHE, |
203 cache_type, | 205 cache_type, |
204 partition_path_.Append(FILE_PATH_LITERAL("Cache")), | 206 partition_path_.Append(FILE_PATH_LITERAL("Cache")), |
205 20 * 1024 * 1024, // 20M | 207 20 * 1024 * 1024, // 20M |
206 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE))); | 208 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE))); |
207 main_http_factory_.reset(main_cache); | 209 main_http_factory_.reset(main_cache); |
208 url_request_context_->set_http_transaction_factory(main_cache); | 210 url_request_context_->set_http_transaction_factory(main_cache); |
209 url_request_context_->set_cookie_store(cookie_store_); | 211 url_request_context_->set_cookie_store(cookie_store_); |
210 | 212 |
211 job_factory_ = CreateJobFactory(&protocol_handlers_); | 213 job_factory_ = CreateJobFactory(&protocol_handlers_); |
212 url_request_context_->set_job_factory(job_factory_.get()); | 214 url_request_context_->set_job_factory(job_factory_.get()); |
| 215 |
| 216 // TODO(sgurun) remove once crbug.com/329681 is fixed. Should be |
| 217 // called only once. |
| 218 net::HttpStreamFactory::EnableNpnSpdy31(); |
213 } | 219 } |
214 | 220 |
215 net::URLRequestContext* AwURLRequestContextGetter::GetURLRequestContext() { | 221 net::URLRequestContext* AwURLRequestContextGetter::GetURLRequestContext() { |
216 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 222 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
217 if (!url_request_context_) | 223 if (!url_request_context_) |
218 InitializeURLRequestContext(); | 224 InitializeURLRequestContext(); |
219 | 225 |
220 return url_request_context_.get(); | 226 return url_request_context_.get(); |
221 } | 227 } |
222 | 228 |
223 scoped_refptr<base::SingleThreadTaskRunner> | 229 scoped_refptr<base::SingleThreadTaskRunner> |
224 AwURLRequestContextGetter::GetNetworkTaskRunner() const { | 230 AwURLRequestContextGetter::GetNetworkTaskRunner() const { |
225 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | 231 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
226 } | 232 } |
227 | 233 |
228 void AwURLRequestContextGetter::SetProtocolHandlers( | 234 void AwURLRequestContextGetter::SetProtocolHandlers( |
229 content::ProtocolHandlerMap* protocol_handlers) { | 235 content::ProtocolHandlerMap* protocol_handlers) { |
230 std::swap(protocol_handlers_, *protocol_handlers); | 236 std::swap(protocol_handlers_, *protocol_handlers); |
231 } | 237 } |
232 | 238 |
233 } // namespace android_webview | 239 } // namespace android_webview |
OLD | NEW |