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

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

Issue 2506263005: Prevent a service worker from keeping itself alive by self postMessage. (Closed)
Patch Set: fix unit test Created 4 years, 1 month 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 bbebd9e8c9f5036bf0000d6b7aa74389f5fb10ab..8c7c6ee124cec798e372821dec0d77ccdf8c170f 100644
--- a/content/browser/service_worker/service_worker_version.h
+++ b/content/browser/service_worker/service_worker_version.h
@@ -413,6 +413,12 @@ class CONTENT_EXPORT ServiceWorkerVersion
return external_request_uuid_to_request_id_.size();
}
+ // Returns the amount of time left until the request with the latest
+ // expiration time expires.
+ base::TimeDelta remaining_timeout() const {
+ return max_request_expiration_time_ - tick_clock_->NowTicks();
+ }
+
private:
friend class base::RefCounted<ServiceWorkerVersion>;
friend class ServiceWorkerMetrics;
@@ -455,6 +461,7 @@ class CONTENT_EXPORT ServiceWorkerVersion
FRIEND_TEST_ALL_PREFIXES(ServiceWorkerActivationTest, SkipWaiting);
FRIEND_TEST_ALL_PREFIXES(ServiceWorkerActivationTest,
SkipWaitingWithInflightRequest);
+ FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionBrowserTest, MessageSelf);
class Metrics;
class PingController;
@@ -588,6 +595,8 @@ class CONTENT_EXPORT ServiceWorkerVersion
static const int kRequestTimeoutMinutes;
// Timeout for the worker to stop.
static const int kStopWorkerTimeoutSeconds;
+ // Time to wait until stopping an idle worker.
+ static const int kIdleWorkerTimeoutSeconds;
~ServiceWorkerVersion() override;
@@ -795,6 +804,8 @@ class CONTENT_EXPORT ServiceWorkerVersion
// long.
base::TimeTicks stale_time_;
+ base::TimeTicks max_request_expiration_time_;
falken 2016/11/21 08:01:48 nit: All these times are hard to keep track off so
Marijn Kruisselbrink 2016/12/01 19:54:30 Done
+
// Keeps track of requests for timeout purposes. Requests are sorted by
// their expiration time (soonest to expire on top of the priority queue). The
// timeout timer periodically checks |timeout_queue_| for entries that should

Powered by Google App Engine
This is Rietveld 408576698