OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/browser/service_worker/service_worker_context_wrapper.h" | 5 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "content/browser/service_worker/service_worker_process_manager.h" | 24 #include "content/browser/service_worker/service_worker_process_manager.h" |
25 #include "content/browser/service_worker/service_worker_quota_client.h" | 25 #include "content/browser/service_worker/service_worker_quota_client.h" |
26 #include "content/browser/service_worker/service_worker_version.h" | 26 #include "content/browser/service_worker/service_worker_version.h" |
27 #include "content/browser/storage_partition_impl.h" | 27 #include "content/browser/storage_partition_impl.h" |
28 #include "content/common/service_worker/service_worker_status_code.h" | 28 #include "content/common/service_worker/service_worker_status_code.h" |
29 #include "content/common/service_worker/service_worker_utils.h" | 29 #include "content/common/service_worker/service_worker_utils.h" |
30 #include "content/public/browser/browser_context.h" | 30 #include "content/public/browser/browser_context.h" |
31 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
32 #include "content/public/browser/service_worker_context_observer.h" | 32 #include "content/public/browser/service_worker_context_observer.h" |
33 #include "net/base/url_util.h" | 33 #include "net/base/url_util.h" |
| 34 #include "storage/browser/blob/blob_storage_context.h" |
34 #include "storage/browser/quota/quota_manager_proxy.h" | 35 #include "storage/browser/quota/quota_manager_proxy.h" |
35 #include "storage/browser/quota/special_storage_policy.h" | 36 #include "storage/browser/quota/special_storage_policy.h" |
36 | 37 |
37 namespace content { | 38 namespace content { |
38 | 39 |
39 namespace { | 40 namespace { |
40 | 41 |
41 typedef std::set<std::string> HeaderNameSet; | 42 typedef std::set<std::string> HeaderNameSet; |
42 base::LazyInstance<HeaderNameSet>::DestructorAtExit g_excluded_header_name_set = | 43 base::LazyInstance<HeaderNameSet>::DestructorAtExit g_excluded_header_name_set = |
43 LAZY_INSTANCE_INITIALIZER; | 44 LAZY_INSTANCE_INITIALIZER; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 // Explicitly remove this object as an observer to avoid use-after-frees in | 142 // Explicitly remove this object as an observer to avoid use-after-frees in |
142 // tests where this object is not guaranteed to outlive the | 143 // tests where this object is not guaranteed to outlive the |
143 // ServiceWorkerContextCore it wraps. | 144 // ServiceWorkerContextCore it wraps. |
144 core_observer_list_->RemoveObserver(this); | 145 core_observer_list_->RemoveObserver(this); |
145 DCHECK(!resource_context_); | 146 DCHECK(!resource_context_); |
146 } | 147 } |
147 | 148 |
148 void ServiceWorkerContextWrapper::Init( | 149 void ServiceWorkerContextWrapper::Init( |
149 const base::FilePath& user_data_directory, | 150 const base::FilePath& user_data_directory, |
150 storage::QuotaManagerProxy* quota_manager_proxy, | 151 storage::QuotaManagerProxy* quota_manager_proxy, |
151 storage::SpecialStoragePolicy* special_storage_policy) { | 152 storage::SpecialStoragePolicy* special_storage_policy, |
| 153 ChromeBlobStorageContext* blob_context, |
| 154 URLLoaderFactoryGetter* loader_factory_getter) { |
152 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 155 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
153 | 156 |
154 is_incognito_ = user_data_directory.empty(); | 157 is_incognito_ = user_data_directory.empty(); |
155 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool(); | 158 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool(); |
156 std::unique_ptr<ServiceWorkerDatabaseTaskManager> database_task_manager( | 159 std::unique_ptr<ServiceWorkerDatabaseTaskManager> database_task_manager( |
157 new ServiceWorkerDatabaseTaskManagerImpl(pool)); | 160 new ServiceWorkerDatabaseTaskManagerImpl(pool)); |
158 scoped_refptr<base::SingleThreadTaskRunner> disk_cache_thread = | 161 scoped_refptr<base::SingleThreadTaskRunner> disk_cache_thread = |
159 BrowserThread::GetTaskRunnerForThread(BrowserThread::CACHE); | 162 BrowserThread::GetTaskRunnerForThread(BrowserThread::CACHE); |
160 InitInternal(user_data_directory, std::move(database_task_manager), | 163 InitInternal(user_data_directory, std::move(database_task_manager), |
161 disk_cache_thread, quota_manager_proxy, special_storage_policy); | 164 disk_cache_thread, quota_manager_proxy, special_storage_policy, |
| 165 blob_context, loader_factory_getter); |
162 } | 166 } |
163 | 167 |
164 void ServiceWorkerContextWrapper::Shutdown() { | 168 void ServiceWorkerContextWrapper::Shutdown() { |
165 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 169 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
166 | 170 |
167 storage_partition_ = nullptr; | 171 storage_partition_ = nullptr; |
168 process_manager_->Shutdown(); | 172 process_manager_->Shutdown(); |
169 BrowserThread::PostTask( | 173 BrowserThread::PostTask( |
170 BrowserThread::IO, | 174 BrowserThread::IO, |
171 FROM_HERE, | 175 FROM_HERE, |
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
782 if (!context_core_) | 786 if (!context_core_) |
783 return false; | 787 return false; |
784 return context_core_->storage()->OriginHasForeignFetchRegistrations(origin); | 788 return context_core_->storage()->OriginHasForeignFetchRegistrations(origin); |
785 } | 789 } |
786 | 790 |
787 void ServiceWorkerContextWrapper::InitInternal( | 791 void ServiceWorkerContextWrapper::InitInternal( |
788 const base::FilePath& user_data_directory, | 792 const base::FilePath& user_data_directory, |
789 std::unique_ptr<ServiceWorkerDatabaseTaskManager> database_task_manager, | 793 std::unique_ptr<ServiceWorkerDatabaseTaskManager> database_task_manager, |
790 const scoped_refptr<base::SingleThreadTaskRunner>& disk_cache_thread, | 794 const scoped_refptr<base::SingleThreadTaskRunner>& disk_cache_thread, |
791 storage::QuotaManagerProxy* quota_manager_proxy, | 795 storage::QuotaManagerProxy* quota_manager_proxy, |
792 storage::SpecialStoragePolicy* special_storage_policy) { | 796 storage::SpecialStoragePolicy* special_storage_policy, |
| 797 ChromeBlobStorageContext* blob_context, |
| 798 URLLoaderFactoryGetter* loader_factory_getter) { |
793 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 799 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
794 BrowserThread::PostTask( | 800 BrowserThread::PostTask( |
795 BrowserThread::IO, FROM_HERE, | 801 BrowserThread::IO, FROM_HERE, |
796 base::Bind(&ServiceWorkerContextWrapper::InitInternal, this, | 802 base::Bind(&ServiceWorkerContextWrapper::InitInternal, this, |
797 user_data_directory, base::Passed(&database_task_manager), | 803 user_data_directory, base::Passed(&database_task_manager), |
798 disk_cache_thread, base::RetainedRef(quota_manager_proxy), | 804 disk_cache_thread, base::RetainedRef(quota_manager_proxy), |
799 base::RetainedRef(special_storage_policy))); | 805 base::RetainedRef(special_storage_policy), |
| 806 base::RetainedRef(blob_context), |
| 807 base::RetainedRef(loader_factory_getter))); |
800 return; | 808 return; |
801 } | 809 } |
802 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. | 810 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. |
803 tracked_objects::ScopedTracker tracking_profile( | 811 tracked_objects::ScopedTracker tracking_profile( |
804 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 812 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
805 "477117 ServiceWorkerContextWrapper::InitInternal")); | 813 "477117 ServiceWorkerContextWrapper::InitInternal")); |
806 DCHECK(!context_core_); | 814 DCHECK(!context_core_); |
807 if (quota_manager_proxy) { | 815 if (quota_manager_proxy) { |
808 quota_manager_proxy->RegisterClient(new ServiceWorkerQuotaClient(this)); | 816 quota_manager_proxy->RegisterClient(new ServiceWorkerQuotaClient(this)); |
809 } | 817 } |
| 818 |
| 819 base::WeakPtr<storage::BlobStorageContext> blob_storage_context = |
| 820 blob_context && blob_context->context() |
| 821 ? blob_context->context()->AsWeakPtr() |
| 822 : nullptr; |
810 context_core_.reset(new ServiceWorkerContextCore( | 823 context_core_.reset(new ServiceWorkerContextCore( |
811 user_data_directory, std::move(database_task_manager), disk_cache_thread, | 824 user_data_directory, std::move(database_task_manager), disk_cache_thread, |
812 quota_manager_proxy, special_storage_policy, core_observer_list_.get(), | 825 quota_manager_proxy, special_storage_policy, blob_storage_context, |
813 this)); | 826 loader_factory_getter, core_observer_list_.get(), this)); |
814 } | 827 } |
815 | 828 |
816 void ServiceWorkerContextWrapper::ShutdownOnIO() { | 829 void ServiceWorkerContextWrapper::ShutdownOnIO() { |
817 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 830 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
818 resource_context_ = nullptr; | 831 resource_context_ = nullptr; |
819 context_core_.reset(); | 832 context_core_.reset(); |
820 } | 833 } |
821 | 834 |
822 bool ServiceWorkerContextWrapper::StartingExternalRequest( | 835 bool ServiceWorkerContextWrapper::StartingExternalRequest( |
823 int64_t service_worker_version_id, | 836 int64_t service_worker_version_id, |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
959 service_worker_provider_id, | 972 service_worker_provider_id, |
960 std::move(client_ptr_info)); | 973 std::move(client_ptr_info)); |
961 } | 974 } |
962 | 975 |
963 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { | 976 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { |
964 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 977 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
965 return context_core_.get(); | 978 return context_core_.get(); |
966 } | 979 } |
967 | 980 |
968 } // namespace content | 981 } // namespace content |
OLD | NEW |