Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(404)

Side by Side Diff: content/browser/service_worker/service_worker_context_wrapper.cc

Issue 1771283002: service worker: Observe when resource context is shutting down (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix unittests Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 DCHECK_CURRENTLY_ON(BrowserThread::UI); 123 DCHECK_CURRENTLY_ON(BrowserThread::UI);
124 124
125 storage_partition_ = nullptr; 125 storage_partition_ = nullptr;
126 process_manager_->Shutdown(); 126 process_manager_->Shutdown();
127 BrowserThread::PostTask( 127 BrowserThread::PostTask(
128 BrowserThread::IO, 128 BrowserThread::IO,
129 FROM_HERE, 129 FROM_HERE,
130 base::Bind(&ServiceWorkerContextWrapper::ShutdownOnIO, this)); 130 base::Bind(&ServiceWorkerContextWrapper::ShutdownOnIO, this));
131 } 131 }
132 132
133 void ServiceWorkerContextWrapper::InitializeResourceContext(
134 ResourceContext* resource_context,
135 scoped_refptr<net::URLRequestContextGetter> request_context_getter) {
136 DCHECK_CURRENTLY_ON(BrowserThread::IO);
137 resource_context_ = resource_context;
138 request_context_getter_ = request_context_getter;
139 // Can be null in tests.
140 if (request_context_getter_)
141 request_context_getter_->AddObserver(this);
142 }
143
144 void ServiceWorkerContextWrapper::OnContextShuttingDown() {
145 DCHECK_CURRENTLY_ON(BrowserThread::IO);
146 request_context_getter_->RemoveObserver(this);
michaeln 2016/03/10 21:15:53 You mentioned this isn't called on ContentShell.
mmenke 2016/03/10 21:20:51 I view this as a hack to resolve incorrect class d
147
148 // OnContextShuttingDown is called when the ProfileIOData (ResourceContext) is
149 // shutting down, so call ShutdownOnIO() to clear resource_context_.
150 // This doesn't seem to be called when using content_shell, so we still must
151 // also call ShutdownOnIO() in Shutdown(), which is called when the storage
152 // partition is destroyed.
153 ShutdownOnIO();
154 }
155
133 void ServiceWorkerContextWrapper::DeleteAndStartOver() { 156 void ServiceWorkerContextWrapper::DeleteAndStartOver() {
134 DCHECK_CURRENTLY_ON(BrowserThread::IO); 157 DCHECK_CURRENTLY_ON(BrowserThread::IO);
135 if (!context_core_) { 158 if (!context_core_) {
136 // The context could be null due to system shutdown or restart failure. In 159 // The context could be null due to system shutdown or restart failure. In
137 // either case, we should not have to recover the system, so just return 160 // either case, we should not have to recover the system, so just return
138 // here. 161 // here.
139 return; 162 return;
140 } 163 }
141 context_core_->DeleteAndStartOver( 164 context_core_->DeleteAndStartOver(
142 base::Bind(&ServiceWorkerContextWrapper::DidDeleteAndStartOver, this)); 165 base::Bind(&ServiceWorkerContextWrapper::DidDeleteAndStartOver, this));
143 } 166 }
144 167
145 StoragePartitionImpl* ServiceWorkerContextWrapper::storage_partition() const { 168 StoragePartitionImpl* ServiceWorkerContextWrapper::storage_partition() const {
146 DCHECK_CURRENTLY_ON(BrowserThread::UI); 169 DCHECK_CURRENTLY_ON(BrowserThread::UI);
147 return storage_partition_; 170 return storage_partition_;
148 } 171 }
149 172
150 void ServiceWorkerContextWrapper::set_storage_partition( 173 void ServiceWorkerContextWrapper::set_storage_partition(
151 StoragePartitionImpl* storage_partition) { 174 StoragePartitionImpl* storage_partition) {
152 DCHECK_CURRENTLY_ON(BrowserThread::UI); 175 DCHECK_CURRENTLY_ON(BrowserThread::UI);
153 storage_partition_ = storage_partition; 176 storage_partition_ = storage_partition;
154 } 177 }
155 178
156 ResourceContext* ServiceWorkerContextWrapper::resource_context() { 179 ResourceContext* ServiceWorkerContextWrapper::resource_context() {
157 DCHECK_CURRENTLY_ON(BrowserThread::IO); 180 DCHECK_CURRENTLY_ON(BrowserThread::IO);
158 return resource_context_; 181 return resource_context_;
159 } 182 }
160 183
161 void ServiceWorkerContextWrapper::set_resource_context(
162 ResourceContext* resource_context) {
163 DCHECK_CURRENTLY_ON(BrowserThread::IO);
164 resource_context_ = resource_context;
165 }
166
167 static void FinishRegistrationOnIO( 184 static void FinishRegistrationOnIO(
168 const ServiceWorkerContext::ResultCallback& continuation, 185 const ServiceWorkerContext::ResultCallback& continuation,
169 ServiceWorkerStatusCode status, 186 ServiceWorkerStatusCode status,
170 const std::string& status_message, 187 const std::string& status_message,
171 int64_t registration_id) { 188 int64_t registration_id) {
172 DCHECK_CURRENTLY_ON(BrowserThread::IO); 189 DCHECK_CURRENTLY_ON(BrowserThread::IO);
173 BrowserThread::PostTask( 190 BrowserThread::PostTask(
174 BrowserThread::UI, 191 BrowserThread::UI,
175 FROM_HERE, 192 FROM_HERE,
176 base::Bind(continuation, status == SERVICE_WORKER_OK)); 193 base::Bind(continuation, status == SERVICE_WORKER_OK));
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 observer_list_->Notify(FROM_HERE, 715 observer_list_->Notify(FROM_HERE,
699 &ServiceWorkerContextObserver::OnStorageWiped); 716 &ServiceWorkerContextObserver::OnStorageWiped);
700 } 717 }
701 718
702 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { 719 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() {
703 DCHECK_CURRENTLY_ON(BrowserThread::IO); 720 DCHECK_CURRENTLY_ON(BrowserThread::IO);
704 return context_core_.get(); 721 return context_core_.get();
705 } 722 }
706 723
707 } // namespace content 724 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_context_wrapper.h ('k') | content/browser/storage_partition_impl_map.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698