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

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 trace(Visitor*) override;
76
77 // Returns the string representation of the given State.
78 static String toString(State);
tyoshino (SeeGerritForStatus) 2015/02/02 04:24:11 give a name from it we understand immediately that
yhirano 2015/02/02 06:05:37 Done.
61 79
62 protected: 80 protected:
63 bool enqueuePreliminaryCheck(); 81 bool enqueuePreliminaryCheck();
64 bool enqueuePostAction(); 82 bool enqueuePostAction();
65 void readPreliminaryCheck(ExceptionState&); 83 void readInternalPreliminaryCheck(ExceptionState&);
66 void readPostAction(); 84 void readInternalPostAction();
67 85
68 private: 86 private:
69 typedef ScriptPromiseProperty<Member<ReadableStream>, ToV8UndefinedGenerator , RefPtrWillBeMember<DOMException> > WaitPromise; 87 using WaitPromise = ScriptPromiseProperty<Member<ReadableStream>, ToV8Undefi nedGenerator, RefPtrWillBeMember<DOMException>>;
70 typedef ScriptPromiseProperty<Member<ReadableStream>, ToV8UndefinedGenerator , RefPtrWillBeMember<DOMException> > ClosedPromise; 88 using ClosedPromise = ScriptPromiseProperty<Member<ReadableStream>, ToV8Unde finedGenerator, RefPtrWillBeMember<DOMException>>;
71 89
72 virtual bool isQueueEmpty() const = 0; 90 virtual bool isQueueEmpty() const = 0;
73 virtual void clearQueue() = 0; 91 virtual void clearQueue() = 0;
74 // This function will call ReadableStream::error on error. 92 // This function will call ReadableStream::error on error.
75 virtual bool shouldApplyBackpressure() = 0; 93 virtual bool shouldApplyBackpressure() = 0;
76 94
77 void callPullIfNeeded(); 95 void callPullIfNeeded();
78 96
79 Member<UnderlyingSource> m_source; 97 Member<UnderlyingSource> m_source;
80 bool m_isStarted; 98 bool m_isStarted;
81 bool m_isDraining; 99 bool m_isDraining;
82 bool m_isPulling; 100 bool m_isPulling;
83 State m_state; 101 State m_state;
84 102
85 Member<WaitPromise> m_ready; 103 Member<WaitPromise> m_ready;
86 Member<ClosedPromise> m_closed; 104 Member<ClosedPromise> m_closed;
105
87 RefPtrWillBeMember<DOMException> m_exception; 106 RefPtrWillBeMember<DOMException> m_exception;
107 Member<ExclusiveStreamReader> m_reader;
88 }; 108 };
89 109
90 } // namespace blink 110 } // namespace blink
91 111
92 #endif // ReadableStream_h 112 #endif // ReadableStream_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698