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

Side by Side Diff: third_party/WebKit/Source/modules/serviceworkers/RespondWithObserver.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: Rebase Created 4 years, 5 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 RespondWithObserver_h 5 #ifndef RespondWithObserver_h
6 #define RespondWithObserver_h 6 #define RespondWithObserver_h
7 7
8 #include "core/dom/ContextLifecycleObserver.h" 8 #include "core/dom/ContextLifecycleObserver.h"
9 #include "core/events/EventTarget.h" 9 #include "core/events/EventTarget.h"
10 #include "modules/ModulesExport.h" 10 #include "modules/ModulesExport.h"
11 #include "modules/serviceworkers/WaitUntilObserver.h"
11 #include "platform/heap/Handle.h" 12 #include "platform/heap/Handle.h"
12 #include "public/platform/WebURLRequest.h" 13 #include "public/platform/WebURLRequest.h"
13 #include "public/platform/modules/serviceworker/WebServiceWorkerResponseError.h" 14 #include "public/platform/modules/serviceworker/WebServiceWorkerResponseError.h"
14 15
15 namespace blink { 16 namespace blink {
16 17
17 class ExceptionState; 18 class ExceptionState;
18 class ExecutionContext; 19 class ExecutionContext;
19 class ScriptPromise; 20 class ScriptPromise;
20 class ScriptState; 21 class ScriptState;
21 class ScriptValue; 22 class ScriptValue;
22 23
23 // This class observes the service worker's handling of a FetchEvent and 24 // This class observes the service worker's handling of a FetchEvent and
24 // notifies the client. 25 // notifies the client.
25 class MODULES_EXPORT RespondWithObserver : public GarbageCollectedFinalized<Resp ondWithObserver>, public ContextLifecycleObserver { 26 class MODULES_EXPORT RespondWithObserver : public GarbageCollectedFinalized<Resp ondWithObserver>, public ContextLifecycleObserver {
26 USING_GARBAGE_COLLECTED_MIXIN(RespondWithObserver); 27 USING_GARBAGE_COLLECTED_MIXIN(RespondWithObserver);
27 public: 28 public:
28 virtual ~RespondWithObserver(); 29 virtual ~RespondWithObserver();
29 30
30 static RespondWithObserver* create(ExecutionContext*, int eventID, const KUR L& requestURL, WebURLRequest::FetchRequestMode, WebURLRequest::FrameType, WebURL Request::RequestContext); 31 static RespondWithObserver* create(ExecutionContext*, int eventID, const KUR L& requestURL, WebURLRequest::FetchRequestMode, WebURLRequest::FrameType, WebURL Request::RequestContext, WaitUntilObserver*);
31 32
32 void contextDestroyed() override; 33 void contextDestroyed() override;
33 34
34 void didDispatchEvent(DispatchEventResult dispatchResult); 35 void didDispatchEvent(DispatchEventResult dispatchResult);
35 36
36 // Observes the promise and delays calling didHandleFetchEvent() until the 37 // Observes the promise and delays calling didHandleFetchEvent() until the
37 // given promise is resolved or rejected. 38 // given promise is resolved or rejected.
38 void respondWith(ScriptState*, ScriptPromise, ExceptionState&); 39 void respondWith(ScriptState*, ScriptPromise, ExceptionState&);
39 40
40 void responseWasRejected(WebServiceWorkerResponseError); 41 void responseWasRejected(WebServiceWorkerResponseError);
41 virtual void responseWasFulfilled(const ScriptValue&); 42 virtual void responseWasFulfilled(const ScriptValue&);
42 43
43 DECLARE_VIRTUAL_TRACE(); 44 DECLARE_VIRTUAL_TRACE();
44 45
45 protected: 46 protected:
46 RespondWithObserver(ExecutionContext*, int eventID, const KURL& requestURL, WebURLRequest::FetchRequestMode, WebURLRequest::FrameType, WebURLRequest::Reques tContext); 47 RespondWithObserver(ExecutionContext*, int eventID, const KURL& requestURL, WebURLRequest::FetchRequestMode, WebURLRequest::FrameType, WebURLRequest::Reques tContext, WaitUntilObserver*);
47 48
48 private: 49 private:
49 class ThenFunction; 50 class ThenFunction;
50 51
51 int m_eventID; 52 int m_eventID;
52 KURL m_requestURL; 53 KURL m_requestURL;
53 WebURLRequest::FetchRequestMode m_requestMode; 54 WebURLRequest::FetchRequestMode m_requestMode;
54 WebURLRequest::FrameType m_frameType; 55 WebURLRequest::FrameType m_frameType;
55 WebURLRequest::RequestContext m_requestContext; 56 WebURLRequest::RequestContext m_requestContext;
56 57
57 enum State { Initial, Pending, Done }; 58 enum State { Initial, Pending, Done };
58 State m_state; 59 State m_state;
60
61 // RespondWith should ensure the ExtendableEvent is alive until the promise
62 // passed to RespondWith is resolved. The lifecycle of the ExtendableEvent
63 // is controlled by WaitUntilObserver, so not only
64 // WaitUntilObserver::ThenFunction but RespondWith needs to have a strong
65 // reference to the WaitUntilObserver.
66 Member<WaitUntilObserver> m_observer;
59 }; 67 };
60 68
61 } // namespace blink 69 } // namespace blink
62 70
63 #endif // RespondWithObserver_h 71 #endif // RespondWithObserver_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698