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

Side by Side Diff: third_party/WebKit/Source/modules/serviceworkers/RespondWithObserver.h

Issue 2715663002: ServiceWorker: Factor out FetchEvent related logics from RespondWithObserver. (Closed)
Patch Set: RespondWithObserver Created 3 years, 9 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"
12 #include "platform/heap/Handle.h" 11 #include "platform/heap/Handle.h"
13 #include "public/platform/WebURLRequest.h"
14 #include "public/platform/modules/serviceworker/WebServiceWorkerResponseError.h" 12 #include "public/platform/modules/serviceworker/WebServiceWorkerResponseError.h"
15 13
16 namespace blink { 14 namespace blink {
17 15
18 class ExceptionState; 16 class ExceptionState;
19 class ExecutionContext; 17 class ExecutionContext;
20 class ScriptPromise; 18 class ScriptPromise;
21 class ScriptState; 19 class ScriptState;
22 class ScriptValue; 20 class ScriptValue;
21 class WaitUntilObserver;
23 22
24 // This class observes the service worker's handling of a FetchEvent and 23 // This class observes the service worker's handling of events which have
shimazu 2017/03/08 01:39:03 I feel it's better to rewrite this comment to desc
falken 2017/03/09 04:59:00 +1. Is this base class ever supposed to be instant
zino 2017/03/10 17:57:17 Done.
25 // notifies the client. 24 // respondWith(), and notifies the client.
26 class MODULES_EXPORT RespondWithObserver 25 class MODULES_EXPORT RespondWithObserver
27 : public GarbageCollectedFinalized<RespondWithObserver>, 26 : public GarbageCollectedFinalized<RespondWithObserver>,
28 public ContextLifecycleObserver { 27 public ContextLifecycleObserver {
29 USING_GARBAGE_COLLECTED_MIXIN(RespondWithObserver); 28 USING_GARBAGE_COLLECTED_MIXIN(RespondWithObserver);
30 29
31 public: 30 public:
32 virtual ~RespondWithObserver(); 31 virtual ~RespondWithObserver();
33 32
34 static RespondWithObserver* create(ExecutionContext*, 33 static RespondWithObserver* create(ExecutionContext*,
35 int fetchEventID, 34 int eventID,
36 const KURL& requestURL,
37 WebURLRequest::FetchRequestMode,
38 WebURLRequest::FetchRedirectMode,
39 WebURLRequest::FrameType,
40 WebURLRequest::RequestContext,
41 WaitUntilObserver*); 35 WaitUntilObserver*);
falken 2017/03/09 04:59:00 Is this function used?
zino 2017/03/10 17:57:17 Done.
42 36
43 void contextDestroyed(ExecutionContext*) override; 37 void contextDestroyed(ExecutionContext*) override;
44 38
45 void willDispatchEvent(); 39 void willDispatchEvent();
46 void didDispatchEvent(DispatchEventResult dispatchResult); 40 virtual void didDispatchEvent(DispatchEventResult dispatchResult);
47 41
48 // Observes the promise and delays calling didHandleFetchEvent() until the 42 // Observes the promise and delays calling didHandle*Event() until the given
falken 2017/03/09 04:59:00 This comment may be confusing since this class doe
49 // given promise is resolved or rejected. 43 // promise is resolved or rejected.
50 void respondWith(ScriptState*, ScriptPromise, ExceptionState&); 44 void respondWith(ScriptState*, ScriptPromise, ExceptionState&);
51 45
52 void responseWasRejected(WebServiceWorkerResponseError); 46 virtual void responseWasRejected(WebServiceWorkerResponseError);
53 virtual void responseWasFulfilled(const ScriptValue&); 47 virtual void responseWasFulfilled(const ScriptValue&);
54 48
55 DECLARE_VIRTUAL_TRACE(); 49 DECLARE_VIRTUAL_TRACE();
56 50
57 protected: 51 protected:
58 RespondWithObserver(ExecutionContext*,
59 int fetchEventID,
60 const KURL& requestURL,
61 WebURLRequest::FetchRequestMode,
62 WebURLRequest::FetchRedirectMode,
63 WebURLRequest::FrameType,
64 WebURLRequest::RequestContext,
65 WaitUntilObserver*);
66
67 private:
68 class ThenFunction; 52 class ThenFunction;
69 53
70 const int m_fetchEventID; 54 RespondWithObserver(ExecutionContext*, int eventID, WaitUntilObserver*);
71 const KURL m_requestURL; 55 const int m_eventID;
72 const WebURLRequest::FetchRequestMode m_requestMode;
73 const WebURLRequest::FetchRedirectMode m_redirectMode;
74 const WebURLRequest::FrameType m_frameType;
75 const WebURLRequest::RequestContext m_requestContext;
76
77 double m_eventDispatchTime = 0; 56 double m_eventDispatchTime = 0;
78 57
79 enum State { Initial, Pending, Done }; 58 enum State { Initial, Pending, Done };
80 State m_state; 59 State m_state;
81 60
82 // RespondWith should ensure the ExtendableEvent is alive until the promise 61 // RespondWith should ensure the ExtendableEvent is alive until the promise
83 // passed to RespondWith is resolved. The lifecycle of the ExtendableEvent 62 // passed to RespondWith is resolved. The lifecycle of the ExtendableEvent
84 // is controlled by WaitUntilObserver, so not only 63 // is controlled by WaitUntilObserver, so not only
85 // WaitUntilObserver::ThenFunction but RespondWith needs to have a strong 64 // WaitUntilObserver::ThenFunction but RespondWith needs to have a strong
86 // reference to the WaitUntilObserver. 65 // reference to the WaitUntilObserver.
87 Member<WaitUntilObserver> m_observer; 66 Member<WaitUntilObserver> m_observer;
88 }; 67 };
89 68
90 } // namespace blink 69 } // namespace blink
91 70
92 #endif // RespondWithObserver_h 71 #endif // RespondWithObserver_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698