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

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: 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/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 39ced7a0f2d5b8610b875a14eab6a271067756e1..1ef9ca7b11c6c823a5d5c46a61df468c1ce69699 100644
--- a/content/browser/service_worker/service_worker_version.h
+++ b/content/browser/service_worker/service_worker_version.h
@@ -236,6 +236,12 @@ 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.
+ // Returns true if the request was successfully scheduled to starrt.
+ 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.
@@ -246,6 +252,11 @@ class CONTENT_EXPORT ServiceWorkerVersion
bool was_handled,
base::Time dispatch_event_time);
+ // Finishes an external request that was started by StartExternalRequest().
+ // Returns false if there was an error finishing the request: e.g. the request
+ // was not found or the worker already terminated.
+ 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
@@ -383,6 +394,11 @@ class CONTENT_EXPORT ServiceWorkerVersion
// requests, in-progress streaming URLRequestJobs, or pending start callbacks.
bool HasWork() const;
+ // Returns the number of pending external request count of this worker.
+ size_t GetExternalRequestCountForTest() const {
+ return external_request_uuid_to_request_id_.size();
+ }
+
private:
friend class base::RefCounted<ServiceWorkerVersion>;
friend class ServiceWorkerMetrics;
@@ -695,6 +711,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_;
@@ -714,6 +734,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.
« no previous file with comments | « content/browser/service_worker/service_worker_metrics.cc ('k') | content/browser/service_worker/service_worker_version.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698