#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "components/services/storage/service_worker/service_worker_resource_ops.h"
#include "base/containers/span.h"
#include "base/numerics/checked_math.h"
#include "base/pickle.h"
#include "base/task/sequenced_task_runner.h"
#include "components/services/storage/public/cpp/big_io_buffer.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/system/data_pipe.h"
#include "net/http/http_response_info.h"
#include "services/network/public/cpp/net_adapters.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "third_party/blink/public/common/blob/blob_utils.h"
namespace storage {
namespace {
enum { … };
network::mojom::URLResponseHeadPtr ConvertHttpResponseInfo(
const net::HttpResponseInfo& http_info,
int64_t response_data_size) { … }
std::unique_ptr<base::Pickle> ConvertToPickle(
network::mojom::URLResponseHeadPtr response_head) { … }
class WrappedPickleIOBuffer : public net::WrappedIOBuffer { … };
}
DiskEntryCreator::DiskEntryCreator(
int64_t resource_id,
base::WeakPtr<ServiceWorkerDiskCache> disk_cache)
: … { … }
DiskEntryCreator::~DiskEntryCreator() = default;
void DiskEntryCreator::EnsureEntryIsCreated(base::OnceClosure callback) { … }
void DiskEntryCreator::DidCreateEntryForFirstAttempt(
int rv,
std::unique_ptr<ServiceWorkerDiskCacheEntry> entry) { … }
void DiskEntryCreator::DidDoomExistingEntry(int rv) { … }
void DiskEntryCreator::DidCreateEntryForSecondAttempt(
int rv,
std::unique_ptr<ServiceWorkerDiskCacheEntry> entry) { … }
void DiskEntryCreator::RunEnsureEntryIsCreatedCallback() { … }
DiskEntryOpener::DiskEntryOpener(
int64_t resource_id,
base::WeakPtr<ServiceWorkerDiskCache> disk_cache)
: … { … }
DiskEntryOpener::~DiskEntryOpener() = default;
void DiskEntryOpener::EnsureEntryIsOpen(base::OnceClosure callback) { … }
void DiskEntryOpener::DidOpenEntry(
base::OnceClosure callback,
int rv,
std::unique_ptr<ServiceWorkerDiskCacheEntry> entry) { … }
class ServiceWorkerResourceReaderImpl::DataReader { … };
ServiceWorkerResourceReaderImpl::ServiceWorkerResourceReaderImpl(
int64_t resource_id,
base::WeakPtr<ServiceWorkerDiskCache> disk_cache,
mojo::PendingReceiver<mojom::ServiceWorkerResourceReader> receiver,
base::OnceClosure disconnect_handler)
: … { … }
ServiceWorkerResourceReaderImpl::~ServiceWorkerResourceReaderImpl() = default;
void ServiceWorkerResourceReaderImpl::ReadResponseHead(
ReadResponseHeadCallback callback) { … }
void ServiceWorkerResourceReaderImpl::PrepareReadData(
int64_t size,
PrepareReadDataCallback callback) { … }
void ServiceWorkerResourceReaderImpl::ReadData(ReadDataCallback callback) { … }
void ServiceWorkerResourceReaderImpl::ContinueReadResponseHead() { … }
void ServiceWorkerResourceReaderImpl::DidReadHttpResponseInfo(
scoped_refptr<net::IOBuffer> buffer,
int status) { … }
void ServiceWorkerResourceReaderImpl::DidReadMetadata(int status) { … }
void ServiceWorkerResourceReaderImpl::FailReadResponseHead(int status) { … }
void ServiceWorkerResourceReaderImpl::CompleteReadResponseHead(int status) { … }
void ServiceWorkerResourceReaderImpl::DidReadDataComplete() { … }
ServiceWorkerResourceWriterImpl::ServiceWorkerResourceWriterImpl(
int64_t resource_id,
base::WeakPtr<ServiceWorkerDiskCache> disk_cache,
mojo::PendingReceiver<mojom::ServiceWorkerResourceWriter> receiver,
base::OnceClosure disconnect_handler)
: … { … }
ServiceWorkerResourceWriterImpl::~ServiceWorkerResourceWriterImpl() = default;
void ServiceWorkerResourceWriterImpl::WriteResponseHead(
network::mojom::URLResponseHeadPtr response_head,
WriteResponseHeadCallback callback) { … }
void ServiceWorkerResourceWriterImpl::WriteData(mojo_base::BigBuffer data,
WriteDataCallback callback) { … }
void ServiceWorkerResourceWriterImpl::WriteResponseHeadToEntry(
network::mojom::URLResponseHeadPtr response_head,
WriteResponseHeadCallback callback) { … }
void ServiceWorkerResourceWriterImpl::DidWriteResponseHead(
scoped_refptr<net::IOBuffer> buffer,
size_t write_amount,
int rv) { … }
void ServiceWorkerResourceWriterImpl::WriteDataToEntry(
mojo_base::BigBuffer data,
WriteDataCallback callback) { … }
void ServiceWorkerResourceWriterImpl::DidWriteData(
scoped_refptr<net::IOBuffer> buffer,
size_t write_amount,
int rv) { … }
ServiceWorkerResourceMetadataWriterImpl::
ServiceWorkerResourceMetadataWriterImpl(
int64_t resource_id,
base::WeakPtr<ServiceWorkerDiskCache> disk_cache,
mojo::PendingReceiver<mojom::ServiceWorkerResourceMetadataWriter>
receiver,
base::OnceClosure disconnect_handler)
: … { … }
ServiceWorkerResourceMetadataWriterImpl::
~ServiceWorkerResourceMetadataWriterImpl() = default;
void ServiceWorkerResourceMetadataWriterImpl::WriteMetadata(
mojo_base::BigBuffer data,
WriteMetadataCallback callback) { … }
void ServiceWorkerResourceMetadataWriterImpl::ContinueWriteMetadata(
mojo_base::BigBuffer data,
WriteMetadataCallback callback) { … }
void ServiceWorkerResourceMetadataWriterImpl::DidWriteMetadata(
scoped_refptr<net::IOBuffer> buffer,
size_t write_amount,
int rv) { … }
}