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

Side by Side Diff: content/browser/service_worker/service_worker_version.h

Issue 2034663002: ServiceWorker: Keep the worker alive until FetchEvent.waitUntil settles (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <functional> 10 #include <functional>
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 58
59 // This class corresponds to a specific version of a ServiceWorker 59 // This class corresponds to a specific version of a ServiceWorker
60 // script for a given pattern. When a script is upgraded, there may be 60 // script for a given pattern. When a script is upgraded, there may be
61 // more than one ServiceWorkerVersion "running" at a time, but only 61 // more than one ServiceWorkerVersion "running" at a time, but only
62 // one of them is activated. This class connects the actual script with a 62 // one of them is activated. This class connects the actual script with a
63 // running worker. 63 // running worker.
64 class CONTENT_EXPORT ServiceWorkerVersion 64 class CONTENT_EXPORT ServiceWorkerVersion
65 : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerVersion>), 65 : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerVersion>),
66 public EmbeddedWorkerInstance::Listener { 66 public EmbeddedWorkerInstance::Listener {
67 public: 67 public:
68 typedef base::Callback<void(ServiceWorkerStatusCode)> StatusCallback; 68 using StatusCallback = base::Callback<void(ServiceWorkerStatusCode)>;
69 using FetchResponseCallback = base::Callback<
70 void(int, ServiceWorkerFetchEventResult, const ServiceWorkerResponse&)>;
69 71
70 enum RunningStatus { 72 enum RunningStatus {
71 STOPPED = EmbeddedWorkerInstance::STOPPED, 73 STOPPED = EmbeddedWorkerInstance::STOPPED,
72 STARTING = EmbeddedWorkerInstance::STARTING, 74 STARTING = EmbeddedWorkerInstance::STARTING,
73 RUNNING = EmbeddedWorkerInstance::RUNNING, 75 RUNNING = EmbeddedWorkerInstance::RUNNING,
74 STOPPING = EmbeddedWorkerInstance::STOPPING, 76 STOPPING = EmbeddedWorkerInstance::STOPPING,
75 }; 77 };
76 78
77 // Current version status; some of the status (e.g. INSTALLED and ACTIVATED) 79 // Current version status; some of the status (e.g. INSTALLED and ACTIVATED)
78 // should be persisted unlike running status. 80 // should be persisted unlike running status.
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 247
246 // For simple events where the full functionality of DispatchEvent is not 248 // For simple events where the full functionality of DispatchEvent is not
247 // needed, this method can be used instead. The ResponseMessage must consist 249 // needed, this method can be used instead. The ResponseMessage must consist
248 // of just a request_id and a blink::WebServiceWorkerEventResult field. The 250 // of just a request_id and a blink::WebServiceWorkerEventResult field. The
249 // result is converted to a ServiceWorkerStatusCode and passed to the error 251 // result is converted to a ServiceWorkerStatusCode and passed to the error
250 // handler associated with the request. Additionally this methods calls 252 // handler associated with the request. Additionally this methods calls
251 // FinishRequest before passing the reply to the callback. 253 // FinishRequest before passing the reply to the callback.
252 template <typename ResponseMessage> 254 template <typename ResponseMessage>
253 void DispatchSimpleEvent(int request_id, const IPC::Message& message); 255 void DispatchSimpleEvent(int request_id, const IPC::Message& message);
254 256
257 // For fetch event, response is returned earlier than the event is done.
258 // In order to handle the both (response and the end of event),
259 // DispatchFetchEvent takes two request ids and handles each callbacks.
260 void DispatchFetchEvent(int response_request_id,
Marijn Kruisselbrink 2016/06/02 16:58:55 It seems very unfortunate to go back to having cod
261 int event_request_id,
262 const ServiceWorkerFetchRequest& fetch_request,
263 const FetchResponseCallback& callback);
264
255 // Adds and removes |provider_host| as a controllee of this ServiceWorker. 265 // Adds and removes |provider_host| as a controllee of this ServiceWorker.
256 // A potential controllee is a host having the version as its .installing 266 // A potential controllee is a host having the version as its .installing
257 // or .waiting version. 267 // or .waiting version.
258 void AddControllee(ServiceWorkerProviderHost* provider_host); 268 void AddControllee(ServiceWorkerProviderHost* provider_host);
259 void RemoveControllee(ServiceWorkerProviderHost* provider_host); 269 void RemoveControllee(ServiceWorkerProviderHost* provider_host);
260 270
261 // Returns if it has controllee. 271 // Returns if it has controllee.
262 bool HasControllee() const { return !controllee_map_.empty(); } 272 bool HasControllee() const { return !controllee_map_.empty(); }
263 std::map<std::string, ServiceWorkerProviderHost*> controllee_map() { 273 std::map<std::string, ServiceWorkerProviderHost*> controllee_map() {
264 return controllee_map_; 274 return controllee_map_;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionBrowserTest, 358 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionBrowserTest,
349 TimeoutWorkerInEvent); 359 TimeoutWorkerInEvent);
350 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerStallInStoppingTest, DetachThenStart); 360 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerStallInStoppingTest, DetachThenStart);
351 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerStallInStoppingTest, DetachThenRestart); 361 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerStallInStoppingTest, DetachThenRestart);
352 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, 362 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest,
353 RegisterForeignFetchScopes); 363 RegisterForeignFetchScopes);
354 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, RequestCustomizedTimeout); 364 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, RequestCustomizedTimeout);
355 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, 365 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest,
356 RequestCustomizedTimeoutKill); 366 RequestCustomizedTimeoutKill);
357 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, MixedRequestTimeouts); 367 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, MixedRequestTimeouts);
368 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerURLRequestJobTest, EarlyResponse);
358 369
359 class Metrics; 370 class Metrics;
360 class PingController; 371 class PingController;
361 372
362 struct RequestInfo { 373 struct RequestInfo {
363 RequestInfo(int id, 374 RequestInfo(int id,
364 ServiceWorkerMetrics::EventType event_type, 375 ServiceWorkerMetrics::EventType event_type,
365 const base::TimeTicks& expiration, 376 const base::TimeTicks& expiration,
366 TimeoutBehavior timeout_behavior); 377 TimeoutBehavior timeout_behavior);
367 ~RequestInfo(); 378 ~RequestInfo();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 mojo::InterfacePtr<Interface> interface_; 436 mojo::InterfacePtr<Interface> interface_;
426 base::WeakPtrFactory<Interface> weak_ptr_factory_; 437 base::WeakPtrFactory<Interface> weak_ptr_factory_;
427 }; 438 };
428 439
429 typedef ServiceWorkerVersion self; 440 typedef ServiceWorkerVersion self;
430 using ServiceWorkerClients = std::vector<ServiceWorkerClientInfo>; 441 using ServiceWorkerClients = std::vector<ServiceWorkerClientInfo>;
431 using RequestInfoPriorityQueue = 442 using RequestInfoPriorityQueue =
432 std::priority_queue<RequestInfo, 443 std::priority_queue<RequestInfo,
433 std::vector<RequestInfo>, 444 std::vector<RequestInfo>,
434 std::greater<RequestInfo>>; 445 std::greater<RequestInfo>>;
446 using WebStatusCallback =
447 base::Callback<void(int, blink::WebServiceWorkerEventResult)>;
435 448
436 // EmbeddedWorkerInstance Listener implementation which calls a callback 449 // EmbeddedWorkerInstance Listener implementation which calls a callback
437 // on receiving a particular IPC message. ResponseMessage is the type of 450 // on receiving a particular IPC message. ResponseMessage is the type of
438 // the IPC message to listen for, while CallbackType should be a callback 451 // the IPC message to listen for, while CallbackType should be a callback
439 // with same arguments as the IPC message. 452 // with same arguments as the IPC message.
440 // Additionally only calls the callback for messages with a specific request 453 // Additionally only calls the callback for messages with a specific request
441 // id, which must be the first argument of the IPC message. 454 // id, which must be the first argument of the IPC message.
442 template <typename ResponseMessage, typename CallbackType> 455 template <typename ResponseMessage, typename CallbackType>
443 class EventResponseHandler : public EmbeddedWorkerInstance::Listener { 456 class EventResponseHandler : public EmbeddedWorkerInstance::Listener {
444 public: 457 public:
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 771
759 // At this point |this| can have been deleted, so don't do anything other 772 // At this point |this| can have been deleted, so don't do anything other
760 // than returning. 773 // than returning.
761 774
762 return true; 775 return true;
763 } 776 }
764 777
765 } // namespace content 778 } // namespace content
766 779
767 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ 780 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698