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

Unified Diff: content/browser/service_worker/service_worker_version.h

Issue 912753002: Stop Service Workers that execute JavaScript for too long. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rethink Created 5 years, 10 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 f95b4ea26f68ec51e8d80560dc92cc70ca1e15de..b39c9c5542df79e066d63ec06d3c5ef2e45fff7c 100644
--- a/content/browser/service_worker/service_worker_version.h
+++ b/content/browser/service_worker/service_worker_version.h
@@ -316,6 +316,12 @@ class CONTENT_EXPORT ServiceWorkerVersion
FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, ScheduleStopWorker);
FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, KeepAlive);
FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, ListenerAvailability);
+ FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionBrowserTest,
+ TimeoutStartingWorker);
+ FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionBrowserTest,
+ TimeoutWorkerInEvent);
+ friend class ServiceWorkerVersionBrowserTest;
+
typedef ServiceWorkerVersion self;
typedef std::map<ServiceWorkerProviderHost*, int> ControlleeMap;
typedef IDMap<ServiceWorkerProviderHost> ControlleeByIDMap;
@@ -323,6 +329,7 @@ class CONTENT_EXPORT ServiceWorkerVersion
~ServiceWorkerVersion() override;
// EmbeddedWorkerInstance::Listener overrides:
+ void OnScriptLoaded() override;
void OnStarted() override;
void OnStopped(EmbeddedWorkerInstance::Status old_status) override;
void OnReportException(const base::string16& error_message,
@@ -380,6 +387,7 @@ class CONTENT_EXPORT ServiceWorkerVersion
void OnFocusClient(int request_id, int client_id);
void OnSkipWaiting(int request_id);
void OnClaimClients(int request_id);
+ void OnPongFromWorker();
void OnFocusClientFinished(int request_id,
int client_id,
@@ -391,6 +399,18 @@ class CONTENT_EXPORT ServiceWorkerVersion
scoped_refptr<GetClientDocumentsCallback> callback,
const ServiceWorkerClientInfo& info);
+ // The ping protocol is for terminating workers that are taking excessively
+ // long executing JavaScript (e.g., stuck in while(true) {}). Periodically a
+ // ping IPC is sent to the worker context and if we timeout waiting for a
+ // pong, the worker is terminated.
+ void PingWorker();
+ void StartPingWorker();
+ void SchedulePingWorker();
+ void OnPingTimeout();
+
+ // ScheduleStopWorker is for terminating idle workers. It schedules an attempt
+ // to stop: if the worker has no inflight requests when the attempt runs, the
+ // worker is terminated, otherwise the attempt is rescheduled.
void ScheduleStopWorker();
void StopWorkerIfIdle();
bool HasInflightRequests() const;
@@ -433,6 +453,8 @@ class CONTENT_EXPORT ServiceWorkerVersion
ServiceWorkerScriptCacheMap script_cache_map_;
base::OneShotTimer<ServiceWorkerVersion> stop_worker_timer_;
base::OneShotTimer<ServiceWorkerVersion> update_timer_;
+ base::OneShotTimer<ServiceWorkerVersion> ping_worker_timer_;
+ bool ping_timed_out_;
bool is_doomed_;
std::vector<int> pending_skip_waiting_requests_;
bool skip_waiting_;
« no previous file with comments | « content/browser/service_worker/service_worker_browsertest.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