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_browser_context.h" | 9 #include "android_webview/browser/aw_browser_context.h" |
10 #include "android_webview/browser/aw_content_browser_client.h" | 10 #include "android_webview/browser/aw_content_browser_client.h" |
11 #include "android_webview/browser/aw_request_interceptor.h" | 11 #include "android_webview/browser/aw_request_interceptor.h" |
12 #include "android_webview/browser/net/aw_network_delegate.h" | 12 #include "android_webview/browser/net/aw_network_delegate.h" |
13 #include "android_webview/browser/net/aw_url_request_job_factory.h" | 13 #include "android_webview/browser/net/aw_url_request_job_factory.h" |
14 #include "android_webview/browser/net/init_native_callback.h" | 14 #include "android_webview/browser/net/init_native_callback.h" |
15 #include "android_webview/common/aw_content_client.h" | 15 #include "android_webview/common/aw_content_client.h" |
16 #include "base/command_line.h" | 16 #include "base/command_line.h" |
17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
18 #include "base/threading/sequenced_worker_pool.h" | 18 #include "base/threading/sequenced_worker_pool.h" |
19 #include "base/threading/worker_pool.h" | 19 #include "base/threading/worker_pool.h" |
20 #include "components/data_reduction_proxy/browser/data_reduction_proxy_auth_requ est_handler.h" | |
20 #include "components/data_reduction_proxy/browser/data_reduction_proxy_config_se rvice.h" | 21 #include "components/data_reduction_proxy/browser/data_reduction_proxy_config_se rvice.h" |
21 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings. h" | 22 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings. h" |
22 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
23 #include "content/public/browser/content_browser_client.h" | 24 #include "content/public/browser/content_browser_client.h" |
24 #include "content/public/browser/cookie_store_factory.h" | 25 #include "content/public/browser/cookie_store_factory.h" |
25 #include "content/public/common/content_client.h" | 26 #include "content/public/common/content_client.h" |
26 #include "content/public/common/content_switches.h" | 27 #include "content/public/common/content_switches.h" |
27 #include "content/public/common/url_constants.h" | 28 #include "content/public/common/url_constants.h" |
28 #include "net/base/cache_type.h" | 29 #include "net/base/cache_type.h" |
29 #include "net/cookies/cookie_store.h" | 30 #include "net/cookies/cookie_store.h" |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
163 | 164 |
164 return job_factory.Pass(); | 165 return job_factory.Pass(); |
165 } | 166 } |
166 | 167 |
167 } // namespace | 168 } // namespace |
168 | 169 |
169 AwURLRequestContextGetter::AwURLRequestContextGetter( | 170 AwURLRequestContextGetter::AwURLRequestContextGetter( |
170 const base::FilePath& partition_path, net::CookieStore* cookie_store) | 171 const base::FilePath& partition_path, net::CookieStore* cookie_store) |
171 : partition_path_(partition_path), | 172 : partition_path_(partition_path), |
172 cookie_store_(cookie_store), | 173 cookie_store_(cookie_store), |
173 proxy_config_service_(new DataReductionProxyConfigService( | 174 data_reduction_proxy_config_service_( |
174 scoped_ptr<net::ProxyConfigService>( | 175 new data_reduction_proxy::DataReductionProxyConfigService( |
175 net::ProxyService::CreateSystemProxyConfigService( | 176 scoped_ptr<net::ProxyConfigService>( |
176 GetNetworkTaskRunner(), | 177 net::ProxyService::CreateSystemProxyConfigService( |
177 NULL /* Ignored on Android */)).Pass())) { | 178 GetNetworkTaskRunner(), |
179 NULL /* Ignored on Android */)).Pass())) { | |
178 // CreateSystemProxyConfigService for Android must be called on main thread. | 180 // CreateSystemProxyConfigService for Android must be called on main thread. |
179 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 181 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
180 } | 182 } |
181 | 183 |
182 AwURLRequestContextGetter::~AwURLRequestContextGetter() { | 184 AwURLRequestContextGetter::~AwURLRequestContextGetter() { |
183 } | 185 } |
184 | 186 |
185 void AwURLRequestContextGetter::InitializeURLRequestContext() { | 187 void AwURLRequestContextGetter::InitializeURLRequestContext() { |
186 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 188 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
187 DCHECK(!url_request_context_); | 189 DCHECK(!url_request_context_); |
188 | 190 |
189 net::URLRequestContextBuilder builder; | 191 net::URLRequestContextBuilder builder; |
190 builder.set_user_agent(GetUserAgent()); | 192 builder.set_user_agent(GetUserAgent()); |
191 AwNetworkDelegate* aw_network_delegate = new AwNetworkDelegate(); | 193 AwNetworkDelegate* aw_network_delegate = new AwNetworkDelegate(); |
192 builder.set_network_delegate(aw_network_delegate); | 194 builder.set_network_delegate(aw_network_delegate); |
193 #if !defined(DISABLE_FTP_SUPPORT) | 195 #if !defined(DISABLE_FTP_SUPPORT) |
194 builder.set_ftp_enabled(false); // Android WebView does not support ftp yet. | 196 builder.set_ftp_enabled(false); // Android WebView does not support ftp yet. |
195 #endif | 197 #endif |
196 builder.set_proxy_config_service(proxy_config_service_.release()); | 198 builder.set_proxy_config_service( |
199 data_reduction_proxy_config_service_.release()); | |
willchan no longer on Chromium
2014/07/31 22:31:34
This should get fixed. AFAICT, this is what happen
sgurun-gerrit only
2014/07/31 23:11:55
agreed with Will. (thanks for doing such a detail
bengr
2014/08/02 01:10:31
Thanks for going into so much detail. I didn't do
| |
197 builder.set_accept_language(net::HttpUtil::GenerateAcceptLanguageHeader( | 200 builder.set_accept_language(net::HttpUtil::GenerateAcceptLanguageHeader( |
198 AwContentBrowserClient::GetAcceptLangsImpl())); | 201 AwContentBrowserClient::GetAcceptLangsImpl())); |
199 ApplyCmdlineOverridesToURLRequestContextBuilder(&builder); | 202 ApplyCmdlineOverridesToURLRequestContextBuilder(&builder); |
200 | 203 |
201 url_request_context_.reset(builder.Build()); | 204 url_request_context_.reset(builder.Build()); |
202 channel_id_service_.reset( | 205 channel_id_service_.reset( |
203 new net::ChannelIDService( | 206 new net::ChannelIDService( |
204 new net::DefaultChannelIDStore(NULL), | 207 new net::DefaultChannelIDStore(NULL), |
205 base::WorkerPool::GetTaskRunner(true))); | 208 base::WorkerPool::GetTaskRunner(true))); |
206 url_request_context_->set_channel_id_service(channel_id_service_.get()); | 209 url_request_context_->set_channel_id_service(channel_id_service_.get()); |
207 // TODO(mnaganov): Fix URLRequestContextBuilder to use proper threads. | 210 // TODO(mnaganov): Fix URLRequestContextBuilder to use proper threads. |
208 net::HttpNetworkSession::Params network_session_params; | 211 net::HttpNetworkSession::Params network_session_params; |
209 | 212 |
210 PopulateNetworkSessionParams(url_request_context_.get(), | 213 PopulateNetworkSessionParams(url_request_context_.get(), |
211 &network_session_params); | 214 &network_session_params); |
212 | 215 |
213 net::HttpCache* main_cache = new net::HttpCache( | 216 net::HttpCache* main_cache = new net::HttpCache( |
214 network_session_params, | 217 network_session_params, |
215 new net::HttpCache::DefaultBackend( | 218 new net::HttpCache::DefaultBackend( |
216 net::DISK_CACHE, | 219 net::DISK_CACHE, |
217 net::CACHE_BACKEND_SIMPLE, | 220 net::CACHE_BACKEND_SIMPLE, |
218 partition_path_.Append(FILE_PATH_LITERAL("Cache")), | 221 partition_path_.Append(FILE_PATH_LITERAL("Cache")), |
219 20 * 1024 * 1024, // 20M | 222 20 * 1024 * 1024, // 20M |
220 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE))); | 223 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE))); |
221 | 224 |
222 #if defined(SPDY_PROXY_AUTH_ORIGIN) | 225 #if defined(SPDY_PROXY_AUTH_ORIGIN) |
223 AwBrowserContext* browser_context = AwBrowserContext::GetDefault(); | 226 AwBrowserContext* browser_context = AwBrowserContext::GetDefault(); |
224 DCHECK(browser_context); | 227 DCHECK(browser_context); |
225 DataReductionProxySettings* drp_settings = | 228 DataReductionProxySettings* data_reduction_proxy_settings = |
226 browser_context->GetDataReductionProxySettings(); | 229 browser_context->GetDataReductionProxySettings(); |
227 if (drp_settings) { | 230 if (data_reduction_proxy_settings) { |
231 data_reduction_proxy_auth_request_handler_.reset( | |
232 new data_reduction_proxy::DataReductionProxyAuthRequestHandler( | |
233 data_reduction_proxy_settings->params(), | |
234 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); | |
235 | |
228 aw_network_delegate->set_data_reduction_proxy_params( | 236 aw_network_delegate->set_data_reduction_proxy_params( |
229 drp_settings->params()); | 237 data_reduction_proxy_settings->params()); |
230 aw_network_delegate->set_data_reduction_proxy_auth_request_handler( | 238 aw_network_delegate->set_data_reduction_proxy_auth_request_handler( |
231 browser_context->GetDataReductionProxyAuthRequestHandler()); | 239 data_reduction_proxy_auth_request_handler_.get()); |
232 } | 240 } |
233 #endif | 241 #endif |
234 | 242 |
235 main_http_factory_.reset(main_cache); | 243 main_http_factory_.reset(main_cache); |
236 url_request_context_->set_http_transaction_factory(main_cache); | 244 url_request_context_->set_http_transaction_factory(main_cache); |
237 url_request_context_->set_cookie_store(cookie_store_); | 245 url_request_context_->set_cookie_store(cookie_store_); |
238 | 246 |
239 job_factory_ = CreateJobFactory(&protocol_handlers_, | 247 job_factory_ = CreateJobFactory(&protocol_handlers_, |
240 request_interceptors_.Pass()); | 248 request_interceptors_.Pass()); |
241 url_request_context_->set_job_factory(job_factory_.get()); | 249 url_request_context_->set_job_factory(job_factory_.get()); |
(...skipping 12 matching lines...) Expand all Loading... | |
254 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | 262 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
255 } | 263 } |
256 | 264 |
257 void AwURLRequestContextGetter::SetHandlersAndInterceptors( | 265 void AwURLRequestContextGetter::SetHandlersAndInterceptors( |
258 content::ProtocolHandlerMap* protocol_handlers, | 266 content::ProtocolHandlerMap* protocol_handlers, |
259 content::URLRequestInterceptorScopedVector request_interceptors) { | 267 content::URLRequestInterceptorScopedVector request_interceptors) { |
260 std::swap(protocol_handlers_, *protocol_handlers); | 268 std::swap(protocol_handlers_, *protocol_handlers); |
261 request_interceptors_.swap(request_interceptors); | 269 request_interceptors_.swap(request_interceptors); |
262 } | 270 } |
263 | 271 |
264 DataReductionProxyConfigService* | 272 data_reduction_proxy::DataReductionProxyConfigService* |
265 AwURLRequestContextGetter::proxy_config_service() { | 273 AwURLRequestContextGetter::GetDataReductionProxyConfigService() const { |
266 // TODO(bengr): return system config if data reduction proxy is disabled. | 274 // TODO(bengr): return system config if data reduction proxy is disabled. |
267 return proxy_config_service_.get(); | 275 return data_reduction_proxy_config_service_.get(); |
276 } | |
277 | |
278 data_reduction_proxy::DataReductionProxyAuthRequestHandler* | |
279 AwURLRequestContextGetter::GetDataReductionProxyAuthRequestHandler() const { | |
280 return data_reduction_proxy_auth_request_handler_.get(); | |
268 } | 281 } |
269 | 282 |
270 } // namespace android_webview | 283 } // namespace android_webview |
OLD | NEW |