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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 } | 63 } |
64 | 64 |
65 // Clean up all isolated app request contexts. | 65 // Clean up all isolated app request contexts. |
66 for (ChromeURLRequestContextGetterMap::iterator iter = | 66 for (ChromeURLRequestContextGetterMap::iterator iter = |
67 app_request_context_getter_map_.begin(); | 67 app_request_context_getter_map_.begin(); |
68 iter != app_request_context_getter_map_.end(); | 68 iter != app_request_context_getter_map_.end(); |
69 ++iter) { | 69 ++iter) { |
70 iter->second->CleanupOnUIThread(); | 70 iter->second->CleanupOnUIThread(); |
71 } | 71 } |
72 | 72 |
73 // Clean up all isolated media request contexts. | |
74 for (ChromeURLRequestContextGetterMap::iterator iter = | |
75 isolated_media_request_context_getter_map_.begin(); | |
76 iter != isolated_media_request_context_getter_map_.end(); | |
77 ++iter) { | |
78 iter->second->CleanupOnUIThread(); | |
79 } | |
80 | |
73 if (io_data_->http_server_properties_manager()) | 81 if (io_data_->http_server_properties_manager()) |
74 io_data_->http_server_properties_manager()->ShutdownOnUIThread(); | 82 io_data_->http_server_properties_manager()->ShutdownOnUIThread(); |
75 io_data_->ShutdownOnUIThread(); | 83 io_data_->ShutdownOnUIThread(); |
76 } | 84 } |
77 | 85 |
78 void ProfileImplIOData::Handle::Init( | 86 void ProfileImplIOData::Handle::Init( |
79 const FilePath& cookie_path, | 87 const FilePath& cookie_path, |
80 const FilePath& server_bound_cert_path, | 88 const FilePath& server_bound_cert_path, |
81 const FilePath& cache_path, | 89 const FilePath& cache_path, |
82 int cache_max_size, | 90 int cache_max_size, |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 return iter->second; | 212 return iter->second; |
205 | 213 |
206 ChromeURLRequestContextGetter* context = | 214 ChromeURLRequestContextGetter* context = |
207 ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp( | 215 ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp( |
208 profile_, io_data_, app_id); | 216 profile_, io_data_, app_id); |
209 app_request_context_getter_map_[app_id] = context; | 217 app_request_context_getter_map_[app_id] = context; |
210 | 218 |
211 return context; | 219 return context; |
212 } | 220 } |
213 | 221 |
222 scoped_refptr<ChromeURLRequestContextGetter> | |
223 ProfileImplIOData::Handle::GetIsolatedMediaRequestContextGetter( | |
224 const std::string& app_id) const { | |
225 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
226 DCHECK(!app_id.empty()); | |
awong
2012/08/17 18:23:16
What happens if app_id is empty? Will this work c
Charlie Reis
2012/08/17 21:04:38
Switched these to CHECKs. (Otherwise it would act
| |
227 LazyInitialize(); | |
228 | |
229 // Keep a map of request context getters, one per requested app ID. | |
230 ChromeURLRequestContextGetterMap::iterator iter = | |
231 isolated_media_request_context_getter_map_.find(app_id); | |
232 if (iter != isolated_media_request_context_getter_map_.end()) | |
233 return iter->second; | |
234 | |
235 ChromeURLRequestContextGetter* context = | |
236 ChromeURLRequestContextGetter::CreateOriginalForIsolatedMedia( | |
237 profile_, io_data_, app_id); | |
238 isolated_media_request_context_getter_map_[app_id] = context; | |
239 | |
240 return context; | |
241 } | |
242 | |
214 void ProfileImplIOData::Handle::ClearNetworkingHistorySince( | 243 void ProfileImplIOData::Handle::ClearNetworkingHistorySince( |
215 base::Time time) { | 244 base::Time time) { |
216 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 245 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
217 LazyInitialize(); | 246 LazyInitialize(); |
218 | 247 |
219 BrowserThread::PostTask( | 248 BrowserThread::PostTask( |
220 BrowserThread::IO, FROM_HERE, | 249 BrowserThread::IO, FROM_HERE, |
221 base::Bind( | 250 base::Bind( |
222 &ProfileImplIOData::ClearNetworkingHistorySinceOnIOThread, | 251 &ProfileImplIOData::ClearNetworkingHistorySinceOnIOThread, |
223 base::Unretained(io_data_), | 252 base::Unretained(io_data_), |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
260 DestroyResourceContext(); | 289 DestroyResourceContext(); |
261 | 290 |
262 if (media_request_context_.get()) | 291 if (media_request_context_.get()) |
263 media_request_context_->AssertNoURLRequests(); | 292 media_request_context_->AssertNoURLRequests(); |
264 } | 293 } |
265 | 294 |
266 void ProfileImplIOData::LazyInitializeInternal( | 295 void ProfileImplIOData::LazyInitializeInternal( |
267 ProfileParams* profile_params) const { | 296 ProfileParams* profile_params) const { |
268 ChromeURLRequestContext* main_context = main_request_context(); | 297 ChromeURLRequestContext* main_context = main_request_context(); |
269 ChromeURLRequestContext* extensions_context = extensions_request_context(); | 298 ChromeURLRequestContext* extensions_context = extensions_request_context(); |
270 media_request_context_.reset(new ChromeURLRequestContext( | |
271 ChromeURLRequestContext::CONTEXT_TYPE_MEDIA, cache_stats())); | |
272 | 299 |
273 IOThread* const io_thread = profile_params->io_thread; | 300 IOThread* const io_thread = profile_params->io_thread; |
274 IOThread::Globals* const io_thread_globals = io_thread->globals(); | 301 IOThread::Globals* const io_thread_globals = io_thread->globals(); |
275 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 302 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
276 // Only allow Record Mode if we are in a Debug build or where we are running | 303 // Only allow Record Mode if we are in a Debug build or where we are running |
277 // a cycle, and the user has limited control. | 304 // a cycle, and the user has limited control. |
278 bool record_mode = command_line.HasSwitch(switches::kRecordMode) && | 305 bool record_mode = command_line.HasSwitch(switches::kRecordMode) && |
279 (chrome::kRecordModeEnabled || | 306 (chrome::kRecordModeEnabled || |
280 command_line.HasSwitch(switches::kVisitURLs)); | 307 command_line.HasSwitch(switches::kVisitURLs)); |
281 bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode); | 308 bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode); |
282 | 309 |
283 // Initialize context members. | 310 // Initialize context members. |
284 | 311 |
285 ApplyProfileParamsToContext(main_context); | 312 ApplyProfileParamsToContext(main_context); |
286 ApplyProfileParamsToContext(media_request_context_.get()); | |
287 ApplyProfileParamsToContext(extensions_context); | 313 ApplyProfileParamsToContext(extensions_context); |
288 | 314 |
289 if (http_server_properties_manager()) | 315 if (http_server_properties_manager()) |
290 http_server_properties_manager()->InitializeOnIOThread(); | 316 http_server_properties_manager()->InitializeOnIOThread(); |
291 | 317 |
292 main_context->set_transport_security_state(transport_security_state()); | 318 main_context->set_transport_security_state(transport_security_state()); |
293 media_request_context_->set_transport_security_state( | |
294 transport_security_state()); | |
295 extensions_context->set_transport_security_state(transport_security_state()); | 319 extensions_context->set_transport_security_state(transport_security_state()); |
296 | 320 |
297 main_context->set_net_log(io_thread->net_log()); | 321 main_context->set_net_log(io_thread->net_log()); |
298 media_request_context_->set_net_log(io_thread->net_log()); | |
299 extensions_context->set_net_log(io_thread->net_log()); | 322 extensions_context->set_net_log(io_thread->net_log()); |
300 | 323 |
301 main_context->set_network_delegate(network_delegate()); | 324 main_context->set_network_delegate(network_delegate()); |
302 media_request_context_->set_network_delegate(network_delegate()); | |
303 | 325 |
304 main_context->set_http_server_properties(http_server_properties_manager()); | 326 main_context->set_http_server_properties(http_server_properties_manager()); |
305 media_request_context_->set_http_server_properties( | |
306 http_server_properties_manager()); | |
307 | 327 |
308 main_context->set_host_resolver( | 328 main_context->set_host_resolver( |
309 io_thread_globals->host_resolver.get()); | 329 io_thread_globals->host_resolver.get()); |
310 media_request_context_->set_host_resolver( | |
311 io_thread_globals->host_resolver.get()); | |
312 main_context->set_cert_verifier( | 330 main_context->set_cert_verifier( |
313 io_thread_globals->cert_verifier.get()); | 331 io_thread_globals->cert_verifier.get()); |
314 media_request_context_->set_cert_verifier( | |
315 io_thread_globals->cert_verifier.get()); | |
316 main_context->set_http_auth_handler_factory( | 332 main_context->set_http_auth_handler_factory( |
317 io_thread_globals->http_auth_handler_factory.get()); | 333 io_thread_globals->http_auth_handler_factory.get()); |
318 media_request_context_->set_http_auth_handler_factory( | |
319 io_thread_globals->http_auth_handler_factory.get()); | |
320 | 334 |
321 main_context->set_fraudulent_certificate_reporter( | 335 main_context->set_fraudulent_certificate_reporter( |
322 fraudulent_certificate_reporter()); | 336 fraudulent_certificate_reporter()); |
323 media_request_context_->set_fraudulent_certificate_reporter( | |
324 fraudulent_certificate_reporter()); | |
325 | 337 |
326 main_context->set_throttler_manager( | 338 main_context->set_throttler_manager( |
327 io_thread_globals->throttler_manager.get()); | 339 io_thread_globals->throttler_manager.get()); |
328 media_request_context_->set_throttler_manager( | |
329 io_thread_globals->throttler_manager.get()); | |
330 extensions_context->set_throttler_manager( | 340 extensions_context->set_throttler_manager( |
331 io_thread_globals->throttler_manager.get()); | 341 io_thread_globals->throttler_manager.get()); |
332 | 342 |
333 main_context->set_proxy_service(proxy_service()); | 343 main_context->set_proxy_service(proxy_service()); |
334 media_request_context_->set_proxy_service(proxy_service()); | |
335 | 344 |
336 scoped_refptr<net::CookieStore> cookie_store = NULL; | 345 scoped_refptr<net::CookieStore> cookie_store = NULL; |
337 net::ServerBoundCertService* server_bound_cert_service = NULL; | 346 net::ServerBoundCertService* server_bound_cert_service = NULL; |
338 if (record_mode || playback_mode) { | 347 if (record_mode || playback_mode) { |
339 // Don't use existing cookies and use an in-memory store. | 348 // Don't use existing cookies and use an in-memory store. |
340 cookie_store = new net::CookieMonster( | 349 cookie_store = new net::CookieMonster( |
341 NULL, profile_params->cookie_monster_delegate); | 350 NULL, profile_params->cookie_monster_delegate); |
342 // Don't use existing server-bound certs and use an in-memory store. | 351 // Don't use existing server-bound certs and use an in-memory store. |
343 server_bound_cert_service = new net::ServerBoundCertService( | 352 server_bound_cert_service = new net::ServerBoundCertService( |
344 new net::DefaultServerBoundCertStore(NULL), | 353 new net::DefaultServerBoundCertStore(NULL), |
(...skipping 19 matching lines...) Expand all Loading... | |
364 new net::CookieMonster( | 373 new net::CookieMonster( |
365 new SQLitePersistentCookieStore( | 374 new SQLitePersistentCookieStore( |
366 lazy_params_->extensions_cookie_path, | 375 lazy_params_->extensions_cookie_path, |
367 lazy_params_->restore_old_session_cookies, NULL), NULL); | 376 lazy_params_->restore_old_session_cookies, NULL), NULL); |
368 // Enable cookies for devtools and extension URLs. | 377 // Enable cookies for devtools and extension URLs. |
369 const char* schemes[] = {chrome::kChromeDevToolsScheme, | 378 const char* schemes[] = {chrome::kChromeDevToolsScheme, |
370 chrome::kExtensionScheme}; | 379 chrome::kExtensionScheme}; |
371 extensions_cookie_store->SetCookieableSchemes(schemes, 2); | 380 extensions_cookie_store->SetCookieableSchemes(schemes, 2); |
372 | 381 |
373 main_context->set_cookie_store(cookie_store); | 382 main_context->set_cookie_store(cookie_store); |
374 media_request_context_->set_cookie_store(cookie_store); | |
375 extensions_context->set_cookie_store(extensions_cookie_store); | 383 extensions_context->set_cookie_store(extensions_cookie_store); |
376 | 384 |
377 // Setup server bound cert service. | 385 // Setup server bound cert service. |
378 if (!server_bound_cert_service) { | 386 if (!server_bound_cert_service) { |
379 DCHECK(!lazy_params_->server_bound_cert_path.empty()); | 387 DCHECK(!lazy_params_->server_bound_cert_path.empty()); |
380 | 388 |
381 scoped_refptr<SQLiteServerBoundCertStore> server_bound_cert_db = | 389 scoped_refptr<SQLiteServerBoundCertStore> server_bound_cert_db = |
382 new SQLiteServerBoundCertStore( | 390 new SQLiteServerBoundCertStore( |
383 lazy_params_->server_bound_cert_path, | 391 lazy_params_->server_bound_cert_path, |
384 new ClearOnExitPolicy(lazy_params_->special_storage_policy)); | 392 new ClearOnExitPolicy(lazy_params_->special_storage_policy)); |
385 server_bound_cert_service = new net::ServerBoundCertService( | 393 server_bound_cert_service = new net::ServerBoundCertService( |
386 new net::DefaultServerBoundCertStore(server_bound_cert_db.get()), | 394 new net::DefaultServerBoundCertStore(server_bound_cert_db.get()), |
387 base::WorkerPool::GetTaskRunner(true)); | 395 base::WorkerPool::GetTaskRunner(true)); |
388 } | 396 } |
389 | 397 |
390 set_server_bound_cert_service(server_bound_cert_service); | 398 set_server_bound_cert_service(server_bound_cert_service); |
391 main_context->set_server_bound_cert_service(server_bound_cert_service); | 399 main_context->set_server_bound_cert_service(server_bound_cert_service); |
392 media_request_context_->set_server_bound_cert_service( | |
393 server_bound_cert_service); | |
394 | 400 |
395 std::string trusted_spdy_proxy; | 401 std::string trusted_spdy_proxy; |
396 if (command_line.HasSwitch(switches::kTrustedSpdyProxy)) { | 402 if (command_line.HasSwitch(switches::kTrustedSpdyProxy)) { |
397 trusted_spdy_proxy = command_line.GetSwitchValueASCII( | 403 trusted_spdy_proxy = command_line.GetSwitchValueASCII( |
398 switches::kTrustedSpdyProxy); | 404 switches::kTrustedSpdyProxy); |
399 } | 405 } |
400 net::HttpCache::DefaultBackend* main_backend = | 406 net::HttpCache::DefaultBackend* main_backend = |
401 new net::HttpCache::DefaultBackend( | 407 new net::HttpCache::DefaultBackend( |
402 net::DISK_CACHE, | 408 net::DISK_CACHE, |
403 lazy_params_->cache_path, | 409 lazy_params_->cache_path, |
404 lazy_params_->cache_max_size, | 410 lazy_params_->cache_max_size, |
405 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); | 411 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); |
406 net::HttpCache* main_cache = new net::HttpCache( | 412 net::HttpCache* main_cache = new net::HttpCache( |
407 main_context->host_resolver(), | 413 main_context->host_resolver(), |
408 main_context->cert_verifier(), | 414 main_context->cert_verifier(), |
409 main_context->server_bound_cert_service(), | 415 main_context->server_bound_cert_service(), |
410 main_context->transport_security_state(), | 416 main_context->transport_security_state(), |
411 main_context->proxy_service(), | 417 main_context->proxy_service(), |
412 GetSSLSessionCacheShard(), | 418 GetSSLSessionCacheShard(), |
413 main_context->ssl_config_service(), | 419 main_context->ssl_config_service(), |
414 main_context->http_auth_handler_factory(), | 420 main_context->http_auth_handler_factory(), |
415 main_context->network_delegate(), | 421 main_context->network_delegate(), |
416 main_context->http_server_properties(), | 422 main_context->http_server_properties(), |
417 main_context->net_log(), | 423 main_context->net_log(), |
418 main_backend, | 424 main_backend, |
419 trusted_spdy_proxy); | 425 trusted_spdy_proxy); |
420 | 426 |
421 net::HttpCache::DefaultBackend* media_backend = | |
422 new net::HttpCache::DefaultBackend( | |
423 net::MEDIA_CACHE, lazy_params_->media_cache_path, | |
424 lazy_params_->media_cache_max_size, | |
425 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); | |
426 net::HttpNetworkSession* main_network_session = main_cache->GetSession(); | |
427 net::HttpCache* media_cache = | |
428 new net::HttpCache(main_network_session, media_backend); | |
429 | |
430 if (record_mode || playback_mode) { | 427 if (record_mode || playback_mode) { |
431 main_cache->set_mode( | 428 main_cache->set_mode( |
432 record_mode ? net::HttpCache::RECORD : net::HttpCache::PLAYBACK); | 429 record_mode ? net::HttpCache::RECORD : net::HttpCache::PLAYBACK); |
433 } | 430 } |
434 | 431 |
435 main_http_factory_.reset(main_cache); | 432 main_http_factory_.reset(main_cache); |
436 media_http_factory_.reset(media_cache); | |
437 main_context->set_http_transaction_factory(main_cache); | 433 main_context->set_http_transaction_factory(main_cache); |
438 media_request_context_->set_http_transaction_factory(media_cache); | |
439 | 434 |
440 ftp_factory_.reset( | 435 ftp_factory_.reset( |
441 new net::FtpNetworkLayer(io_thread_globals->host_resolver.get())); | 436 new net::FtpNetworkLayer(io_thread_globals->host_resolver.get())); |
442 main_context->set_ftp_transaction_factory(ftp_factory_.get()); | 437 main_context->set_ftp_transaction_factory(ftp_factory_.get()); |
443 media_request_context_->set_ftp_transaction_factory(ftp_factory_.get()); | |
444 | 438 |
445 main_context->set_chrome_url_data_manager_backend( | 439 main_context->set_chrome_url_data_manager_backend( |
446 chrome_url_data_manager_backend()); | 440 chrome_url_data_manager_backend()); |
447 | 441 |
442 // Create a media request context based on the main context, but using a | |
443 // media cache. | |
444 media_request_context_.reset(InitializeMediaRequestContext(main_context, "")); | |
445 | |
446 // TODO(creis): Ensure these job factories get created for isolated app and | |
447 // isolated media request contexts. | |
448 main_job_factory_.reset(new net::URLRequestJobFactory); | 448 main_job_factory_.reset(new net::URLRequestJobFactory); |
449 media_request_job_factory_.reset(new net::URLRequestJobFactory); | 449 media_request_job_factory_.reset(new net::URLRequestJobFactory); |
450 extensions_job_factory_.reset(new net::URLRequestJobFactory); | 450 extensions_job_factory_.reset(new net::URLRequestJobFactory); |
451 | 451 |
452 net::URLRequestJobFactory* job_factories[3]; | 452 net::URLRequestJobFactory* job_factories[3]; |
453 job_factories[0] = main_job_factory_.get(); | 453 job_factories[0] = main_job_factory_.get(); |
454 job_factories[1] = media_request_job_factory_.get(); | 454 job_factories[1] = media_request_job_factory_.get(); |
455 job_factories[2] = extensions_job_factory_.get(); | 455 job_factories[2] = extensions_job_factory_.get(); |
456 | 456 |
457 net::FtpAuthCache* ftp_auth_caches[3]; | 457 net::FtpAuthCache* ftp_auth_caches[3]; |
(...skipping 12 matching lines...) Expand all Loading... | |
470 media_request_context_->set_job_factory(media_request_job_factory_.get()); | 470 media_request_context_->set_job_factory(media_request_job_factory_.get()); |
471 extensions_context->set_job_factory(extensions_job_factory_.get()); | 471 extensions_context->set_job_factory(extensions_job_factory_.get()); |
472 | 472 |
473 lazy_params_.reset(); | 473 lazy_params_.reset(); |
474 } | 474 } |
475 | 475 |
476 ChromeURLRequestContext* | 476 ChromeURLRequestContext* |
477 ProfileImplIOData::InitializeAppRequestContext( | 477 ProfileImplIOData::InitializeAppRequestContext( |
478 ChromeURLRequestContext* main_context, | 478 ChromeURLRequestContext* main_context, |
479 const std::string& app_id) const { | 479 const std::string& app_id) const { |
480 AppRequestContext* context = new AppRequestContext(cache_stats()); | |
481 | |
482 // If this is for a guest process, we should not persist cookies and http | 480 // If this is for a guest process, we should not persist cookies and http |
483 // cache. | 481 // cache. |
484 bool guest_process = (app_id.find("guest-") != std::string::npos); | 482 bool is_guest_process = (app_id.find("guest-") != std::string::npos); |
485 | 483 |
486 // Copy most state from the main context. | 484 // Copy most state from the main context. |
485 AppRequestContext* context = new AppRequestContext(cache_stats()); | |
487 context->CopyFrom(main_context); | 486 context->CopyFrom(main_context); |
488 | 487 |
489 FilePath app_path = app_path_.AppendASCII(app_id); | 488 FilePath app_path = app_path_.AppendASCII(app_id); |
490 FilePath cookie_path = app_path.Append(chrome::kCookieFilename); | 489 FilePath cookie_path = app_path.Append(chrome::kCookieFilename); |
491 FilePath cache_path = app_path.Append(chrome::kCacheDirname); | 490 FilePath cache_path = app_path.Append(chrome::kCacheDirname); |
492 // TODO(creis): Determine correct cache size. | 491 // TODO(creis): Determine correct cache size. |
493 int cache_max_size = 0; | 492 int cache_max_size = 0; |
494 | 493 |
495 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 494 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
496 // Only allow Record Mode if we are in a Debug build or where we are running | 495 // Only allow Record Mode if we are in a Debug build or where we are running |
497 // a cycle, and the user has limited control. | 496 // a cycle, and the user has limited control. |
498 bool record_mode = command_line.HasSwitch(switches::kRecordMode) && | 497 bool record_mode = command_line.HasSwitch(switches::kRecordMode) && |
499 (chrome::kRecordModeEnabled || | 498 (chrome::kRecordModeEnabled || |
500 command_line.HasSwitch(switches::kVisitURLs)); | 499 command_line.HasSwitch(switches::kVisitURLs)); |
501 bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode); | 500 bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode); |
502 | 501 |
503 // Use a separate HTTP disk cache for isolated apps. | 502 // Use a separate HTTP disk cache for isolated apps. |
504 net::HttpCache::BackendFactory* app_backend = NULL; | 503 net::HttpCache::BackendFactory* app_backend = NULL; |
505 if (guest_process) { | 504 if (is_guest_process) { |
506 app_backend = net::HttpCache::DefaultBackend::InMemory(0); | 505 app_backend = net::HttpCache::DefaultBackend::InMemory(0); |
507 } else { | 506 } else { |
508 app_backend = new net::HttpCache::DefaultBackend( | 507 app_backend = new net::HttpCache::DefaultBackend( |
509 net::DISK_CACHE, | 508 net::DISK_CACHE, |
510 cache_path, | 509 cache_path, |
511 cache_max_size, | 510 cache_max_size, |
512 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); | 511 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); |
513 } | 512 } |
514 net::HttpNetworkSession* main_network_session = | 513 net::HttpNetworkSession* main_network_session = |
515 main_http_factory_->GetSession(); | 514 main_http_factory_->GetSession(); |
516 net::HttpCache* app_http_cache = | 515 net::HttpCache* app_http_cache = |
517 new net::HttpCache(main_network_session, app_backend); | 516 new net::HttpCache(main_network_session, app_backend); |
518 | 517 |
519 scoped_refptr<net::CookieStore> cookie_store = NULL; | 518 scoped_refptr<net::CookieStore> cookie_store = NULL; |
520 if (guest_process) { | 519 if (is_guest_process) { |
521 cookie_store = new net::CookieMonster(NULL, NULL); | 520 cookie_store = new net::CookieMonster(NULL, NULL); |
522 } else if (record_mode || playback_mode) { | 521 } else if (record_mode || playback_mode) { |
523 // Don't use existing cookies and use an in-memory store. | 522 // Don't use existing cookies and use an in-memory store. |
524 // TODO(creis): We should have a cookie delegate for notifying the cookie | 523 // TODO(creis): We should have a cookie delegate for notifying the cookie |
525 // extensions API, but we need to update it to understand isolated apps | 524 // extensions API, but we need to update it to understand isolated apps |
526 // first. | 525 // first. |
527 cookie_store = new net::CookieMonster(NULL, NULL); | 526 cookie_store = new net::CookieMonster(NULL, NULL); |
528 app_http_cache->set_mode( | 527 app_http_cache->set_mode( |
529 record_mode ? net::HttpCache::RECORD : net::HttpCache::PLAYBACK); | 528 record_mode ? net::HttpCache::RECORD : net::HttpCache::PLAYBACK); |
530 } | 529 } |
531 | 530 |
532 // Use an app-specific cookie store. | 531 // Use an app-specific cookie store. |
533 if (!cookie_store) { | 532 if (!cookie_store) { |
534 DCHECK(!cookie_path.empty()); | 533 DCHECK(!cookie_path.empty()); |
535 | 534 |
536 scoped_refptr<SQLitePersistentCookieStore> cookie_db = | 535 scoped_refptr<SQLitePersistentCookieStore> cookie_db = |
537 new SQLitePersistentCookieStore(cookie_path, false, NULL); | 536 new SQLitePersistentCookieStore(cookie_path, false, NULL); |
538 // TODO(creis): We should have a cookie delegate for notifying the cookie | 537 // TODO(creis): We should have a cookie delegate for notifying the cookie |
539 // extensions API, but we need to update it to understand isolated apps | 538 // extensions API, but we need to update it to understand isolated apps |
540 // first. | 539 // first. |
541 cookie_store = new net::CookieMonster(cookie_db.get(), NULL); | 540 cookie_store = new net::CookieMonster(cookie_db.get(), NULL); |
542 } | 541 } |
543 | 542 |
543 // Transfer ownership of the cookies and cache to AppRequestContext. | |
544 context->SetCookieStore(cookie_store); | 544 context->SetCookieStore(cookie_store); |
545 context->SetHttpTransactionFactory(app_http_cache); | 545 context->SetHttpTransactionFactory(app_http_cache); |
546 | 546 |
547 // TODO(creis): This is missing the job factory initialization from | |
548 // LazyInitializeInternal. | |
awong
2012/08/17 18:23:16
I'm unclear on the implications of this TODO as we
Charlie Reis
2012/08/17 21:04:38
Looks like we at least copy the existing job facto
| |
549 | |
547 return context; | 550 return context; |
548 } | 551 } |
549 | 552 |
553 ChromeURLRequestContext* | |
554 ProfileImplIOData::InitializeMediaRequestContext( | |
555 ChromeURLRequestContext* original_context, | |
556 const std::string& app_id) const { | |
557 // If this is for a guest process, we do not persist storage, so we can | |
558 // simply use the app's in-memory cache (like off-the-record mode). | |
559 if (app_id.find("guest-") != std::string::npos) | |
560 return original_context; | |
561 | |
562 // Copy most state from the original context. | |
563 MediaRequestContext* context = new MediaRequestContext(cache_stats()); | |
564 context->CopyFrom(original_context); | |
565 | |
566 FilePath app_path = app_path_.AppendASCII(app_id); | |
567 FilePath cache_path; | |
568 // TODO(creis): Determine correct cache size to use for isolated media. | |
awong
2012/08/17 18:23:16
File bug?
Charlie Reis
2012/08/17 21:04:38
Fixed instead, similar to how we handle app_path_.
| |
569 int cache_max_size = 0; | |
570 if (app_id.empty()) { | |
571 cache_path = lazy_params_->media_cache_path; | |
572 cache_max_size = lazy_params_->media_cache_max_size; | |
573 } else { | |
574 cache_path = app_path.Append(chrome::kMediaCacheDirname); | |
575 } | |
576 | |
577 // Use a separate HTTP disk cache for isolated apps. | |
578 net::HttpCache::BackendFactory* media_backend = | |
579 new net::HttpCache::DefaultBackend( | |
580 net::MEDIA_CACHE, | |
581 cache_path, | |
582 cache_max_size, | |
583 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); | |
584 net::HttpNetworkSession* main_network_session = | |
585 main_http_factory_->GetSession(); | |
586 net::HttpCache* media_http_cache = | |
587 new net::HttpCache(main_network_session, media_backend); | |
588 | |
589 // Transfer ownership of the cache to MediaRequestContext. | |
590 context->SetHttpTransactionFactory(media_http_cache); | |
591 | |
592 // TODO(creis): This is missing the job factory initialization from | |
593 // LazyInitializeInternal. | |
594 | |
595 return context; | |
596 } | |
597 | |
550 ChromeURLRequestContext* | 598 ChromeURLRequestContext* |
551 ProfileImplIOData::AcquireMediaRequestContext() const { | 599 ProfileImplIOData::AcquireMediaRequestContext() const { |
552 DCHECK(media_request_context_.get()); | 600 DCHECK(media_request_context_.get()); |
553 return media_request_context_.get(); | 601 return media_request_context_.get(); |
554 } | 602 } |
555 | 603 |
556 ChromeURLRequestContext* | 604 ChromeURLRequestContext* |
557 ProfileImplIOData::AcquireIsolatedAppRequestContext( | 605 ProfileImplIOData::AcquireIsolatedAppRequestContext( |
558 ChromeURLRequestContext* main_context, | 606 ChromeURLRequestContext* main_context, |
559 const std::string& app_id) const { | 607 const std::string& app_id) const { |
560 // We create per-app contexts on demand, unlike the others above. | 608 // We create per-app contexts on demand, unlike the others above. |
561 ChromeURLRequestContext* app_request_context = | 609 ChromeURLRequestContext* app_request_context = |
562 InitializeAppRequestContext(main_context, app_id); | 610 InitializeAppRequestContext(main_context, app_id); |
563 DCHECK(app_request_context); | 611 DCHECK(app_request_context); |
564 return app_request_context; | 612 return app_request_context; |
565 } | 613 } |
566 | 614 |
615 ChromeURLRequestContext* | |
616 ProfileImplIOData::AcquireIsolatedMediaRequestContext( | |
617 ChromeURLRequestContext* app_context, | |
618 const std::string& app_id) const { | |
619 // We create per-app media contexts on demand, unlike the others above. | |
620 ChromeURLRequestContext* media_request_context = | |
621 InitializeMediaRequestContext(app_context, app_id); | |
622 DCHECK(media_request_context); | |
623 return media_request_context; | |
624 } | |
625 | |
567 chrome_browser_net::CacheStats* ProfileImplIOData::GetCacheStats( | 626 chrome_browser_net::CacheStats* ProfileImplIOData::GetCacheStats( |
568 IOThread::Globals* io_thread_globals) const { | 627 IOThread::Globals* io_thread_globals) const { |
569 return io_thread_globals->cache_stats.get(); | 628 return io_thread_globals->cache_stats.get(); |
570 } | 629 } |
571 | 630 |
572 void ProfileImplIOData::CreateFtpProtocolHandler( | 631 void ProfileImplIOData::CreateFtpProtocolHandler( |
573 net::URLRequestJobFactory* job_factory, | 632 net::URLRequestJobFactory* job_factory, |
574 net::FtpAuthCache* ftp_auth_cache) const { | 633 net::FtpAuthCache* ftp_auth_cache) const { |
575 job_factory->SetProtocolHandler( | 634 job_factory->SetProtocolHandler( |
576 chrome::kFtpScheme, | 635 chrome::kFtpScheme, |
577 new net::FtpProtocolHandler(network_delegate(), | 636 new net::FtpProtocolHandler(network_delegate(), |
578 ftp_factory_.get(), | 637 ftp_factory_.get(), |
579 ftp_auth_cache)); | 638 ftp_auth_cache)); |
580 } | 639 } |
581 | 640 |
582 void ProfileImplIOData::ClearNetworkingHistorySinceOnIOThread( | 641 void ProfileImplIOData::ClearNetworkingHistorySinceOnIOThread( |
583 base::Time time) { | 642 base::Time time) { |
584 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 643 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
585 LazyInitialize(); | 644 LazyInitialize(); |
586 | 645 |
587 DCHECK(transport_security_state()); | 646 DCHECK(transport_security_state()); |
588 transport_security_state()->DeleteSince(time); | 647 transport_security_state()->DeleteSince(time); |
589 DCHECK(http_server_properties_manager()); | 648 DCHECK(http_server_properties_manager()); |
590 http_server_properties_manager()->Clear(); | 649 http_server_properties_manager()->Clear(); |
591 } | 650 } |
OLD | NEW |