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

Side by Side Diff: third_party/WebKit/Source/modules/serviceworkers/WaitUntilObserver.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 WaitUntilObserver_h 5 #ifndef WaitUntilObserver_h
6 #define WaitUntilObserver_h 6 #define WaitUntilObserver_h
7 7
8 #include "core/dom/ContextLifecycleObserver.h" 8 #include "core/dom/ContextLifecycleObserver.h"
9 #include "modules/ModulesExport.h" 9 #include "modules/ModulesExport.h"
10 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" 10 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h"
11 #include "platform/Timer.h" 11 #include "platform/Timer.h"
12 #include "wtf/Forward.h" 12 #include "wtf/Forward.h"
13 13
14 namespace blink { 14 namespace blink {
15 15
16 class ExceptionState; 16 class ExceptionState;
17 class ExecutionContext; 17 class ExecutionContext;
18 class ScriptPromise; 18 class ScriptPromise;
19 class ScriptState; 19 class ScriptState;
20 class ScriptValue; 20 class ScriptValue;
21 21
22 // Created for each ExtendableEvent instance. 22 // Created for each ExtendableEvent instance.
23 class MODULES_EXPORT WaitUntilObserver final : public GarbageCollectedFinalized< WaitUntilObserver>, public ContextLifecycleObserver { 23 class MODULES_EXPORT WaitUntilObserver final : public GarbageCollectedFinalized< WaitUntilObserver>, public ContextLifecycleObserver {
24 USING_GARBAGE_COLLECTED_MIXIN(WaitUntilObserver); 24 USING_GARBAGE_COLLECTED_MIXIN(WaitUntilObserver);
25 public: 25 public:
26 enum EventType { 26 enum EventType {
27 Activate, 27 Activate,
28 Fetch,
28 Install, 29 Install,
29 Message, 30 Message,
30 NotificationClick, 31 NotificationClick,
31 NotificationClose, 32 NotificationClose,
32 Push, 33 Push,
33 Sync 34 Sync
34 }; 35 };
35 36
36 static WaitUntilObserver* create(ExecutionContext*, EventType, int eventID); 37 static WaitUntilObserver* create(ExecutionContext*, EventType, int eventID);
37 38
38 // Must be called before and after dispatching the event. 39 // Must be called before and after dispatching the event.
39 void willDispatchEvent(); 40 void willDispatchEvent();
40 void didDispatchEvent(bool errorOccurred); 41 void didDispatchEvent(bool errorOccurred);
41 42
42 // Observes the promise and delays calling the continuation until 43 // Observes the promise and delays calling the continuation until
43 // the given promise is resolved or rejected. 44 // the given promise is resolved or rejected.
44 void waitUntil(ScriptState*, ScriptPromise, ExceptionState&); 45 void waitUntil(ScriptState*, ScriptPromise, ExceptionState&);
45 46
47 // These methods can be called when the lifecycle of ExtendableEvent
48 // observed by this WaitUntilObserver should be extended by other reason
49 // than ExtendableEvent.waitUntil.
50 void incrementPendingActivity();
51 void decrementPendingActivity();
52
46 DECLARE_VIRTUAL_TRACE(); 53 DECLARE_VIRTUAL_TRACE();
47 54
48 private: 55 private:
49 friend class InternalsServiceWorker; 56 friend class InternalsServiceWorker;
50 class ThenFunction; 57 class ThenFunction;
51 58
52 WaitUntilObserver(ExecutionContext*, EventType, int eventID); 59 WaitUntilObserver(ExecutionContext*, EventType, int eventID);
53 60
54 void reportError(const ScriptValue&); 61 void reportError(const ScriptValue&);
55 62
56 void incrementPendingActivity();
57 void decrementPendingActivity();
58
59 void consumeWindowInteraction(Timer<WaitUntilObserver>*); 63 void consumeWindowInteraction(Timer<WaitUntilObserver>*);
60 64
61 EventType m_type; 65 EventType m_type;
62 int m_eventID; 66 int m_eventID;
63 int m_pendingActivity; 67 int m_pendingActivity;
64 bool m_hasError; 68 bool m_hasError;
65 bool m_eventDispatched; 69 bool m_eventDispatched;
66 Timer<WaitUntilObserver> m_consumeWindowInteractionTimer; 70 Timer<WaitUntilObserver> m_consumeWindowInteractionTimer;
67 }; 71 };
68 72
69 } // namespace blink 73 } // namespace blink
70 74
71 #endif // WaitUntilObserver_h 75 #endif // WaitUntilObserver_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698