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