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

Unified Diff: content/child/service_worker/service_worker_provider_context.cc

Issue 849163002: ServiceWorker: Expose registration within ServiceWorkerGlobalScope [2/3] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove dcheck Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: content/child/service_worker/service_worker_provider_context.cc
diff --git a/content/child/service_worker/service_worker_provider_context.cc b/content/child/service_worker/service_worker_provider_context.cc
index 326b25b6f75d6d9d4e21b720fe50f59597209f5f..f37cc65c6854dc7e49310bedbc18f8f51d79bf9f 100644
--- a/content/child/service_worker/service_worker_provider_context.cc
+++ b/content/child/service_worker/service_worker_provider_context.cc
@@ -33,6 +33,7 @@ ServiceWorkerProviderContext::ServiceWorkerProviderContext(int provider_id)
ServiceWorkerProviderContext::~ServiceWorkerProviderContext() {
if (ServiceWorkerDispatcher* dispatcher =
ServiceWorkerDispatcher::GetThreadSpecificInstance()) {
+ // Remove this context from the dispatcher living on the main thread.
dispatcher->RemoveProviderContext(this);
}
}
@@ -44,12 +45,15 @@ ServiceWorkerHandleReference* ServiceWorkerProviderContext::controller() {
ServiceWorkerRegistrationHandleReference*
ServiceWorkerProviderContext::registration() {
- DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread());
+ base::AutoLock lock(lock_);
return registration_.get();
}
ServiceWorkerVersionAttributes
ServiceWorkerProviderContext::GetVersionAttributes() {
+ base::AutoLock lock(lock_);
+ DCHECK(registration_);
+
ServiceWorkerVersionAttributes attrs;
if (installing_)
attrs.installing = installing_->info();
@@ -63,6 +67,7 @@ ServiceWorkerProviderContext::GetVersionAttributes() {
void ServiceWorkerProviderContext::SetVersionAttributes(
ChangedVersionAttributesMask mask,
const ServiceWorkerVersionAttributes& attrs) {
+ base::AutoLock lock(lock_);
DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread());
DCHECK(registration_);
@@ -83,6 +88,7 @@ void ServiceWorkerProviderContext::SetVersionAttributes(
void ServiceWorkerProviderContext::OnAssociateRegistration(
const ServiceWorkerRegistrationObjectInfo& info,
const ServiceWorkerVersionAttributes& attrs) {
+ base::AutoLock lock(lock_);
DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread());
DCHECK(!registration_);
DCHECK_NE(kInvalidServiceWorkerRegistrationId, info.registration_id);
@@ -99,7 +105,9 @@ void ServiceWorkerProviderContext::OnAssociateRegistration(
}
void ServiceWorkerProviderContext::OnDisassociateRegistration() {
+ base::AutoLock lock(lock_);
DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread());
+
controller_.reset();
active_.reset();
waiting_.reset();
@@ -110,6 +118,7 @@ void ServiceWorkerProviderContext::OnDisassociateRegistration() {
void ServiceWorkerProviderContext::OnServiceWorkerStateChanged(
int handle_id,
blink::WebServiceWorkerState state) {
+ base::AutoLock lock(lock_);
DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread());
ServiceWorkerHandleReference* which = NULL;
@@ -176,4 +185,12 @@ int ServiceWorkerProviderContext::registration_handle_id() const {
: kInvalidServiceWorkerRegistrationHandleId;
}
+void ServiceWorkerProviderContext::DestructOnMainThread() const {
+ if (!main_thread_loop_proxy_->RunsTasksOnCurrentThread() &&
+ main_thread_loop_proxy_->DeleteSoon(FROM_HERE, this)) {
+ return;
+ }
+ delete this;
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698