| 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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 new base::ObserverListThreadSafe<ServiceWorkerContextObserver>()), | 107 new base::ObserverListThreadSafe<ServiceWorkerContextObserver>()), |
| 108 process_manager_(new ServiceWorkerProcessManager(browser_context)), | 108 process_manager_(new ServiceWorkerProcessManager(browser_context)), |
| 109 is_incognito_(false), | 109 is_incognito_(false), |
| 110 storage_partition_(nullptr), | 110 storage_partition_(nullptr), |
| 111 resource_context_(nullptr) { | 111 resource_context_(nullptr) { |
| 112 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 112 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 113 } | 113 } |
| 114 | 114 |
| 115 ServiceWorkerContextWrapper::~ServiceWorkerContextWrapper() { | 115 ServiceWorkerContextWrapper::~ServiceWorkerContextWrapper() { |
| 116 DCHECK(!resource_context_); | 116 DCHECK(!resource_context_); |
| 117 DCHECK(!request_context_getter_); | |
| 118 } | 117 } |
| 119 | 118 |
| 120 void ServiceWorkerContextWrapper::Init( | 119 void ServiceWorkerContextWrapper::Init( |
| 121 const base::FilePath& user_data_directory, | 120 const base::FilePath& user_data_directory, |
| 122 storage::QuotaManagerProxy* quota_manager_proxy, | 121 storage::QuotaManagerProxy* quota_manager_proxy, |
| 123 storage::SpecialStoragePolicy* special_storage_policy) { | 122 storage::SpecialStoragePolicy* special_storage_policy) { |
| 124 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 123 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 125 | 124 |
| 126 is_incognito_ = user_data_directory.empty(); | 125 is_incognito_ = user_data_directory.empty(); |
| 127 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool(); | 126 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 138 | 137 |
| 139 storage_partition_ = nullptr; | 138 storage_partition_ = nullptr; |
| 140 process_manager_->Shutdown(); | 139 process_manager_->Shutdown(); |
| 141 BrowserThread::PostTask( | 140 BrowserThread::PostTask( |
| 142 BrowserThread::IO, | 141 BrowserThread::IO, |
| 143 FROM_HERE, | 142 FROM_HERE, |
| 144 base::Bind(&ServiceWorkerContextWrapper::ShutdownOnIO, this)); | 143 base::Bind(&ServiceWorkerContextWrapper::ShutdownOnIO, this)); |
| 145 } | 144 } |
| 146 | 145 |
| 147 void ServiceWorkerContextWrapper::InitializeResourceContext( | 146 void ServiceWorkerContextWrapper::InitializeResourceContext( |
| 148 ResourceContext* resource_context, | 147 ResourceContext* resource_context) { |
| 149 scoped_refptr<net::URLRequestContextGetter> request_context_getter) { | |
| 150 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 148 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 151 resource_context_ = resource_context; | 149 resource_context_ = resource_context; |
| 152 request_context_getter_ = request_context_getter; | |
| 153 // Can be null in tests. | |
| 154 if (request_context_getter_) | |
| 155 request_context_getter_->AddObserver(this); | |
| 156 } | |
| 157 | |
| 158 void ServiceWorkerContextWrapper::OnContextShuttingDown() { | |
| 159 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 160 | |
| 161 // OnContextShuttingDown is called when the ProfileIOData (ResourceContext) is | |
| 162 // shutting down, so call ShutdownOnIO() to clear resource_context_. | |
| 163 // This doesn't seem to be called when using content_shell, so we still must | |
| 164 // also call ShutdownOnIO() in Shutdown(), which is called when the storage | |
| 165 // partition is destroyed. | |
| 166 ShutdownOnIO(); | |
| 167 } | 150 } |
| 168 | 151 |
| 169 void ServiceWorkerContextWrapper::DeleteAndStartOver() { | 152 void ServiceWorkerContextWrapper::DeleteAndStartOver() { |
| 170 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 153 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 171 if (!context_core_) { | 154 if (!context_core_) { |
| 172 // The context could be null due to system shutdown or restart failure. In | 155 // The context could be null due to system shutdown or restart failure. In |
| 173 // either case, we should not have to recover the system, so just return | 156 // either case, we should not have to recover the system, so just return |
| 174 // here. | 157 // here. |
| 175 return; | 158 return; |
| 176 } | 159 } |
| (...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 if (quota_manager_proxy) { | 695 if (quota_manager_proxy) { |
| 713 quota_manager_proxy->RegisterClient(new ServiceWorkerQuotaClient(this)); | 696 quota_manager_proxy->RegisterClient(new ServiceWorkerQuotaClient(this)); |
| 714 } | 697 } |
| 715 context_core_.reset(new ServiceWorkerContextCore( | 698 context_core_.reset(new ServiceWorkerContextCore( |
| 716 user_data_directory, std::move(database_task_manager), disk_cache_thread, | 699 user_data_directory, std::move(database_task_manager), disk_cache_thread, |
| 717 quota_manager_proxy, special_storage_policy, observer_list_.get(), this)); | 700 quota_manager_proxy, special_storage_policy, observer_list_.get(), this)); |
| 718 } | 701 } |
| 719 | 702 |
| 720 void ServiceWorkerContextWrapper::ShutdownOnIO() { | 703 void ServiceWorkerContextWrapper::ShutdownOnIO() { |
| 721 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 704 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 722 // Can be null in tests. | |
| 723 if (request_context_getter_) | |
| 724 request_context_getter_->RemoveObserver(this); | |
| 725 request_context_getter_ = nullptr; | |
| 726 resource_context_ = nullptr; | 705 resource_context_ = nullptr; |
| 727 context_core_.reset(); | 706 context_core_.reset(); |
| 728 } | 707 } |
| 729 | 708 |
| 730 void ServiceWorkerContextWrapper::DidDeleteAndStartOver( | 709 void ServiceWorkerContextWrapper::DidDeleteAndStartOver( |
| 731 ServiceWorkerStatusCode status) { | 710 ServiceWorkerStatusCode status) { |
| 732 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 711 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 733 if (status != SERVICE_WORKER_OK) { | 712 if (status != SERVICE_WORKER_OK) { |
| 734 context_core_.reset(); | 713 context_core_.reset(); |
| 735 return; | 714 return; |
| 736 } | 715 } |
| 737 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); | 716 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); |
| 738 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; | 717 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; |
| 739 | 718 |
| 740 observer_list_->Notify(FROM_HERE, | 719 observer_list_->Notify(FROM_HERE, |
| 741 &ServiceWorkerContextObserver::OnStorageWiped); | 720 &ServiceWorkerContextObserver::OnStorageWiped); |
| 742 } | 721 } |
| 743 | 722 |
| 744 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { | 723 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { |
| 745 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 724 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 746 return context_core_.get(); | 725 return context_core_.get(); |
| 747 } | 726 } |
| 748 | 727 |
| 749 } // namespace content | 728 } // namespace content |
| OLD | NEW |