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

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

Issue 2277143002: Use BytesConsumer in BodyStreamBuffer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bytes-consumer-tee
Patch Set: rebase Created 4 years, 3 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" 8 #include "bindings/core/v8/ScriptPromise.h"
9 #include "bindings/core/v8/ScriptValue.h" 9 #include "bindings/core/v8/ScriptValue.h"
10 #include "core/dom/DOMException.h" 10 #include "core/dom/DOMException.h"
11 #include "core/streams/UnderlyingSourceBase.h" 11 #include "core/streams/UnderlyingSourceBase.h"
12 #include "modules/ModulesExport.h" 12 #include "modules/ModulesExport.h"
13 #include "modules/fetch/BytesConsumer.h"
13 #include "modules/fetch/FetchDataConsumerHandle.h" 14 #include "modules/fetch/FetchDataConsumerHandle.h"
14 #include "modules/fetch/FetchDataLoader.h" 15 #include "modules/fetch/FetchDataLoader.h"
15 #include "platform/heap/Handle.h" 16 #include "platform/heap/Handle.h"
16 #include "public/platform/WebDataConsumerHandle.h" 17 #include "public/platform/WebDataConsumerHandle.h"
17 #include <memory> 18 #include <memory>
18 19
19 namespace blink { 20 namespace blink {
20 21
21 class EncodedFormData; 22 class EncodedFormData;
22 class ScriptState; 23 class ScriptState;
23 24
24 class MODULES_EXPORT BodyStreamBuffer final : public UnderlyingSourceBase, publi c WebDataConsumerHandle::Client { 25 class MODULES_EXPORT BodyStreamBuffer final : public UnderlyingSourceBase, publi c BytesConsumer::Client {
25 WTF_MAKE_NONCOPYABLE(BodyStreamBuffer); 26 WTF_MAKE_NONCOPYABLE(BodyStreamBuffer);
26 USING_GARBAGE_COLLECTED_MIXIN(BodyStreamBuffer); 27 USING_GARBAGE_COLLECTED_MIXIN(BodyStreamBuffer);
27 public: 28 public:
28 // Needed because we have to release |m_reader| promptly.
29 EAGERLY_FINALIZE();
30 // |handle| cannot be null and cannot be locked. 29 // |handle| cannot be null and cannot be locked.
31 // This function must be called with entering an appropriate V8 context. 30 // This function must be called with entering an appropriate V8 context.
32 BodyStreamBuffer(ScriptState*, std::unique_ptr<FetchDataConsumerHandle> /* h andle */); 31 BodyStreamBuffer(ScriptState*, std::unique_ptr<FetchDataConsumerHandle> /* h andle */);
32 // |consumer| must not have a client.
33 // This function must be called with entering an appropriate V8 context.
34 BodyStreamBuffer(ScriptState*, BytesConsumer* /* consumer */);
33 // |ReadableStreamOperations::isReadableStream(stream)| must hold. 35 // |ReadableStreamOperations::isReadableStream(stream)| must hold.
34 // This function must be called with entering an appropriate V8 context. 36 // This function must be called with entering an appropriate V8 context.
35 BodyStreamBuffer(ScriptState*, ScriptValue stream); 37 BodyStreamBuffer(ScriptState*, ScriptValue stream);
36 38
37 ScriptValue stream(); 39 ScriptValue stream();
38 40
39 // Callable only when neither locked nor disturbed. 41 // Callable only when neither locked nor disturbed.
40 PassRefPtr<BlobDataHandle> drainAsBlobDataHandle(FetchDataConsumerHandle::Re ader::BlobSizePolicy); 42 PassRefPtr<BlobDataHandle> drainAsBlobDataHandle(BytesConsumer::BlobSizePoli cy);
41 PassRefPtr<EncodedFormData> drainAsFormData(); 43 PassRefPtr<EncodedFormData> drainAsFormData();
42 void startLoading(FetchDataLoader*, FetchDataLoader::Client* /* client */); 44 void startLoading(FetchDataLoader*, FetchDataLoader::Client* /* client */);
43 void tee(BodyStreamBuffer**, BodyStreamBuffer**); 45 void tee(BodyStreamBuffer**, BodyStreamBuffer**);
44 46
45 // UnderlyingSourceBase 47 // UnderlyingSourceBase
46 ScriptPromise pull(ScriptState*) override; 48 ScriptPromise pull(ScriptState*) override;
47 ScriptPromise cancel(ScriptState*, ScriptValue reason) override; 49 ScriptPromise cancel(ScriptState*, ScriptValue reason) override;
48 bool hasPendingActivity() const override; 50 bool hasPendingActivity() const override;
49 void stop() override; 51 void stop() override;
50 52
51 // WebDataConsumerHandle::Client 53 // BytesConsumer::Client
52 void didGetReadable() override; 54 void onStateChange() override;
53 55
54 bool isStreamReadable(); 56 bool isStreamReadable();
55 bool isStreamClosed(); 57 bool isStreamClosed();
56 bool isStreamErrored(); 58 bool isStreamErrored();
57 bool isStreamLocked(); 59 bool isStreamLocked();
58 bool isStreamDisturbed(); 60 bool isStreamDisturbed();
59 void closeAndLockAndDisturb(); 61 void closeAndLockAndDisturb();
60 ScriptState* scriptState() { return m_scriptState.get(); } 62 ScriptState* scriptState() { return m_scriptState.get(); }
61 63
62 DEFINE_INLINE_TRACE() 64 DEFINE_INLINE_TRACE()
63 { 65 {
66 visitor->trace(m_consumer);
64 visitor->trace(m_loader); 67 visitor->trace(m_loader);
65 UnderlyingSourceBase::trace(visitor); 68 UnderlyingSourceBase::trace(visitor);
66 } 69 }
67 70
68 private: 71 private:
69 class LoaderClient; 72 class LoaderClient;
70 73
74 BytesConsumer* releaseHandle();
71 void close(); 75 void close();
72 void error(); 76 void error();
77 void cancelConsumer();
73 void processData(); 78 void processData();
74 void endLoading(); 79 void endLoading();
75 void stopLoading(); 80 void stopLoading();
76 std::unique_ptr<FetchDataConsumerHandle> releaseHandle();
77 81
78 RefPtr<ScriptState> m_scriptState; 82 RefPtr<ScriptState> m_scriptState;
79 std::unique_ptr<FetchDataConsumerHandle> m_handle; 83 Member<BytesConsumer> m_consumer;
80 std::unique_ptr<FetchDataConsumerHandle::Reader> m_reader;
81 // We need this member to keep it alive while loading. 84 // We need this member to keep it alive while loading.
82 Member<FetchDataLoader> m_loader; 85 Member<FetchDataLoader> m_loader;
83 bool m_streamNeedsMore = false; 86 bool m_streamNeedsMore = false;
84 bool m_madeFromReadableStream; 87 bool m_madeFromReadableStream;
85 }; 88 };
86 89
87 } // namespace blink 90 } // namespace blink
88 91
89 #endif // BodyStreamBuffer_h 92 #endif // BodyStreamBuffer_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/fetch/BUILD.gn ('k') | third_party/WebKit/Source/modules/fetch/BodyStreamBuffer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698