| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef ServiceWorkerGlobalScopeClient_h | 31 #ifndef PromiseTracker_h |
| 32 #define ServiceWorkerGlobalScopeClient_h | 32 #define PromiseTracker_h |
| 33 | 33 |
| 34 #include "core/workers/WorkerClients.h" | 34 #include "bindings/v8/custom/V8PromiseCustom.h" |
| 35 #include "wtf/Forward.h" | 35 #include "bindings/v8/ScriptObjectTraits.h" |
| 36 #include "core/inspector/ScriptCallStack.h" |
| 37 #include "wtf/HashMap.h" |
| 36 #include "wtf/Noncopyable.h" | 38 #include "wtf/Noncopyable.h" |
| 39 #include "wtf/RefPtr.h" |
| 37 | 40 |
| 38 namespace WebCore { | 41 namespace WebCore { |
| 39 | 42 |
| 40 class ExecutionContext; | 43 class ExecutionContext; |
| 41 class Response; | |
| 42 class WorkerClients; | |
| 43 | 44 |
| 44 class ServiceWorkerGlobalScopeClient : public Supplement<WorkerClients> { | 45 class PromiseTracker { |
| 45 WTF_MAKE_NONCOPYABLE(ServiceWorkerGlobalScopeClient); | 46 WTF_MAKE_NONCOPYABLE(PromiseTracker); |
| 46 public: | 47 public: |
| 47 virtual ~ServiceWorkerGlobalScopeClient() { } | 48 PromiseTracker() : m_isEnabled(false) { } |
| 48 | 49 |
| 49 virtual void didHandleInstallEvent(int installEventID) = 0; | 50 bool isEnabled() const { return m_isEnabled; } |
| 50 // A null response means no valid response was provided by the service worke
r, so fallback to native. | 51 void enable(); |
| 51 virtual void didHandleFetchEvent(int fetchEventID, PassRefPtr<Response> = nu
llptr) = 0; | 52 void disable(); |
| 52 | 53 |
| 53 static const char* supplementName(); | 54 void clear(); |
| 54 static ServiceWorkerGlobalScopeClient* from(ExecutionContext*); | |
| 55 | 55 |
| 56 protected: | 56 void didCreatePromise(const ScriptObject& promise); |
| 57 ServiceWorkerGlobalScopeClient() { } | 57 void didUpdatePromiseParent(const ScriptObject& promise, const ScriptObject&
parentPromise); |
| 58 void didUpdatePromiseState(const ScriptObject& promise, V8PromiseCustom::Pro
miseState, const ScriptValue& result); |
| 59 |
| 60 private: |
| 61 class PromiseData : public RefCounted<PromiseData> { |
| 62 public: |
| 63 PromiseData(const ScriptObject& promise, const ScriptObject& parentPromi
se, const ScriptValue& result, V8PromiseCustom::PromiseState state, double times
tamp); |
| 64 |
| 65 void didSettlePromise(double timestamp); |
| 66 |
| 67 ScriptObject m_promise; |
| 68 ScriptObject m_parentPromise; |
| 69 ScriptValue m_result; |
| 70 V8PromiseCustom::PromiseState m_state; |
| 71 |
| 72 // Time in milliseconds. |
| 73 double m_timeOnCreate; |
| 74 double m_timeOnSettle; |
| 75 |
| 76 RefPtr<ScriptCallStack> m_callStackOnCreate; |
| 77 RefPtr<ScriptCallStack> m_callStackOnSettle; |
| 78 }; |
| 79 |
| 80 bool m_isEnabled; |
| 81 typedef HashMap<ScriptObject, RefPtr<PromiseData>, ScriptObjectHash, ScriptO
bjectHashTraits> PromiseDataMap; |
| 82 PromiseDataMap m_promiseDataMap; |
| 58 }; | 83 }; |
| 59 | 84 |
| 60 void provideServiceWorkerGlobalScopeClientToWorker(WorkerClients*, PassOwnPtr<Se
rviceWorkerGlobalScopeClient>); | |
| 61 | |
| 62 } // namespace WebCore | 85 } // namespace WebCore |
| 63 | 86 |
| 64 #endif // ServiceWorkerGlobalScopeClient_h | 87 #endif // !defined(PromiseTracker_h) |
| OLD | NEW |