| 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/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 168 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 169 // Don't call LazyInitialize here, since the resource context is created at | 169 // Don't call LazyInitialize here, since the resource context is created at |
| 170 // the beginning of initalization and is used by some members while they're | 170 // the beginning of initalization and is used by some members while they're |
| 171 // being initialized (i.e. AppCacheService). | 171 // being initialized (i.e. AppCacheService). |
| 172 return io_data_->GetResourceContext(); | 172 return io_data_->GetResourceContext(); |
| 173 } | 173 } |
| 174 | 174 |
| 175 scoped_refptr<ChromeURLRequestContextGetter> | 175 scoped_refptr<ChromeURLRequestContextGetter> |
| 176 ProfileImplIOData::Handle::CreateMainRequestContextGetter( | 176 ProfileImplIOData::Handle::CreateMainRequestContextGetter( |
| 177 content::ProtocolHandlerMap* protocol_handlers, | 177 content::ProtocolHandlerMap* protocol_handlers, |
| 178 content::ProtocolHandlerScopedVector protocol_interceptors, |
| 178 PrefService* local_state, | 179 PrefService* local_state, |
| 179 IOThread* io_thread) const { | 180 IOThread* io_thread) const { |
| 180 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 181 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 181 LazyInitialize(); | 182 LazyInitialize(); |
| 182 DCHECK(!main_request_context_getter_.get()); | 183 DCHECK(!main_request_context_getter_.get()); |
| 183 main_request_context_getter_ = ChromeURLRequestContextGetter::Create( | 184 main_request_context_getter_ = ChromeURLRequestContextGetter::Create( |
| 184 profile_, io_data_, protocol_handlers); | 185 profile_, io_data_, protocol_handlers, protocol_interceptors.Pass()); |
| 185 | 186 |
| 186 io_data_->predictor_ | 187 io_data_->predictor_ |
| 187 ->InitNetworkPredictor(profile_->GetPrefs(), | 188 ->InitNetworkPredictor(profile_->GetPrefs(), |
| 188 local_state, | 189 local_state, |
| 189 io_thread, | 190 io_thread, |
| 190 main_request_context_getter_.get()); | 191 main_request_context_getter_.get()); |
| 191 | 192 |
| 192 content::NotificationService::current()->Notify( | 193 content::NotificationService::current()->Notify( |
| 193 chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED, | 194 chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED, |
| 194 content::Source<Profile>(profile_), | 195 content::Source<Profile>(profile_), |
| (...skipping 20 matching lines...) Expand all Loading... |
| 215 extensions_request_context_getter_ = | 216 extensions_request_context_getter_ = |
| 216 ChromeURLRequestContextGetter::CreateForExtensions(profile_, io_data_); | 217 ChromeURLRequestContextGetter::CreateForExtensions(profile_, io_data_); |
| 217 } | 218 } |
| 218 return extensions_request_context_getter_; | 219 return extensions_request_context_getter_; |
| 219 } | 220 } |
| 220 | 221 |
| 221 scoped_refptr<ChromeURLRequestContextGetter> | 222 scoped_refptr<ChromeURLRequestContextGetter> |
| 222 ProfileImplIOData::Handle::CreateIsolatedAppRequestContextGetter( | 223 ProfileImplIOData::Handle::CreateIsolatedAppRequestContextGetter( |
| 223 const base::FilePath& partition_path, | 224 const base::FilePath& partition_path, |
| 224 bool in_memory, | 225 bool in_memory, |
| 225 content::ProtocolHandlerMap* protocol_handlers) const { | 226 content::ProtocolHandlerMap* protocol_handlers, |
| 227 content::ProtocolHandlerScopedVector protocol_interceptors) const { |
| 226 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 228 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 227 // Check that the partition_path is not the same as the base profile path. We | 229 // Check that the partition_path is not the same as the base profile path. We |
| 228 // expect isolated partition, which will never go to the default profile path. | 230 // expect isolated partition, which will never go to the default profile path. |
| 229 CHECK(partition_path != profile_->GetPath()); | 231 CHECK(partition_path != profile_->GetPath()); |
| 230 LazyInitialize(); | 232 LazyInitialize(); |
| 231 | 233 |
| 232 // Keep a map of request context getters, one per requested storage partition. | 234 // Keep a map of request context getters, one per requested storage partition. |
| 233 StoragePartitionDescriptor descriptor(partition_path, in_memory); | 235 StoragePartitionDescriptor descriptor(partition_path, in_memory); |
| 234 ChromeURLRequestContextGetterMap::iterator iter = | 236 ChromeURLRequestContextGetterMap::iterator iter = |
| 235 app_request_context_getter_map_.find(descriptor); | 237 app_request_context_getter_map_.find(descriptor); |
| 236 if (iter != app_request_context_getter_map_.end()) | 238 if (iter != app_request_context_getter_map_.end()) |
| 237 return iter->second; | 239 return iter->second; |
| 238 | 240 |
| 239 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> | 241 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> |
| 240 protocol_handler_interceptor( | 242 protocol_handler_interceptor( |
| 241 ProtocolHandlerRegistryFactory::GetForProfile(profile_)-> | 243 ProtocolHandlerRegistryFactory::GetForProfile(profile_)-> |
| 242 CreateJobInterceptorFactory()); | 244 CreateJobInterceptorFactory()); |
| 243 ChromeURLRequestContextGetter* context = | 245 ChromeURLRequestContextGetter* context = |
| 244 ChromeURLRequestContextGetter::CreateForIsolatedApp( | 246 ChromeURLRequestContextGetter::CreateForIsolatedApp( |
| 245 profile_, io_data_, descriptor, | 247 profile_, io_data_, descriptor, |
| 246 protocol_handler_interceptor.Pass(), | 248 protocol_handler_interceptor.Pass(), |
| 247 protocol_handlers); | 249 protocol_handlers, |
| 250 protocol_interceptors.Pass()); |
| 248 app_request_context_getter_map_[descriptor] = context; | 251 app_request_context_getter_map_[descriptor] = context; |
| 249 | 252 |
| 250 return context; | 253 return context; |
| 251 } | 254 } |
| 252 | 255 |
| 253 scoped_refptr<ChromeURLRequestContextGetter> | 256 scoped_refptr<ChromeURLRequestContextGetter> |
| 254 ProfileImplIOData::Handle::GetIsolatedMediaRequestContextGetter( | 257 ProfileImplIOData::Handle::GetIsolatedMediaRequestContextGetter( |
| 255 const base::FilePath& partition_path, | 258 const base::FilePath& partition_path, |
| 256 bool in_memory) const { | 259 bool in_memory) const { |
| 257 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 | 342 |
| 340 ProfileImplIOData::~ProfileImplIOData() { | 343 ProfileImplIOData::~ProfileImplIOData() { |
| 341 DestroyResourceContext(); | 344 DestroyResourceContext(); |
| 342 | 345 |
| 343 if (media_request_context_) | 346 if (media_request_context_) |
| 344 media_request_context_->AssertNoURLRequests(); | 347 media_request_context_->AssertNoURLRequests(); |
| 345 } | 348 } |
| 346 | 349 |
| 347 void ProfileImplIOData::InitializeInternal( | 350 void ProfileImplIOData::InitializeInternal( |
| 348 ProfileParams* profile_params, | 351 ProfileParams* profile_params, |
| 349 content::ProtocolHandlerMap* protocol_handlers) const { | 352 content::ProtocolHandlerMap* protocol_handlers, |
| 353 content::ProtocolHandlerScopedVector protocol_interceptors) const { |
| 350 ChromeURLRequestContext* main_context = main_request_context(); | 354 ChromeURLRequestContext* main_context = main_request_context(); |
| 351 | 355 |
| 352 IOThread* const io_thread = profile_params->io_thread; | 356 IOThread* const io_thread = profile_params->io_thread; |
| 353 IOThread::Globals* const io_thread_globals = io_thread->globals(); | 357 IOThread::Globals* const io_thread_globals = io_thread->globals(); |
| 354 | 358 |
| 355 network_delegate()->set_predictor(predictor_.get()); | 359 network_delegate()->set_predictor(predictor_.get()); |
| 356 | 360 |
| 357 // Initialize context members. | 361 // Initialize context members. |
| 358 | 362 |
| 359 ApplyProfileParamsToContext(main_context); | 363 ApplyProfileParamsToContext(main_context); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 #if !defined(DISABLE_FTP_SUPPORT) | 470 #if !defined(DISABLE_FTP_SUPPORT) |
| 467 ftp_factory_.reset( | 471 ftp_factory_.reset( |
| 468 new net::FtpNetworkLayer(io_thread_globals->host_resolver.get())); | 472 new net::FtpNetworkLayer(io_thread_globals->host_resolver.get())); |
| 469 #endif // !defined(DISABLE_FTP_SUPPORT) | 473 #endif // !defined(DISABLE_FTP_SUPPORT) |
| 470 | 474 |
| 471 scoped_ptr<net::URLRequestJobFactoryImpl> main_job_factory( | 475 scoped_ptr<net::URLRequestJobFactoryImpl> main_job_factory( |
| 472 new net::URLRequestJobFactoryImpl()); | 476 new net::URLRequestJobFactoryImpl()); |
| 473 InstallProtocolHandlers(main_job_factory.get(), protocol_handlers); | 477 InstallProtocolHandlers(main_job_factory.get(), protocol_handlers); |
| 474 main_job_factory_ = SetUpJobFactoryDefaults( | 478 main_job_factory_ = SetUpJobFactoryDefaults( |
| 475 main_job_factory.Pass(), | 479 main_job_factory.Pass(), |
| 480 protocol_interceptors.Pass(), |
| 476 profile_params->protocol_handler_interceptor.Pass(), | 481 profile_params->protocol_handler_interceptor.Pass(), |
| 477 network_delegate(), | 482 network_delegate(), |
| 478 ftp_factory_.get()); | 483 ftp_factory_.get()); |
| 479 main_context->set_job_factory(main_job_factory_.get()); | 484 main_context->set_job_factory(main_job_factory_.get()); |
| 480 | 485 |
| 481 #if defined(ENABLE_EXTENSIONS) | 486 #if defined(ENABLE_EXTENSIONS) |
| 482 InitializeExtensionsRequestContext(profile_params); | 487 InitializeExtensionsRequestContext(profile_params); |
| 483 #endif | 488 #endif |
| 484 | 489 |
| 485 // Create a media request context based on the main context, but using a | 490 // Create a media request context based on the main context, but using a |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 scoped_ptr<net::URLRequestJobFactoryImpl> extensions_job_factory( | 527 scoped_ptr<net::URLRequestJobFactoryImpl> extensions_job_factory( |
| 523 new net::URLRequestJobFactoryImpl()); | 528 new net::URLRequestJobFactoryImpl()); |
| 524 // TODO(shalev): The extensions_job_factory has a NULL NetworkDelegate. | 529 // TODO(shalev): The extensions_job_factory has a NULL NetworkDelegate. |
| 525 // Without a network_delegate, this protocol handler will never | 530 // Without a network_delegate, this protocol handler will never |
| 526 // handle file: requests, but as a side effect it makes | 531 // handle file: requests, but as a side effect it makes |
| 527 // job_factory::IsHandledProtocol return true, which prevents attempts to | 532 // job_factory::IsHandledProtocol return true, which prevents attempts to |
| 528 // handle the protocol externally. We pass NULL in to | 533 // handle the protocol externally. We pass NULL in to |
| 529 // SetUpJobFactory() to get this effect. | 534 // SetUpJobFactory() to get this effect. |
| 530 extensions_job_factory_ = SetUpJobFactoryDefaults( | 535 extensions_job_factory_ = SetUpJobFactoryDefaults( |
| 531 extensions_job_factory.Pass(), | 536 extensions_job_factory.Pass(), |
| 537 content::ProtocolHandlerScopedVector(), |
| 532 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>(), | 538 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>(), |
| 533 NULL, | 539 NULL, |
| 534 ftp_factory_.get()); | 540 ftp_factory_.get()); |
| 535 extensions_context->set_job_factory(extensions_job_factory_.get()); | 541 extensions_context->set_job_factory(extensions_job_factory_.get()); |
| 536 } | 542 } |
| 537 | 543 |
| 538 ChromeURLRequestContext* | 544 ChromeURLRequestContext* |
| 539 ProfileImplIOData::InitializeAppRequestContext( | 545 ProfileImplIOData::InitializeAppRequestContext( |
| 540 ChromeURLRequestContext* main_context, | 546 ChromeURLRequestContext* main_context, |
| 541 const StoragePartitionDescriptor& partition_descriptor, | 547 const StoragePartitionDescriptor& partition_descriptor, |
| 542 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> | 548 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> |
| 543 protocol_handler_interceptor, | 549 protocol_handler_interceptor, |
| 544 content::ProtocolHandlerMap* protocol_handlers) const { | 550 content::ProtocolHandlerMap* protocol_handlers, |
| 551 content::ProtocolHandlerScopedVector protocol_interceptors) const { |
| 545 // Copy most state from the main context. | 552 // Copy most state from the main context. |
| 546 AppRequestContext* context = new AppRequestContext(); | 553 AppRequestContext* context = new AppRequestContext(); |
| 547 context->CopyFrom(main_context); | 554 context->CopyFrom(main_context); |
| 548 | 555 |
| 549 base::FilePath cookie_path = partition_descriptor.path.Append( | 556 base::FilePath cookie_path = partition_descriptor.path.Append( |
| 550 chrome::kCookieFilename); | 557 chrome::kCookieFilename); |
| 551 base::FilePath cache_path = | 558 base::FilePath cache_path = |
| 552 partition_descriptor.path.Append(chrome::kCacheDirname); | 559 partition_descriptor.path.Append(chrome::kCacheDirname); |
| 553 | 560 |
| 554 // Use a separate HTTP disk cache for isolated apps. | 561 // Use a separate HTTP disk cache for isolated apps. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 cookie_config.crypto_delegate = | 604 cookie_config.crypto_delegate = |
| 598 chrome_browser_net::GetCookieCryptoDelegate(); | 605 chrome_browser_net::GetCookieCryptoDelegate(); |
| 599 cookie_store = content::CreateCookieStore(cookie_config); | 606 cookie_store = content::CreateCookieStore(cookie_config); |
| 600 } | 607 } |
| 601 | 608 |
| 602 // Transfer ownership of the cookies and cache to AppRequestContext. | 609 // Transfer ownership of the cookies and cache to AppRequestContext. |
| 603 context->SetCookieStore(cookie_store.get()); | 610 context->SetCookieStore(cookie_store.get()); |
| 604 context->SetHttpTransactionFactory( | 611 context->SetHttpTransactionFactory( |
| 605 scoped_ptr<net::HttpTransactionFactory>(app_http_cache)); | 612 scoped_ptr<net::HttpTransactionFactory>(app_http_cache)); |
| 606 | 613 |
| 614 // TODO TODOTODO_kinuko |
| 607 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( | 615 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( |
| 608 new net::URLRequestJobFactoryImpl()); | 616 new net::URLRequestJobFactoryImpl()); |
| 609 InstallProtocolHandlers(job_factory.get(), protocol_handlers); | 617 InstallProtocolHandlers(job_factory.get(), protocol_handlers); |
| 610 scoped_ptr<net::URLRequestJobFactory> top_job_factory( | 618 scoped_ptr<net::URLRequestJobFactory> top_job_factory( |
| 611 SetUpJobFactoryDefaults( | 619 SetUpJobFactoryDefaults( |
| 612 job_factory.Pass(), protocol_handler_interceptor.Pass(), | 620 job_factory.Pass(), |
| 621 protocol_interceptors.Pass(), |
| 622 protocol_handler_interceptor.Pass(), |
| 613 network_delegate(), | 623 network_delegate(), |
| 614 ftp_factory_.get())); | 624 ftp_factory_.get())); |
| 615 context->SetJobFactory(top_job_factory.Pass()); | 625 context->SetJobFactory(top_job_factory.Pass()); |
| 616 | 626 |
| 617 return context; | 627 return context; |
| 618 } | 628 } |
| 619 | 629 |
| 620 ChromeURLRequestContext* | 630 ChromeURLRequestContext* |
| 621 ProfileImplIOData::InitializeMediaRequestContext( | 631 ProfileImplIOData::InitializeMediaRequestContext( |
| 622 ChromeURLRequestContext* original_context, | 632 ChromeURLRequestContext* original_context, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 DCHECK(media_request_context_); | 684 DCHECK(media_request_context_); |
| 675 return media_request_context_.get(); | 685 return media_request_context_.get(); |
| 676 } | 686 } |
| 677 | 687 |
| 678 ChromeURLRequestContext* | 688 ChromeURLRequestContext* |
| 679 ProfileImplIOData::AcquireIsolatedAppRequestContext( | 689 ProfileImplIOData::AcquireIsolatedAppRequestContext( |
| 680 ChromeURLRequestContext* main_context, | 690 ChromeURLRequestContext* main_context, |
| 681 const StoragePartitionDescriptor& partition_descriptor, | 691 const StoragePartitionDescriptor& partition_descriptor, |
| 682 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> | 692 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> |
| 683 protocol_handler_interceptor, | 693 protocol_handler_interceptor, |
| 684 content::ProtocolHandlerMap* protocol_handlers) const { | 694 content::ProtocolHandlerMap* protocol_handlers, |
| 695 content::ProtocolHandlerScopedVector protocol_interceptors) const { |
| 685 // We create per-app contexts on demand, unlike the others above. | 696 // We create per-app contexts on demand, unlike the others above. |
| 686 ChromeURLRequestContext* app_request_context = | 697 ChromeURLRequestContext* app_request_context = |
| 687 InitializeAppRequestContext(main_context, partition_descriptor, | 698 InitializeAppRequestContext(main_context, partition_descriptor, |
| 688 protocol_handler_interceptor.Pass(), | 699 protocol_handler_interceptor.Pass(), |
| 689 protocol_handlers); | 700 protocol_handlers, |
| 701 protocol_interceptors.Pass()); |
| 690 DCHECK(app_request_context); | 702 DCHECK(app_request_context); |
| 691 return app_request_context; | 703 return app_request_context; |
| 692 } | 704 } |
| 693 | 705 |
| 694 ChromeURLRequestContext* | 706 ChromeURLRequestContext* |
| 695 ProfileImplIOData::AcquireIsolatedMediaRequestContext( | 707 ProfileImplIOData::AcquireIsolatedMediaRequestContext( |
| 696 ChromeURLRequestContext* app_context, | 708 ChromeURLRequestContext* app_context, |
| 697 const StoragePartitionDescriptor& partition_descriptor) const { | 709 const StoragePartitionDescriptor& partition_descriptor) const { |
| 698 // We create per-app media contexts on demand, unlike the others above. | 710 // We create per-app media contexts on demand, unlike the others above. |
| 699 ChromeURLRequestContext* media_request_context = | 711 ChromeURLRequestContext* media_request_context = |
| 700 InitializeMediaRequestContext(app_context, partition_descriptor); | 712 InitializeMediaRequestContext(app_context, partition_descriptor); |
| 701 DCHECK(media_request_context); | 713 DCHECK(media_request_context); |
| 702 return media_request_context; | 714 return media_request_context; |
| 703 } | 715 } |
| 704 | 716 |
| 705 void ProfileImplIOData::ClearNetworkingHistorySinceOnIOThread( | 717 void ProfileImplIOData::ClearNetworkingHistorySinceOnIOThread( |
| 706 base::Time time, | 718 base::Time time, |
| 707 const base::Closure& completion) { | 719 const base::Closure& completion) { |
| 708 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 720 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 709 DCHECK(initialized()); | 721 DCHECK(initialized()); |
| 710 | 722 |
| 711 DCHECK(transport_security_state()); | 723 DCHECK(transport_security_state()); |
| 712 // Completes synchronously. | 724 // Completes synchronously. |
| 713 transport_security_state()->DeleteAllDynamicDataSince(time); | 725 transport_security_state()->DeleteAllDynamicDataSince(time); |
| 714 DCHECK(http_server_properties_manager_); | 726 DCHECK(http_server_properties_manager_); |
| 715 http_server_properties_manager_->Clear(completion); | 727 http_server_properties_manager_->Clear(completion); |
| 716 } | 728 } |
| OLD | NEW |