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

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

Issue 1525743002: Allow ServiceWorker events to have custom durations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Logic bug Created 5 years 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 244378b841b160e35c2bf38c837ffd4d9ab13426..994b4b55ef99e70d4e6fbc6ee94c850947b21597 100644
--- a/content/browser/service_worker/service_worker_version.h
+++ b/content/browser/service_worker/service_worker_version.h
@@ -214,11 +214,13 @@ class CONTENT_EXPORT ServiceWorkerVersion
// Sends sync event to the associated embedded worker and asynchronously calls
// |callback| when it errors out or it gets a response from the worker to
- // notify completion.
+ // notify completion. |expiration| is the TimeTick at which the event should
+ // stop running.
//
// This must be called when the status() is ACTIVATED.
void DispatchSyncEvent(BackgroundSyncRegistrationHandle::HandleId handle_id,
BackgroundSyncEventLastChance last_chance,
+ base::TimeTicks expiration,
const StatusCallback& callback);
// Sends notificationclick event to the associated embedded worker and
@@ -343,6 +345,7 @@ class CONTENT_EXPORT ServiceWorkerVersion
friend class ServiceWorkerURLRequestJobTest;
friend class ServiceWorkerStallInStoppingTest;
friend class ServiceWorkerVersionBrowserTest;
+ friend class ServiceWorkerVersionTest;
FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTest,
ActivateWaitingVersion);
@@ -365,13 +368,13 @@ class CONTENT_EXPORT ServiceWorkerVersion
FRIEND_TEST_ALL_PREFIXES(ServiceWorkerStallInStoppingTest, DetachThenRestart);
FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest,
RegisterForeignFetchScopes);
+ FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, RequestCustomizedTimeout);
+ FRIEND_TEST_ALL_PREFIXES(ServiceWorkerWaitForeverInFetchTest,
+ MixedRequestTimeouts);
class Metrics;
class PingController;
- typedef ServiceWorkerVersion self;
- using ServiceWorkerClients = std::vector<ServiceWorkerClientInfo>;
-
// Used for UMA; add new entries to the end, before NUM_REQUEST_TYPES.
enum RequestType {
REQUEST_ACTIVATE,
@@ -386,11 +389,12 @@ class CONTENT_EXPORT ServiceWorkerVersion
};
struct RequestInfo {
- RequestInfo(int id, RequestType type, const base::TimeTicks& time);
+ RequestInfo(int id, RequestType type, const base::TimeTicks& expiration);
~RequestInfo();
+ bool operator>(const RequestInfo& other) const;
int id;
RequestType type;
- base::TimeTicks time;
+ base::TimeTicks expiration;
};
template <typename CallbackType>
@@ -402,6 +406,13 @@ class CONTENT_EXPORT ServiceWorkerVersion
base::TimeTicks start_time;
};
+ typedef ServiceWorkerVersion self;
+ using ServiceWorkerClients = std::vector<ServiceWorkerClientInfo>;
+ using RequestInfoPriorityQueue =
+ std::priority_queue<RequestInfo,
+ std::vector<RequestInfo>,
+ std::greater<RequestInfo>>;
+
// The timeout timer interval.
static const int kTimeoutTimerDelaySeconds;
// Timeout for an installed worker to start.
@@ -551,8 +562,16 @@ class CONTENT_EXPORT ServiceWorkerVersion
IDMap<PendingRequest<CallbackType>, IDMapOwnPointer>* callback_map,
RequestType request_type);
+ template <typename CallbackType>
+ int AddRequestWithExpiration(
+ const CallbackType& callback,
+ IDMap<PendingRequest<CallbackType>, IDMapOwnPointer>* callback_map,
+ RequestType request_type,
+ base::TimeTicks expiration);
+
bool MaybeTimeOutRequest(const RequestInfo& info);
- void SetAllRequestTimes(const base::TimeTicks& ticks);
+ bool ShouldStopIfRequestTimesOut(const RequestInfo& info);
+ void SetAllRequestExpirations(const base::TimeTicks& expiration);
// Returns the reason the embedded worker failed to start, using information
// inaccessible to EmbeddedWorkerInstance. Returns |default_code| if it can't
@@ -632,10 +651,11 @@ class CONTENT_EXPORT ServiceWorkerVersion
base::TimeTicks stale_time_;
// New requests are added to |requests_| along with their entry in a callback
- // map. The timeout timer periodically checks |requests_| for entries that
- // should time out or have already been fulfilled (i.e., removed from the
- // callback map).
- std::queue<RequestInfo> requests_;
+ // map. Requests are sorted by their expiration time (soonest to expire on top
+ // of the priority queue). The timeout timer periodically checks |requests_|
+ // for entries that should time out or have already been fulfilled (i.e.,
+ // removed from the callback map).
+ RequestInfoPriorityQueue requests_;
bool skip_waiting_ = false;
bool skip_recording_startup_time_ = false;

Powered by Google App Engine
This is Rietveld 408576698