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

Unified 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: (temp) alternative to calling didGetReadable in sync. 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 side-by-side diff with in-line comments
Download patch
Index: Source/modules/fetch/Body.h
diff --git a/Source/modules/fetch/Body.h b/Source/modules/fetch/Body.h
index 6a9435d7bf9c4ea313fb574ab3d1aac6590aa943..f3706d489349e1309878613e7d106bb25ab04f77 100644
--- a/Source/modules/fetch/Body.h
+++ b/Source/modules/fetch/Body.h
@@ -10,9 +10,9 @@
#include "bindings/core/v8/ScriptWrappable.h"
#include "core/dom/ActiveDOMObject.h"
#include "core/dom/DOMArrayBuffer.h"
-#include "core/fileapi/FileReaderLoader.h"
-#include "core/fileapi/FileReaderLoaderClient.h"
#include "modules/ModulesExport.h"
+#include "modules/fetch/FetchDataConsumerHandle.h"
+#include "modules/fetch/FetchDataLoader.h"
#include "platform/blob/BlobData.h"
#include "platform/heap/Handle.h"
#include "wtf/RefPtr.h"
@@ -20,6 +20,7 @@
namespace blink {
class BodyStreamBuffer;
+class DrainingBodyStreamBuffer;
class BodyStreamSource;
class DOMException;
class ReadableByteStream;
@@ -29,9 +30,9 @@ class MODULES_EXPORT Body
: public GarbageCollectedFinalized<Body>
, public ScriptWrappable
, public ActiveDOMObject
- , public FileReaderLoaderClient {
+ , public FetchDataLoader::Client {
DEFINE_WRAPPERTYPEINFO();
- WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(Body);
+ USING_GARBAGE_COLLECTED_MIXIN(Body);
public:
class ReadableStreamSource;
enum ResponseType {
@@ -60,62 +61,44 @@ public:
bool bodyUsed() const;
void lockBody(LockBodyOption = LockBodyOptionNone);
- // Returns true if the body stream is (possibly partially) consumed.
- bool isBodyConsumed() const;
- // Sets |m_stream| to a newly created stream from |source|.
- void setBody(ReadableStreamSource* /* source */);
-
- void setBody(PassRefPtr<BlobDataHandle> handle)
- {
- setBody(createBodySource(handle));
- }
- void setBody(BodyStreamBuffer* buffer)
- {
- setBody(createBodySource(buffer));
- }
-
- // Creates a new BodyStreamBuffer to drain the data from the ReadableStream.
- BodyStreamBuffer* createDrainingStream();
+ // Creates a DrainingBodyStreamBuffer to access body data.
+ // Returns nullptr if underlying BodyStreamBuffer is null.
+ PassOwnPtr<DrainingBodyStreamBuffer> createDrainingStream();
// ActiveDOMObject override.
virtual void stop() override;
virtual bool hasPendingActivity() const override;
- ReadableStreamSource* createBodySource(PassRefPtr<BlobDataHandle>);
- ReadableStreamSource* createBodySource(BodyStreamBuffer*);
-
DECLARE_VIRTUAL_TRACE();
- BodyStreamBuffer* bufferForTest() const { return buffer(); }
+protected:
+ // Sets |m_stream| to a newly created stream from |buffer|.
+ // |buffer| can be null.
+ // This is called when the underlying buffer is set/modified.
+ // TODO(hiroshige): Merge FetchRequest/ResponseData::buffer() and
+ // integrate Body::setBody(), Request/Response::refreshBody(),
+ // FetchRequestData::setBuffer() and
+ // FetchResponseData::replaceBodyStreamBuffer().
+ void setBody(BodyStreamBuffer* /* buffer */);
private:
- class BlobHandleReceiver;
-
void pullSource();
void readAllFromStream();
ScriptPromise readAsync(ScriptState*, ResponseType);
- void readAsyncFromBlob(PassRefPtr<BlobDataHandle>);
+ void resolveWithEmptyDataSynchronously();
+ void readAsyncFromDrainingBodyStreamBuffer(PassOwnPtr<DrainingBodyStreamBuffer>, const String& mimeType);
void resolveJSON(const String&);
- // FileReaderLoaderClient functions.
- virtual void didStartLoading() override;
- virtual void didReceiveData() override;
- virtual void didFinishLoading() override;
- virtual void didFail(FileError::ErrorCode) override;
+ void didFetchDataLoadFinishedFromDrainingStream();
- void didBlobHandleReceiveError(DOMException*);
+ // FetchDataLoader::Client functions.
+ void didFetchDataLoadFailed() override;
+ void didFetchDataLoadedBlobHandle(PassRefPtr<BlobDataHandle>) override;
+ void didFetchDataLoadedArrayBuffer(PassRefPtr<DOMArrayBuffer>) override;
+ void didFetchDataLoadedString(const String&) override;
- // We use BlobDataHandle or BodyStreamBuffer as data container of the Body.
- // BodyStreamBuffer is used only when the Response object is created by
- // fetch() API.
- // FIXME: We should seek a cleaner way to handle the data.
- virtual PassRefPtr<BlobDataHandle> blobDataHandle() const = 0;
- virtual BodyStreamBuffer* buffer() const = 0;
virtual String mimeType() const = 0;
- void didFinishLoadingViaStream(PassRefPtr<DOMArrayBuffer>);
-
- OwnPtr<FileReaderLoader> m_loader;
bool m_bodyUsed;
ResponseType m_responseType;
RefPtrWillBeMember<ScriptPromiseResolver> m_resolver;

Powered by Google App Engine
This is Rietveld 408576698