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

Side by Side Diff: third_party/WebKit/Source/modules/fetch/BodyStreamBuffer.h

Issue 1899873006: Make Response::body return v8-extra based stream behind flag (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@notify-locked-released
Patch Set: Created 4 years, 8 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 BodyStreamBuffer_h 5 #ifndef BodyStreamBuffer_h
6 #define BodyStreamBuffer_h 6 #define BodyStreamBuffer_h
7 7
8 #include "bindings/core/v8/ScriptPromise.h"
9 #include "bindings/core/v8/ScriptValue.h"
8 #include "core/dom/DOMException.h" 10 #include "core/dom/DOMException.h"
9 #include "core/streams/ReadableByteStream.h" 11 #include "core/streams/ReadableByteStream.h"
10 #include "core/streams/ReadableByteStreamReader.h" 12 #include "core/streams/ReadableByteStreamReader.h"
11 #include "core/streams/UnderlyingSource.h" 13 #include "core/streams/UnderlyingSource.h"
14 #include "core/streams/UnderlyingSourceBase.h"
12 #include "modules/ModulesExport.h" 15 #include "modules/ModulesExport.h"
13 #include "modules/fetch/FetchDataConsumerHandle.h" 16 #include "modules/fetch/FetchDataConsumerHandle.h"
14 #include "modules/fetch/FetchDataLoader.h" 17 #include "modules/fetch/FetchDataLoader.h"
15 #include "platform/heap/Handle.h" 18 #include "platform/heap/Handle.h"
16 #include "public/platform/WebDataConsumerHandle.h" 19 #include "public/platform/WebDataConsumerHandle.h"
17 #include "wtf/OwnPtr.h" 20 #include "wtf/OwnPtr.h"
18 #include "wtf/PassOwnPtr.h" 21 #include "wtf/PassOwnPtr.h"
19 22
20 namespace blink { 23 namespace blink {
21 24
22 class EncodedFormData; 25 class EncodedFormData;
23 class ExecutionContext; 26 class ScriptState;
24 27
25 class MODULES_EXPORT BodyStreamBuffer final : public GarbageCollectedFinalized<B odyStreamBuffer>, public UnderlyingSource, public WebDataConsumerHandle::Client { 28 class MODULES_EXPORT BodyStreamBuffer final : public UnderlyingSourceBase, publi c UnderlyingSource, public WebDataConsumerHandle::Client {
26 WTF_MAKE_NONCOPYABLE(BodyStreamBuffer); 29 WTF_MAKE_NONCOPYABLE(BodyStreamBuffer);
27 USING_GARBAGE_COLLECTED_MIXIN(BodyStreamBuffer); 30 USING_GARBAGE_COLLECTED_MIXIN(BodyStreamBuffer);
28 // Needed because we have to release |m_reader| promptly. 31 // Needed because we have to release |m_reader| promptly.
29 EAGERLY_FINALIZE(); 32 EAGERLY_FINALIZE();
30 public: 33 public:
31 // |handle| cannot be null and cannot be locked. 34 // |handle| cannot be null and cannot be locked.
32 explicit BodyStreamBuffer(PassOwnPtr<FetchDataConsumerHandle> /* handle */); 35 BodyStreamBuffer(ScriptState*, PassOwnPtr<FetchDataConsumerHandle> /* handle */);
33 36
34 ReadableByteStream* stream() { return m_stream; } 37 ScriptValue stream();
35 38
36 // Callable only when neither locked nor disturbed. 39 // Callable only when neither locked nor disturbed.
37 PassRefPtr<BlobDataHandle> drainAsBlobDataHandle(ExecutionContext*, FetchDat aConsumerHandle::Reader::BlobSizePolicy); 40 PassRefPtr<BlobDataHandle> drainAsBlobDataHandle(FetchDataConsumerHandle::Re ader::BlobSizePolicy);
38 PassRefPtr<EncodedFormData> drainAsFormData(ExecutionContext*); 41 PassRefPtr<EncodedFormData> drainAsFormData();
39 void startLoading(ExecutionContext*, FetchDataLoader*, FetchDataLoader::Clie nt* /* client */); 42 void startLoading(FetchDataLoader*, FetchDataLoader::Client* /* client */);
40 43
41 // Callable only when not locked. Returns a non-null handle. 44 // Callable only when not locked. Returns a non-null handle.
42 // There is no means to "return" the handle to the body buffer: Calling 45 // There is no means to "return" the handle to the body buffer: Calling
43 // this function locks, disturbs and closes the stream and no one will 46 // this function locks, disturbs and closes the stream and no one will
44 // not be able to get any information from the stream and this buffer after 47 // not be able to get any information from the stream and this buffer after
45 // that. 48 // that.
46 PassOwnPtr<FetchDataConsumerHandle> releaseHandle(ExecutionContext*); 49 PassOwnPtr<FetchDataConsumerHandle> releaseHandle();
47 50
48 bool hasPendingActivity() const; 51 bool hasPendingActivity() const;
49 void stop(); 52 void stop();
50 53
51 // UnderlyingSource 54 // UnderlyingSource
52 void pullSource() override; 55 void pullSource() override;
53 ScriptPromise cancelSource(ScriptState*, ScriptValue reason) override; 56 ScriptPromise cancelSource(ScriptState*, ScriptValue reason) override;
54 57
58 // UnderlyingSourceBase
59 ScriptPromise pull(ScriptState*) override;
60 ScriptPromise cancel(ScriptState*, ScriptValue reason) override;
61
55 // WebDataConsumerHandle::Client 62 // WebDataConsumerHandle::Client
56 void didGetReadable() override; 63 void didGetReadable() override;
57 64
58 bool isStreamReadable() const; 65 bool isStreamReadable();
59 bool isStreamClosed() const; 66 bool isStreamClosed();
60 bool isStreamErrored() const; 67 bool isStreamErrored();
61 bool isStreamLocked() const; 68 bool isStreamLocked();
62 bool isStreamDisturbed() const; 69 bool isStreamDisturbed();
70 void setDisturbed();
63 71
64 DEFINE_INLINE_TRACE() 72 DEFINE_INLINE_TRACE()
65 { 73 {
66 visitor->trace(m_stream); 74 visitor->trace(m_stream);
67 visitor->trace(m_loader); 75 visitor->trace(m_loader);
76 UnderlyingSourceBase::trace(visitor);
68 UnderlyingSource::trace(visitor); 77 UnderlyingSource::trace(visitor);
69 } 78 }
70 79
71 private: 80 private:
72 class LoaderClient; 81 class LoaderClient;
82
83 void lockAndDisturb();
73 void close(); 84 void close();
74 void error(); 85 void error();
75 void processData(); 86 void processData();
76 void endLoading(); 87 void endLoading();
77 void stopLoading(); 88 void stopLoading();
78 89
90 RefPtr<ScriptState> m_scriptState;
79 OwnPtr<FetchDataConsumerHandle> m_handle; 91 OwnPtr<FetchDataConsumerHandle> m_handle;
80 OwnPtr<FetchDataConsumerHandle::Reader> m_reader; 92 OwnPtr<FetchDataConsumerHandle::Reader> m_reader;
81 Member<ReadableByteStream> m_stream; 93 Member<ReadableByteStream> m_stream;
haraken 2016/04/21 04:36:28 Just curious but is m_stream going to be removed i
yhirano 2016/04/21 08:14:22 Yes. Actually we are planning to retire blink::Rea
82 // We need this member to keep it alive while loading. 94 // We need this member to keep it alive while loading.
83 Member<FetchDataLoader> m_loader; 95 Member<FetchDataLoader> m_loader;
84 bool m_streamNeedsMore; 96 bool m_streamNeedsMore = false;
85 }; 97 };
86 98
87 } // namespace blink 99 } // namespace blink
88 100
89 #endif // BodyStreamBuffer_h 101 #endif // BodyStreamBuffer_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698