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" |
11 #include "platform/wtf/Forward.h" | 11 #include "platform/wtf/Forward.h" |
12 | 12 |
13 namespace blink { | 13 namespace blink { |
14 | 14 |
15 class ExceptionState; | 15 class ExceptionState; |
16 class ExecutionContext; | 16 class ExecutionContext; |
17 class ScriptPromise; | 17 class ScriptPromise; |
18 class ScriptState; | 18 class ScriptState; |
19 class ScriptValue; | |
20 | 19 |
21 // Created for each ExtendableEvent instance. | 20 // Created for each ExtendableEvent instance. |
22 class MODULES_EXPORT WaitUntilObserver final | 21 class MODULES_EXPORT WaitUntilObserver final |
23 : public GarbageCollectedFinalized<WaitUntilObserver> { | 22 : public GarbageCollectedFinalized<WaitUntilObserver> { |
24 public: | 23 public: |
25 enum EventType { | 24 enum EventType { |
26 kActivate, | 25 kActivate, |
27 kFetch, | 26 kFetch, |
28 kInstall, | 27 kInstall, |
29 kMessage, | 28 kMessage, |
30 kNotificationClick, | 29 kNotificationClick, |
31 kNotificationClose, | 30 kNotificationClose, |
32 kPaymentRequest, | 31 kPaymentRequest, |
33 kPush, | 32 kPush, |
34 kSync, | 33 kSync, |
35 kBackgroundFetchAbort, | 34 kBackgroundFetchAbort, |
36 kBackgroundFetchClick, | 35 kBackgroundFetchClick, |
37 kBackgroundFetchFail, | 36 kBackgroundFetchFail, |
38 kBackgroundFetched | 37 kBackgroundFetched |
39 }; | 38 }; |
40 | 39 |
41 static WaitUntilObserver* Create(ExecutionContext*, EventType, int event_id); | 40 static WaitUntilObserver* Create(ExecutionContext*, EventType, int event_id); |
42 | 41 |
43 // Must be called before and after dispatching the event. | 42 // Must be called before dispatching the event. |
44 void WillDispatchEvent(); | 43 void WillDispatchEvent(); |
45 void DidDispatchEvent(bool error_occurred); | 44 // Must be called after dispatching the event. If |event_dispatch_failed|, |
45 // this WaitUntilObserver will soon report to ServiceWorkerGlobalScopeClient | |
falken
2017/05/10 05:25:12
my bad, I didn't realize the DidDispatchEvent will
leonhsl(Using Gerrit)
2017/05/10 07:07:52
Done.
| |
46 // that the event finished, without waiting for all waitUntil promises to | |
47 // settle. | |
48 void DidDispatchEvent(bool event_dispatch_failed); | |
46 | 49 |
47 // Observes the promise and delays calling the continuation until | 50 // Observes the promise and delays calling the continuation until |
48 // the given promise is resolved or rejected. | 51 // the given promise is resolved or rejected. |
49 void WaitUntil(ScriptState*, ScriptPromise, ExceptionState&); | 52 void WaitUntil(ScriptState*, ScriptPromise, ExceptionState&); |
50 | 53 |
51 // These methods can be called when the lifecycle of ExtendableEvent | 54 // These methods can be called when the lifecycle of ExtendableEvent |
52 // observed by this WaitUntilObserver should be extended by other reason | 55 // observed by this WaitUntilObserver should be extended by other reason |
53 // than ExtendableEvent.waitUntil. | 56 // than ExtendableEvent.waitUntil. |
54 // Note: There is no need to call decrementPendingActivity() after the context | 57 // Note: There is no need to call decrementPendingActivity() after the context |
55 // is being destroyed. | 58 // is being destroyed. |
56 void IncrementPendingActivity(); | 59 void IncrementPendingActivity(); |
57 void DecrementPendingActivity(); | 60 void DecrementPendingActivity(); |
58 | 61 |
59 DECLARE_VIRTUAL_TRACE(); | 62 DECLARE_VIRTUAL_TRACE(); |
60 | 63 |
61 private: | 64 private: |
62 friend class InternalsServiceWorker; | 65 friend class InternalsServiceWorker; |
63 class ThenFunction; | 66 class ThenFunction; |
64 | 67 |
65 WaitUntilObserver(ExecutionContext*, EventType, int event_id); | 68 WaitUntilObserver(ExecutionContext*, EventType, int event_id); |
66 | 69 |
67 void ReportError(const ScriptValue&); | 70 // Called when a promise passed to a waitUntil() call that is associated with |
71 // this observer has completed. |rejected| indicates whether the promise is | |
72 // rejected. | |
73 void OnPromiseCompleted(bool rejected); | |
68 | 74 |
69 void ConsumeWindowInteraction(TimerBase*); | 75 void ConsumeWindowInteraction(TimerBase*); |
70 | 76 |
77 enum EventDispatchState { kInitial, kCompleted, kFailed }; | |
shimazu
2017/05/10 05:20:14
"enum class" is better here:
https://www.chromium.
falken
2017/05/10 05:25:12
Can you document:
// Event dispatch has not yet f
leonhsl(Using Gerrit)
2017/05/10 07:07:52
Done.
leonhsl(Using Gerrit)
2017/05/10 07:07:52
Done.
| |
78 EventDispatchState event_dispatch_state_ = kInitial; | |
shimazu
2017/05/10 05:20:14
It would be better to initialize this at the const
falken
2017/05/10 05:26:52
I thought so too but pending_activity_ and has_rej
leonhsl(Using Gerrit)
2017/05/10 07:07:52
We set class member's default value in .h file, so
| |
79 | |
71 Member<ExecutionContext> execution_context_; | 80 Member<ExecutionContext> execution_context_; |
72 EventType type_; | 81 EventType type_; |
73 int event_id_; | 82 int event_id_; |
74 int pending_activity_ = 0; | 83 int pending_activity_ = 0; |
75 bool has_error_ = false; | 84 bool has_rejected_promise_ = false; |
76 bool event_dispatched_ = false; | |
77 double event_dispatch_time_ = 0; | 85 double event_dispatch_time_ = 0; |
78 TaskRunnerTimer<WaitUntilObserver> consume_window_interaction_timer_; | 86 TaskRunnerTimer<WaitUntilObserver> consume_window_interaction_timer_; |
79 }; | 87 }; |
80 | 88 |
81 } // namespace blink | 89 } // namespace blink |
82 | 90 |
83 #endif // WaitUntilObserver_h | 91 #endif // WaitUntilObserver_h |
OLD | NEW |