Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / modules / serviceworkers / WaitUntilObserver.h
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
3 // found in the LICENSE file.
4
5 #ifndef WaitUntilObserver_h
6 #define WaitUntilObserver_h
7
8 #include "core/dom/ContextLifecycleObserver.h"
9 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h"
10 #include "wtf/Forward.h"
11 #include "wtf/RefCounted.h"
12
13 namespace WebCore {
14
15 class ExecutionContext;
16 class ScriptValue;
17
18 // Created for each InstallPhaseEvent instance.
19 class WaitUntilObserver FINAL :
20     public ContextLifecycleObserver,
21     public RefCounted<WaitUntilObserver> {
22 public:
23     static PassRefPtr<WaitUntilObserver> create(ExecutionContext*, int eventID);
24
25     ~WaitUntilObserver();
26
27     // Must be called before and after dispatching the event.
28     void willDispatchEvent();
29     void didDispatchEvent();
30
31     // Observes the promise and delays calling didHandleInstallEvent() until
32     // the given promise is resolved or rejected.
33     void waitUntil(const ScriptValue&);
34
35 private:
36     class ThenFunction;
37
38     WaitUntilObserver(ExecutionContext*, int eventID);
39
40     void reportError(const ScriptValue&);
41
42     void incrementPendingActivity();
43     void decrementPendingActivity();
44
45     int m_eventID;
46     int m_pendingActivity;
47 };
48
49 } // namespace WebCore
50
51 #endif // WaitUntilObserver_h