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

Unified Diff: content/browser/service_worker/service_worker_version.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: address comments from Devlin + MichaelN 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/browser/service_worker/service_worker_version.h
diff --git a/content/browser/service_worker/service_worker_version.h b/content/browser/service_worker/service_worker_version.h
index 5026700bcbe09f5a78f3a83a27c1700d9fe29a70..ff17826518658597412722d91f8bd6e80a82d2df 100644
--- a/content/browser/service_worker/service_worker_version.h
+++ b/content/browser/service_worker/service_worker_version.h
@@ -235,6 +235,11 @@ class CONTENT_EXPORT ServiceWorkerVersion
const base::TimeDelta& timeout,
TimeoutBehavior timeout_behavior);
+ // Starts a request of type EventType::EXTERNAL_REQUEST.
+ // Provides a mechanism to external clients to keep the worker running.
+ // |request_uuid| is a GUID for clients to identify the request.
+ bool StartExternalRequest(const std::string& request_uuid);
+
// Informs ServiceWorkerVersion that an event has finished being dispatched.
// Returns false if no pending requests with the provided id exist, for
// example if the request has already timed out.
@@ -245,6 +250,9 @@ class CONTENT_EXPORT ServiceWorkerVersion
bool was_handled,
base::Time dispatch_event_time);
+ // Finishes an external request that was started by StartExternalRequest().
+ bool FinishExternalRequest(const std::string& request_uuid);
+
// Connects to a specific mojo service exposed by the (running) service
// worker. If a connection to a service for the same Interface already exists
// this will return that existing connection. The |request_id| must be a value
@@ -681,6 +689,10 @@ class CONTENT_EXPORT ServiceWorkerVersion
// callbacks.
void FinishStartWorker(ServiceWorkerStatusCode status);
+ // Removes any pending external request that has GUID of |request_uuid|.
+ void CleanUpExternalRequest(const std::string& request_uuid,
+ ServiceWorkerStatusCode status);
+
const int64_t version_id_;
const int64_t registration_id_;
const GURL script_url_;
@@ -700,6 +712,11 @@ class CONTENT_EXPORT ServiceWorkerVersion
// fetch, sync, etc. events.
IDMap<PendingRequest, IDMapOwnPointer> pending_requests_;
+ // Container for pending external requests for this service worker.
+ // (key, value): (request uuid, request id).
+ using RequestUUIDToRequestIDMap = std::map<std::string, int>;
+ RequestUUIDToRequestIDMap external_request_uuid_to_request_id_;
+
// Stores all open connections to mojo services. Maps the service name to
// the actual interface pointer. When a connection is closed it is removed
// from this map.

Powered by Google App Engine
This is Rietveld 408576698