#include "storage/browser/blob/blob_builder_from_stream.h"
#include "base/containers/span.h"
#include "base/functional/bind.h"
#include "base/metrics/histogram_macros.h"
#include "base/numerics/safe_conversions.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/thread_pool.h"
#include "base/time/time.h"
#include "base/uuid.h"
#include "mojo/public/c/system/types.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "storage/browser/blob/blob_data_item.h"
#include "storage/browser/blob/blob_storage_context.h"
#include "storage/browser/blob/shareable_file_reference.h"
namespace storage {
namespace {
constexpr size_t kMaxMemoryChunkSize = …;
void OnPipeReady(
mojo::ScopedDataPipeConsumerHandle pipe,
base::OnceCallback<void(mojo::ScopedDataPipeConsumerHandle)> callback,
std::unique_ptr<mojo::SimpleWatcher> watcher,
MojoResult result,
const mojo::HandleSignalsState& state) { … }
void RunCallbackWhenDataPipeReady(
mojo::ScopedDataPipeConsumerHandle pipe,
base::OnceCallback<void(mojo::ScopedDataPipeConsumerHandle)> callback) { … }
class DataPipeConsumerHelper { … };
}
class BlobBuilderFromStream::WritePipeToFileHelper
: public DataPipeConsumerHelper { … };
class BlobBuilderFromStream::WritePipeToFutureDataHelper
: public DataPipeConsumerHelper { … };
BlobBuilderFromStream::BlobBuilderFromStream(
base::WeakPtr<BlobStorageContext> context,
std::string content_type,
std::string content_disposition,
ResultCallback callback)
: … { … }
BlobBuilderFromStream::~BlobBuilderFromStream() { … }
void BlobBuilderFromStream::Start(
uint64_t length_hint,
mojo::ScopedDataPipeConsumerHandle data,
mojo::PendingAssociatedRemote<blink::mojom::ProgressClient>
progress_client) { … }
void BlobBuilderFromStream::Abort() { … }
void BlobBuilderFromStream::AllocateMoreMemorySpace(
uint64_t length_hint,
mojo::PendingAssociatedRemote<blink::mojom::ProgressClient> progress_client,
mojo::ScopedDataPipeConsumerHandle pipe) { … }
void BlobBuilderFromStream::MemoryQuotaAllocated(
mojo::ScopedDataPipeConsumerHandle pipe,
mojo::PendingAssociatedRemote<blink::mojom::ProgressClient> progress_client,
std::vector<scoped_refptr<ShareableBlobDataItem>> chunk_items,
size_t item_to_populate,
bool success) { … }
void BlobBuilderFromStream::DidWriteToMemory(
std::vector<scoped_refptr<ShareableBlobDataItem>> chunk_items,
size_t populated_item_index,
uint64_t bytes_written,
mojo::ScopedDataPipeConsumerHandle pipe,
mojo::PendingAssociatedRemote<blink::mojom::ProgressClient>
progress_client) { … }
void BlobBuilderFromStream::AllocateMoreFileSpace(
uint64_t length_hint,
mojo::PendingAssociatedRemote<blink::mojom::ProgressClient> progress_client,
mojo::ScopedDataPipeConsumerHandle pipe) { … }
void BlobBuilderFromStream::FileQuotaAllocated(
mojo::ScopedDataPipeConsumerHandle pipe,
mojo::PendingAssociatedRemote<blink::mojom::ProgressClient> progress_client,
std::vector<scoped_refptr<ShareableBlobDataItem>> chunk_items,
size_t item_to_populate,
std::vector<BlobMemoryController::FileCreationInfo> info,
bool success) { … }
void BlobBuilderFromStream::DidWriteToFile(
std::vector<scoped_refptr<ShareableBlobDataItem>> chunk_items,
std::vector<BlobMemoryController::FileCreationInfo> info,
size_t populated_item_index,
bool success,
uint64_t bytes_written,
mojo::ScopedDataPipeConsumerHandle pipe,
mojo::PendingAssociatedRemote<blink::mojom::ProgressClient> progress_client,
const base::Time& modification_time) { … }
void BlobBuilderFromStream::DidWriteToExtendedFile(
scoped_refptr<ShareableFileReference> file_reference,
uint64_t old_file_size,
bool success,
uint64_t bytes_written,
mojo::ScopedDataPipeConsumerHandle pipe,
mojo::PendingAssociatedRemote<blink::mojom::ProgressClient> progress_client,
const base::Time& modification_time) { … }
void BlobBuilderFromStream::OnError(Result result) { … }
void BlobBuilderFromStream::OnSuccess() { … }
bool BlobBuilderFromStream::ShouldStoreNextBlockOnDisk(uint64_t length_hint) { … }
}