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

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

Issue 2517223002: Move content/renderer/background_sync to Blink (Closed)
Patch Set: Remove extra includes and make DEPS more specific Created 4 years, 1 month 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 "public/platform/modules/serviceworker/service_worker_event_status.mojo m-shared.h"
12 #include "wtf/Forward.h" 13 #include "wtf/Forward.h"
14 #include <memory>
13 15
14 namespace blink { 16 namespace blink {
15 17
16 class ExceptionState; 18 class ExceptionState;
17 class ExecutionContext; 19 class ExecutionContext;
18 class ScriptPromise; 20 class ScriptPromise;
19 class ScriptState; 21 class ScriptState;
20 class ScriptValue; 22 class ScriptValue;
21 23
22 // Created for each ExtendableEvent instance. 24 // Created for each ExtendableEvent instance.
23 class MODULES_EXPORT WaitUntilObserver final 25 class MODULES_EXPORT WaitUntilObserver final
24 : public GarbageCollectedFinalized<WaitUntilObserver>, 26 : public GarbageCollectedFinalized<WaitUntilObserver>,
25 public ContextLifecycleObserver { 27 public ContextLifecycleObserver {
26 USING_GARBAGE_COLLECTED_MIXIN(WaitUntilObserver); 28 USING_GARBAGE_COLLECTED_MIXIN(WaitUntilObserver);
29 using Callback = WTF::Function<void(blink::mojom::ServiceWorkerEventStatus,
30 const double&)>;
jbroman 2016/11/21 21:36:01 A few nits: 1. "blink::" is unnecessary while in n
27 31
28 public: 32 public:
29 enum EventType { 33 enum EventType {
30 Activate, 34 Activate,
31 Fetch, 35 Fetch,
32 Install, 36 Install,
33 Message, 37 Message,
34 NotificationClick, 38 NotificationClick,
35 NotificationClose, 39 NotificationClose,
36 Push, 40 Push,
37 Sync 41 Sync
38 }; 42 };
39 43
40 static WaitUntilObserver* create(ExecutionContext*, EventType, int eventID); 44 static WaitUntilObserver* create(ExecutionContext*, EventType, int eventID);
45 static WaitUntilObserver* create(ExecutionContext*,
46 EventType,
47 std::unique_ptr<Callback>);
41 48
42 // Must be called before and after dispatching the event. 49 // Must be called before and after dispatching the event.
43 void willDispatchEvent(); 50 void willDispatchEvent();
44 void didDispatchEvent(bool errorOccurred); 51 void didDispatchEvent(bool errorOccurred);
45 52
46 // Observes the promise and delays calling the continuation until 53 // Observes the promise and delays calling the continuation until
47 // the given promise is resolved or rejected. 54 // the given promise is resolved or rejected.
48 void waitUntil(ScriptState*, ScriptPromise, ExceptionState&); 55 void waitUntil(ScriptState*, ScriptPromise, ExceptionState&);
49 56
50 // These methods can be called when the lifecycle of ExtendableEvent 57 // These methods can be called when the lifecycle of ExtendableEvent
51 // observed by this WaitUntilObserver should be extended by other reason 58 // observed by this WaitUntilObserver should be extended by other reason
52 // than ExtendableEvent.waitUntil. 59 // than ExtendableEvent.waitUntil.
53 // Note: There is no need to call decrementPendingActivity() after the context 60 // Note: There is no need to call decrementPendingActivity() after the context
54 // is being destroyed. 61 // is being destroyed.
55 void incrementPendingActivity(); 62 void incrementPendingActivity();
56 void decrementPendingActivity(); 63 void decrementPendingActivity();
57 64
65 // Overriden from LifecycleObserver
jbroman 2016/11/21 21:36:01 spelling nit: "Overridden"
66 void contextDestroyed() override;
67
58 DECLARE_VIRTUAL_TRACE(); 68 DECLARE_VIRTUAL_TRACE();
59 69
60 private: 70 private:
61 friend class InternalsServiceWorker; 71 friend class InternalsServiceWorker;
62 class ThenFunction; 72 class ThenFunction;
63 73
64 WaitUntilObserver(ExecutionContext*, EventType, int eventID); 74 WaitUntilObserver(ExecutionContext*,
75 EventType,
76 int eventID,
77 std::unique_ptr<Callback>);
65 78
66 void reportError(const ScriptValue&); 79 void reportError(const ScriptValue&);
67 80
68 void consumeWindowInteraction(TimerBase*); 81 void consumeWindowInteraction(TimerBase*);
69 82
70 EventType m_type; 83 EventType m_type;
71 int m_eventID; 84 int m_eventID;
72 int m_pendingActivity = 0; 85 int m_pendingActivity = 0;
73 bool m_hasError = false; 86 bool m_hasError = false;
74 bool m_eventDispatched = false; 87 bool m_eventDispatched = false;
75 double m_eventDispatchTime = 0; 88 double m_eventDispatchTime = 0;
76 Timer<WaitUntilObserver> m_consumeWindowInteractionTimer; 89 Timer<WaitUntilObserver> m_consumeWindowInteractionTimer;
90 std::unique_ptr<Callback> m_callback;
77 }; 91 };
78 92
79 } // namespace blink 93 } // namespace blink
80 94
81 #endif // WaitUntilObserver_h 95 #endif // WaitUntilObserver_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698