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

Unified Diff: content/public/browser/service_worker_context.h

Issue 2166523003: Add ref count to service workers for extension API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sync@tott Created 4 years, 2 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/public/browser/service_worker_context.h
diff --git a/content/public/browser/service_worker_context.h b/content/public/browser/service_worker_context.h
index 47f355c734ae46b1a5e17b04968f898a526901c0..c095f9d1314c7fe028441bb19479c2f73d4fc99e 100644
--- a/content/public/browser/service_worker_context.h
+++ b/content/public/browser/service_worker_context.h
@@ -23,15 +23,18 @@ class ServiceWorkerContext {
public:
// https://rawgithub.com/slightlyoff/ServiceWorker/master/spec/service_worker/index.html#url-scope:
// roughly, must be of the form "<origin>/<path>/*".
- typedef GURL Scope;
+ using Scope = GURL;
- typedef base::Callback<void(bool success)> ResultCallback;
+ using ResultCallback = base::Callback<void(bool success)>;
- typedef base::Callback<void(const std::vector<ServiceWorkerUsageInfo>&
- usage_info)> GetUsageInfoCallback;
+ using GetUsageInfoCallback = base::Callback<void(
+ const std::vector<ServiceWorkerUsageInfo>& usage_info)>;
- typedef base::Callback<void(bool has_service_worker)>
- CheckHasServiceWorkerCallback;
+ using CheckHasServiceWorkerCallback =
+ base::Callback<void(bool has_service_worker)>;
+
+ using CountExternalRequestsCallback =
+ base::Callback<void(size_t external_request_count)>;
// Registers the header name which should not be passed to the ServiceWorker.
// Must be called from the IO thread.
@@ -60,6 +63,21 @@ class ServiceWorkerContext {
const GURL& script_url,
const ResultCallback& callback) = 0;
+ // Mechanism for embedder to increment/decrement ref count of a service
+ // worker.
+ // Embedders can call StartingExternalRequest() while it is performing some
+ // work with the worker. The worker is considered to be working until embedder
+ // calls FinishedExternalRequest(). This ensures that content/ does not
+ // shut the worker down while embedder is expecting the worker to be kept
+ // alive.
+ //
+ // Must be called from the IO thread. Returns whether or not changing the ref
+ // count succeeded.
+ virtual bool StartingExternalRequest(int64_t service_worker_version_id,
+ const std::string& request_uuid) = 0;
+ virtual bool FinishedExternalRequest(int64_t service_worker_version_id,
+ const std::string& request_uuid) = 0;
+
// Equivalent to calling navigator.serviceWorker.unregister(pattern) from a
// renderer, except that |pattern| is an absolute URL instead of relative to
// some current origin. |callback| is passed true when the JS promise is
@@ -96,6 +114,12 @@ class ServiceWorkerContext {
const GURL& other_url,
const CheckHasServiceWorkerCallback& callback) = 0;
+ // Returns the pending external request count for the worker with the
+ // specified |origin| via |callback|.
+ virtual void CountExternalRequestsForTest(
+ const GURL& origin,
+ const CountExternalRequestsCallback& callback) = 0;
+
// Stops all running workers on the given |origin|.
//
// This function can be called from any thread.
« no previous file with comments | « content/browser/service_worker/service_worker_version.cc ('k') | content/public/renderer/content_renderer_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698