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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 job_factory.Pass(), make_scoped_ptr(*i))); | 161 job_factory.Pass(), make_scoped_ptr(*i))); |
161 } | 162 } |
162 request_interceptors.weak_clear(); | 163 request_interceptors.weak_clear(); |
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, |
172 scoped_ptr<data_reduction_proxy::DataReductionProxyConfigService> | |
173 config_service) | |
171 : partition_path_(partition_path), | 174 : partition_path_(partition_path), |
172 cookie_store_(cookie_store), | 175 cookie_store_(cookie_store) { |
173 proxy_config_service_(new DataReductionProxyConfigService( | 176 data_reduction_proxy_config_service_ = config_service.Pass(); |
174 scoped_ptr<net::ProxyConfigService>( | |
175 net::ProxyService::CreateSystemProxyConfigService( | |
176 GetNetworkTaskRunner(), | |
177 NULL /* Ignored on Android */)).Pass())) { | |
178 // CreateSystemProxyConfigService for Android must be called on main thread. | 177 // CreateSystemProxyConfigService for Android must be called on main thread. |
179 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 178 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
180 } | 179 } |
181 | 180 |
182 AwURLRequestContextGetter::~AwURLRequestContextGetter() { | 181 AwURLRequestContextGetter::~AwURLRequestContextGetter() { |
183 } | 182 } |
184 | 183 |
185 void AwURLRequestContextGetter::InitializeURLRequestContext() { | 184 void AwURLRequestContextGetter::InitializeURLRequestContext() { |
186 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 185 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
187 DCHECK(!url_request_context_); | 186 DCHECK(!url_request_context_); |
188 | 187 |
189 net::URLRequestContextBuilder builder; | 188 net::URLRequestContextBuilder builder; |
190 builder.set_user_agent(GetUserAgent()); | 189 builder.set_user_agent(GetUserAgent()); |
191 AwNetworkDelegate* aw_network_delegate = new AwNetworkDelegate(); | 190 AwNetworkDelegate* aw_network_delegate = new AwNetworkDelegate(); |
192 builder.set_network_delegate(aw_network_delegate); | 191 builder.set_network_delegate(aw_network_delegate); |
193 #if !defined(DISABLE_FTP_SUPPORT) | 192 #if !defined(DISABLE_FTP_SUPPORT) |
194 builder.set_ftp_enabled(false); // Android WebView does not support ftp yet. | 193 builder.set_ftp_enabled(false); // Android WebView does not support ftp yet. |
195 #endif | 194 #endif |
196 builder.set_proxy_config_service(proxy_config_service_.release()); | 195 #if defined(SPDY_PROXY_AUTH_ORIGIN) |
196 builder.set_proxy_config_service( | |
197 data_reduction_proxy_config_service_.release()); | |
198 #endif | |
197 builder.set_accept_language(net::HttpUtil::GenerateAcceptLanguageHeader( | 199 builder.set_accept_language(net::HttpUtil::GenerateAcceptLanguageHeader( |
198 AwContentBrowserClient::GetAcceptLangsImpl())); | 200 AwContentBrowserClient::GetAcceptLangsImpl())); |
199 ApplyCmdlineOverridesToURLRequestContextBuilder(&builder); | 201 ApplyCmdlineOverridesToURLRequestContextBuilder(&builder); |
200 | 202 |
201 url_request_context_.reset(builder.Build()); | 203 url_request_context_.reset(builder.Build()); |
202 channel_id_service_.reset( | 204 channel_id_service_.reset( |
203 new net::ChannelIDService( | 205 new net::ChannelIDService( |
204 new net::DefaultChannelIDStore(NULL), | 206 new net::DefaultChannelIDStore(NULL), |
205 base::WorkerPool::GetTaskRunner(true))); | 207 base::WorkerPool::GetTaskRunner(true))); |
206 url_request_context_->set_channel_id_service(channel_id_service_.get()); | 208 url_request_context_->set_channel_id_service(channel_id_service_.get()); |
207 // TODO(mnaganov): Fix URLRequestContextBuilder to use proper threads. | 209 // TODO(mnaganov): Fix URLRequestContextBuilder to use proper threads. |
208 net::HttpNetworkSession::Params network_session_params; | 210 net::HttpNetworkSession::Params network_session_params; |
209 | 211 |
210 PopulateNetworkSessionParams(url_request_context_.get(), | 212 PopulateNetworkSessionParams(url_request_context_.get(), |
211 &network_session_params); | 213 &network_session_params); |
212 | 214 |
213 net::HttpCache* main_cache = new net::HttpCache( | 215 net::HttpCache* main_cache = new net::HttpCache( |
214 network_session_params, | 216 network_session_params, |
215 new net::HttpCache::DefaultBackend( | 217 new net::HttpCache::DefaultBackend( |
216 net::DISK_CACHE, | 218 net::DISK_CACHE, |
217 net::CACHE_BACKEND_SIMPLE, | 219 net::CACHE_BACKEND_SIMPLE, |
218 partition_path_.Append(FILE_PATH_LITERAL("Cache")), | 220 partition_path_.Append(FILE_PATH_LITERAL("Cache")), |
219 20 * 1024 * 1024, // 20M | 221 20 * 1024 * 1024, // 20M |
220 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE))); | 222 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE))); |
221 | 223 |
222 #if defined(SPDY_PROXY_AUTH_ORIGIN) | 224 #if defined(SPDY_PROXY_AUTH_ORIGIN) |
223 AwBrowserContext* browser_context = AwBrowserContext::GetDefault(); | 225 AwBrowserContext* browser_context = AwBrowserContext::GetDefault(); |
224 DCHECK(browser_context); | 226 DCHECK(browser_context); |
225 DataReductionProxySettings* drp_settings = | 227 DataReductionProxySettings* data_reduction_proxy_settings = |
226 browser_context->GetDataReductionProxySettings(); | 228 browser_context->GetDataReductionProxySettings(); |
227 if (drp_settings) { | 229 if (data_reduction_proxy_settings) { |
sgurun-gerrit only
2014/08/05 01:26:35
is it an error if data_reduction_proxy_settings do
bengr
2014/08/05 02:35:07
You are right. Done.
| |
230 data_reduction_proxy_auth_request_handler_.reset( | |
231 new data_reduction_proxy::DataReductionProxyAuthRequestHandler( | |
232 data_reduction_proxy_settings->params(), | |
233 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); | |
234 | |
228 aw_network_delegate->set_data_reduction_proxy_params( | 235 aw_network_delegate->set_data_reduction_proxy_params( |
229 drp_settings->params()); | 236 data_reduction_proxy_settings->params()); |
230 aw_network_delegate->set_data_reduction_proxy_auth_request_handler( | 237 aw_network_delegate->set_data_reduction_proxy_auth_request_handler( |
231 browser_context->GetDataReductionProxyAuthRequestHandler()); | 238 data_reduction_proxy_auth_request_handler_.get()); |
232 } | 239 } |
233 #endif | 240 #endif |
234 | 241 |
235 main_http_factory_.reset(main_cache); | 242 main_http_factory_.reset(main_cache); |
236 url_request_context_->set_http_transaction_factory(main_cache); | 243 url_request_context_->set_http_transaction_factory(main_cache); |
237 url_request_context_->set_cookie_store(cookie_store_); | 244 url_request_context_->set_cookie_store(cookie_store_); |
238 | 245 |
239 job_factory_ = CreateJobFactory(&protocol_handlers_, | 246 job_factory_ = CreateJobFactory(&protocol_handlers_, |
240 request_interceptors_.Pass()); | 247 request_interceptors_.Pass()); |
241 url_request_context_->set_job_factory(job_factory_.get()); | 248 url_request_context_->set_job_factory(job_factory_.get()); |
(...skipping 12 matching lines...) Expand all Loading... | |
254 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | 261 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
255 } | 262 } |
256 | 263 |
257 void AwURLRequestContextGetter::SetHandlersAndInterceptors( | 264 void AwURLRequestContextGetter::SetHandlersAndInterceptors( |
258 content::ProtocolHandlerMap* protocol_handlers, | 265 content::ProtocolHandlerMap* protocol_handlers, |
259 content::URLRequestInterceptorScopedVector request_interceptors) { | 266 content::URLRequestInterceptorScopedVector request_interceptors) { |
260 std::swap(protocol_handlers_, *protocol_handlers); | 267 std::swap(protocol_handlers_, *protocol_handlers); |
261 request_interceptors_.swap(request_interceptors); | 268 request_interceptors_.swap(request_interceptors); |
262 } | 269 } |
263 | 270 |
264 DataReductionProxyConfigService* | 271 data_reduction_proxy::DataReductionProxyAuthRequestHandler* |
265 AwURLRequestContextGetter::proxy_config_service() { | 272 AwURLRequestContextGetter::GetDataReductionProxyAuthRequestHandler() const { |
266 // TODO(bengr): return system config if data reduction proxy is disabled. | 273 return data_reduction_proxy_auth_request_handler_.get(); |
267 return proxy_config_service_.get(); | |
268 } | 274 } |
269 | 275 |
270 } // namespace android_webview | 276 } // namespace android_webview |
OLD | NEW |