#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "content/browser/service_worker/service_worker_cache_writer.h"
#include <algorithm>
#include <string>
#include "base/containers/span.h"
#include "base/functional/bind.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/numerics/safe_conversions.h"
#include "base/task/sequenced_task_runner.h"
#include "crypto/secure_hash.h"
#include "crypto/sha2.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/system/simple_watcher.h"
#include "net/base/completion_once_callback.h"
#include "services/network/public/cpp/net_adapters.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h"
namespace {
const size_t kCopyBufferSize = …;
class AsyncOnlyCompletionCallbackAdaptor
: public base::RefCounted<AsyncOnlyCompletionCallbackAdaptor> { … };
}
namespace content {
class ServiceWorkerCacheWriter::ReadResponseHeadCallbackAdapter
: public base::RefCounted<
ServiceWorkerCacheWriter::ReadResponseHeadCallbackAdapter> { … };
int ServiceWorkerCacheWriter::DoLoop(int status) { … }
ServiceWorkerCacheWriter::ServiceWorkerCacheWriter(
mojo::Remote<storage::mojom::ServiceWorkerResourceReader> compare_reader,
mojo::Remote<storage::mojom::ServiceWorkerResourceReader> copy_reader,
mojo::Remote<storage::mojom::ServiceWorkerResourceWriter> writer,
int64_t writer_resource_id,
bool pause_when_not_identical,
ChecksumUpdateTiming checksum_update_timing)
: … { … }
ServiceWorkerCacheWriter::~ServiceWorkerCacheWriter() { … }
std::unique_ptr<ServiceWorkerCacheWriter>
ServiceWorkerCacheWriter::CreateForCopy(
mojo::Remote<storage::mojom::ServiceWorkerResourceReader> copy_reader,
mojo::Remote<storage::mojom::ServiceWorkerResourceWriter> writer,
int64_t writer_resource_id) { … }
std::unique_ptr<ServiceWorkerCacheWriter>
ServiceWorkerCacheWriter::CreateForWriteBack(
mojo::Remote<storage::mojom::ServiceWorkerResourceWriter> writer,
int64_t writer_resource_id) { … }
std::unique_ptr<ServiceWorkerCacheWriter>
ServiceWorkerCacheWriter::CreateForComparison(
mojo::Remote<storage::mojom::ServiceWorkerResourceReader> compare_reader,
mojo::Remote<storage::mojom::ServiceWorkerResourceReader> copy_reader,
mojo::Remote<storage::mojom::ServiceWorkerResourceWriter> writer,
int64_t writer_resource_id,
bool pause_when_not_identical,
ChecksumUpdateTiming checksum_update_timing) { … }
net::Error ServiceWorkerCacheWriter::MaybeWriteHeaders(
network::mojom::URLResponseHeadPtr response_head,
OnWriteCompleteCallback callback) { … }
net::Error ServiceWorkerCacheWriter::MaybeWriteData(
net::IOBuffer* buf,
size_t buf_size,
OnWriteCompleteCallback callback) { … }
net::Error ServiceWorkerCacheWriter::Resume(OnWriteCompleteCallback callback) { … }
net::Error ServiceWorkerCacheWriter::StartCopy(
OnWriteCompleteCallback callback) { … }
bool ServiceWorkerCacheWriter::IsCopying() const { … }
void ServiceWorkerCacheWriter::FlushRemotesForTesting() { … }
int64_t ServiceWorkerCacheWriter::writer_resource_id() const { … }
int ServiceWorkerCacheWriter::DoStart(int result) { … }
int ServiceWorkerCacheWriter::DoReadHeadersForCompare(int result) { … }
int ServiceWorkerCacheWriter::DoReadHeadersForCompareDone(int result) { … }
int ServiceWorkerCacheWriter::DoReadDataForCompare(int result) { … }
int ServiceWorkerCacheWriter::DoReadDataForCompareDone(int result) { … }
int ServiceWorkerCacheWriter::DoReadHeadersForCopy(int result) { … }
int ServiceWorkerCacheWriter::DoReadHeadersForCopyDone(int result) { … }
int ServiceWorkerCacheWriter::DoWriteHeadersForCopy(int result) { … }
int ServiceWorkerCacheWriter::DoWriteHeadersForCopyDone(int result) { … }
int ServiceWorkerCacheWriter::DoReadDataForCopy(int result) { … }
int ServiceWorkerCacheWriter::DoReadDataForCopyDone(int result) { … }
int ServiceWorkerCacheWriter::DoWriteDataForCopy(int result) { … }
int ServiceWorkerCacheWriter::DoWriteDataForCopyDone(int result) { … }
int ServiceWorkerCacheWriter::DoWriteHeadersForPassthrough(int result) { … }
int ServiceWorkerCacheWriter::DoWriteHeadersForPassthroughDone(int result) { … }
int ServiceWorkerCacheWriter::DoWriteDataForPassthrough(int result) { … }
int ServiceWorkerCacheWriter::DoWriteDataForPassthroughDone(int result) { … }
int ServiceWorkerCacheWriter::DoDone(int result) { … }
int ServiceWorkerCacheWriter::ReadResponseHead(
storage::mojom::ServiceWorkerResourceReader* reader) { … }
class ServiceWorkerCacheWriter::DataPipeReader { … };
int ServiceWorkerCacheWriter::ReadDataHelper(
storage::mojom::ServiceWorkerResourceReader* reader,
std::unique_ptr<DataPipeReader>& data_pipe_reader,
scoped_refptr<net::IOBuffer> buf,
int buf_len) { … }
int ServiceWorkerCacheWriter::WriteResponseHeadToResponseWriter(
network::mojom::URLResponseHeadPtr response_head) { … }
int ServiceWorkerCacheWriter::WriteResponseHead(
network::mojom::URLResponseHeadPtr response_head) { … }
int ServiceWorkerCacheWriter::WriteDataToResponseWriter(
scoped_refptr<net::IOBuffer> data,
size_t length) { … }
int ServiceWorkerCacheWriter::WriteData(scoped_refptr<net::IOBuffer> data,
size_t length) { … }
void ServiceWorkerCacheWriter::OnWillWriteDataCompleted(
scoped_refptr<net::IOBuffer> data,
size_t length,
net::Error error) { … }
void ServiceWorkerCacheWriter::OnRemoteDisconnected() { … }
void ServiceWorkerCacheWriter::AsyncDoLoop(int result) { … }
std::string ServiceWorkerCacheWriter::GetSha256Checksum() { … }
}