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" |
(...skipping 12 matching lines...) Expand all Loading... |
23 class ExceptionState; | 23 class ExceptionState; |
24 class ReadableStreamReader; | 24 class ReadableStreamReader; |
25 class UnderlyingSource; | 25 class UnderlyingSource; |
26 | 26 |
27 class ReadableStream : public GarbageCollectedFinalized<ReadableStream>, public
ScriptWrappable, public ActiveDOMObject { | 27 class ReadableStream : public GarbageCollectedFinalized<ReadableStream>, public
ScriptWrappable, public ActiveDOMObject { |
28 DEFINE_WRAPPERTYPEINFO(); | 28 DEFINE_WRAPPERTYPEINFO(); |
29 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(ReadableStream); | 29 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(ReadableStream); |
30 public: | 30 public: |
31 enum State { | 31 enum State { |
32 Readable, | 32 Readable, |
33 Waiting, | |
34 Closed, | 33 Closed, |
35 Errored, | 34 Errored, |
36 }; | 35 }; |
37 | 36 |
38 // After ReadableStream construction, |didSourceStart| must be called when | 37 // After ReadableStream construction, |didSourceStart| must be called when |
39 // |source| initialization succeeds and |error| must be called when | 38 // |source| initialization succeeds and |error| must be called when |
40 // |source| initialization fails. | 39 // |source| initialization fails. |
41 ReadableStream(ExecutionContext*, UnderlyingSource* /* source */); | 40 ReadableStream(ExecutionContext*, UnderlyingSource* /* source */); |
42 virtual ~ReadableStream(); | 41 virtual ~ReadableStream(); |
43 | 42 |
44 bool isStarted() const { return m_isStarted; } | 43 bool isStarted() const { return m_isStarted; } |
45 bool isDraining() const { return m_isDraining; } | 44 bool isDraining() const { return m_isDraining; } |
46 bool isPulling() const { return m_isPulling; } | 45 bool isPulling() const { return m_isPulling; } |
47 State stateInternal() const { return m_state; } | 46 State stateInternal() const { return m_state; } |
48 DOMException* storedException() { return m_exception.get(); } | 47 DOMException* storedException() { return m_exception.get(); } |
49 | 48 |
50 // |stateString|, |read| and |ready| are affected by an exclusive lock. Use | 49 virtual ScriptPromise read(ScriptState*) = 0; |
51 // |stateInternal|, |readInternal| and |readyInternal| if you want to avoid | |
52 // that. | |
53 String stateString() const; | |
54 ScriptValue read(ScriptState*, ExceptionState&); | |
55 ScriptPromise ready(ScriptState*); | |
56 ScriptPromise cancel(ScriptState*, ScriptValue reason); | 50 ScriptPromise cancel(ScriptState*, ScriptValue reason); |
57 ScriptPromise closed(ScriptState*); | 51 ScriptPromise cancelInternal(ScriptState*, ScriptValue reason); |
58 | 52 |
59 virtual ScriptValue readInternal(ScriptState*, ExceptionState&) = 0; | 53 virtual bool hasPendingReads() const = 0; |
60 ScriptPromise readyInternal(ScriptState*); | 54 virtual void resolveAllPendingReadsAsDone() = 0; |
| 55 virtual void rejectAllPendingReads(PassRefPtrWillBeRawPtr<DOMException>) = 0
; |
61 | 56 |
62 void close(); | 57 void close(); |
63 void error(PassRefPtrWillBeRawPtr<DOMException>); | 58 void error(PassRefPtrWillBeRawPtr<DOMException>); |
64 | 59 |
65 void didSourceStart(); | 60 void didSourceStart(); |
66 | 61 |
67 // This function is not a getter. It creates an ReadableStreamReader and | 62 // This function is not a getter. It creates an ReadableStreamReader and |
68 // returns it. | 63 // returns it. |
69 ReadableStreamReader* getReader(ExceptionState&); | 64 ReadableStreamReader* getReader(ExceptionState&); |
70 // Only ReadableStreamReader methods should call this function. | 65 // Only ReadableStreamReader methods should call this function. |
71 void setReader(ReadableStreamReader*); | 66 void setReader(ReadableStreamReader*); |
72 | 67 |
73 bool isLocked() const { return m_reader; } | 68 bool isLocked() const { return m_reader; } |
74 bool isLockedTo(const ReadableStreamReader* reader) const { return m_reader
== reader; } | 69 bool isLockedTo(const ReadableStreamReader* reader) const { return m_reader
== reader; } |
75 | 70 |
76 bool hasPendingActivity() const override; | 71 bool hasPendingActivity() const override; |
77 void stop() override; | 72 void stop() override; |
78 DECLARE_VIRTUAL_TRACE(); | 73 DECLARE_VIRTUAL_TRACE(); |
79 | 74 |
80 // Returns the string representation of the given State. | |
81 static String stateToString(State); | |
82 | |
83 protected: | 75 protected: |
84 bool enqueuePreliminaryCheck(); | 76 bool enqueuePreliminaryCheck(); |
85 bool enqueuePostAction(); | 77 bool enqueuePostAction(); |
86 void readInternalPreliminaryCheck(ExceptionState&); | |
87 void readInternalPostAction(); | 78 void readInternalPostAction(); |
88 | 79 |
89 private: | 80 private: |
90 using WaitPromise = ScriptPromiseProperty<Member<ReadableStream>, ToV8Undefi
nedGenerator, RefPtrWillBeMember<DOMException>>; | 81 using WaitPromise = ScriptPromiseProperty<Member<ReadableStream>, ToV8Undefi
nedGenerator, RefPtrWillBeMember<DOMException>>; |
91 using ClosedPromise = ScriptPromiseProperty<Member<ReadableStream>, ToV8Unde
finedGenerator, RefPtrWillBeMember<DOMException>>; | 82 using ClosedPromise = ScriptPromiseProperty<Member<ReadableStream>, ToV8Unde
finedGenerator, RefPtrWillBeMember<DOMException>>; |
92 | 83 |
93 virtual bool isQueueEmpty() const = 0; | 84 virtual bool isQueueEmpty() const = 0; |
94 virtual void clearQueue() = 0; | 85 virtual void clearQueue() = 0; |
95 // This function will call ReadableStream::error on error. | 86 // This function will call ReadableStream::error on error. |
96 virtual bool shouldApplyBackpressure() = 0; | 87 virtual bool shouldApplyBackpressure() = 0; |
97 | 88 |
98 void callPullIfNeeded(); | 89 void callPullIfNeeded(); |
| 90 void closeInternal(); |
99 | 91 |
100 Member<UnderlyingSource> m_source; | 92 Member<UnderlyingSource> m_source; |
101 bool m_isStarted; | 93 bool m_isStarted; |
102 bool m_isDraining; | 94 bool m_isDraining; |
103 bool m_isPulling; | 95 bool m_isPulling; |
104 State m_state; | 96 State m_state; |
105 | 97 |
106 Member<WaitPromise> m_ready; | |
107 Member<ClosedPromise> m_closed; | |
108 | |
109 RefPtrWillBeMember<DOMException> m_exception; | 98 RefPtrWillBeMember<DOMException> m_exception; |
110 Member<ReadableStreamReader> m_reader; | 99 Member<ReadableStreamReader> m_reader; |
111 }; | 100 }; |
112 | 101 |
113 } // namespace blink | 102 } // namespace blink |
114 | 103 |
115 #endif // ReadableStream_h | 104 #endif // ReadableStream_h |
OLD | NEW |