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 "modules/ModulesExport.h" | 8 #include "modules/ModulesExport.h" |
9 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" | 9 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" |
10 #include "platform/Timer.h" | 10 #include "platform/Timer.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 // all waitUntil promises to settle. | 47 // all waitUntil promises to settle. |
48 void DidDispatchEvent(bool event_dispatch_failed); | 48 void DidDispatchEvent(bool event_dispatch_failed); |
49 | 49 |
50 // Observes the promise and delays calling the continuation until | 50 // Observes the promise and delays calling the continuation until |
51 // the given promise is resolved or rejected. | 51 // the given promise is resolved or rejected. |
52 void WaitUntil(ScriptState*, ScriptPromise, ExceptionState&); | 52 void WaitUntil(ScriptState*, ScriptPromise, ExceptionState&); |
53 | 53 |
54 // These methods can be called when the lifecycle of ExtendableEvent | 54 // These methods can be called when the lifecycle of ExtendableEvent |
55 // observed by this WaitUntilObserver should be extended by other reason | 55 // observed by this WaitUntilObserver should be extended by other reason |
56 // than ExtendableEvent.waitUntil. | 56 // than ExtendableEvent.waitUntil. |
57 // Note: There is no need to call decrementPendingActivity() after the context | 57 // Note: There is no need to call DecrementPendingPromise() after the context |
58 // is being destroyed. | 58 // is being destroyed. |
59 void IncrementPendingActivity(); | 59 void IncrementPendingPromise(); |
60 void DecrementPendingActivity(); | 60 void DecrementPendingPromise(); |
61 | 61 |
62 DECLARE_VIRTUAL_TRACE(); | 62 DECLARE_VIRTUAL_TRACE(); |
63 | 63 |
64 private: | 64 private: |
65 friend class InternalsServiceWorker; | 65 friend class InternalsServiceWorker; |
66 class ThenFunction; | 66 class ThenFunction; |
67 | 67 |
68 enum class EventDispatchState { | 68 enum class EventDispatchState { |
69 // Event dispatch has not yet finished. | 69 // Event dispatch has not yet started. |
70 kInitial, | 70 kInitial, |
| 71 // Event dispatch has started but not yet finished. |
| 72 kDispatching, |
71 // Event dispatch completed. There may still be outstanding waitUntil | 73 // Event dispatch completed. There may still be outstanding waitUntil |
72 // promises that must settle before notifying ServiceWorkerGlobalScopeClient | 74 // promises that must settle before notifying ServiceWorkerGlobalScopeClient |
73 // that the event finished. | 75 // that the event finished. |
74 kCompleted, | 76 kDispatched, |
75 // Event dispatch failed. Any outstanding waitUntil promises are ignored. | 77 // Event dispatch failed. Any outstanding waitUntil promises are ignored. |
76 kFailed | 78 kFailed |
77 }; | 79 }; |
78 | 80 |
79 WaitUntilObserver(ExecutionContext*, EventType, int event_id); | 81 WaitUntilObserver(ExecutionContext*, EventType, int event_id); |
80 | 82 |
81 // Called when a promise passed to a waitUntil() call that is associated with | 83 // Called when a promise passed to a waitUntil() call that is associated with |
82 // this observer was fulfilled. | 84 // this observer was fulfilled. |
83 void OnPromiseFulfilled(); | 85 void OnPromiseFulfilled(); |
84 // Called when a promise passed to a waitUntil() call that is associated with | 86 // Called when a promise passed to a waitUntil() call that is associated with |
85 // this observer was rejected. | 87 // this observer was rejected. |
86 void OnPromiseRejected(); | 88 void OnPromiseRejected(); |
87 | 89 |
88 void ConsumeWindowInteraction(TimerBase*); | 90 void ConsumeWindowInteraction(TimerBase*); |
89 | 91 |
| 92 void MaybeCompleteEvent(); |
| 93 |
90 Member<ExecutionContext> execution_context_; | 94 Member<ExecutionContext> execution_context_; |
91 EventType type_; | 95 EventType type_; |
92 int event_id_; | 96 int event_id_; |
93 int pending_activity_ = 0; | 97 int pending_promises_ = 0; |
94 EventDispatchState event_dispatch_state_ = EventDispatchState::kInitial; | 98 EventDispatchState event_dispatch_state_ = EventDispatchState::kInitial; |
95 bool has_rejected_promise_ = false; | 99 bool has_rejected_promise_ = false; |
96 double event_dispatch_time_ = 0; | 100 double event_dispatch_time_ = 0; |
97 TaskRunnerTimer<WaitUntilObserver> consume_window_interaction_timer_; | 101 TaskRunnerTimer<WaitUntilObserver> consume_window_interaction_timer_; |
98 }; | 102 }; |
99 | 103 |
100 } // namespace blink | 104 } // namespace blink |
101 | 105 |
102 #endif // WaitUntilObserver_h | 106 #endif // WaitUntilObserver_h |
OLD | NEW |