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

Unified Diff: content/browser/service_worker/service_worker_context_wrapper.cc

Issue 2166523003: Add ref count to service workers for extension API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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/browser/service_worker/service_worker_context_wrapper.cc
diff --git a/content/browser/service_worker/service_worker_context_wrapper.cc b/content/browser/service_worker/service_worker_context_wrapper.cc
index 0c32d7168594bb9f4070c13c35cdde1da532f790..368488a33986be49725b762c2a859c253b329811 100644
--- a/content/browser/service_worker/service_worker_context_wrapper.cc
+++ b/content/browser/service_worker/service_worker_context_wrapper.cc
@@ -20,6 +20,7 @@
#include "base/single_thread_task_runner.h"
#include "base/threading/sequenced_worker_pool.h"
#include "base/threading/thread_task_runner_handle.h"
+#include "content/browser/service_worker/embedded_worker_registry.h"
#include "content/browser/service_worker/service_worker_context_core.h"
#include "content/browser/service_worker/service_worker_context_observer.h"
#include "content/browser/service_worker/service_worker_process_manager.h"
@@ -101,6 +102,22 @@ bool ServiceWorkerContext::IsExcludedHeaderNameForFetchEvent(
g_excluded_header_name_set.Get().end();
}
+// static.
+void ServiceWorkerContext::IncrementEmbeddedWorkerRefCount(
+ StoragePartition* storage_partition,
+ int embedded_worker_id) {
+ ServiceWorkerContextWrapper::IncrementEmbeddedWorkerRefCount(
+ storage_partition, embedded_worker_id);
+}
+
+// static.
+void ServiceWorkerContext::DecrementEmbeddedWorkerRefCount(
+ StoragePartition* storage_partition,
+ int embedded_worker_id) {
+ ServiceWorkerContextWrapper::DecrementEmbeddedWorkerRefCount(
+ storage_partition, embedded_worker_id);
+}
+
ServiceWorkerContextWrapper::ServiceWorkerContextWrapper(
BrowserContext* browser_context)
: observer_list_(
@@ -727,6 +744,49 @@ void ServiceWorkerContextWrapper::ShutdownOnIO() {
context_core_.reset();
}
+// static.
+void ServiceWorkerContextWrapper::IncrementEmbeddedWorkerRefCount(
+ StoragePartition* storage_partition,
+ int embedded_worker_id) {
+ ServiceWorkerContextWrapper* context_wrapper =
+ static_cast<ServiceWorkerContextWrapper*>(
+ storage_partition->GetServiceWorkerContext());
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(
+ &ServiceWorkerContextWrapper::IncrementEmbeddedWorkerRefCountOnIO,
+ context_wrapper, embedded_worker_id));
+}
+
+// static.
+void ServiceWorkerContextWrapper::DecrementEmbeddedWorkerRefCount(
+ StoragePartition* storage_partition,
+ int embedded_worker_id) {
+ ServiceWorkerContextWrapper* context_wrapper =
+ static_cast<ServiceWorkerContextWrapper*>(
+ storage_partition->GetServiceWorkerContext());
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(
+ &ServiceWorkerContextWrapper::DecrementEmbeddedWorkerRefCountOnIO,
+ context_wrapper, embedded_worker_id));
+}
+
+void ServiceWorkerContextWrapper::IncrementEmbeddedWorkerRefCountOnIO(
+ int embedded_worker_id) {
+ context()
+ ->embedded_worker_registry()
+ ->GetWorker(embedded_worker_id)
+ ->IncrementRefCount();
+}
+void ServiceWorkerContextWrapper::DecrementEmbeddedWorkerRefCountOnIO(
+ int embedded_worker_id) {
+ context()
+ ->embedded_worker_registry()
+ ->GetWorker(embedded_worker_id)
+ ->DecrementRefCount();
+}
+
void ServiceWorkerContextWrapper::DidDeleteAndStartOver(
ServiceWorkerStatusCode status) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);

Powered by Google App Engine
This is Rietveld 408576698