OLD | NEW |
(Empty) | |
| 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 ReadableStream_h |
| 6 #define ReadableStream_h |
| 7 |
| 8 #include "bindings/core/v8/ScriptPromise.h" |
| 9 #include "bindings/core/v8/ScriptState.h" |
| 10 #include "bindings/core/v8/ScriptValue.h" |
| 11 #include "bindings/core/v8/V8Binding.h" |
| 12 #include "platform/heap/Handle.h" |
| 13 #include "wtf/RefPtr.h" |
| 14 |
| 15 namespace blink { |
| 16 |
| 17 class ExceptionState; |
| 18 class UnderlyingSource; |
| 19 |
| 20 class ReadableStream FINAL : public GarbageCollectedFinalized<ReadableStream> { |
| 21 public: |
| 22 enum State { |
| 23 Readable, |
| 24 Waiting, |
| 25 Closed, |
| 26 Errored, |
| 27 }; |
| 28 |
| 29 // FIXME: Define Strategy here. |
| 30 // FIXME: Add |strategy| constructor parameter. |
| 31 ReadableStream(ScriptState*, UnderlyingSource*, ExceptionState*); |
| 32 virtual ~ReadableStream(); |
| 33 |
| 34 template <typename T> |
| 35 bool enqueue(const T& chunk) |
| 36 { |
| 37 ScriptState::Scope scope(m_scriptState.get()); |
| 38 return enqueueInternal(ScriptValue(m_scriptState.get(), V8ValueTraits<T>
::toV8Value(chunk))); |
| 39 } |
| 40 |
| 41 bool isStarted() const { return m_isStarted; } |
| 42 bool isDraining() const { return m_isDraining; } |
| 43 bool isPulling() const { return m_isPulling; } |
| 44 State state() const { return m_state; } |
| 45 |
| 46 // FIXME: Implement these APIs. |
| 47 // bool read(); |
| 48 // ScriptPromise wait(); |
| 49 // void close(); |
| 50 |
| 51 void error(ScriptValue error); |
| 52 |
| 53 void trace(Visitor*); |
| 54 |
| 55 private: |
| 56 class OnStarted; |
| 57 class OnStartFailed; |
| 58 |
| 59 void onStarted(void); |
| 60 bool enqueueInternal(ScriptValue chunk); |
| 61 |
| 62 RefPtr<ScriptState> m_scriptState; |
| 63 Member<UnderlyingSource> m_source; |
| 64 bool m_isStarted; |
| 65 bool m_isDraining; |
| 66 bool m_isPulling; |
| 67 State m_state; |
| 68 }; |
| 69 |
| 70 } // namespace blink |
| 71 |
| 72 #endif // ReadableStream_h |
| 73 |
OLD | NEW |