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 "chrome/browser/profiles/profile_impl_io_data.h" | 5 #include "chrome/browser/profiles/profile_impl_io_data.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 } | 65 } |
66 | 66 |
67 // Clean up all isolated app request contexts. | 67 // Clean up all isolated app request contexts. |
68 for (ChromeURLRequestContextGetterMap::iterator iter = | 68 for (ChromeURLRequestContextGetterMap::iterator iter = |
69 app_request_context_getter_map_.begin(); | 69 app_request_context_getter_map_.begin(); |
70 iter != app_request_context_getter_map_.end(); | 70 iter != app_request_context_getter_map_.end(); |
71 ++iter) { | 71 ++iter) { |
72 iter->second->CleanupOnUIThread(); | 72 iter->second->CleanupOnUIThread(); |
73 } | 73 } |
74 | 74 |
| 75 // Clean up all isolated media request contexts. |
| 76 for (ChromeURLRequestContextGetterMap::iterator iter = |
| 77 isolated_media_request_context_getter_map_.begin(); |
| 78 iter != isolated_media_request_context_getter_map_.end(); |
| 79 ++iter) { |
| 80 iter->second->CleanupOnUIThread(); |
| 81 } |
| 82 |
75 if (io_data_->http_server_properties_manager()) | 83 if (io_data_->http_server_properties_manager()) |
76 io_data_->http_server_properties_manager()->ShutdownOnUIThread(); | 84 io_data_->http_server_properties_manager()->ShutdownOnUIThread(); |
77 io_data_->ShutdownOnUIThread(); | 85 io_data_->ShutdownOnUIThread(); |
78 } | 86 } |
79 | 87 |
80 void ProfileImplIOData::Handle::Init( | 88 void ProfileImplIOData::Handle::Init( |
81 const FilePath& cookie_path, | 89 const FilePath& cookie_path, |
82 const FilePath& server_bound_cert_path, | 90 const FilePath& server_bound_cert_path, |
83 const FilePath& cache_path, | 91 const FilePath& cache_path, |
84 int cache_max_size, | 92 int cache_max_size, |
(...skipping 17 matching lines...) Expand all Loading... |
102 lazy_params->cache_path = cache_path; | 110 lazy_params->cache_path = cache_path; |
103 lazy_params->cache_max_size = cache_max_size; | 111 lazy_params->cache_max_size = cache_max_size; |
104 lazy_params->media_cache_path = media_cache_path; | 112 lazy_params->media_cache_path = media_cache_path; |
105 lazy_params->media_cache_max_size = media_cache_max_size; | 113 lazy_params->media_cache_max_size = media_cache_max_size; |
106 lazy_params->extensions_cookie_path = extensions_cookie_path; | 114 lazy_params->extensions_cookie_path = extensions_cookie_path; |
107 lazy_params->restore_old_session_cookies = restore_old_session_cookies; | 115 lazy_params->restore_old_session_cookies = restore_old_session_cookies; |
108 lazy_params->special_storage_policy = special_storage_policy; | 116 lazy_params->special_storage_policy = special_storage_policy; |
109 | 117 |
110 io_data_->lazy_params_.reset(lazy_params); | 118 io_data_->lazy_params_.reset(lazy_params); |
111 | 119 |
112 // Keep track of isolated app path separately so we can use it on demand. | 120 // Keep track of isolated app path and cache sizes separately so we can use |
| 121 // them on demand. |
113 io_data_->app_path_ = app_path; | 122 io_data_->app_path_ = app_path; |
| 123 io_data_->app_cache_max_size_ = cache_max_size; |
| 124 io_data_->app_media_cache_max_size_ = media_cache_max_size; |
114 | 125 |
115 io_data_->predictor_.reset(predictor); | 126 io_data_->predictor_.reset(predictor); |
116 | 127 |
117 if (!main_request_context_getter_) { | 128 if (!main_request_context_getter_) { |
118 main_request_context_getter_ = | 129 main_request_context_getter_ = |
119 ChromeURLRequestContextGetter::CreateOriginal( | 130 ChromeURLRequestContextGetter::CreateOriginal( |
120 profile_, io_data_); | 131 profile_, io_data_); |
121 } | 132 } |
122 io_data_->predictor_->InitNetworkPredictor(profile_->GetPrefs(), | 133 io_data_->predictor_->InitNetworkPredictor(profile_->GetPrefs(), |
123 local_state, | 134 local_state, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 ChromeURLRequestContextGetter::CreateOriginalForExtensions( | 200 ChromeURLRequestContextGetter::CreateOriginalForExtensions( |
190 profile_, io_data_); | 201 profile_, io_data_); |
191 } | 202 } |
192 return extensions_request_context_getter_; | 203 return extensions_request_context_getter_; |
193 } | 204 } |
194 | 205 |
195 scoped_refptr<ChromeURLRequestContextGetter> | 206 scoped_refptr<ChromeURLRequestContextGetter> |
196 ProfileImplIOData::Handle::GetIsolatedAppRequestContextGetter( | 207 ProfileImplIOData::Handle::GetIsolatedAppRequestContextGetter( |
197 const std::string& app_id) const { | 208 const std::string& app_id) const { |
198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
199 DCHECK(!app_id.empty()); | 210 CHECK(!app_id.empty()); |
200 LazyInitialize(); | 211 LazyInitialize(); |
201 | 212 |
202 // Keep a map of request context getters, one per requested app ID. | 213 // Keep a map of request context getters, one per requested app ID. |
203 ChromeURLRequestContextGetterMap::iterator iter = | 214 ChromeURLRequestContextGetterMap::iterator iter = |
204 app_request_context_getter_map_.find(app_id); | 215 app_request_context_getter_map_.find(app_id); |
205 if (iter != app_request_context_getter_map_.end()) | 216 if (iter != app_request_context_getter_map_.end()) |
206 return iter->second; | 217 return iter->second; |
207 | 218 |
208 ChromeURLRequestContextGetter* context = | 219 ChromeURLRequestContextGetter* context = |
209 ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp( | 220 ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp( |
210 profile_, io_data_, app_id); | 221 profile_, io_data_, app_id); |
211 app_request_context_getter_map_[app_id] = context; | 222 app_request_context_getter_map_[app_id] = context; |
212 | 223 |
213 return context; | 224 return context; |
214 } | 225 } |
215 | 226 |
| 227 scoped_refptr<ChromeURLRequestContextGetter> |
| 228 ProfileImplIOData::Handle::GetIsolatedMediaRequestContextGetter( |
| 229 const std::string& app_id) const { |
| 230 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 231 // We must have an app ID, or this will act like the default media context. |
| 232 CHECK(!app_id.empty()); |
| 233 LazyInitialize(); |
| 234 |
| 235 // Keep a map of request context getters, one per requested app ID. |
| 236 ChromeURLRequestContextGetterMap::iterator iter = |
| 237 isolated_media_request_context_getter_map_.find(app_id); |
| 238 if (iter != isolated_media_request_context_getter_map_.end()) |
| 239 return iter->second; |
| 240 |
| 241 ChromeURLRequestContextGetter* context = |
| 242 ChromeURLRequestContextGetter::CreateOriginalForIsolatedMedia( |
| 243 profile_, io_data_, app_id); |
| 244 isolated_media_request_context_getter_map_[app_id] = context; |
| 245 |
| 246 return context; |
| 247 } |
| 248 |
216 void ProfileImplIOData::Handle::ClearNetworkingHistorySince( | 249 void ProfileImplIOData::Handle::ClearNetworkingHistorySince( |
217 base::Time time) { | 250 base::Time time) { |
218 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 251 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
219 LazyInitialize(); | 252 LazyInitialize(); |
220 | 253 |
221 BrowserThread::PostTask( | 254 BrowserThread::PostTask( |
222 BrowserThread::IO, FROM_HERE, | 255 BrowserThread::IO, FROM_HERE, |
223 base::Bind( | 256 base::Bind( |
224 &ProfileImplIOData::ClearNetworkingHistorySinceOnIOThread, | 257 &ProfileImplIOData::ClearNetworkingHistorySinceOnIOThread, |
225 base::Unretained(io_data_), | 258 base::Unretained(io_data_), |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 DestroyResourceContext(); | 295 DestroyResourceContext(); |
263 | 296 |
264 if (media_request_context_.get()) | 297 if (media_request_context_.get()) |
265 media_request_context_->AssertNoURLRequests(); | 298 media_request_context_->AssertNoURLRequests(); |
266 } | 299 } |
267 | 300 |
268 void ProfileImplIOData::LazyInitializeInternal( | 301 void ProfileImplIOData::LazyInitializeInternal( |
269 ProfileParams* profile_params) const { | 302 ProfileParams* profile_params) const { |
270 ChromeURLRequestContext* main_context = main_request_context(); | 303 ChromeURLRequestContext* main_context = main_request_context(); |
271 ChromeURLRequestContext* extensions_context = extensions_request_context(); | 304 ChromeURLRequestContext* extensions_context = extensions_request_context(); |
272 media_request_context_.reset(new ChromeURLRequestContext( | |
273 ChromeURLRequestContext::CONTEXT_TYPE_MEDIA, load_time_stats())); | |
274 | 305 |
275 IOThread* const io_thread = profile_params->io_thread; | 306 IOThread* const io_thread = profile_params->io_thread; |
276 IOThread::Globals* const io_thread_globals = io_thread->globals(); | 307 IOThread::Globals* const io_thread_globals = io_thread->globals(); |
277 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 308 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
278 // Only allow Record Mode if we are in a Debug build or where we are running | 309 // Only allow Record Mode if we are in a Debug build or where we are running |
279 // a cycle, and the user has limited control. | 310 // a cycle, and the user has limited control. |
280 bool record_mode = command_line.HasSwitch(switches::kRecordMode) && | 311 bool record_mode = command_line.HasSwitch(switches::kRecordMode) && |
281 (chrome::kRecordModeEnabled || | 312 (chrome::kRecordModeEnabled || |
282 command_line.HasSwitch(switches::kVisitURLs)); | 313 command_line.HasSwitch(switches::kVisitURLs)); |
283 bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode); | 314 bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode); |
284 | 315 |
285 // Initialize context members. | 316 // Initialize context members. |
286 | 317 |
287 ApplyProfileParamsToContext(main_context); | 318 ApplyProfileParamsToContext(main_context); |
288 ApplyProfileParamsToContext(media_request_context_.get()); | |
289 ApplyProfileParamsToContext(extensions_context); | 319 ApplyProfileParamsToContext(extensions_context); |
290 | 320 |
291 if (http_server_properties_manager()) | 321 if (http_server_properties_manager()) |
292 http_server_properties_manager()->InitializeOnIOThread(); | 322 http_server_properties_manager()->InitializeOnIOThread(); |
293 | 323 |
294 main_context->set_transport_security_state(transport_security_state()); | 324 main_context->set_transport_security_state(transport_security_state()); |
295 media_request_context_->set_transport_security_state( | |
296 transport_security_state()); | |
297 extensions_context->set_transport_security_state(transport_security_state()); | 325 extensions_context->set_transport_security_state(transport_security_state()); |
298 | 326 |
299 main_context->set_net_log(io_thread->net_log()); | 327 main_context->set_net_log(io_thread->net_log()); |
300 media_request_context_->set_net_log(io_thread->net_log()); | |
301 extensions_context->set_net_log(io_thread->net_log()); | 328 extensions_context->set_net_log(io_thread->net_log()); |
302 | 329 |
303 main_context->set_network_delegate(network_delegate()); | 330 main_context->set_network_delegate(network_delegate()); |
304 media_request_context_->set_network_delegate(network_delegate()); | |
305 | 331 |
306 main_context->set_http_server_properties(http_server_properties_manager()); | 332 main_context->set_http_server_properties(http_server_properties_manager()); |
307 media_request_context_->set_http_server_properties( | |
308 http_server_properties_manager()); | |
309 | 333 |
310 main_context->set_host_resolver( | 334 main_context->set_host_resolver( |
311 io_thread_globals->host_resolver.get()); | 335 io_thread_globals->host_resolver.get()); |
312 media_request_context_->set_host_resolver( | |
313 io_thread_globals->host_resolver.get()); | |
314 main_context->set_cert_verifier( | 336 main_context->set_cert_verifier( |
315 io_thread_globals->cert_verifier.get()); | 337 io_thread_globals->cert_verifier.get()); |
316 media_request_context_->set_cert_verifier( | |
317 io_thread_globals->cert_verifier.get()); | |
318 main_context->set_http_auth_handler_factory( | 338 main_context->set_http_auth_handler_factory( |
319 io_thread_globals->http_auth_handler_factory.get()); | 339 io_thread_globals->http_auth_handler_factory.get()); |
320 media_request_context_->set_http_auth_handler_factory( | |
321 io_thread_globals->http_auth_handler_factory.get()); | |
322 | 340 |
323 main_context->set_fraudulent_certificate_reporter( | 341 main_context->set_fraudulent_certificate_reporter( |
324 fraudulent_certificate_reporter()); | 342 fraudulent_certificate_reporter()); |
325 media_request_context_->set_fraudulent_certificate_reporter( | |
326 fraudulent_certificate_reporter()); | |
327 | 343 |
328 main_context->set_throttler_manager( | 344 main_context->set_throttler_manager( |
329 io_thread_globals->throttler_manager.get()); | 345 io_thread_globals->throttler_manager.get()); |
330 media_request_context_->set_throttler_manager( | |
331 io_thread_globals->throttler_manager.get()); | |
332 extensions_context->set_throttler_manager( | 346 extensions_context->set_throttler_manager( |
333 io_thread_globals->throttler_manager.get()); | 347 io_thread_globals->throttler_manager.get()); |
334 | 348 |
335 main_context->set_proxy_service(proxy_service()); | 349 main_context->set_proxy_service(proxy_service()); |
336 media_request_context_->set_proxy_service(proxy_service()); | |
337 | 350 |
338 scoped_refptr<net::CookieStore> cookie_store = NULL; | 351 scoped_refptr<net::CookieStore> cookie_store = NULL; |
339 net::ServerBoundCertService* server_bound_cert_service = NULL; | 352 net::ServerBoundCertService* server_bound_cert_service = NULL; |
340 if (record_mode || playback_mode) { | 353 if (record_mode || playback_mode) { |
341 // Don't use existing cookies and use an in-memory store. | 354 // Don't use existing cookies and use an in-memory store. |
342 cookie_store = new net::CookieMonster( | 355 cookie_store = new net::CookieMonster( |
343 NULL, profile_params->cookie_monster_delegate); | 356 NULL, profile_params->cookie_monster_delegate); |
344 // Don't use existing server-bound certs and use an in-memory store. | 357 // Don't use existing server-bound certs and use an in-memory store. |
345 server_bound_cert_service = new net::ServerBoundCertService( | 358 server_bound_cert_service = new net::ServerBoundCertService( |
346 new net::DefaultServerBoundCertStore(NULL), | 359 new net::DefaultServerBoundCertStore(NULL), |
(...skipping 19 matching lines...) Expand all Loading... |
366 new net::CookieMonster( | 379 new net::CookieMonster( |
367 new SQLitePersistentCookieStore( | 380 new SQLitePersistentCookieStore( |
368 lazy_params_->extensions_cookie_path, | 381 lazy_params_->extensions_cookie_path, |
369 lazy_params_->restore_old_session_cookies, NULL), NULL); | 382 lazy_params_->restore_old_session_cookies, NULL), NULL); |
370 // Enable cookies for devtools and extension URLs. | 383 // Enable cookies for devtools and extension URLs. |
371 const char* schemes[] = {chrome::kChromeDevToolsScheme, | 384 const char* schemes[] = {chrome::kChromeDevToolsScheme, |
372 chrome::kExtensionScheme}; | 385 chrome::kExtensionScheme}; |
373 extensions_cookie_store->SetCookieableSchemes(schemes, 2); | 386 extensions_cookie_store->SetCookieableSchemes(schemes, 2); |
374 | 387 |
375 main_context->set_cookie_store(cookie_store); | 388 main_context->set_cookie_store(cookie_store); |
376 media_request_context_->set_cookie_store(cookie_store); | |
377 extensions_context->set_cookie_store(extensions_cookie_store); | 389 extensions_context->set_cookie_store(extensions_cookie_store); |
378 | 390 |
379 // Setup server bound cert service. | 391 // Setup server bound cert service. |
380 if (!server_bound_cert_service) { | 392 if (!server_bound_cert_service) { |
381 DCHECK(!lazy_params_->server_bound_cert_path.empty()); | 393 DCHECK(!lazy_params_->server_bound_cert_path.empty()); |
382 | 394 |
383 scoped_refptr<SQLiteServerBoundCertStore> server_bound_cert_db = | 395 scoped_refptr<SQLiteServerBoundCertStore> server_bound_cert_db = |
384 new SQLiteServerBoundCertStore( | 396 new SQLiteServerBoundCertStore( |
385 lazy_params_->server_bound_cert_path, | 397 lazy_params_->server_bound_cert_path, |
386 new ClearOnExitPolicy(lazy_params_->special_storage_policy)); | 398 new ClearOnExitPolicy(lazy_params_->special_storage_policy)); |
387 server_bound_cert_service = new net::ServerBoundCertService( | 399 server_bound_cert_service = new net::ServerBoundCertService( |
388 new net::DefaultServerBoundCertStore(server_bound_cert_db.get()), | 400 new net::DefaultServerBoundCertStore(server_bound_cert_db.get()), |
389 base::WorkerPool::GetTaskRunner(true)); | 401 base::WorkerPool::GetTaskRunner(true)); |
390 } | 402 } |
391 | 403 |
392 set_server_bound_cert_service(server_bound_cert_service); | 404 set_server_bound_cert_service(server_bound_cert_service); |
393 main_context->set_server_bound_cert_service(server_bound_cert_service); | 405 main_context->set_server_bound_cert_service(server_bound_cert_service); |
394 media_request_context_->set_server_bound_cert_service( | |
395 server_bound_cert_service); | |
396 | 406 |
397 std::string trusted_spdy_proxy; | 407 std::string trusted_spdy_proxy; |
398 if (command_line.HasSwitch(switches::kTrustedSpdyProxy)) { | 408 if (command_line.HasSwitch(switches::kTrustedSpdyProxy)) { |
399 trusted_spdy_proxy = command_line.GetSwitchValueASCII( | 409 trusted_spdy_proxy = command_line.GetSwitchValueASCII( |
400 switches::kTrustedSpdyProxy); | 410 switches::kTrustedSpdyProxy); |
401 } | 411 } |
402 net::HttpCache::DefaultBackend* main_backend = | 412 net::HttpCache::DefaultBackend* main_backend = |
403 new net::HttpCache::DefaultBackend( | 413 new net::HttpCache::DefaultBackend( |
404 net::DISK_CACHE, | 414 net::DISK_CACHE, |
405 lazy_params_->cache_path, | 415 lazy_params_->cache_path, |
406 lazy_params_->cache_max_size, | 416 lazy_params_->cache_max_size, |
407 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); | 417 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); |
408 net::HttpCache* main_cache = new net::HttpCache( | 418 net::HttpCache* main_cache = new net::HttpCache( |
409 main_context->host_resolver(), | 419 main_context->host_resolver(), |
410 main_context->cert_verifier(), | 420 main_context->cert_verifier(), |
411 main_context->server_bound_cert_service(), | 421 main_context->server_bound_cert_service(), |
412 main_context->transport_security_state(), | 422 main_context->transport_security_state(), |
413 main_context->proxy_service(), | 423 main_context->proxy_service(), |
414 GetSSLSessionCacheShard(), | 424 GetSSLSessionCacheShard(), |
415 main_context->ssl_config_service(), | 425 main_context->ssl_config_service(), |
416 main_context->http_auth_handler_factory(), | 426 main_context->http_auth_handler_factory(), |
417 main_context->network_delegate(), | 427 main_context->network_delegate(), |
418 main_context->http_server_properties(), | 428 main_context->http_server_properties(), |
419 main_context->net_log(), | 429 main_context->net_log(), |
420 main_backend, | 430 main_backend, |
421 trusted_spdy_proxy); | 431 trusted_spdy_proxy); |
422 | 432 |
423 net::HttpCache::DefaultBackend* media_backend = | |
424 new net::HttpCache::DefaultBackend( | |
425 net::MEDIA_CACHE, lazy_params_->media_cache_path, | |
426 lazy_params_->media_cache_max_size, | |
427 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); | |
428 net::HttpNetworkSession* main_network_session = main_cache->GetSession(); | |
429 net::HttpCache* media_cache = | |
430 new net::HttpCache(main_network_session, media_backend); | |
431 | |
432 if (record_mode || playback_mode) { | 433 if (record_mode || playback_mode) { |
433 main_cache->set_mode( | 434 main_cache->set_mode( |
434 record_mode ? net::HttpCache::RECORD : net::HttpCache::PLAYBACK); | 435 record_mode ? net::HttpCache::RECORD : net::HttpCache::PLAYBACK); |
435 } | 436 } |
436 | 437 |
437 main_http_factory_.reset(main_cache); | 438 main_http_factory_.reset(main_cache); |
438 media_http_factory_.reset(media_cache); | |
439 main_context->set_http_transaction_factory(main_cache); | 439 main_context->set_http_transaction_factory(main_cache); |
440 media_request_context_->set_http_transaction_factory(media_cache); | |
441 | 440 |
442 ftp_factory_.reset( | 441 ftp_factory_.reset( |
443 new net::FtpNetworkLayer(io_thread_globals->host_resolver.get())); | 442 new net::FtpNetworkLayer(io_thread_globals->host_resolver.get())); |
444 main_context->set_ftp_transaction_factory(ftp_factory_.get()); | 443 main_context->set_ftp_transaction_factory(ftp_factory_.get()); |
445 media_request_context_->set_ftp_transaction_factory(ftp_factory_.get()); | |
446 | 444 |
447 main_context->set_chrome_url_data_manager_backend( | 445 main_context->set_chrome_url_data_manager_backend( |
448 chrome_url_data_manager_backend()); | 446 chrome_url_data_manager_backend()); |
449 | 447 |
| 448 // Create a media request context based on the main context, but using a |
| 449 // media cache. |
| 450 media_request_context_.reset(InitializeMediaRequestContext(main_context, "")); |
| 451 |
450 main_job_factory_.reset(new net::URLRequestJobFactory); | 452 main_job_factory_.reset(new net::URLRequestJobFactory); |
451 media_request_job_factory_.reset(new net::URLRequestJobFactory); | 453 media_request_job_factory_.reset(new net::URLRequestJobFactory); |
452 extensions_job_factory_.reset(new net::URLRequestJobFactory); | 454 extensions_job_factory_.reset(new net::URLRequestJobFactory); |
453 | 455 |
454 int set_protocol = main_job_factory_->SetProtocolHandler( | 456 int set_protocol = main_job_factory_->SetProtocolHandler( |
455 chrome::kFileScheme, new net::FileProtocolHandler(network_delegate())); | 457 chrome::kFileScheme, new net::FileProtocolHandler(network_delegate())); |
456 DCHECK(set_protocol); | 458 DCHECK(set_protocol); |
457 set_protocol = media_request_job_factory_->SetProtocolHandler( | 459 set_protocol = media_request_job_factory_->SetProtocolHandler( |
458 chrome::kFileScheme, new net::FileProtocolHandler(network_delegate())); | 460 chrome::kFileScheme, new net::FileProtocolHandler(network_delegate())); |
459 DCHECK(set_protocol); | 461 DCHECK(set_protocol); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 media_request_context_->set_job_factory(media_request_job_factory_.get()); | 503 media_request_context_->set_job_factory(media_request_job_factory_.get()); |
502 extensions_context->set_job_factory(extensions_job_factory_.get()); | 504 extensions_context->set_job_factory(extensions_job_factory_.get()); |
503 | 505 |
504 lazy_params_.reset(); | 506 lazy_params_.reset(); |
505 } | 507 } |
506 | 508 |
507 ChromeURLRequestContext* | 509 ChromeURLRequestContext* |
508 ProfileImplIOData::InitializeAppRequestContext( | 510 ProfileImplIOData::InitializeAppRequestContext( |
509 ChromeURLRequestContext* main_context, | 511 ChromeURLRequestContext* main_context, |
510 const std::string& app_id) const { | 512 const std::string& app_id) const { |
511 AppRequestContext* context = new AppRequestContext(load_time_stats()); | |
512 | |
513 // If this is for a guest process, we should not persist cookies and http | 513 // If this is for a guest process, we should not persist cookies and http |
514 // cache. | 514 // cache. |
515 bool guest_process = (app_id.find("guest-") != std::string::npos); | 515 bool is_guest_process = (app_id.find("guest-") != std::string::npos); |
516 | 516 |
517 // Copy most state from the main context. | 517 // Copy most state from the main context. |
| 518 AppRequestContext* context = new AppRequestContext(load_time_stats()); |
518 context->CopyFrom(main_context); | 519 context->CopyFrom(main_context); |
519 | 520 |
520 FilePath app_path = app_path_.AppendASCII(app_id); | 521 FilePath app_path = app_path_.AppendASCII(app_id); |
521 FilePath cookie_path = app_path.Append(chrome::kCookieFilename); | 522 FilePath cookie_path = app_path.Append(chrome::kCookieFilename); |
522 FilePath cache_path = app_path.Append(chrome::kCacheDirname); | 523 FilePath cache_path = app_path.Append(chrome::kCacheDirname); |
523 // TODO(creis): Determine correct cache size. | |
524 int cache_max_size = 0; | |
525 | 524 |
526 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 525 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
527 // Only allow Record Mode if we are in a Debug build or where we are running | 526 // Only allow Record Mode if we are in a Debug build or where we are running |
528 // a cycle, and the user has limited control. | 527 // a cycle, and the user has limited control. |
529 bool record_mode = command_line.HasSwitch(switches::kRecordMode) && | 528 bool record_mode = command_line.HasSwitch(switches::kRecordMode) && |
530 (chrome::kRecordModeEnabled || | 529 (chrome::kRecordModeEnabled || |
531 command_line.HasSwitch(switches::kVisitURLs)); | 530 command_line.HasSwitch(switches::kVisitURLs)); |
532 bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode); | 531 bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode); |
533 | 532 |
534 // Use a separate HTTP disk cache for isolated apps. | 533 // Use a separate HTTP disk cache for isolated apps. |
535 net::HttpCache::BackendFactory* app_backend = NULL; | 534 net::HttpCache::BackendFactory* app_backend = NULL; |
536 if (guest_process) { | 535 if (is_guest_process) { |
537 app_backend = net::HttpCache::DefaultBackend::InMemory(0); | 536 app_backend = net::HttpCache::DefaultBackend::InMemory(0); |
538 } else { | 537 } else { |
539 app_backend = new net::HttpCache::DefaultBackend( | 538 app_backend = new net::HttpCache::DefaultBackend( |
540 net::DISK_CACHE, | 539 net::DISK_CACHE, |
541 cache_path, | 540 cache_path, |
542 cache_max_size, | 541 app_cache_max_size_, |
543 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); | 542 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); |
544 } | 543 } |
545 net::HttpNetworkSession* main_network_session = | 544 net::HttpNetworkSession* main_network_session = |
546 main_http_factory_->GetSession(); | 545 main_http_factory_->GetSession(); |
547 net::HttpCache* app_http_cache = | 546 net::HttpCache* app_http_cache = |
548 new net::HttpCache(main_network_session, app_backend); | 547 new net::HttpCache(main_network_session, app_backend); |
549 | 548 |
550 scoped_refptr<net::CookieStore> cookie_store = NULL; | 549 scoped_refptr<net::CookieStore> cookie_store = NULL; |
551 if (guest_process) { | 550 if (is_guest_process) { |
552 cookie_store = new net::CookieMonster(NULL, NULL); | 551 cookie_store = new net::CookieMonster(NULL, NULL); |
553 } else if (record_mode || playback_mode) { | 552 } else if (record_mode || playback_mode) { |
554 // Don't use existing cookies and use an in-memory store. | 553 // Don't use existing cookies and use an in-memory store. |
555 // TODO(creis): We should have a cookie delegate for notifying the cookie | 554 // TODO(creis): We should have a cookie delegate for notifying the cookie |
556 // extensions API, but we need to update it to understand isolated apps | 555 // extensions API, but we need to update it to understand isolated apps |
557 // first. | 556 // first. |
558 cookie_store = new net::CookieMonster(NULL, NULL); | 557 cookie_store = new net::CookieMonster(NULL, NULL); |
559 app_http_cache->set_mode( | 558 app_http_cache->set_mode( |
560 record_mode ? net::HttpCache::RECORD : net::HttpCache::PLAYBACK); | 559 record_mode ? net::HttpCache::RECORD : net::HttpCache::PLAYBACK); |
561 } | 560 } |
562 | 561 |
563 // Use an app-specific cookie store. | 562 // Use an app-specific cookie store. |
564 if (!cookie_store) { | 563 if (!cookie_store) { |
565 DCHECK(!cookie_path.empty()); | 564 DCHECK(!cookie_path.empty()); |
566 | 565 |
567 scoped_refptr<SQLitePersistentCookieStore> cookie_db = | 566 scoped_refptr<SQLitePersistentCookieStore> cookie_db = |
568 new SQLitePersistentCookieStore(cookie_path, false, NULL); | 567 new SQLitePersistentCookieStore(cookie_path, false, NULL); |
569 // TODO(creis): We should have a cookie delegate for notifying the cookie | 568 // TODO(creis): We should have a cookie delegate for notifying the cookie |
570 // extensions API, but we need to update it to understand isolated apps | 569 // extensions API, but we need to update it to understand isolated apps |
571 // first. | 570 // first. |
572 cookie_store = new net::CookieMonster(cookie_db.get(), NULL); | 571 cookie_store = new net::CookieMonster(cookie_db.get(), NULL); |
573 } | 572 } |
574 | 573 |
| 574 // Transfer ownership of the cookies and cache to AppRequestContext. |
575 context->SetCookieStore(cookie_store); | 575 context->SetCookieStore(cookie_store); |
576 context->SetHttpTransactionFactory(app_http_cache); | 576 context->SetHttpTransactionFactory(app_http_cache); |
577 | 577 |
578 return context; | 578 return context; |
579 } | 579 } |
580 | 580 |
581 ChromeURLRequestContext* | 581 ChromeURLRequestContext* |
| 582 ProfileImplIOData::InitializeMediaRequestContext( |
| 583 ChromeURLRequestContext* original_context, |
| 584 const std::string& app_id) const { |
| 585 // If this is for a guest process, we do not persist storage, so we can |
| 586 // simply use the app's in-memory cache (like off-the-record mode). |
| 587 if (app_id.find("guest-") != std::string::npos) |
| 588 return original_context; |
| 589 |
| 590 // Copy most state from the original context. |
| 591 MediaRequestContext* context = new MediaRequestContext(load_time_stats()); |
| 592 context->CopyFrom(original_context); |
| 593 |
| 594 FilePath app_path = app_path_.AppendASCII(app_id); |
| 595 FilePath cache_path; |
| 596 int cache_max_size = app_media_cache_max_size_; |
| 597 if (app_id.empty()) { |
| 598 // lazy_params_ is only valid for the default media context creation. |
| 599 cache_path = lazy_params_->media_cache_path; |
| 600 cache_max_size = lazy_params_->media_cache_max_size; |
| 601 } else { |
| 602 cache_path = app_path.Append(chrome::kMediaCacheDirname); |
| 603 } |
| 604 |
| 605 // Use a separate HTTP disk cache for isolated apps. |
| 606 net::HttpCache::BackendFactory* media_backend = |
| 607 new net::HttpCache::DefaultBackend( |
| 608 net::MEDIA_CACHE, |
| 609 cache_path, |
| 610 cache_max_size, |
| 611 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); |
| 612 net::HttpNetworkSession* main_network_session = |
| 613 main_http_factory_->GetSession(); |
| 614 net::HttpCache* media_http_cache = |
| 615 new net::HttpCache(main_network_session, media_backend); |
| 616 |
| 617 // Transfer ownership of the cache to MediaRequestContext. |
| 618 context->SetHttpTransactionFactory(media_http_cache); |
| 619 |
| 620 return context; |
| 621 } |
| 622 |
| 623 ChromeURLRequestContext* |
582 ProfileImplIOData::AcquireMediaRequestContext() const { | 624 ProfileImplIOData::AcquireMediaRequestContext() const { |
583 DCHECK(media_request_context_.get()); | 625 DCHECK(media_request_context_.get()); |
584 return media_request_context_.get(); | 626 return media_request_context_.get(); |
585 } | 627 } |
586 | 628 |
587 ChromeURLRequestContext* | 629 ChromeURLRequestContext* |
588 ProfileImplIOData::AcquireIsolatedAppRequestContext( | 630 ProfileImplIOData::AcquireIsolatedAppRequestContext( |
589 ChromeURLRequestContext* main_context, | 631 ChromeURLRequestContext* main_context, |
590 const std::string& app_id) const { | 632 const std::string& app_id) const { |
591 // We create per-app contexts on demand, unlike the others above. | 633 // We create per-app contexts on demand, unlike the others above. |
592 ChromeURLRequestContext* app_request_context = | 634 ChromeURLRequestContext* app_request_context = |
593 InitializeAppRequestContext(main_context, app_id); | 635 InitializeAppRequestContext(main_context, app_id); |
594 DCHECK(app_request_context); | 636 DCHECK(app_request_context); |
595 return app_request_context; | 637 return app_request_context; |
596 } | 638 } |
597 | 639 |
| 640 ChromeURLRequestContext* |
| 641 ProfileImplIOData::AcquireIsolatedMediaRequestContext( |
| 642 ChromeURLRequestContext* app_context, |
| 643 const std::string& app_id) const { |
| 644 // We create per-app media contexts on demand, unlike the others above. |
| 645 ChromeURLRequestContext* media_request_context = |
| 646 InitializeMediaRequestContext(app_context, app_id); |
| 647 DCHECK(media_request_context); |
| 648 return media_request_context; |
| 649 } |
| 650 |
598 chrome_browser_net::LoadTimeStats* ProfileImplIOData::GetLoadTimeStats( | 651 chrome_browser_net::LoadTimeStats* ProfileImplIOData::GetLoadTimeStats( |
599 IOThread::Globals* io_thread_globals) const { | 652 IOThread::Globals* io_thread_globals) const { |
600 return io_thread_globals->load_time_stats.get(); | 653 return io_thread_globals->load_time_stats.get(); |
601 } | 654 } |
602 | 655 |
603 void ProfileImplIOData::CreateFtpProtocolHandler( | 656 void ProfileImplIOData::CreateFtpProtocolHandler( |
604 net::URLRequestJobFactory* job_factory, | 657 net::URLRequestJobFactory* job_factory, |
605 net::FtpAuthCache* ftp_auth_cache) const { | 658 net::FtpAuthCache* ftp_auth_cache) const { |
606 job_factory->SetProtocolHandler( | 659 job_factory->SetProtocolHandler( |
607 chrome::kFtpScheme, | 660 chrome::kFtpScheme, |
608 new net::FtpProtocolHandler(network_delegate(), | 661 new net::FtpProtocolHandler(network_delegate(), |
609 ftp_factory_.get(), | 662 ftp_factory_.get(), |
610 ftp_auth_cache)); | 663 ftp_auth_cache)); |
611 } | 664 } |
612 | 665 |
613 void ProfileImplIOData::ClearNetworkingHistorySinceOnIOThread( | 666 void ProfileImplIOData::ClearNetworkingHistorySinceOnIOThread( |
614 base::Time time) { | 667 base::Time time) { |
615 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 668 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
616 LazyInitialize(); | 669 LazyInitialize(); |
617 | 670 |
618 DCHECK(transport_security_state()); | 671 DCHECK(transport_security_state()); |
619 transport_security_state()->DeleteSince(time); | 672 transport_security_state()->DeleteSince(time); |
620 DCHECK(http_server_properties_manager()); | 673 DCHECK(http_server_properties_manager()); |
621 http_server_properties_manager()->Clear(); | 674 http_server_properties_manager()->Clear(); |
622 } | 675 } |
OLD | NEW |