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_, |
| 248 io_data_, |
| 249 descriptor, |
246 protocol_handler_interceptor.Pass(), | 250 protocol_handler_interceptor.Pass(), |
247 protocol_handlers); | 251 protocol_handlers, |
| 252 protocol_interceptors.Pass()); |
248 app_request_context_getter_map_[descriptor] = context; | 253 app_request_context_getter_map_[descriptor] = context; |
249 | 254 |
250 return context; | 255 return context; |
251 } | 256 } |
252 | 257 |
253 scoped_refptr<ChromeURLRequestContextGetter> | 258 scoped_refptr<ChromeURLRequestContextGetter> |
254 ProfileImplIOData::Handle::GetIsolatedMediaRequestContextGetter( | 259 ProfileImplIOData::Handle::GetIsolatedMediaRequestContextGetter( |
255 const base::FilePath& partition_path, | 260 const base::FilePath& partition_path, |
256 bool in_memory) const { | 261 bool in_memory) const { |
257 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 262 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 | 344 |
340 ProfileImplIOData::~ProfileImplIOData() { | 345 ProfileImplIOData::~ProfileImplIOData() { |
341 DestroyResourceContext(); | 346 DestroyResourceContext(); |
342 | 347 |
343 if (media_request_context_) | 348 if (media_request_context_) |
344 media_request_context_->AssertNoURLRequests(); | 349 media_request_context_->AssertNoURLRequests(); |
345 } | 350 } |
346 | 351 |
347 void ProfileImplIOData::InitializeInternal( | 352 void ProfileImplIOData::InitializeInternal( |
348 ProfileParams* profile_params, | 353 ProfileParams* profile_params, |
349 content::ProtocolHandlerMap* protocol_handlers) const { | 354 content::ProtocolHandlerMap* protocol_handlers, |
| 355 content::ProtocolHandlerScopedVector protocol_interceptors) const { |
350 ChromeURLRequestContext* main_context = main_request_context(); | 356 ChromeURLRequestContext* main_context = main_request_context(); |
351 | 357 |
352 IOThread* const io_thread = profile_params->io_thread; | 358 IOThread* const io_thread = profile_params->io_thread; |
353 IOThread::Globals* const io_thread_globals = io_thread->globals(); | 359 IOThread::Globals* const io_thread_globals = io_thread->globals(); |
354 | 360 |
355 network_delegate()->set_predictor(predictor_.get()); | 361 network_delegate()->set_predictor(predictor_.get()); |
356 | 362 |
357 // Initialize context members. | 363 // Initialize context members. |
358 | 364 |
359 ApplyProfileParamsToContext(main_context); | 365 ApplyProfileParamsToContext(main_context); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 #if !defined(DISABLE_FTP_SUPPORT) | 472 #if !defined(DISABLE_FTP_SUPPORT) |
467 ftp_factory_.reset( | 473 ftp_factory_.reset( |
468 new net::FtpNetworkLayer(io_thread_globals->host_resolver.get())); | 474 new net::FtpNetworkLayer(io_thread_globals->host_resolver.get())); |
469 #endif // !defined(DISABLE_FTP_SUPPORT) | 475 #endif // !defined(DISABLE_FTP_SUPPORT) |
470 | 476 |
471 scoped_ptr<net::URLRequestJobFactoryImpl> main_job_factory( | 477 scoped_ptr<net::URLRequestJobFactoryImpl> main_job_factory( |
472 new net::URLRequestJobFactoryImpl()); | 478 new net::URLRequestJobFactoryImpl()); |
473 InstallProtocolHandlers(main_job_factory.get(), protocol_handlers); | 479 InstallProtocolHandlers(main_job_factory.get(), protocol_handlers); |
474 main_job_factory_ = SetUpJobFactoryDefaults( | 480 main_job_factory_ = SetUpJobFactoryDefaults( |
475 main_job_factory.Pass(), | 481 main_job_factory.Pass(), |
| 482 protocol_interceptors.Pass(), |
476 profile_params->protocol_handler_interceptor.Pass(), | 483 profile_params->protocol_handler_interceptor.Pass(), |
477 network_delegate(), | 484 network_delegate(), |
478 ftp_factory_.get()); | 485 ftp_factory_.get()); |
479 main_context->set_job_factory(main_job_factory_.get()); | 486 main_context->set_job_factory(main_job_factory_.get()); |
480 | 487 |
481 #if defined(ENABLE_EXTENSIONS) | 488 #if defined(ENABLE_EXTENSIONS) |
482 InitializeExtensionsRequestContext(profile_params); | 489 InitializeExtensionsRequestContext(profile_params); |
483 #endif | 490 #endif |
484 | 491 |
485 // Create a media request context based on the main context, but using a | 492 // 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( | 529 scoped_ptr<net::URLRequestJobFactoryImpl> extensions_job_factory( |
523 new net::URLRequestJobFactoryImpl()); | 530 new net::URLRequestJobFactoryImpl()); |
524 // TODO(shalev): The extensions_job_factory has a NULL NetworkDelegate. | 531 // TODO(shalev): The extensions_job_factory has a NULL NetworkDelegate. |
525 // Without a network_delegate, this protocol handler will never | 532 // Without a network_delegate, this protocol handler will never |
526 // handle file: requests, but as a side effect it makes | 533 // handle file: requests, but as a side effect it makes |
527 // job_factory::IsHandledProtocol return true, which prevents attempts to | 534 // job_factory::IsHandledProtocol return true, which prevents attempts to |
528 // handle the protocol externally. We pass NULL in to | 535 // handle the protocol externally. We pass NULL in to |
529 // SetUpJobFactory() to get this effect. | 536 // SetUpJobFactory() to get this effect. |
530 extensions_job_factory_ = SetUpJobFactoryDefaults( | 537 extensions_job_factory_ = SetUpJobFactoryDefaults( |
531 extensions_job_factory.Pass(), | 538 extensions_job_factory.Pass(), |
| 539 content::ProtocolHandlerScopedVector(), |
532 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>(), | 540 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>(), |
533 NULL, | 541 NULL, |
534 ftp_factory_.get()); | 542 ftp_factory_.get()); |
535 extensions_context->set_job_factory(extensions_job_factory_.get()); | 543 extensions_context->set_job_factory(extensions_job_factory_.get()); |
536 } | 544 } |
537 | 545 |
538 ChromeURLRequestContext* | 546 ChromeURLRequestContext* ProfileImplIOData::InitializeAppRequestContext( |
539 ProfileImplIOData::InitializeAppRequestContext( | |
540 ChromeURLRequestContext* main_context, | 547 ChromeURLRequestContext* main_context, |
541 const StoragePartitionDescriptor& partition_descriptor, | 548 const StoragePartitionDescriptor& partition_descriptor, |
542 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> | 549 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> |
543 protocol_handler_interceptor, | 550 protocol_handler_interceptor, |
544 content::ProtocolHandlerMap* protocol_handlers) const { | 551 content::ProtocolHandlerMap* protocol_handlers, |
| 552 content::ProtocolHandlerScopedVector protocol_interceptors) const { |
545 // Copy most state from the main context. | 553 // Copy most state from the main context. |
546 AppRequestContext* context = new AppRequestContext(); | 554 AppRequestContext* context = new AppRequestContext(); |
547 context->CopyFrom(main_context); | 555 context->CopyFrom(main_context); |
548 | 556 |
549 base::FilePath cookie_path = partition_descriptor.path.Append( | 557 base::FilePath cookie_path = partition_descriptor.path.Append( |
550 chrome::kCookieFilename); | 558 chrome::kCookieFilename); |
551 base::FilePath cache_path = | 559 base::FilePath cache_path = |
552 partition_descriptor.path.Append(chrome::kCacheDirname); | 560 partition_descriptor.path.Append(chrome::kCacheDirname); |
553 | 561 |
554 // Use a separate HTTP disk cache for isolated apps. | 562 // Use a separate HTTP disk cache for isolated apps. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 | 609 |
602 // Transfer ownership of the cookies and cache to AppRequestContext. | 610 // Transfer ownership of the cookies and cache to AppRequestContext. |
603 context->SetCookieStore(cookie_store.get()); | 611 context->SetCookieStore(cookie_store.get()); |
604 context->SetHttpTransactionFactory( | 612 context->SetHttpTransactionFactory( |
605 scoped_ptr<net::HttpTransactionFactory>(app_http_cache)); | 613 scoped_ptr<net::HttpTransactionFactory>(app_http_cache)); |
606 | 614 |
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(job_factory.Pass(), |
612 job_factory.Pass(), protocol_handler_interceptor.Pass(), | 620 protocol_interceptors.Pass(), |
613 network_delegate(), | 621 protocol_handler_interceptor.Pass(), |
614 ftp_factory_.get())); | 622 network_delegate(), |
| 623 ftp_factory_.get())); |
615 context->SetJobFactory(top_job_factory.Pass()); | 624 context->SetJobFactory(top_job_factory.Pass()); |
616 | 625 |
617 return context; | 626 return context; |
618 } | 627 } |
619 | 628 |
620 ChromeURLRequestContext* | 629 ChromeURLRequestContext* |
621 ProfileImplIOData::InitializeMediaRequestContext( | 630 ProfileImplIOData::InitializeMediaRequestContext( |
622 ChromeURLRequestContext* original_context, | 631 ChromeURLRequestContext* original_context, |
623 const StoragePartitionDescriptor& partition_descriptor) const { | 632 const StoragePartitionDescriptor& partition_descriptor) const { |
624 // Copy most state from the original context. | 633 // Copy most state from the original context. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 | 677 |
669 return context; | 678 return context; |
670 } | 679 } |
671 | 680 |
672 ChromeURLRequestContext* | 681 ChromeURLRequestContext* |
673 ProfileImplIOData::AcquireMediaRequestContext() const { | 682 ProfileImplIOData::AcquireMediaRequestContext() const { |
674 DCHECK(media_request_context_); | 683 DCHECK(media_request_context_); |
675 return media_request_context_.get(); | 684 return media_request_context_.get(); |
676 } | 685 } |
677 | 686 |
678 ChromeURLRequestContext* | 687 ChromeURLRequestContext* ProfileImplIOData::AcquireIsolatedAppRequestContext( |
679 ProfileImplIOData::AcquireIsolatedAppRequestContext( | |
680 ChromeURLRequestContext* main_context, | 688 ChromeURLRequestContext* main_context, |
681 const StoragePartitionDescriptor& partition_descriptor, | 689 const StoragePartitionDescriptor& partition_descriptor, |
682 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> | 690 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> |
683 protocol_handler_interceptor, | 691 protocol_handler_interceptor, |
684 content::ProtocolHandlerMap* protocol_handlers) const { | 692 content::ProtocolHandlerMap* protocol_handlers, |
| 693 content::ProtocolHandlerScopedVector protocol_interceptors) const { |
685 // We create per-app contexts on demand, unlike the others above. | 694 // We create per-app contexts on demand, unlike the others above. |
686 ChromeURLRequestContext* app_request_context = | 695 ChromeURLRequestContext* app_request_context = |
687 InitializeAppRequestContext(main_context, partition_descriptor, | 696 InitializeAppRequestContext(main_context, |
| 697 partition_descriptor, |
688 protocol_handler_interceptor.Pass(), | 698 protocol_handler_interceptor.Pass(), |
689 protocol_handlers); | 699 protocol_handlers, |
| 700 protocol_interceptors.Pass()); |
690 DCHECK(app_request_context); | 701 DCHECK(app_request_context); |
691 return app_request_context; | 702 return app_request_context; |
692 } | 703 } |
693 | 704 |
694 ChromeURLRequestContext* | 705 ChromeURLRequestContext* |
695 ProfileImplIOData::AcquireIsolatedMediaRequestContext( | 706 ProfileImplIOData::AcquireIsolatedMediaRequestContext( |
696 ChromeURLRequestContext* app_context, | 707 ChromeURLRequestContext* app_context, |
697 const StoragePartitionDescriptor& partition_descriptor) const { | 708 const StoragePartitionDescriptor& partition_descriptor) const { |
698 // We create per-app media contexts on demand, unlike the others above. | 709 // We create per-app media contexts on demand, unlike the others above. |
699 ChromeURLRequestContext* media_request_context = | 710 ChromeURLRequestContext* media_request_context = |
700 InitializeMediaRequestContext(app_context, partition_descriptor); | 711 InitializeMediaRequestContext(app_context, partition_descriptor); |
701 DCHECK(media_request_context); | 712 DCHECK(media_request_context); |
702 return media_request_context; | 713 return media_request_context; |
703 } | 714 } |
704 | 715 |
705 void ProfileImplIOData::ClearNetworkingHistorySinceOnIOThread( | 716 void ProfileImplIOData::ClearNetworkingHistorySinceOnIOThread( |
706 base::Time time, | 717 base::Time time, |
707 const base::Closure& completion) { | 718 const base::Closure& completion) { |
708 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 719 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
709 DCHECK(initialized()); | 720 DCHECK(initialized()); |
710 | 721 |
711 DCHECK(transport_security_state()); | 722 DCHECK(transport_security_state()); |
712 // Completes synchronously. | 723 // Completes synchronously. |
713 transport_security_state()->DeleteAllDynamicDataSince(time); | 724 transport_security_state()->DeleteAllDynamicDataSince(time); |
714 DCHECK(http_server_properties_manager_); | 725 DCHECK(http_server_properties_manager_); |
715 http_server_properties_manager_->Clear(completion); | 726 http_server_properties_manager_->Clear(completion); |
716 } | 727 } |
OLD | NEW |