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 26 matching lines...) Expand all Loading... |
37 #include "content/public/browser/cookie_store_factory.h" | 37 #include "content/public/browser/cookie_store_factory.h" |
38 #include "content/public/browser/notification_service.h" | 38 #include "content/public/browser/notification_service.h" |
39 #include "content/public/browser/resource_context.h" | 39 #include "content/public/browser/resource_context.h" |
40 #include "content/public/browser/storage_partition.h" | 40 #include "content/public/browser/storage_partition.h" |
41 #include "extensions/browser/extension_protocols.h" | 41 #include "extensions/browser/extension_protocols.h" |
42 #include "extensions/common/constants.h" | 42 #include "extensions/common/constants.h" |
43 #include "net/base/cache_type.h" | 43 #include "net/base/cache_type.h" |
44 #include "net/ftp/ftp_network_layer.h" | 44 #include "net/ftp/ftp_network_layer.h" |
45 #include "net/http/http_cache.h" | 45 #include "net/http/http_cache.h" |
46 #include "net/ssl/server_bound_cert_service.h" | 46 #include "net/ssl/server_bound_cert_service.h" |
47 #include "net/url_request/protocol_intercept_job_factory.h" | |
48 #include "net/url_request/url_request_job_factory_impl.h" | 47 #include "net/url_request/url_request_job_factory_impl.h" |
49 #include "webkit/browser/quota/special_storage_policy.h" | 48 #include "webkit/browser/quota/special_storage_policy.h" |
50 | 49 |
51 #if defined(OS_ANDROID) || defined(OS_IOS) | 50 #if defined(OS_ANDROID) || defined(OS_IOS) |
52 #if defined(SPDY_PROXY_AUTH_VALUE) | 51 #if defined(SPDY_PROXY_AUTH_VALUE) |
53 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.
h" | 52 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.
h" |
54 #endif | 53 #endif |
55 #endif | 54 #endif |
56 | 55 |
57 namespace { | 56 namespace { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 178 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
180 // Don't call LazyInitialize here, since the resource context is created at | 179 // Don't call LazyInitialize here, since the resource context is created at |
181 // the beginning of initalization and is used by some members while they're | 180 // the beginning of initalization and is used by some members while they're |
182 // being initialized (i.e. AppCacheService). | 181 // being initialized (i.e. AppCacheService). |
183 return io_data_->GetResourceContext(); | 182 return io_data_->GetResourceContext(); |
184 } | 183 } |
185 | 184 |
186 scoped_refptr<ChromeURLRequestContextGetter> | 185 scoped_refptr<ChromeURLRequestContextGetter> |
187 ProfileImplIOData::Handle::CreateMainRequestContextGetter( | 186 ProfileImplIOData::Handle::CreateMainRequestContextGetter( |
188 content::ProtocolHandlerMap* protocol_handlers, | 187 content::ProtocolHandlerMap* protocol_handlers, |
189 content::ProtocolHandlerScopedVector protocol_interceptors, | 188 content::URLRequestInterceptorScopedVector request_interceptors, |
190 PrefService* local_state, | 189 PrefService* local_state, |
191 IOThread* io_thread) const { | 190 IOThread* io_thread) const { |
192 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 191 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
193 LazyInitialize(); | 192 LazyInitialize(); |
194 DCHECK(!main_request_context_getter_.get()); | 193 DCHECK(!main_request_context_getter_.get()); |
195 main_request_context_getter_ = ChromeURLRequestContextGetter::Create( | 194 main_request_context_getter_ = ChromeURLRequestContextGetter::Create( |
196 profile_, io_data_, protocol_handlers, protocol_interceptors.Pass()); | 195 profile_, io_data_, protocol_handlers, request_interceptors.Pass()); |
197 | 196 |
198 io_data_->predictor_ | 197 io_data_->predictor_ |
199 ->InitNetworkPredictor(profile_->GetPrefs(), | 198 ->InitNetworkPredictor(profile_->GetPrefs(), |
200 local_state, | 199 local_state, |
201 io_thread, | 200 io_thread, |
202 main_request_context_getter_.get()); | 201 main_request_context_getter_.get()); |
203 | 202 |
204 content::NotificationService::current()->Notify( | 203 content::NotificationService::current()->Notify( |
205 chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED, | 204 chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED, |
206 content::Source<Profile>(profile_), | 205 content::Source<Profile>(profile_), |
(...skipping 21 matching lines...) Expand all Loading... |
228 ChromeURLRequestContextGetter::CreateForExtensions(profile_, io_data_); | 227 ChromeURLRequestContextGetter::CreateForExtensions(profile_, io_data_); |
229 } | 228 } |
230 return extensions_request_context_getter_; | 229 return extensions_request_context_getter_; |
231 } | 230 } |
232 | 231 |
233 scoped_refptr<ChromeURLRequestContextGetter> | 232 scoped_refptr<ChromeURLRequestContextGetter> |
234 ProfileImplIOData::Handle::CreateIsolatedAppRequestContextGetter( | 233 ProfileImplIOData::Handle::CreateIsolatedAppRequestContextGetter( |
235 const base::FilePath& partition_path, | 234 const base::FilePath& partition_path, |
236 bool in_memory, | 235 bool in_memory, |
237 content::ProtocolHandlerMap* protocol_handlers, | 236 content::ProtocolHandlerMap* protocol_handlers, |
238 content::ProtocolHandlerScopedVector protocol_interceptors) const { | 237 content::URLRequestInterceptorScopedVector request_interceptors) const { |
239 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 238 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
240 // Check that the partition_path is not the same as the base profile path. We | 239 // Check that the partition_path is not the same as the base profile path. We |
241 // expect isolated partition, which will never go to the default profile path. | 240 // expect isolated partition, which will never go to the default profile path. |
242 CHECK(partition_path != profile_->GetPath()); | 241 CHECK(partition_path != profile_->GetPath()); |
243 LazyInitialize(); | 242 LazyInitialize(); |
244 | 243 |
245 // Keep a map of request context getters, one per requested storage partition. | 244 // Keep a map of request context getters, one per requested storage partition. |
246 StoragePartitionDescriptor descriptor(partition_path, in_memory); | 245 StoragePartitionDescriptor descriptor(partition_path, in_memory); |
247 ChromeURLRequestContextGetterMap::iterator iter = | 246 ChromeURLRequestContextGetterMap::iterator iter = |
248 app_request_context_getter_map_.find(descriptor); | 247 app_request_context_getter_map_.find(descriptor); |
249 if (iter != app_request_context_getter_map_.end()) | 248 if (iter != app_request_context_getter_map_.end()) |
250 return iter->second; | 249 return iter->second; |
251 | 250 |
252 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> | 251 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> |
253 protocol_handler_interceptor( | 252 protocol_handler_interceptor( |
254 ProtocolHandlerRegistryFactory::GetForProfile(profile_)-> | 253 ProtocolHandlerRegistryFactory::GetForProfile(profile_)-> |
255 CreateJobInterceptorFactory()); | 254 CreateJobInterceptorFactory()); |
256 ChromeURLRequestContextGetter* context = | 255 ChromeURLRequestContextGetter* context = |
257 ChromeURLRequestContextGetter::CreateForIsolatedApp( | 256 ChromeURLRequestContextGetter::CreateForIsolatedApp( |
258 profile_, | 257 profile_, |
259 io_data_, | 258 io_data_, |
260 descriptor, | 259 descriptor, |
261 protocol_handler_interceptor.Pass(), | 260 protocol_handler_interceptor.Pass(), |
262 protocol_handlers, | 261 protocol_handlers, |
263 protocol_interceptors.Pass()); | 262 request_interceptors.Pass()); |
264 app_request_context_getter_map_[descriptor] = context; | 263 app_request_context_getter_map_[descriptor] = context; |
265 | 264 |
266 return context; | 265 return context; |
267 } | 266 } |
268 | 267 |
269 scoped_refptr<ChromeURLRequestContextGetter> | 268 scoped_refptr<ChromeURLRequestContextGetter> |
270 ProfileImplIOData::Handle::GetIsolatedMediaRequestContextGetter( | 269 ProfileImplIOData::Handle::GetIsolatedMediaRequestContextGetter( |
271 const base::FilePath& partition_path, | 270 const base::FilePath& partition_path, |
272 bool in_memory) const { | 271 bool in_memory) const { |
273 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 272 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 ProfileImplIOData::~ProfileImplIOData() { | 370 ProfileImplIOData::~ProfileImplIOData() { |
372 DestroyResourceContext(); | 371 DestroyResourceContext(); |
373 | 372 |
374 if (media_request_context_) | 373 if (media_request_context_) |
375 media_request_context_->AssertNoURLRequests(); | 374 media_request_context_->AssertNoURLRequests(); |
376 } | 375 } |
377 | 376 |
378 void ProfileImplIOData::InitializeInternal( | 377 void ProfileImplIOData::InitializeInternal( |
379 ProfileParams* profile_params, | 378 ProfileParams* profile_params, |
380 content::ProtocolHandlerMap* protocol_handlers, | 379 content::ProtocolHandlerMap* protocol_handlers, |
381 content::ProtocolHandlerScopedVector protocol_interceptors) const { | 380 content::URLRequestInterceptorScopedVector request_interceptors) const { |
382 ChromeURLRequestContext* main_context = main_request_context(); | 381 ChromeURLRequestContext* main_context = main_request_context(); |
383 | 382 |
384 IOThread* const io_thread = profile_params->io_thread; | 383 IOThread* const io_thread = profile_params->io_thread; |
385 IOThread::Globals* const io_thread_globals = io_thread->globals(); | 384 IOThread::Globals* const io_thread_globals = io_thread->globals(); |
386 | 385 |
387 network_delegate()->set_predictor(predictor_.get()); | 386 network_delegate()->set_predictor(predictor_.get()); |
388 | 387 |
389 // Initialize context members. | 388 // Initialize context members. |
390 | 389 |
391 ApplyProfileParamsToContext(main_context); | 390 ApplyProfileParamsToContext(main_context); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 #if !defined(DISABLE_FTP_SUPPORT) | 500 #if !defined(DISABLE_FTP_SUPPORT) |
502 ftp_factory_.reset( | 501 ftp_factory_.reset( |
503 new net::FtpNetworkLayer(io_thread_globals->host_resolver.get())); | 502 new net::FtpNetworkLayer(io_thread_globals->host_resolver.get())); |
504 #endif // !defined(DISABLE_FTP_SUPPORT) | 503 #endif // !defined(DISABLE_FTP_SUPPORT) |
505 | 504 |
506 scoped_ptr<net::URLRequestJobFactoryImpl> main_job_factory( | 505 scoped_ptr<net::URLRequestJobFactoryImpl> main_job_factory( |
507 new net::URLRequestJobFactoryImpl()); | 506 new net::URLRequestJobFactoryImpl()); |
508 InstallProtocolHandlers(main_job_factory.get(), protocol_handlers); | 507 InstallProtocolHandlers(main_job_factory.get(), protocol_handlers); |
509 main_job_factory_ = SetUpJobFactoryDefaults( | 508 main_job_factory_ = SetUpJobFactoryDefaults( |
510 main_job_factory.Pass(), | 509 main_job_factory.Pass(), |
511 protocol_interceptors.Pass(), | 510 request_interceptors.Pass(), |
512 profile_params->protocol_handler_interceptor.Pass(), | 511 profile_params->protocol_handler_interceptor.Pass(), |
513 network_delegate(), | 512 network_delegate(), |
514 ftp_factory_.get()); | 513 ftp_factory_.get()); |
515 main_context->set_job_factory(main_job_factory_.get()); | 514 main_context->set_job_factory(main_job_factory_.get()); |
516 | 515 |
517 #if defined(ENABLE_EXTENSIONS) | 516 #if defined(ENABLE_EXTENSIONS) |
518 InitializeExtensionsRequestContext(profile_params); | 517 InitializeExtensionsRequestContext(profile_params); |
519 #endif | 518 #endif |
520 | 519 |
521 // Create a media request context based on the main context, but using a | 520 // Create a media request context based on the main context, but using a |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 scoped_ptr<net::URLRequestJobFactoryImpl> extensions_job_factory( | 566 scoped_ptr<net::URLRequestJobFactoryImpl> extensions_job_factory( |
568 new net::URLRequestJobFactoryImpl()); | 567 new net::URLRequestJobFactoryImpl()); |
569 // TODO(shalev): The extensions_job_factory has a NULL NetworkDelegate. | 568 // TODO(shalev): The extensions_job_factory has a NULL NetworkDelegate. |
570 // Without a network_delegate, this protocol handler will never | 569 // Without a network_delegate, this protocol handler will never |
571 // handle file: requests, but as a side effect it makes | 570 // handle file: requests, but as a side effect it makes |
572 // job_factory::IsHandledProtocol return true, which prevents attempts to | 571 // job_factory::IsHandledProtocol return true, which prevents attempts to |
573 // handle the protocol externally. We pass NULL in to | 572 // handle the protocol externally. We pass NULL in to |
574 // SetUpJobFactory() to get this effect. | 573 // SetUpJobFactory() to get this effect. |
575 extensions_job_factory_ = SetUpJobFactoryDefaults( | 574 extensions_job_factory_ = SetUpJobFactoryDefaults( |
576 extensions_job_factory.Pass(), | 575 extensions_job_factory.Pass(), |
577 content::ProtocolHandlerScopedVector(), | 576 content::URLRequestInterceptorScopedVector(), |
578 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>(), | 577 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>(), |
579 NULL, | 578 NULL, |
580 ftp_factory_.get()); | 579 ftp_factory_.get()); |
581 extensions_context->set_job_factory(extensions_job_factory_.get()); | 580 extensions_context->set_job_factory(extensions_job_factory_.get()); |
582 } | 581 } |
583 | 582 |
584 ChromeURLRequestContext* ProfileImplIOData::InitializeAppRequestContext( | 583 ChromeURLRequestContext* ProfileImplIOData::InitializeAppRequestContext( |
585 ChromeURLRequestContext* main_context, | 584 ChromeURLRequestContext* main_context, |
586 const StoragePartitionDescriptor& partition_descriptor, | 585 const StoragePartitionDescriptor& partition_descriptor, |
587 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> | 586 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> |
588 protocol_handler_interceptor, | 587 protocol_handler_interceptor, |
589 content::ProtocolHandlerMap* protocol_handlers, | 588 content::ProtocolHandlerMap* protocol_handlers, |
590 content::ProtocolHandlerScopedVector protocol_interceptors) const { | 589 content::URLRequestInterceptorScopedVector request_interceptors) const { |
591 // Copy most state from the main context. | 590 // Copy most state from the main context. |
592 AppRequestContext* context = new AppRequestContext(); | 591 AppRequestContext* context = new AppRequestContext(); |
593 context->CopyFrom(main_context); | 592 context->CopyFrom(main_context); |
594 | 593 |
595 base::FilePath cookie_path = partition_descriptor.path.Append( | 594 base::FilePath cookie_path = partition_descriptor.path.Append( |
596 chrome::kCookieFilename); | 595 chrome::kCookieFilename); |
597 base::FilePath cache_path = | 596 base::FilePath cache_path = |
598 partition_descriptor.path.Append(chrome::kCacheDirname); | 597 partition_descriptor.path.Append(chrome::kCacheDirname); |
599 | 598 |
600 // Use a separate HTTP disk cache for isolated apps. | 599 // Use a separate HTTP disk cache for isolated apps. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 // Transfer ownership of the cookies and cache to AppRequestContext. | 647 // Transfer ownership of the cookies and cache to AppRequestContext. |
649 context->SetCookieStore(cookie_store.get()); | 648 context->SetCookieStore(cookie_store.get()); |
650 context->SetHttpTransactionFactory( | 649 context->SetHttpTransactionFactory( |
651 scoped_ptr<net::HttpTransactionFactory>(app_http_cache)); | 650 scoped_ptr<net::HttpTransactionFactory>(app_http_cache)); |
652 | 651 |
653 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( | 652 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( |
654 new net::URLRequestJobFactoryImpl()); | 653 new net::URLRequestJobFactoryImpl()); |
655 InstallProtocolHandlers(job_factory.get(), protocol_handlers); | 654 InstallProtocolHandlers(job_factory.get(), protocol_handlers); |
656 scoped_ptr<net::URLRequestJobFactory> top_job_factory( | 655 scoped_ptr<net::URLRequestJobFactory> top_job_factory( |
657 SetUpJobFactoryDefaults(job_factory.Pass(), | 656 SetUpJobFactoryDefaults(job_factory.Pass(), |
658 protocol_interceptors.Pass(), | 657 request_interceptors.Pass(), |
659 protocol_handler_interceptor.Pass(), | 658 protocol_handler_interceptor.Pass(), |
660 network_delegate(), | 659 network_delegate(), |
661 ftp_factory_.get())); | 660 ftp_factory_.get())); |
662 context->SetJobFactory(top_job_factory.Pass()); | 661 context->SetJobFactory(top_job_factory.Pass()); |
663 | 662 |
664 return context; | 663 return context; |
665 } | 664 } |
666 | 665 |
667 ChromeURLRequestContext* | 666 ChromeURLRequestContext* |
668 ProfileImplIOData::InitializeMediaRequestContext( | 667 ProfileImplIOData::InitializeMediaRequestContext( |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 DCHECK(media_request_context_); | 720 DCHECK(media_request_context_); |
722 return media_request_context_.get(); | 721 return media_request_context_.get(); |
723 } | 722 } |
724 | 723 |
725 ChromeURLRequestContext* ProfileImplIOData::AcquireIsolatedAppRequestContext( | 724 ChromeURLRequestContext* ProfileImplIOData::AcquireIsolatedAppRequestContext( |
726 ChromeURLRequestContext* main_context, | 725 ChromeURLRequestContext* main_context, |
727 const StoragePartitionDescriptor& partition_descriptor, | 726 const StoragePartitionDescriptor& partition_descriptor, |
728 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> | 727 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> |
729 protocol_handler_interceptor, | 728 protocol_handler_interceptor, |
730 content::ProtocolHandlerMap* protocol_handlers, | 729 content::ProtocolHandlerMap* protocol_handlers, |
731 content::ProtocolHandlerScopedVector protocol_interceptors) const { | 730 content::URLRequestInterceptorScopedVector request_interceptors) const { |
732 // We create per-app contexts on demand, unlike the others above. | 731 // We create per-app contexts on demand, unlike the others above. |
733 ChromeURLRequestContext* app_request_context = | 732 ChromeURLRequestContext* app_request_context = |
734 InitializeAppRequestContext(main_context, | 733 InitializeAppRequestContext(main_context, |
735 partition_descriptor, | 734 partition_descriptor, |
736 protocol_handler_interceptor.Pass(), | 735 protocol_handler_interceptor.Pass(), |
737 protocol_handlers, | 736 protocol_handlers, |
738 protocol_interceptors.Pass()); | 737 request_interceptors.Pass()); |
739 DCHECK(app_request_context); | 738 DCHECK(app_request_context); |
740 return app_request_context; | 739 return app_request_context; |
741 } | 740 } |
742 | 741 |
743 ChromeURLRequestContext* | 742 ChromeURLRequestContext* |
744 ProfileImplIOData::AcquireIsolatedMediaRequestContext( | 743 ProfileImplIOData::AcquireIsolatedMediaRequestContext( |
745 ChromeURLRequestContext* app_context, | 744 ChromeURLRequestContext* app_context, |
746 const StoragePartitionDescriptor& partition_descriptor) const { | 745 const StoragePartitionDescriptor& partition_descriptor) const { |
747 // We create per-app media contexts on demand, unlike the others above. | 746 // We create per-app media contexts on demand, unlike the others above. |
748 ChromeURLRequestContext* media_request_context = | 747 ChromeURLRequestContext* media_request_context = |
(...skipping 19 matching lines...) Expand all Loading... |
768 domain_reliability::DomainReliabilityClearMode mode, | 767 domain_reliability::DomainReliabilityClearMode mode, |
769 const base::Closure& completion) { | 768 const base::Closure& completion) { |
770 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 769 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
771 DCHECK(initialized()); | 770 DCHECK(initialized()); |
772 | 771 |
773 if (domain_reliability_monitor_) | 772 if (domain_reliability_monitor_) |
774 domain_reliability_monitor_->ClearBrowsingData(mode); | 773 domain_reliability_monitor_->ClearBrowsingData(mode); |
775 | 774 |
776 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, completion); | 775 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, completion); |
777 } | 776 } |
OLD | NEW |