| 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 #ifndef ReadableStream_h | 5 #ifndef ReadableStream_h |
| 6 #define ReadableStream_h | 6 #define ReadableStream_h |
| 7 | 7 |
| 8 #include "bindings/core/v8/ScriptPromise.h" | 8 #include "bindings/core/v8/ScriptPromise.h" |
| 9 #include "bindings/core/v8/ScriptPromiseProperty.h" | 9 #include "bindings/core/v8/ScriptPromiseProperty.h" |
| 10 #include "bindings/core/v8/ScriptState.h" | 10 #include "bindings/core/v8/ScriptState.h" |
| 11 #include "bindings/core/v8/ScriptValue.h" | 11 #include "bindings/core/v8/ScriptValue.h" |
| 12 #include "bindings/core/v8/ScriptWrappable.h" | 12 #include "bindings/core/v8/ScriptWrappable.h" |
| 13 #include "bindings/core/v8/V8Binding.h" | 13 #include "bindings/core/v8/V8Binding.h" |
| 14 #include "core/dom/ContextLifecycleObserver.h" | 14 #include "core/dom/ContextLifecycleObserver.h" |
| 15 #include "platform/heap/Handle.h" | 15 #include "platform/heap/Handle.h" |
| 16 #include "wtf/Forward.h" | 16 #include "wtf/Forward.h" |
| 17 #include "wtf/PassRefPtr.h" | 17 #include "wtf/PassRefPtr.h" |
| 18 #include "wtf/RefPtr.h" | 18 #include "wtf/RefPtr.h" |
| 19 | 19 |
| 20 namespace blink { | 20 namespace blink { |
| 21 | 21 |
| 22 class DOMException; | 22 class DOMException; |
| 23 class ExceptionState; | 23 class ExceptionState; |
| 24 class UnderlyingSource; | 24 class UnderlyingSource; |
| 25 | 25 |
| 26 class ReadableStream : public GarbageCollectedFinalized<ReadableStream>, public
ScriptWrappable, public ContextLifecycleObserver { | 26 class ReadableStream : public GarbageCollectedFinalized<ReadableStream>, public
ScriptWrappable { |
| 27 public: | 27 public: |
| 28 enum State { | 28 enum State { |
| 29 Readable, | 29 Readable, |
| 30 Waiting, | 30 Waiting, |
| 31 Closed, | 31 Closed, |
| 32 Errored, | 32 Errored, |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 // FIXME: Define Strategy here. | 35 // FIXME: Define Strategy here. |
| 36 // FIXME: Add |strategy| constructor parameter. | 36 // FIXME: Add |strategy| constructor parameter. |
| 37 ReadableStream(ScriptState*, UnderlyingSource*, ExceptionState*); | 37 // After ReadableStream construction, |didSourceStart| must be called when |
| 38 // |source| initialization succeeds and |error| must be called when |
| 39 // |source| initialization fails. |
| 40 ReadableStream(ExecutionContext*, UnderlyingSource* /* source */); |
| 38 virtual ~ReadableStream(); | 41 virtual ~ReadableStream(); |
| 39 | 42 |
| 40 bool isStarted() const { return m_isStarted; } | 43 bool isStarted() const { return m_isStarted; } |
| 41 bool isDraining() const { return m_isDraining; } | 44 bool isDraining() const { return m_isDraining; } |
| 42 bool isPulling() const { return m_isPulling; } | 45 bool isPulling() const { return m_isPulling; } |
| 43 State state() const { return m_state; } | 46 State state() const { return m_state; } |
| 47 String stateString() const; |
| 44 | 48 |
| 45 virtual ScriptValue read(ScriptState*, ExceptionState*) = 0; | 49 virtual ScriptValue read(ScriptState*, ExceptionState&) = 0; |
| 46 ScriptPromise wait(ScriptState*); | 50 ScriptPromise wait(ScriptState*); |
| 47 ScriptPromise cancel(ScriptState*, ScriptValue reason); | 51 ScriptPromise cancel(ScriptState*, ScriptValue reason); |
| 48 ScriptPromise closed(ScriptState*); | 52 ScriptPromise closed(ScriptState*); |
| 49 | 53 |
| 50 void close(); | 54 void close(); |
| 51 void error(PassRefPtrWillBeRawPtr<DOMException>); | 55 void error(PassRefPtrWillBeRawPtr<DOMException>); |
| 52 | 56 |
| 57 void didSourceStart(); |
| 58 |
| 53 virtual void trace(Visitor*); | 59 virtual void trace(Visitor*); |
| 54 | 60 |
| 55 protected: | 61 protected: |
| 56 bool enqueuePreliminaryCheck(size_t chunkSize); | 62 bool enqueuePreliminaryCheck(size_t chunkSize); |
| 57 bool enqueuePostAction(size_t totalQueueSize); | 63 bool enqueuePostAction(size_t totalQueueSize); |
| 58 void readPreliminaryCheck(ExceptionState*); | 64 void readPreliminaryCheck(ExceptionState&); |
| 59 void readPostAction(); | 65 void readPostAction(); |
| 60 | 66 |
| 61 private: | 67 private: |
| 62 class OnStarted; | |
| 63 typedef ScriptPromiseProperty<Member<ReadableStream>, V8UndefinedType, RefPt
rWillBeMember<DOMException> > WaitPromise; | 68 typedef ScriptPromiseProperty<Member<ReadableStream>, V8UndefinedType, RefPt
rWillBeMember<DOMException> > WaitPromise; |
| 64 typedef ScriptPromiseProperty<Member<ReadableStream>, V8UndefinedType, RefPt
rWillBeMember<DOMException> > ClosedPromise; | 69 typedef ScriptPromiseProperty<Member<ReadableStream>, V8UndefinedType, RefPt
rWillBeMember<DOMException> > ClosedPromise; |
| 65 | 70 |
| 66 virtual bool isQueueEmpty() const = 0; | 71 virtual bool isQueueEmpty() const = 0; |
| 67 virtual void clearQueue() = 0; | 72 virtual void clearQueue() = 0; |
| 68 | 73 |
| 69 void onStarted(void); | |
| 70 void callOrSchedulePull(); | 74 void callOrSchedulePull(); |
| 71 | 75 |
| 72 Member<UnderlyingSource> m_source; | 76 Member<UnderlyingSource> m_source; |
| 73 bool m_isStarted; | 77 bool m_isStarted; |
| 74 bool m_isDraining; | 78 bool m_isDraining; |
| 75 bool m_isPulling; | 79 bool m_isPulling; |
| 76 bool m_isSchedulingPull; | 80 bool m_isSchedulingPull; |
| 77 State m_state; | 81 State m_state; |
| 78 | 82 |
| 79 Member<WaitPromise> m_wait; | 83 Member<WaitPromise> m_wait; |
| 80 Member<ClosedPromise> m_closed; | 84 Member<ClosedPromise> m_closed; |
| 81 RefPtrWillBeMember<DOMException> m_exception; | 85 RefPtrWillBeMember<DOMException> m_exception; |
| 82 }; | 86 }; |
| 83 | 87 |
| 84 } // namespace blink | 88 } // namespace blink |
| 85 | 89 |
| 86 #endif // ReadableStream_h | 90 #endif // ReadableStream_h |
| 87 | 91 |
| OLD | NEW |