Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: Source/core/streams/ReadableStream.h

Issue 1004623007: Streams Implementation Update: async read (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@stream-reader-read
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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*);
58 51
59 virtual ScriptValue readInternal(ScriptState*, ExceptionState&) = 0; 52 virtual bool hasPendingReads() const = 0;
60 ScriptPromise readyInternal(ScriptState*); 53 virtual void resolveAllPendingReadsAsDone() = 0;
54 virtual void rejectAllPendingReads(PassRefPtrWillBeRawPtr<DOMException>) = 0 ;
61 55
62 void close(); 56 void close();
63 void error(PassRefPtrWillBeRawPtr<DOMException>); 57 void error(PassRefPtrWillBeRawPtr<DOMException>);
64 58
65 void didSourceStart(); 59 void didSourceStart();
66 60
67 // This function is not a getter. It creates an ReadableStreamReader and 61 // This function is not a getter. It creates an ReadableStreamReader and
68 // returns it. 62 // returns it.
69 ReadableStreamReader* getReader(ExceptionState&); 63 ReadableStreamReader* getReader(ExceptionState&);
70 // Only ReadableStreamReader methods should call this function. 64 // Only ReadableStreamReader methods should call this function.
71 void setReader(ReadableStreamReader*); 65 void setReader(ReadableStreamReader*);
72 66
73 bool isLocked() const { return m_reader; } 67 bool isLocked() const { return m_reader; }
74 bool isLockedTo(const ReadableStreamReader* reader) const { return m_reader == reader; } 68 bool isLockedTo(const ReadableStreamReader* reader) const { return m_reader == reader; }
75 69
76 bool hasPendingActivity() const override; 70 bool hasPendingActivity() const override;
77 void stop() override; 71 void stop() override;
78 DECLARE_VIRTUAL_TRACE(); 72 DECLARE_VIRTUAL_TRACE();
79 73
80 // Returns the string representation of the given State.
81 static String stateToString(State);
82
83 protected: 74 protected:
84 bool enqueuePreliminaryCheck(); 75 bool enqueuePreliminaryCheck();
85 bool enqueuePostAction(); 76 bool enqueuePostAction();
86 void readInternalPreliminaryCheck(ExceptionState&);
87 void readInternalPostAction(); 77 void readInternalPostAction();
88 78
89 private: 79 private:
90 using WaitPromise = ScriptPromiseProperty<Member<ReadableStream>, ToV8Undefi nedGenerator, RefPtrWillBeMember<DOMException>>; 80 using WaitPromise = ScriptPromiseProperty<Member<ReadableStream>, ToV8Undefi nedGenerator, RefPtrWillBeMember<DOMException>>;
91 using ClosedPromise = ScriptPromiseProperty<Member<ReadableStream>, ToV8Unde finedGenerator, RefPtrWillBeMember<DOMException>>; 81 using ClosedPromise = ScriptPromiseProperty<Member<ReadableStream>, ToV8Unde finedGenerator, RefPtrWillBeMember<DOMException>>;
92 82
93 virtual bool isQueueEmpty() const = 0; 83 virtual bool isQueueEmpty() const = 0;
94 virtual void clearQueue() = 0; 84 virtual void clearQueue() = 0;
95 // This function will call ReadableStream::error on error. 85 // This function will call ReadableStream::error on error.
96 virtual bool shouldApplyBackpressure() = 0; 86 virtual bool shouldApplyBackpressure() = 0;
97 87
98 void callPullIfNeeded(); 88 void callPullIfNeeded();
99 89
100 Member<UnderlyingSource> m_source; 90 Member<UnderlyingSource> m_source;
101 bool m_isStarted; 91 bool m_isStarted;
102 bool m_isDraining; 92 bool m_isDraining;
103 bool m_isPulling; 93 bool m_isPulling;
104 State m_state; 94 State m_state;
105 95
106 Member<WaitPromise> m_ready;
107 Member<ClosedPromise> m_closed;
108
109 RefPtrWillBeMember<DOMException> m_exception; 96 RefPtrWillBeMember<DOMException> m_exception;
110 Member<ReadableStreamReader> m_reader; 97 Member<ReadableStreamReader> m_reader;
111 }; 98 };
112 99
113 } // namespace blink 100 } // namespace blink
114 101
115 #endif // ReadableStream_h 102 #endif // ReadableStream_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698