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

Side by Side Diff: Source/modules/fetch/Body.h

Issue 1192913007: Change BodyStreamBuffer to be FetchDataConsumerHandle-based and enable backpressure in Fetch API (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase. Created 5 years, 6 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 Body_h 5 #ifndef Body_h
6 #define Body_h 6 #define Body_h
7 7
8 #include "bindings/core/v8/ScriptPromise.h" 8 #include "bindings/core/v8/ScriptPromise.h"
9 #include "bindings/core/v8/ScriptPromiseResolver.h" 9 #include "bindings/core/v8/ScriptPromiseResolver.h"
10 #include "bindings/core/v8/ScriptWrappable.h" 10 #include "bindings/core/v8/ScriptWrappable.h"
11 #include "core/dom/ActiveDOMObject.h" 11 #include "core/dom/ActiveDOMObject.h"
12 #include "core/dom/DOMArrayBuffer.h" 12 #include "core/dom/DOMArrayBuffer.h"
13 #include "core/fileapi/FileReaderLoader.h"
14 #include "core/fileapi/FileReaderLoaderClient.h"
15 #include "modules/ModulesExport.h" 13 #include "modules/ModulesExport.h"
14 #include "modules/fetch/FetchDataConsumerHandle.h"
15 #include "modules/fetch/FetchDataLoader.h"
16 #include "platform/blob/BlobData.h" 16 #include "platform/blob/BlobData.h"
17 #include "platform/heap/Handle.h" 17 #include "platform/heap/Handle.h"
18 #include "wtf/RefPtr.h" 18 #include "wtf/RefPtr.h"
19 19
20 namespace blink { 20 namespace blink {
21 21
22 class BodyStreamBuffer; 22 class BodyStreamBuffer2;
23 class BodyStreamSource; 23 class BodyStreamSource;
24 class DOMException; 24 class DOMException;
25 class ReadableByteStream; 25 class ReadableByteStream;
26 class ScriptState; 26 class ScriptState;
27 27
28 class MODULES_EXPORT Body 28 class MODULES_EXPORT Body
29 : public GarbageCollectedFinalized<Body> 29 : public GarbageCollectedFinalized<Body>
30 , public ScriptWrappable 30 , public ScriptWrappable
31 , public ActiveDOMObject 31 , public ActiveDOMObject
32 , public FileReaderLoaderClient { 32 , public FetchDataLoader::Client {
33 DEFINE_WRAPPERTYPEINFO(); 33 DEFINE_WRAPPERTYPEINFO();
34 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(Body); 34 USING_GARBAGE_COLLECTED_MIXIN(Body);
35 public: 35 public:
36 class ReadableStreamSource; 36 class ReadableStreamSource;
37 enum ResponseType { 37 enum ResponseType {
38 ResponseUnknown, 38 ResponseUnknown,
39 ResponseAsArrayBuffer, 39 ResponseAsArrayBuffer,
40 ResponseAsBlob, 40 ResponseAsBlob,
41 ResponseAsFormData, 41 ResponseAsFormData,
42 ResponseAsJSON, 42 ResponseAsJSON,
43 ResponseAsText 43 ResponseAsText
44 }; 44 };
(...skipping 13 matching lines...) Expand all
58 ReadableByteStream* body(); 58 ReadableByteStream* body();
59 59
60 bool bodyUsed() const; 60 bool bodyUsed() const;
61 void lockBody(LockBodyOption = LockBodyOptionNone); 61 void lockBody(LockBodyOption = LockBodyOptionNone);
62 62
63 // Returns true if the body stream is (possibly partially) consumed. 63 // Returns true if the body stream is (possibly partially) consumed.
64 bool isBodyConsumed() const; 64 bool isBodyConsumed() const;
65 // Sets |m_stream| to a newly created stream from |source|. 65 // Sets |m_stream| to a newly created stream from |source|.
66 void setBody(ReadableStreamSource* /* source */); 66 void setBody(ReadableStreamSource* /* source */);
67 67
68 void setBody(PassRefPtr<BlobDataHandle> handle) 68 // |buffer| can be null.
69 { 69 void setBody(BodyStreamBuffer2* buffer)
70 setBody(createBodySource(handle));
71 }
72 void setBody(BodyStreamBuffer* buffer)
73 { 70 {
74 setBody(createBodySource(buffer)); 71 setBody(createBodySource(buffer));
75 } 72 }
76 73
77 // Creates a new BodyStreamBuffer to drain the data from the ReadableStream. 74 // Creates a new BodyStreamBuffer to drain the data from the ReadableStream.
78 BodyStreamBuffer* createDrainingStream(); 75 BodyStreamBuffer2* createDrainingStream();
79 76
80 // ActiveDOMObject override. 77 // ActiveDOMObject override.
81 virtual void stop() override; 78 virtual void stop() override;
82 virtual bool hasPendingActivity() const override; 79 virtual bool hasPendingActivity() const override;
83 80
84 ReadableStreamSource* createBodySource(PassRefPtr<BlobDataHandle>); 81 ReadableStreamSource* createBodySource(BodyStreamBuffer2*);
85 ReadableStreamSource* createBodySource(BodyStreamBuffer*);
86 82
87 DECLARE_VIRTUAL_TRACE(); 83 DECLARE_VIRTUAL_TRACE();
88 84
89 BodyStreamBuffer* bufferForTest() const { return buffer(); } 85 BodyStreamBuffer2* bufferForTest() const { return buffer(); }
90 86
91 private: 87 private:
92 class BlobHandleReceiver; 88 class BlobHandleReceiver;
93 89
94 void pullSource(); 90 void pullSource();
95 void readAllFromStream(); 91 void readAllFromStream();
96 ScriptPromise readAsync(ScriptState*, ResponseType); 92 ScriptPromise readAsync(ScriptState*, ResponseType);
97 void readAsyncFromBlob(PassRefPtr<BlobDataHandle>); 93 void readAsyncFromBlob(PassRefPtr<BlobDataHandle>);
94 void readAsyncFromFetchDataConsumerHandle(BodyStreamBuffer2*, const String& mimeType);
98 void resolveJSON(const String&); 95 void resolveJSON(const String&);
99 96
100 // FileReaderLoaderClient functions. 97 // FetchDataLoader::Client functions.
101 virtual void didStartLoading() override; 98 void didFetchDataLoadFailed() override;
102 virtual void didReceiveData() override; 99 void didFetchDataLoadedBlobHandle(PassRefPtr<BlobDataHandle>) override;
103 virtual void didFinishLoading() override; 100 void didFetchDataLoadedArrayBuffer(PassRefPtr<DOMArrayBuffer>) override;
104 virtual void didFail(FileError::ErrorCode) override; 101 void didFetchDataLoadedString(const String&) override;
105 102
106 void didBlobHandleReceiveError(DOMException*); 103 // We use BodyStreamBuffer2 as data container of the Body.
107 104 virtual BodyStreamBuffer2* buffer() const = 0;
108 // We use BlobDataHandle or BodyStreamBuffer as data container of the Body.
109 // BodyStreamBuffer is used only when the Response object is created by
110 // fetch() API.
111 // FIXME: We should seek a cleaner way to handle the data.
112 virtual PassRefPtr<BlobDataHandle> blobDataHandle() const = 0;
113 virtual BodyStreamBuffer* buffer() const = 0;
114 virtual String mimeType() const = 0; 105 virtual String mimeType() const = 0;
115 106
116 void didFinishLoadingViaStream(PassRefPtr<DOMArrayBuffer>); 107 void didFinishLoadingViaStream(PassRefPtr<DOMArrayBuffer>);
117 108
118 OwnPtr<FileReaderLoader> m_loader; 109 Member<FetchDataLoader> m_fetchDataLoader;
119 bool m_bodyUsed; 110 bool m_bodyUsed;
120 ResponseType m_responseType; 111 ResponseType m_responseType;
121 RefPtrWillBeMember<ScriptPromiseResolver> m_resolver; 112 RefPtrWillBeMember<ScriptPromiseResolver> m_resolver;
122 Member<ReadableStreamSource> m_streamSource; 113 Member<ReadableStreamSource> m_streamSource;
123 Member<ReadableByteStream> m_stream; 114 Member<ReadableByteStream> m_stream;
124 }; 115 };
125 116
126 } // namespace blink 117 } // namespace blink
127 118
128 #endif // Body_h 119 #endif // Body_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698