| 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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 CHECK(partition_path != profile_->GetPath()); | 195 CHECK(partition_path != profile_->GetPath()); |
| 196 LazyInitialize(); | 196 LazyInitialize(); |
| 197 | 197 |
| 198 // Keep a map of request context getters, one per requested storage partition. | 198 // Keep a map of request context getters, one per requested storage partition. |
| 199 StoragePartitionDescriptor descriptor(partition_path, in_memory); | 199 StoragePartitionDescriptor descriptor(partition_path, in_memory); |
| 200 ChromeURLRequestContextGetterMap::iterator iter = | 200 ChromeURLRequestContextGetterMap::iterator iter = |
| 201 app_request_context_getter_map_.find(descriptor); | 201 app_request_context_getter_map_.find(descriptor); |
| 202 if (iter != app_request_context_getter_map_.end()) | 202 if (iter != app_request_context_getter_map_.end()) |
| 203 return iter->second; | 203 return iter->second; |
| 204 | 204 |
| 205 scoped_ptr<net::URLRequestJobFactory::Interceptor> | 205 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> |
| 206 protocol_handler_interceptor( | 206 protocol_handler_interceptor( |
| 207 ProtocolHandlerRegistryFactory::GetForProfile(profile_)-> | 207 ProtocolHandlerRegistryFactory::GetForProfile(profile_)-> |
| 208 CreateURLInterceptor()); | 208 CreateJobInterceptorFactory()); |
| 209 ChromeURLRequestContextGetter* context = | 209 ChromeURLRequestContextGetter* context = |
| 210 ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp( | 210 ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp( |
| 211 profile_, io_data_, descriptor, | 211 profile_, io_data_, descriptor, |
| 212 protocol_handler_interceptor.Pass()); | 212 protocol_handler_interceptor.Pass()); |
| 213 app_request_context_getter_map_[descriptor] = context; | 213 app_request_context_getter_map_[descriptor] = context; |
| 214 | 214 |
| 215 return context; | 215 return context; |
| 216 } | 216 } |
| 217 | 217 |
| 218 scoped_refptr<ChromeURLRequestContextGetter> | 218 scoped_refptr<ChromeURLRequestContextGetter> |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 ftp_factory_.reset( | 416 ftp_factory_.reset( |
| 417 new net::FtpNetworkLayer(io_thread_globals->host_resolver.get())); | 417 new net::FtpNetworkLayer(io_thread_globals->host_resolver.get())); |
| 418 main_context->set_ftp_transaction_factory(ftp_factory_.get()); | 418 main_context->set_ftp_transaction_factory(ftp_factory_.get()); |
| 419 #endif // !defined(DISABLE_FTP_SUPPORT) | 419 #endif // !defined(DISABLE_FTP_SUPPORT) |
| 420 | 420 |
| 421 main_context->set_chrome_url_data_manager_backend( | 421 main_context->set_chrome_url_data_manager_backend( |
| 422 chrome_url_data_manager_backend()); | 422 chrome_url_data_manager_backend()); |
| 423 | 423 |
| 424 scoped_ptr<net::URLRequestJobFactoryImpl> main_job_factory( | 424 scoped_ptr<net::URLRequestJobFactoryImpl> main_job_factory( |
| 425 new net::URLRequestJobFactoryImpl()); | 425 new net::URLRequestJobFactoryImpl()); |
| 426 SetUpJobFactoryDefaults(main_job_factory.get(), | 426 main_job_factory_ = SetUpJobFactoryDefaults( |
| 427 profile_params->protocol_handler_interceptor.Pass(), | 427 main_job_factory.Pass(), |
| 428 network_delegate(), | 428 profile_params->protocol_handler_interceptor.Pass(), |
| 429 main_context->ftp_transaction_factory(), | 429 network_delegate(), |
| 430 main_context->ftp_auth_cache()); | 430 main_context->ftp_transaction_factory(), |
| 431 main_job_factory_ = main_job_factory.Pass(); | 431 main_context->ftp_auth_cache()); |
| 432 main_context->set_job_factory(main_job_factory_.get()); | 432 main_context->set_job_factory(main_job_factory_.get()); |
| 433 | 433 |
| 434 #if defined(ENABLE_EXTENSIONS) | 434 #if defined(ENABLE_EXTENSIONS) |
| 435 InitializeExtensionsRequestContext(profile_params); | 435 InitializeExtensionsRequestContext(profile_params); |
| 436 #endif | 436 #endif |
| 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. It shares the same job factory as the main context. | 439 // media cache. It shares the same job factory as the main context. |
| 440 StoragePartitionDescriptor details(profile_path_, false); | 440 StoragePartitionDescriptor details(profile_path_, false); |
| 441 media_request_context_.reset(InitializeMediaRequestContext(main_context, | 441 media_request_context_.reset(InitializeMediaRequestContext(main_context, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 #endif // !defined(DISABLE_FTP_SUPPORT) | 475 #endif // !defined(DISABLE_FTP_SUPPORT) |
| 476 | 476 |
| 477 scoped_ptr<net::URLRequestJobFactoryImpl> extensions_job_factory( | 477 scoped_ptr<net::URLRequestJobFactoryImpl> extensions_job_factory( |
| 478 new net::URLRequestJobFactoryImpl()); | 478 new net::URLRequestJobFactoryImpl()); |
| 479 // TODO(shalev): The extensions_job_factory has a NULL NetworkDelegate. | 479 // TODO(shalev): The extensions_job_factory has a NULL NetworkDelegate. |
| 480 // Without a network_delegate, this protocol handler will never | 480 // Without a network_delegate, this protocol handler will never |
| 481 // handle file: requests, but as a side effect it makes | 481 // handle file: requests, but as a side effect it makes |
| 482 // job_factory::IsHandledProtocol return true, which prevents attempts to | 482 // job_factory::IsHandledProtocol return true, which prevents attempts to |
| 483 // handle the protocol externally. We pass NULL in to | 483 // handle the protocol externally. We pass NULL in to |
| 484 // SetUpJobFactory() to get this effect. | 484 // SetUpJobFactory() to get this effect. |
| 485 SetUpJobFactoryDefaults( | 485 extensions_job_factory_ = SetUpJobFactoryDefaults( |
| 486 extensions_job_factory.get(), | 486 extensions_job_factory.Pass(), |
| 487 scoped_ptr<net::URLRequestJobFactoryImpl::Interceptor>(NULL), | 487 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>(NULL), |
| 488 NULL, | 488 NULL, |
| 489 extensions_context->ftp_transaction_factory(), | 489 extensions_context->ftp_transaction_factory(), |
| 490 extensions_context->ftp_auth_cache()); | 490 extensions_context->ftp_auth_cache()); |
| 491 extensions_job_factory_ = extensions_job_factory.Pass(); | |
| 492 extensions_context->set_job_factory(extensions_job_factory_.get()); | 491 extensions_context->set_job_factory(extensions_job_factory_.get()); |
| 493 } | 492 } |
| 494 | 493 |
| 495 ChromeURLRequestContext* | 494 ChromeURLRequestContext* |
| 496 ProfileImplIOData::InitializeAppRequestContext( | 495 ProfileImplIOData::InitializeAppRequestContext( |
| 497 ChromeURLRequestContext* main_context, | 496 ChromeURLRequestContext* main_context, |
| 498 const StoragePartitionDescriptor& partition_descriptor, | 497 const StoragePartitionDescriptor& partition_descriptor, |
| 499 scoped_ptr<net::URLRequestJobFactory::Interceptor> | 498 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> |
| 500 protocol_handler_interceptor) const { | 499 protocol_handler_interceptor) const { |
| 501 // Copy most state from the main context. | 500 // Copy most state from the main context. |
| 502 AppRequestContext* context = new AppRequestContext(load_time_stats()); | 501 AppRequestContext* context = new AppRequestContext(load_time_stats()); |
| 503 context->CopyFrom(main_context); | 502 context->CopyFrom(main_context); |
| 504 | 503 |
| 505 FilePath cookie_path = partition_descriptor.path.Append( | 504 FilePath cookie_path = partition_descriptor.path.Append( |
| 506 chrome::kCookieFilename); | 505 chrome::kCookieFilename); |
| 507 FilePath cache_path = partition_descriptor.path.Append(chrome::kCacheDirname); | 506 FilePath cache_path = partition_descriptor.path.Append(chrome::kCacheDirname); |
| 508 | 507 |
| 509 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 508 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 // extensions API, but we need to update it to understand isolated apps | 552 // extensions API, but we need to update it to understand isolated apps |
| 554 // first. | 553 // first. |
| 555 cookie_store = new net::CookieMonster(cookie_db.get(), NULL); | 554 cookie_store = new net::CookieMonster(cookie_db.get(), NULL); |
| 556 } | 555 } |
| 557 | 556 |
| 558 // Transfer ownership of the cookies and cache to AppRequestContext. | 557 // Transfer ownership of the cookies and cache to AppRequestContext. |
| 559 context->SetCookieStore(cookie_store); | 558 context->SetCookieStore(cookie_store); |
| 560 context->SetHttpTransactionFactory( | 559 context->SetHttpTransactionFactory( |
| 561 scoped_ptr<net::HttpTransactionFactory>(app_http_cache)); | 560 scoped_ptr<net::HttpTransactionFactory>(app_http_cache)); |
| 562 | 561 |
| 562 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( |
| 563 new net::URLRequestJobFactoryImpl()); |
| 564 scoped_ptr<net::URLRequestJobFactory> top_job_factory; |
| 563 // Overwrite the job factory that we inherit from the main context so | 565 // Overwrite the job factory that we inherit from the main context so |
| 564 // that we can later provide our own handlers for storage related protocols. | 566 // that we can later provide our own handlers for storage related protocols. |
| 565 // Install all the usual protocol handlers unless we are in a browser plugin | 567 // Install all the usual protocol handlers unless we are in a browser plugin |
| 566 // guest process, in which case only web-safe schemes are allowed. | 568 // guest process, in which case only web-safe schemes are allowed. |
| 567 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( | |
| 568 new net::URLRequestJobFactoryImpl()); | |
| 569 if (!partition_descriptor.in_memory) { | 569 if (!partition_descriptor.in_memory) { |
| 570 SetUpJobFactoryDefaults( | 570 top_job_factory = SetUpJobFactoryDefaults( |
| 571 job_factory.get(), protocol_handler_interceptor.Pass(), | 571 job_factory.Pass(), protocol_handler_interceptor.Pass(), |
| 572 network_delegate(), | 572 network_delegate(), |
| 573 context->ftp_transaction_factory(), | 573 context->ftp_transaction_factory(), |
| 574 context->ftp_auth_cache()); | 574 context->ftp_auth_cache()); |
| 575 } else { |
| 576 top_job_factory = job_factory.PassAs<net::URLRequestJobFactory>(); |
| 575 } | 577 } |
| 576 context->SetJobFactory(job_factory.PassAs<net::URLRequestJobFactory>()); | 578 context->SetJobFactory(top_job_factory.Pass()); |
| 577 | 579 |
| 578 return context; | 580 return context; |
| 579 } | 581 } |
| 580 | 582 |
| 581 ChromeURLRequestContext* | 583 ChromeURLRequestContext* |
| 582 ProfileImplIOData::InitializeMediaRequestContext( | 584 ProfileImplIOData::InitializeMediaRequestContext( |
| 583 ChromeURLRequestContext* original_context, | 585 ChromeURLRequestContext* original_context, |
| 584 const StoragePartitionDescriptor& partition_descriptor) const { | 586 const StoragePartitionDescriptor& partition_descriptor) const { |
| 585 // If this is for a in_memory partition, we can simply use the original | 587 // If this is for a in_memory partition, we can simply use the original |
| 586 // context (like off-the-record mode). | 588 // context (like off-the-record mode). |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 ChromeURLRequestContext* | 631 ChromeURLRequestContext* |
| 630 ProfileImplIOData::AcquireMediaRequestContext() const { | 632 ProfileImplIOData::AcquireMediaRequestContext() const { |
| 631 DCHECK(media_request_context_.get()); | 633 DCHECK(media_request_context_.get()); |
| 632 return media_request_context_.get(); | 634 return media_request_context_.get(); |
| 633 } | 635 } |
| 634 | 636 |
| 635 ChromeURLRequestContext* | 637 ChromeURLRequestContext* |
| 636 ProfileImplIOData::AcquireIsolatedAppRequestContext( | 638 ProfileImplIOData::AcquireIsolatedAppRequestContext( |
| 637 ChromeURLRequestContext* main_context, | 639 ChromeURLRequestContext* main_context, |
| 638 const StoragePartitionDescriptor& partition_descriptor, | 640 const StoragePartitionDescriptor& partition_descriptor, |
| 639 scoped_ptr<net::URLRequestJobFactory::Interceptor> | 641 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> |
| 640 protocol_handler_interceptor) const { | 642 protocol_handler_interceptor) const { |
| 641 // We create per-app contexts on demand, unlike the others above. | 643 // We create per-app contexts on demand, unlike the others above. |
| 642 ChromeURLRequestContext* app_request_context = | 644 ChromeURLRequestContext* app_request_context = |
| 643 InitializeAppRequestContext(main_context, partition_descriptor, | 645 InitializeAppRequestContext(main_context, partition_descriptor, |
| 644 protocol_handler_interceptor.Pass()); | 646 protocol_handler_interceptor.Pass()); |
| 645 DCHECK(app_request_context); | 647 DCHECK(app_request_context); |
| 646 return app_request_context; | 648 return app_request_context; |
| 647 } | 649 } |
| 648 | 650 |
| 649 ChromeURLRequestContext* | 651 ChromeURLRequestContext* |
| (...skipping 16 matching lines...) Expand all Loading... |
| 666 base::Time time, | 668 base::Time time, |
| 667 const base::Closure& completion) { | 669 const base::Closure& completion) { |
| 668 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 670 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 669 LazyInitialize(); | 671 LazyInitialize(); |
| 670 | 672 |
| 671 DCHECK(transport_security_state()); | 673 DCHECK(transport_security_state()); |
| 672 transport_security_state()->DeleteSince(time); // Completes synchronously. | 674 transport_security_state()->DeleteSince(time); // Completes synchronously. |
| 673 DCHECK(http_server_properties_manager_); | 675 DCHECK(http_server_properties_manager_); |
| 674 http_server_properties_manager_->Clear(completion); | 676 http_server_properties_manager_->Clear(completion); |
| 675 } | 677 } |
| OLD | NEW |