OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chromecast/browser/url_request_context_factory.h" | 5 #include "chromecast/browser/url_request_context_factory.h" |
6 | 6 |
| 7 #include <utility> |
| 8 |
7 #include "base/command_line.h" | 9 #include "base/command_line.h" |
8 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
9 #include "base/macros.h" | 11 #include "base/macros.h" |
10 #include "base/threading/worker_pool.h" | 12 #include "base/threading/worker_pool.h" |
11 #include "chromecast/base/chromecast_switches.h" | 13 #include "chromecast/base/chromecast_switches.h" |
12 #include "chromecast/browser/cast_http_user_agent_settings.h" | 14 #include "chromecast/browser/cast_http_user_agent_settings.h" |
13 #include "chromecast/browser/cast_network_delegate.h" | 15 #include "chromecast/browser/cast_network_delegate.h" |
14 #include "content/public/browser/browser_context.h" | 16 #include "content/public/browser/browser_context.h" |
15 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
16 #include "content/public/browser/cookie_store_factory.h" | 18 #include "content/public/browser/cookie_store_factory.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 class URLRequestContextFactory::MainURLRequestContextGetter | 96 class URLRequestContextFactory::MainURLRequestContextGetter |
95 : public net::URLRequestContextGetter { | 97 : public net::URLRequestContextGetter { |
96 public: | 98 public: |
97 MainURLRequestContextGetter( | 99 MainURLRequestContextGetter( |
98 URLRequestContextFactory* factory, | 100 URLRequestContextFactory* factory, |
99 content::BrowserContext* browser_context, | 101 content::BrowserContext* browser_context, |
100 content::ProtocolHandlerMap* protocol_handlers, | 102 content::ProtocolHandlerMap* protocol_handlers, |
101 content::URLRequestInterceptorScopedVector request_interceptors) | 103 content::URLRequestInterceptorScopedVector request_interceptors) |
102 : browser_context_(browser_context), | 104 : browser_context_(browser_context), |
103 factory_(factory), | 105 factory_(factory), |
104 request_interceptors_(request_interceptors.Pass()) { | 106 request_interceptors_(std::move(request_interceptors)) { |
105 std::swap(protocol_handlers_, *protocol_handlers); | 107 std::swap(protocol_handlers_, *protocol_handlers); |
106 } | 108 } |
107 | 109 |
108 net::URLRequestContext* GetURLRequestContext() override { | 110 net::URLRequestContext* GetURLRequestContext() override { |
109 if (!request_context_) { | 111 if (!request_context_) { |
110 request_context_.reset(factory_->CreateMainRequestContext( | 112 request_context_.reset(factory_->CreateMainRequestContext( |
111 browser_context_, &protocol_handlers_, request_interceptors_.Pass())); | 113 browser_context_, &protocol_handlers_, |
| 114 std::move(request_interceptors_))); |
112 protocol_handlers_.clear(); | 115 protocol_handlers_.clear(); |
113 } | 116 } |
114 return request_context_.get(); | 117 return request_context_.get(); |
115 } | 118 } |
116 | 119 |
117 scoped_refptr<base::SingleThreadTaskRunner> | 120 scoped_refptr<base::SingleThreadTaskRunner> |
118 GetNetworkTaskRunner() const override { | 121 GetNetworkTaskRunner() const override { |
119 return content::BrowserThread::GetMessageLoopProxyForThread( | 122 return content::BrowserThread::GetMessageLoopProxyForThread( |
120 content::BrowserThread::IO); | 123 content::BrowserThread::IO); |
121 } | 124 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 | 163 |
161 net_log_ = net_log; | 164 net_log_ = net_log; |
162 } | 165 } |
163 | 166 |
164 net::URLRequestContextGetter* URLRequestContextFactory::CreateMainGetter( | 167 net::URLRequestContextGetter* URLRequestContextFactory::CreateMainGetter( |
165 content::BrowserContext* browser_context, | 168 content::BrowserContext* browser_context, |
166 content::ProtocolHandlerMap* protocol_handlers, | 169 content::ProtocolHandlerMap* protocol_handlers, |
167 content::URLRequestInterceptorScopedVector request_interceptors) { | 170 content::URLRequestInterceptorScopedVector request_interceptors) { |
168 DCHECK(!main_getter_.get()) | 171 DCHECK(!main_getter_.get()) |
169 << "Main URLRequestContextGetter already initialized"; | 172 << "Main URLRequestContextGetter already initialized"; |
170 main_getter_ = new MainURLRequestContextGetter(this, | 173 main_getter_ = |
171 browser_context, | 174 new MainURLRequestContextGetter(this, browser_context, protocol_handlers, |
172 protocol_handlers, | 175 std::move(request_interceptors)); |
173 request_interceptors.Pass()); | |
174 return main_getter_.get(); | 176 return main_getter_.get(); |
175 } | 177 } |
176 | 178 |
177 net::URLRequestContextGetter* URLRequestContextFactory::GetMainGetter() { | 179 net::URLRequestContextGetter* URLRequestContextFactory::GetMainGetter() { |
178 CHECK(main_getter_.get()); | 180 CHECK(main_getter_.get()); |
179 return main_getter_.get(); | 181 return main_getter_.get(); |
180 } | 182 } |
181 | 183 |
182 net::URLRequestContextGetter* URLRequestContextFactory::GetSystemGetter() { | 184 net::URLRequestContextGetter* URLRequestContextFactory::GetSystemGetter() { |
183 if (!system_getter_.get()) { | 185 if (!system_getter_.get()) { |
(...skipping 22 matching lines...) Expand all Loading... |
206 transport_security_state_.reset(new net::TransportSecurityState()); | 208 transport_security_state_.reset(new net::TransportSecurityState()); |
207 http_auth_handler_factory_ = | 209 http_auth_handler_factory_ = |
208 net::HttpAuthHandlerFactory::CreateDefault(host_resolver_.get()); | 210 net::HttpAuthHandlerFactory::CreateDefault(host_resolver_.get()); |
209 | 211 |
210 // TODO(lcwu): http://crbug.com/392352. For performance reasons, | 212 // TODO(lcwu): http://crbug.com/392352. For performance reasons, |
211 // a persistent (on-disk) HttpServerProperties might be desirable | 213 // a persistent (on-disk) HttpServerProperties might be desirable |
212 // in the future. | 214 // in the future. |
213 http_server_properties_.reset(new net::HttpServerPropertiesImpl); | 215 http_server_properties_.reset(new net::HttpServerPropertiesImpl); |
214 | 216 |
215 proxy_service_ = net::ProxyService::CreateUsingSystemProxyResolver( | 217 proxy_service_ = net::ProxyService::CreateUsingSystemProxyResolver( |
216 proxy_config_service_.Pass(), 0, NULL); | 218 std::move(proxy_config_service_), 0, NULL); |
217 system_dependencies_initialized_ = true; | 219 system_dependencies_initialized_ = true; |
218 } | 220 } |
219 | 221 |
220 void URLRequestContextFactory::InitializeMainContextDependencies( | 222 void URLRequestContextFactory::InitializeMainContextDependencies( |
221 net::HttpTransactionFactory* transaction_factory, | 223 net::HttpTransactionFactory* transaction_factory, |
222 content::ProtocolHandlerMap* protocol_handlers, | 224 content::ProtocolHandlerMap* protocol_handlers, |
223 content::URLRequestInterceptorScopedVector request_interceptors) { | 225 content::URLRequestInterceptorScopedVector request_interceptors) { |
224 if (main_dependencies_initialized_) | 226 if (main_dependencies_initialized_) |
225 return; | 227 return; |
226 | 228 |
(...skipping 19 matching lines...) Expand all Loading... |
246 set_protocol = job_factory->SetProtocolHandler( | 248 set_protocol = job_factory->SetProtocolHandler( |
247 url::kFileScheme, | 249 url::kFileScheme, |
248 make_scoped_ptr(new net::FileProtocolHandler( | 250 make_scoped_ptr(new net::FileProtocolHandler( |
249 content::BrowserThread::GetBlockingPool() | 251 content::BrowserThread::GetBlockingPool() |
250 ->GetTaskRunnerWithShutdownBehavior( | 252 ->GetTaskRunnerWithShutdownBehavior( |
251 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)))); | 253 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)))); |
252 DCHECK(set_protocol); | 254 DCHECK(set_protocol); |
253 } | 255 } |
254 | 256 |
255 // Set up interceptors in the reverse order. | 257 // Set up interceptors in the reverse order. |
256 scoped_ptr<net::URLRequestJobFactory> top_job_factory = job_factory.Pass(); | 258 scoped_ptr<net::URLRequestJobFactory> top_job_factory = |
| 259 std::move(job_factory); |
257 for (content::URLRequestInterceptorScopedVector::reverse_iterator i = | 260 for (content::URLRequestInterceptorScopedVector::reverse_iterator i = |
258 request_interceptors.rbegin(); | 261 request_interceptors.rbegin(); |
259 i != request_interceptors.rend(); | 262 i != request_interceptors.rend(); |
260 ++i) { | 263 ++i) { |
261 top_job_factory.reset(new net::URLRequestInterceptingJobFactory( | 264 top_job_factory.reset(new net::URLRequestInterceptingJobFactory( |
262 top_job_factory.Pass(), make_scoped_ptr(*i))); | 265 std::move(top_job_factory), make_scoped_ptr(*i))); |
263 } | 266 } |
264 request_interceptors.weak_clear(); | 267 request_interceptors.weak_clear(); |
265 | 268 |
266 main_job_factory_.reset(top_job_factory.release()); | 269 main_job_factory_.reset(top_job_factory.release()); |
267 | 270 |
268 main_dependencies_initialized_ = true; | 271 main_dependencies_initialized_ = true; |
269 } | 272 } |
270 | 273 |
271 void URLRequestContextFactory::InitializeMediaContextDependencies( | 274 void URLRequestContextFactory::InitializeMediaContextDependencies( |
272 net::HttpTransactionFactory* transaction_factory) { | 275 net::HttpTransactionFactory* transaction_factory) { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | 363 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
361 if (cmd_line->HasSwitch(switches::kIgnoreCertificateErrors)) { | 364 if (cmd_line->HasSwitch(switches::kIgnoreCertificateErrors)) { |
362 ignore_certificate_errors = true; | 365 ignore_certificate_errors = true; |
363 } | 366 } |
364 net::HttpNetworkSession::Params network_session_params; | 367 net::HttpNetworkSession::Params network_session_params; |
365 PopulateNetworkSessionParams(ignore_certificate_errors, | 368 PopulateNetworkSessionParams(ignore_certificate_errors, |
366 &network_session_params); | 369 &network_session_params); |
367 InitializeMainContextDependencies( | 370 InitializeMainContextDependencies( |
368 new net::HttpNetworkLayer( | 371 new net::HttpNetworkLayer( |
369 new net::HttpNetworkSession(network_session_params)), | 372 new net::HttpNetworkSession(network_session_params)), |
370 protocol_handlers, | 373 protocol_handlers, std::move(request_interceptors)); |
371 request_interceptors.Pass()); | |
372 | 374 |
373 content::CookieStoreConfig cookie_config( | 375 content::CookieStoreConfig cookie_config( |
374 browser_context->GetPath().Append(kCookieStoreFile), | 376 browser_context->GetPath().Append(kCookieStoreFile), |
375 content::CookieStoreConfig::PERSISTANT_SESSION_COOKIES, | 377 content::CookieStoreConfig::PERSISTANT_SESSION_COOKIES, |
376 NULL, NULL); | 378 NULL, NULL); |
377 cookie_config.background_task_runner = | 379 cookie_config.background_task_runner = |
378 scoped_refptr<base::SequencedTaskRunner>(); | 380 scoped_refptr<base::SequencedTaskRunner>(); |
379 scoped_refptr<net::CookieStore> cookie_store = | 381 scoped_refptr<net::CookieStore> cookie_store = |
380 content::CreateCookieStore(cookie_config); | 382 content::CreateCookieStore(cookie_config); |
381 | 383 |
(...skipping 22 matching lines...) Expand all Loading... |
404 | 406 |
405 void URLRequestContextFactory::InitializeNetworkDelegates() { | 407 void URLRequestContextFactory::InitializeNetworkDelegates() { |
406 app_network_delegate_->Initialize(false); | 408 app_network_delegate_->Initialize(false); |
407 LOG(INFO) << "Initialized app network delegate."; | 409 LOG(INFO) << "Initialized app network delegate."; |
408 system_network_delegate_->Initialize(false); | 410 system_network_delegate_->Initialize(false); |
409 LOG(INFO) << "Initialized system network delegate."; | 411 LOG(INFO) << "Initialized system network delegate."; |
410 } | 412 } |
411 | 413 |
412 } // namespace shell | 414 } // namespace shell |
413 } // namespace chromecast | 415 } // namespace chromecast |
OLD | NEW |