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

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

Issue 837673002: Introduce ExclusiveStreamReader. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 10 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"
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/ActiveDOMObject.h" 14 #include "core/dom/ActiveDOMObject.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 ExclusiveStreamReader;
24 class UnderlyingSource; 25 class UnderlyingSource;
25 26
26 class ReadableStream : public GarbageCollectedFinalized<ReadableStream>, public ScriptWrappable, public ActiveDOMObject { 27 class ReadableStream : public GarbageCollectedFinalized<ReadableStream>, public ScriptWrappable, public ActiveDOMObject {
27 DEFINE_WRAPPERTYPEINFO(); 28 DEFINE_WRAPPERTYPEINFO();
28 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(ReadableStream); 29 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(ReadableStream);
29 public: 30 public:
30 enum State { 31 enum State {
31 Readable, 32 Readable,
32 Waiting, 33 Waiting,
33 Closed, 34 Closed,
34 Errored, 35 Errored,
35 }; 36 };
36 37
37 // After ReadableStream construction, |didSourceStart| must be called when 38 // After ReadableStream construction, |didSourceStart| must be called when
38 // |source| initialization succeeds and |error| must be called when 39 // |source| initialization succeeds and |error| must be called when
39 // |source| initialization fails. 40 // |source| initialization fails.
40 ReadableStream(ExecutionContext*, UnderlyingSource* /* source */); 41 ReadableStream(ExecutionContext*, UnderlyingSource* /* source */);
41 virtual ~ReadableStream(); 42 virtual ~ReadableStream();
42 43
43 bool isStarted() const { return m_isStarted; } 44 bool isStarted() const { return m_isStarted; }
44 bool isDraining() const { return m_isDraining; } 45 bool isDraining() const { return m_isDraining; }
45 bool isPulling() const { return m_isPulling; } 46 bool isPulling() const { return m_isPulling; }
46 State state() const { return m_state; } 47 State stateInternal() const { return m_state; }
48 DOMException* storedException() { return m_exception.get(); }
49
50 // |stateString|, |read| and |ready| are affected by an exclusive lock. Use
51 // |stateInternal|, |readInternal| and |readyInternal| if you want to avoid
52 // that.
47 String stateString() const; 53 String stateString() const;
48 54 ScriptValue read(ScriptState*, ExceptionState&);
49 virtual ScriptValue read(ScriptState*, ExceptionState&) = 0;
50 ScriptPromise ready(ScriptState*); 55 ScriptPromise ready(ScriptState*);
51 ScriptPromise cancel(ScriptState*, ScriptValue reason); 56 ScriptPromise cancel(ScriptState*, ScriptValue reason);
52 ScriptPromise closed(ScriptState*); 57 ScriptPromise closed(ScriptState*);
53 58
59 virtual ScriptValue readInternal(ScriptState*, ExceptionState&) = 0;
60 ScriptPromise readyInternal(ScriptState*);
61
54 void close(); 62 void close();
55 void error(PassRefPtrWillBeRawPtr<DOMException>); 63 void error(PassRefPtrWillBeRawPtr<DOMException>);
56 64
57 void didSourceStart(); 65 void didSourceStart();
58 66
67 // This function is not a getter. It creates an ExclusiveStreamReader and
68 // returns it.
69 ExclusiveStreamReader* getReader(ExceptionState&);
70 // Only ExclusiveStreamReader methods should call this function.
71 void setReader(ExclusiveStreamReader*);
72 bool isLockedTo(const ExclusiveStreamReader* reader) const { return m_reader == reader; }
73
59 bool hasPendingActivity() const override; 74 bool hasPendingActivity() const override;
60 virtual void trace(Visitor*) override; 75 void stop() override;
76 void trace(Visitor*) override;
77
78 // Returns the string representation of the given State.
79 static String stateToString(State);
61 80
62 protected: 81 protected:
63 bool enqueuePreliminaryCheck(); 82 bool enqueuePreliminaryCheck();
64 bool enqueuePostAction(); 83 bool enqueuePostAction();
65 void readPreliminaryCheck(ExceptionState&); 84 void readInternalPreliminaryCheck(ExceptionState&);
66 void readPostAction(); 85 void readInternalPostAction();
67 86
68 private: 87 private:
69 typedef ScriptPromiseProperty<Member<ReadableStream>, ToV8UndefinedGenerator , RefPtrWillBeMember<DOMException> > WaitPromise; 88 using WaitPromise = ScriptPromiseProperty<Member<ReadableStream>, ToV8Undefi nedGenerator, RefPtrWillBeMember<DOMException>>;
70 typedef ScriptPromiseProperty<Member<ReadableStream>, ToV8UndefinedGenerator , RefPtrWillBeMember<DOMException> > ClosedPromise; 89 using ClosedPromise = ScriptPromiseProperty<Member<ReadableStream>, ToV8Unde finedGenerator, RefPtrWillBeMember<DOMException>>;
71 90
72 virtual bool isQueueEmpty() const = 0; 91 virtual bool isQueueEmpty() const = 0;
73 virtual void clearQueue() = 0; 92 virtual void clearQueue() = 0;
74 // This function will call ReadableStream::error on error. 93 // This function will call ReadableStream::error on error.
75 virtual bool shouldApplyBackpressure() = 0; 94 virtual bool shouldApplyBackpressure() = 0;
76 95
77 void callPullIfNeeded(); 96 void callPullIfNeeded();
78 97
79 Member<UnderlyingSource> m_source; 98 Member<UnderlyingSource> m_source;
80 bool m_isStarted; 99 bool m_isStarted;
81 bool m_isDraining; 100 bool m_isDraining;
82 bool m_isPulling; 101 bool m_isPulling;
83 State m_state; 102 State m_state;
84 103
85 Member<WaitPromise> m_ready; 104 Member<WaitPromise> m_ready;
86 Member<ClosedPromise> m_closed; 105 Member<ClosedPromise> m_closed;
106
87 RefPtrWillBeMember<DOMException> m_exception; 107 RefPtrWillBeMember<DOMException> m_exception;
108 Member<ExclusiveStreamReader> m_reader;
88 }; 109 };
89 110
90 } // namespace blink 111 } // namespace blink
91 112
92 #endif // ReadableStream_h 113 #endif // ReadableStream_h
OLDNEW
« no previous file with comments | « Source/core/streams/ExclusiveStreamReaderTest.cpp ('k') | Source/core/streams/ReadableStream.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698