| 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 #include "config.h" | 5 #include "config.h" |
| 6 #include "modules/serviceworkers/WaitUntilObserver.h" | 6 #include "modules/serviceworkers/WaitUntilObserver.h" |
| 7 | 7 |
| 8 #include "bindings/v8/ScriptFunction.h" | 8 #include "bindings/v8/ScriptFunction.h" |
| 9 #include "bindings/v8/ScriptPromise.h" | 9 #include "bindings/v8/ScriptPromise.h" |
| 10 #include "bindings/v8/ScriptValue.h" | 10 #include "bindings/v8/ScriptValue.h" |
| 11 #include "core/dom/ExecutionContext.h" | 11 #include "core/dom/ExecutionContext.h" |
| 12 #include "platform/NotImplemented.h" | 12 #include "platform/NotImplemented.h" |
| 13 #include "wtf/Assertions.h" | 13 #include "wtf/Assertions.h" |
| 14 #include "wtf/RefCounted.h" | 14 #include "wtf/RefCounted.h" |
| 15 #include "wtf/RefPtr.h" | 15 #include "wtf/RefPtr.h" |
| 16 | 16 |
| 17 namespace WebCore { | 17 namespace WebCore { |
| 18 | 18 |
| 19 DEFINE_GC_INFO(WaitUntilObserver); | |
| 20 | |
| 21 class WaitUntilObserver::ThenFunction FINAL : public ScriptFunction { | 19 class WaitUntilObserver::ThenFunction FINAL : public ScriptFunction { |
| 22 public: | 20 public: |
| 23 enum ResolveType { | 21 enum ResolveType { |
| 24 Fulfilled, | 22 Fulfilled, |
| 25 Rejected, | 23 Rejected, |
| 26 }; | 24 }; |
| 27 | 25 |
| 28 static PassOwnPtr<ScriptFunction> create(PassRefPtrWillBeRawPtr<WaitUntilObs
erver> observer, ResolveType type) | 26 static PassOwnPtr<ScriptFunction> create(PassRefPtr<WaitUntilObserver> obser
ver, ResolveType type) |
| 29 { | 27 { |
| 30 return adoptPtr(new ThenFunction(toIsolate(observer->executionContext())
, observer, type)); | 28 return adoptPtr(new ThenFunction(toIsolate(observer->executionContext())
, observer, type)); |
| 31 } | 29 } |
| 32 | 30 |
| 33 private: | 31 private: |
| 34 ThenFunction(v8::Isolate* isolate, PassRefPtrWillBeRawPtr<WaitUntilObserver>
observer, ResolveType type) | 32 ThenFunction(v8::Isolate* isolate, PassRefPtr<WaitUntilObserver> observer, R
esolveType type) |
| 35 : ScriptFunction(isolate) | 33 : ScriptFunction(isolate) |
| 36 , m_observer(observer) | 34 , m_observer(observer) |
| 37 , m_resolveType(type) | 35 , m_resolveType(type) |
| 38 { | 36 { |
| 39 } | 37 } |
| 40 | 38 |
| 41 virtual ScriptValue call(ScriptValue value) OVERRIDE | 39 virtual ScriptValue call(ScriptValue value) OVERRIDE |
| 42 { | 40 { |
| 43 ASSERT(m_observer); | 41 ASSERT(m_observer); |
| 44 ASSERT(m_resolveType == Fulfilled || m_resolveType == Rejected); | 42 ASSERT(m_resolveType == Fulfilled || m_resolveType == Rejected); |
| 45 if (m_resolveType == Rejected) | 43 if (m_resolveType == Rejected) |
| 46 m_observer->reportError(value); | 44 m_observer->reportError(value); |
| 47 m_observer->decrementPendingActivity(); | 45 m_observer->decrementPendingActivity(); |
| 48 m_observer = 0; | 46 m_observer = 0; |
| 49 return value; | 47 return value; |
| 50 } | 48 } |
| 51 | 49 |
| 52 RefPtrWillBePersistent<WaitUntilObserver> m_observer; | 50 RefPtr<WaitUntilObserver> m_observer; |
| 53 ResolveType m_resolveType; | 51 ResolveType m_resolveType; |
| 54 }; | 52 }; |
| 55 | 53 |
| 56 PassRefPtrWillBeRawPtr<WaitUntilObserver> WaitUntilObserver::create(ExecutionCon
text* context, int eventID) | 54 PassRefPtr<WaitUntilObserver> WaitUntilObserver::create(ExecutionContext* contex
t, int eventID) |
| 57 { | 55 { |
| 58 return adoptRefWillBeNoop(new WaitUntilObserver(context, eventID)); | 56 return adoptRef(new WaitUntilObserver(context, eventID)); |
| 59 } | 57 } |
| 60 | 58 |
| 61 WaitUntilObserver::~WaitUntilObserver() | 59 WaitUntilObserver::~WaitUntilObserver() |
| 62 { | 60 { |
| 63 ASSERT(!m_pendingActivity); | 61 ASSERT(!m_pendingActivity); |
| 64 } | 62 } |
| 65 | 63 |
| 66 void WaitUntilObserver::willDispatchEvent() | 64 void WaitUntilObserver::willDispatchEvent() |
| 67 { | 65 { |
| 68 incrementPendingActivity(); | 66 incrementPendingActivity(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 { | 101 { |
| 104 ASSERT(m_pendingActivity > 0); | 102 ASSERT(m_pendingActivity > 0); |
| 105 if (--m_pendingActivity || !executionContext()) | 103 if (--m_pendingActivity || !executionContext()) |
| 106 return; | 104 return; |
| 107 | 105 |
| 108 ServiceWorkerGlobalScopeClient::from(executionContext())->didHandleInstallEv
ent(m_eventID); | 106 ServiceWorkerGlobalScopeClient::from(executionContext())->didHandleInstallEv
ent(m_eventID); |
| 109 observeContext(0); | 107 observeContext(0); |
| 110 } | 108 } |
| 111 | 109 |
| 112 } // namespace WebCore | 110 } // namespace WebCore |
| OLD | NEW |