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