OLD | NEW |
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/serviceworkers/ServiceWorkerGlobalScopeClient.h" | 9 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" |
10 #include "wtf/Forward.h" | 10 #include "wtf/Forward.h" |
11 #include "wtf/RefCounted.h" | 11 #include "wtf/RefCounted.h" |
12 | 12 |
13 namespace WebCore { | 13 namespace WebCore { |
14 | 14 |
15 class ExecutionContext; | 15 class ExecutionContext; |
16 class ScriptState; | |
17 class ScriptValue; | 16 class ScriptValue; |
18 | 17 |
19 // Created for each InstallPhaseEvent instance. | 18 // Created for each InstallPhaseEvent instance. |
20 class WaitUntilObserver FINAL : | 19 class WaitUntilObserver FINAL : |
21 public ContextLifecycleObserver, | 20 public ContextLifecycleObserver, |
22 public RefCounted<WaitUntilObserver> { | 21 public RefCounted<WaitUntilObserver> { |
23 public: | 22 public: |
24 enum EventType { | 23 enum EventType { |
25 Activate, | 24 Activate, |
26 Install | 25 Install |
27 }; | 26 }; |
28 | 27 |
29 static PassRefPtr<WaitUntilObserver> create(ExecutionContext*, EventType, in
t eventID); | 28 static PassRefPtr<WaitUntilObserver> create(ExecutionContext*, EventType, in
t eventID); |
30 | 29 |
31 ~WaitUntilObserver(); | 30 ~WaitUntilObserver(); |
32 | 31 |
33 // Must be called before and after dispatching the event. | 32 // Must be called before and after dispatching the event. |
34 void willDispatchEvent(); | 33 void willDispatchEvent(); |
35 void didDispatchEvent(); | 34 void didDispatchEvent(); |
36 | 35 |
37 // Observes the promise and delays calling the continuation until | 36 // Observes the promise and delays calling the continuation until |
38 // the given promise is resolved or rejected. | 37 // the given promise is resolved or rejected. |
39 void waitUntil(ScriptState*, const ScriptValue&); | 38 void waitUntil(const ScriptValue&); |
40 | 39 |
41 private: | 40 private: |
42 class ThenFunction; | 41 class ThenFunction; |
43 | 42 |
44 WaitUntilObserver(ExecutionContext*, EventType, int eventID); | 43 WaitUntilObserver(ExecutionContext*, EventType, int eventID); |
45 | 44 |
46 void reportError(const ScriptValue&); | 45 void reportError(const ScriptValue&); |
47 | 46 |
48 void incrementPendingActivity(); | 47 void incrementPendingActivity(); |
49 void decrementPendingActivity(); | 48 void decrementPendingActivity(); |
50 | 49 |
51 EventType m_type; | 50 EventType m_type; |
52 int m_eventID; | 51 int m_eventID; |
53 int m_pendingActivity; | 52 int m_pendingActivity; |
54 bool m_hasError; | 53 bool m_hasError; |
55 }; | 54 }; |
56 | 55 |
57 } // namespace WebCore | 56 } // namespace WebCore |
58 | 57 |
59 #endif // WaitUntilObserver_h | 58 #endif // WaitUntilObserver_h |
OLD | NEW |