blob: 3ea115ffc5cc4ec367080673c758eac01c67033f [file] [log] [blame]
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_FETCH_BLOB_BYTES_CONSUMER_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_FETCH_BLOB_BYTES_CONSUMER_H_
#include <memory>
#include "base/memory/scoped_refptr.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/platform/bindings/trace_wrapper_member.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/loader/fetch/bytes_consumer.h"
namespace blink {
class BlobDataHandle;
class ExecutionContext;
// A BlobBytesConsumer is created from a blob handle and it will
// return a valid handle from drainAsBlobDataHandle as much as possible.
class CORE_EXPORT BlobBytesConsumer final : public BytesConsumer {
public:
// |handle| can be null. In that case this consumer gets closed.
BlobBytesConsumer(ExecutionContext*,
scoped_refptr<BlobDataHandle> /* handle */);
~BlobBytesConsumer() override;
// BytesConsumer implementation
Result BeginRead(const char** buffer, size_t* available) override;
Result EndRead(size_t read_size) override;
scoped_refptr<BlobDataHandle> DrainAsBlobDataHandle(BlobSizePolicy) override;
scoped_refptr<EncodedFormData> DrainAsFormData() override;
void SetClient(BytesConsumer::Client*) override;
void ClearClient() override;
void Cancel() override;
PublicState GetPublicState() const override;
Error GetError() const override;
String DebugName() const override { return "BlobBytesConsumer"; }
void Trace(blink::Visitor*) override;
private:
Member<ExecutionContext> execution_context_;
scoped_refptr<BlobDataHandle> blob_data_handle_;
TraceWrapperMember<BytesConsumer> nested_consumer_;
Member<BytesConsumer::Client> client_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_FETCH_BLOB_BYTES_CONSUMER_H_