Chromium Code Reviews| 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 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 436 chrome_url_data_manager_backend()); | 436 chrome_url_data_manager_backend()); |
| 437 | 437 |
| 438 // Create a media request context based on the main context, but using a | 438 // Create a media request context based on the main context, but using a |
| 439 // media cache. | 439 // media cache. |
| 440 media_request_context_.reset(InitializeMediaRequestContext(main_context, "")); | 440 media_request_context_.reset(InitializeMediaRequestContext(main_context, "")); |
| 441 | 441 |
| 442 main_job_factory_.reset(new net::URLRequestJobFactoryImpl); | 442 main_job_factory_.reset(new net::URLRequestJobFactoryImpl); |
| 443 media_request_job_factory_.reset(new net::URLRequestJobFactoryImpl); | 443 media_request_job_factory_.reset(new net::URLRequestJobFactoryImpl); |
| 444 extensions_job_factory_.reset(new net::URLRequestJobFactoryImpl); | 444 extensions_job_factory_.reset(new net::URLRequestJobFactoryImpl); |
| 445 | 445 |
| 446 int set_protocol = main_job_factory_->SetProtocolHandler( | 446 SetupJobFactory(main_job_factory_.get(), network_delegate(), |
| 447 chrome::kFileScheme, new net::FileProtocolHandler()); | 447 main_context->ftp_auth_cache()); |
| 448 DCHECK(set_protocol); | 448 SetupJobFactory(media_request_job_factory_.get(), network_delegate(), |
| 449 set_protocol = media_request_job_factory_->SetProtocolHandler( | 449 media_request_context_->ftp_auth_cache()); |
| 450 chrome::kFileScheme, new net::FileProtocolHandler()); | |
| 451 DCHECK(set_protocol); | |
| 452 // TODO(shalev): The extensions_job_factory has a NULL NetworkDelegate. | 450 // TODO(shalev): The extensions_job_factory has a NULL NetworkDelegate. |
| 453 // Without a network_delegate, this protocol handler will never | 451 // Without a network_delegate, this protocol handler will never |
| 454 // handle file: requests, but as a side effect it makes | 452 // handle file: requests, but as a side effect it makes |
| 455 // job_factory::IsHandledProtocol return true, which prevents attempts to | 453 // job_factory::IsHandledProtocol return true, which prevents attempts to |
| 456 // handle the protocol externally. | 454 // handle the protocol externally. We pass NULL in to SetupJobFactory to |
| 457 set_protocol = extensions_job_factory_->SetProtocolHandler( | 455 // get this effect. |
| 458 chrome::kFileScheme, new net::FileProtocolHandler()); | 456 SetupJobFactory(extensions_job_factory_.get(), NULL, |
| 459 DCHECK(set_protocol); | 457 extensions_context->ftp_auth_cache()); |
| 460 | |
| 461 set_protocol = main_job_factory_->SetProtocolHandler( | |
| 462 chrome::kChromeDevToolsScheme, | |
| 463 CreateDevToolsProtocolHandler(chrome_url_data_manager_backend(), | |
| 464 network_delegate())); | |
| 465 DCHECK(set_protocol); | |
| 466 set_protocol = media_request_job_factory_->SetProtocolHandler( | |
| 467 chrome::kChromeDevToolsScheme, | |
| 468 CreateDevToolsProtocolHandler(chrome_url_data_manager_backend(), | |
| 469 network_delegate())); | |
| 470 DCHECK(set_protocol); | |
| 471 set_protocol = extensions_job_factory_->SetProtocolHandler( | |
| 472 chrome::kChromeDevToolsScheme, | |
| 473 CreateDevToolsProtocolHandler(chrome_url_data_manager_backend(), NULL)); | |
| 474 DCHECK(set_protocol); | |
| 475 | |
| 476 net::URLRequestJobFactory* job_factories[3]; | |
| 477 job_factories[0] = main_job_factory_.get(); | |
| 478 job_factories[1] = media_request_job_factory_.get(); | |
| 479 job_factories[2] = extensions_job_factory_.get(); | |
| 480 | |
| 481 net::FtpAuthCache* ftp_auth_caches[3]; | |
| 482 ftp_auth_caches[0] = main_context->ftp_auth_cache(); | |
| 483 ftp_auth_caches[1] = media_request_context_->ftp_auth_cache(); | |
| 484 ftp_auth_caches[2] = extensions_context->ftp_auth_cache(); | |
| 485 | |
| 486 for (int i = 0; i < 3; i++) { | |
| 487 SetUpJobFactoryDefaults(job_factories[i]); | |
| 488 job_factories[i]->SetProtocolHandler(chrome::kAboutScheme, | |
| 489 new net::AboutProtocolHandler()); | |
| 490 CreateFtpProtocolHandler(job_factories[i], ftp_auth_caches[i]); | |
| 491 job_factories[i]->AddInterceptor( | |
| 492 new chrome_browser_net::ConnectInterceptor(predictor_.get())); | |
| 493 } | |
| 494 | 458 |
| 495 main_context->set_job_factory(main_job_factory_.get()); | 459 main_context->set_job_factory(main_job_factory_.get()); |
| 496 media_request_context_->set_job_factory(media_request_job_factory_.get()); | 460 media_request_context_->set_job_factory(media_request_job_factory_.get()); |
| 497 extensions_context->set_job_factory(extensions_job_factory_.get()); | 461 extensions_context->set_job_factory(extensions_job_factory_.get()); |
| 498 | 462 |
| 499 lazy_params_.reset(); | 463 lazy_params_.reset(); |
| 500 } | 464 } |
| 501 | 465 |
| 502 ChromeURLRequestContext* | 466 ChromeURLRequestContext* |
| 503 ProfileImplIOData::InitializeAppRequestContext( | 467 ProfileImplIOData::InitializeAppRequestContext( |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 562 scoped_refptr<SQLitePersistentCookieStore> cookie_db = | 526 scoped_refptr<SQLitePersistentCookieStore> cookie_db = |
| 563 new SQLitePersistentCookieStore(cookie_path, false, NULL); | 527 new SQLitePersistentCookieStore(cookie_path, false, NULL); |
| 564 // TODO(creis): We should have a cookie delegate for notifying the cookie | 528 // TODO(creis): We should have a cookie delegate for notifying the cookie |
| 565 // extensions API, but we need to update it to understand isolated apps | 529 // extensions API, but we need to update it to understand isolated apps |
| 566 // first. | 530 // first. |
| 567 cookie_store = new net::CookieMonster(cookie_db.get(), NULL); | 531 cookie_store = new net::CookieMonster(cookie_db.get(), NULL); |
| 568 } | 532 } |
| 569 | 533 |
| 570 // Transfer ownership of the cookies and cache to AppRequestContext. | 534 // Transfer ownership of the cookies and cache to AppRequestContext. |
| 571 context->SetCookieStore(cookie_store); | 535 context->SetCookieStore(cookie_store); |
| 572 context->SetHttpTransactionFactory(app_http_cache); | 536 context->SetHttpTransactionFactory( |
| 537 scoped_ptr<net::HttpTransactionFactory>(app_http_cache)); | |
| 538 | |
| 539 // Overwrite the job factory that we inherit from the main context so | |
| 540 // that we can later provide our own handles for storage related protocols. | |
| 541 scoped_ptr<net::URLRequestJobFactory> job_factory( | |
| 542 new net::URLRequestJobFactoryImpl()); | |
| 543 SetupJobFactory(job_factory.get(), network_delegate(), | |
| 544 context->ftp_auth_cache()); | |
| 545 context->SetJobFactory(job_factory.Pass()); | |
| 573 | 546 |
| 574 return context; | 547 return context; |
| 575 } | 548 } |
| 576 | 549 |
| 577 ChromeURLRequestContext* | 550 ChromeURLRequestContext* |
| 578 ProfileImplIOData::InitializeMediaRequestContext( | 551 ProfileImplIOData::InitializeMediaRequestContext( |
| 579 ChromeURLRequestContext* original_context, | 552 ChromeURLRequestContext* original_context, |
| 580 const std::string& app_id) const { | 553 const std::string& app_id) const { |
| 581 // If this is for a guest process, we do not persist storage, so we can | 554 // If this is for a guest process, we do not persist storage, so we can |
| 582 // simply use the app's in-memory cache (like off-the-record mode). | 555 // simply use the app's in-memory cache (like off-the-record mode). |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 602 | 575 |
| 603 // Use a separate HTTP disk cache for isolated apps. | 576 // Use a separate HTTP disk cache for isolated apps. |
| 604 net::HttpCache::BackendFactory* media_backend = | 577 net::HttpCache::BackendFactory* media_backend = |
| 605 new net::HttpCache::DefaultBackend( | 578 new net::HttpCache::DefaultBackend( |
| 606 net::MEDIA_CACHE, | 579 net::MEDIA_CACHE, |
| 607 cache_path, | 580 cache_path, |
| 608 cache_max_size, | 581 cache_max_size, |
| 609 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); | 582 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); |
| 610 net::HttpNetworkSession* main_network_session = | 583 net::HttpNetworkSession* main_network_session = |
| 611 main_http_factory_->GetSession(); | 584 main_http_factory_->GetSession(); |
| 612 net::HttpCache* media_http_cache = | 585 scoped_ptr<net::HttpTransactionFactory> media_http_cache( |
| 613 new net::HttpCache(main_network_session, media_backend); | 586 new net::HttpCache(main_network_session, media_backend)); |
| 614 | 587 |
| 615 // Transfer ownership of the cache to MediaRequestContext. | 588 // Transfer ownership of the cache to MediaRequestContext. |
| 616 context->SetHttpTransactionFactory(media_http_cache); | 589 context->SetHttpTransactionFactory(media_http_cache.Pass()); |
|
Charlie Reis
2012/09/20 17:47:03
Why don't we need to call SetupJobFactory here as
awong
2012/09/20 22:11:00
Because MediaRequestContext actually reuses the jo
| |
| 617 | 590 |
| 618 return context; | 591 return context; |
| 619 } | 592 } |
| 620 | 593 |
| 621 ChromeURLRequestContext* | 594 ChromeURLRequestContext* |
| 622 ProfileImplIOData::AcquireMediaRequestContext() const { | 595 ProfileImplIOData::AcquireMediaRequestContext() const { |
| 623 DCHECK(media_request_context_.get()); | 596 DCHECK(media_request_context_.get()); |
| 624 return media_request_context_.get(); | 597 return media_request_context_.get(); |
| 625 } | 598 } |
| 626 | 599 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 644 InitializeMediaRequestContext(app_context, app_id); | 617 InitializeMediaRequestContext(app_context, app_id); |
| 645 DCHECK(media_request_context); | 618 DCHECK(media_request_context); |
| 646 return media_request_context; | 619 return media_request_context; |
| 647 } | 620 } |
| 648 | 621 |
| 649 chrome_browser_net::LoadTimeStats* ProfileImplIOData::GetLoadTimeStats( | 622 chrome_browser_net::LoadTimeStats* ProfileImplIOData::GetLoadTimeStats( |
| 650 IOThread::Globals* io_thread_globals) const { | 623 IOThread::Globals* io_thread_globals) const { |
| 651 return io_thread_globals->load_time_stats.get(); | 624 return io_thread_globals->load_time_stats.get(); |
| 652 } | 625 } |
| 653 | 626 |
| 627 void ProfileImplIOData::SetupJobFactory( | |
| 628 net::URLRequestJobFactory* job_factory, | |
| 629 net::NetworkDelegate* network_delegate, | |
| 630 net::FtpAuthCache* ftp_auth_cache) const { | |
| 631 int set_protocol = job_factory->SetProtocolHandler( | |
| 632 chrome::kFileScheme, new net::FileProtocolHandler()); | |
| 633 DCHECK(set_protocol); | |
| 634 | |
| 635 set_protocol = job_factory->SetProtocolHandler( | |
| 636 chrome::kChromeDevToolsScheme, | |
| 637 CreateDevToolsProtocolHandler(chrome_url_data_manager_backend(), | |
| 638 network_delegate)); | |
| 639 DCHECK(set_protocol); | |
| 640 | |
| 641 SetUpJobFactoryDefaults(job_factory); | |
| 642 job_factory->SetProtocolHandler(chrome::kAboutScheme, | |
| 643 new net::AboutProtocolHandler()); | |
| 644 CreateFtpProtocolHandler(job_factory, ftp_auth_cache); | |
| 645 job_factory->AddInterceptor( | |
| 646 new chrome_browser_net::ConnectInterceptor(predictor_.get())); | |
| 647 } | |
| 648 | |
| 654 void ProfileImplIOData::CreateFtpProtocolHandler( | 649 void ProfileImplIOData::CreateFtpProtocolHandler( |
| 655 net::URLRequestJobFactory* job_factory, | 650 net::URLRequestJobFactory* job_factory, |
| 656 net::FtpAuthCache* ftp_auth_cache) const { | 651 net::FtpAuthCache* ftp_auth_cache) const { |
| 657 #if !defined(DISABLE_FTP_SUPPORT) | 652 #if !defined(DISABLE_FTP_SUPPORT) |
| 658 job_factory->SetProtocolHandler( | 653 job_factory->SetProtocolHandler( |
| 659 chrome::kFtpScheme, | 654 chrome::kFtpScheme, |
| 660 new net::FtpProtocolHandler(ftp_factory_.get(), | 655 new net::FtpProtocolHandler(ftp_factory_.get(), |
| 661 ftp_auth_cache)); | 656 ftp_auth_cache)); |
| 662 #endif // !defined(DISABLE_FTP_SUPPORT) | 657 #endif // !defined(DISABLE_FTP_SUPPORT) |
| 663 } | 658 } |
| 664 | 659 |
| 665 void ProfileImplIOData::ClearNetworkingHistorySinceOnIOThread( | 660 void ProfileImplIOData::ClearNetworkingHistorySinceOnIOThread( |
| 666 base::Time time) { | 661 base::Time time) { |
| 667 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 662 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 668 LazyInitialize(); | 663 LazyInitialize(); |
| 669 | 664 |
| 670 DCHECK(transport_security_state()); | 665 DCHECK(transport_security_state()); |
| 671 transport_security_state()->DeleteSince(time); | 666 transport_security_state()->DeleteSince(time); |
| 672 DCHECK(http_server_properties_manager()); | 667 DCHECK(http_server_properties_manager()); |
| 673 http_server_properties_manager()->Clear(); | 668 http_server_properties_manager()->Clear(); |
| 674 } | 669 } |
| OLD | NEW |