Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 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. | |
| 29 */ | |
| 30 | |
| 31 #ifndef Future_h | |
| 32 #define Future_h | |
| 33 | |
| 34 #include "bindings/v8/ScriptValue.h" | |
| 35 #include "core/dom/ActiveDOMObject.h" | |
| 36 #include "core/dom/AnyCallback.h" | |
| 37 #include "core/dom/FutureInit.h" | |
| 38 #include "core/dom/FutureResolver.h" | |
| 39 #include "wtf/PassRefPtr.h" | |
| 40 #include "wtf/RefCounted.h" | |
| 41 #include "wtf/RefPtr.h" | |
| 42 #include "wtf/Vector.h" | |
| 43 | |
| 44 namespace WebCore { | |
| 45 | |
| 46 // Needed due to circular dependency. | |
| 47 class AnyCallback; | |
| 48 class FutureInit; | |
| 49 | |
| 50 class Future : public RefCounted<Future>, public ActiveDOMObject { | |
| 51 public: | |
| 52 enum State { | |
| 53 Pending, | |
| 54 Accepted, | |
| 55 Rejected | |
| 56 }; | |
| 57 | |
| 58 static PassRefPtr<Future> createAndRunInit(PassRefPtr<FutureInit>); | |
| 59 | |
| 60 static PassRefPtr<Future> accept(const ScriptValue&); | |
| 61 static PassRefPtr<Future> resolve(const ScriptValue&); | |
| 62 static PassRefPtr<Future> reject(const ScriptValue&); | |
| 63 | |
| 64 static PassRefPtr<Future> anyof(Vector<ScriptValue>&); | |
| 65 static PassRefPtr<Future> every(Vector<ScriptValue>&); | |
| 66 static PassRefPtr<Future> some(Vector<ScriptValue>&); | |
| 67 | |
| 68 PassRefPtr<Future> then(PassRefPtr<AnyCallback>, PassRefPtr<AnyCallback>); | |
| 69 void done(PassRefPtr<AnyCallback>, PassRefPtr<AnyCallback>); | |
| 70 | |
| 71 void then(PassRefPtr<Future>); | |
| 72 | |
| 73 void setResolver(PassRefPtr<FutureResolver> resolver) { m_resolver = resolve r; } | |
| 74 PassRefPtr<FutureResolver> getResolver() { return m_resolver; } | |
| 75 | |
| 76 // Methods for m_resolver to modify the associated Future instance. | |
| 77 | |
| 78 void setState(State state) { m_state = state; } | |
| 79 void setResult(const ScriptValue& result) { m_result = result; } | |
| 80 | |
| 81 void processAcceptCallbacks(const ScriptValue&); | |
| 82 void queueProcessAcceptCallbacksTask(const ScriptValue&); | |
| 83 void processRejectCallbacks(const ScriptValue&); | |
| 84 void queueProcessRejectCallbacksTask(const ScriptValue&); | |
| 85 | |
| 86 // For RefCounted<Future>. | |
| 87 virtual ~Future(); | |
| 88 | |
| 89 private: | |
| 90 class FutureCallback : public RefCounted<FutureCallback> { | |
| 91 public: | |
| 92 enum Algorithm { | |
| 93 NoAlgorithm, | |
| 94 WrapperAlgorithm, | |
| 95 AcceptAlgorithm, | |
| 96 ResolveAlgorithm, | |
| 97 RejectAlgorithm | |
| 98 }; | |
| 99 | |
| 100 static PassRefPtr<FutureCallback> create(Algorithm algorithm, PassRefPtr <FutureResolver> resolver, PassRefPtr<AnyCallback> callback) | |
| 101 { | |
| 102 return adoptRef(new FutureCallback(algorithm, resolver, callback)); | |
| 103 } | |
| 104 | |
| 105 void invoke(const ScriptValue&); | |
| 106 | |
| 107 private: | |
| 108 FutureCallback(Algorithm algorithm, PassRefPtr<FutureResolver> resolver, PassRefPtr<AnyCallback> callback) | |
| 109 : m_algorithm(algorithm) | |
| 110 , m_resolver(resolver) | |
| 111 , m_callback(callback) | |
| 112 { | |
| 113 } | |
| 114 | |
| 115 Algorithm m_algorithm; | |
| 116 RefPtr<FutureResolver> m_resolver; | |
| 117 RefPtr<AnyCallback> m_callback; | |
| 118 }; | |
| 119 | |
| 120 static PassRefPtr<Future> create(); | |
| 121 | |
| 122 explicit Future(ScriptExecutionContext*); | |
| 123 | |
| 124 void appendCallbacks(PassRefPtr<FutureCallback> acceptCallback, PassRefPtr<F utureCallback> rejectCallback); | |
| 125 | |
| 126 Vector<RefPtr<FutureCallback> > m_acceptCallbacks; | |
| 127 Vector<RefPtr<FutureCallback> > m_rejectCallbacks; | |
| 128 State m_state; | |
| 129 ScriptValue m_result; | |
|
abarth-chromium
2013/05/23 17:56:47
We should talk more about the general approach. U
| |
| 130 | |
| 131 // The associated FutureResolver instance. | |
| 132 RefPtr<FutureResolver> m_resolver; | |
| 133 }; | |
| 134 | |
| 135 } // namespace WebCore | |
| 136 | |
| 137 #endif // Future_h | |
| OLD | NEW |