#include "storage/browser/blob/blob_storage_context.h"
#include <inttypes.h>
#include <algorithm>
#include <limits>
#include <memory>
#include <set>
#include <utility>
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/numerics/safe_conversions.h"
#include "base/numerics/safe_math.h"
#include "base/strings/stringprintf.h"
#include "base/task/single_thread_task_runner.h"
#include "base/task/task_runner.h"
#include "base/task/thread_pool.h"
#include "base/time/time.h"
#include "base/trace_event/memory_dump_manager.h"
#include "base/trace_event/trace_event.h"
#include "mojo/public/cpp/bindings/callback_helpers.h"
#include "storage/browser/blob/blob_data_builder.h"
#include "storage/browser/blob/blob_data_item.h"
#include "storage/browser/blob/blob_data_snapshot.h"
#include "storage/browser/blob/blob_impl.h"
#include "storage/browser/blob/shareable_blob_data_item.h"
#include "storage/browser/blob/write_blob_to_file.h"
#include "third_party/blink/public/common/blob/blob_utils.h"
#include "third_party/blink/public/mojom/blob/data_element.mojom.h"
#include "url/gurl.h"
namespace storage {
namespace {
ItemCopyEntry;
QuotaAllocationTask;
}
BlobStorageContext::BlobStorageContext()
: … { … }
BlobStorageContext::BlobStorageContext(
const base::FilePath& profile_directory,
const base::FilePath& storage_directory,
scoped_refptr<base::TaskRunner> file_runner)
: … { … }
BlobStorageContext::~BlobStorageContext() { … }
std::unique_ptr<BlobDataHandle> BlobStorageContext::GetBlobDataFromUUID(
const std::string& uuid) { … }
void BlobStorageContext::GetBlobDataFromBlobRemote(
mojo::PendingRemote<blink::mojom::Blob> blob,
base::OnceCallback<void(std::unique_ptr<BlobDataHandle>)> callback) { … }
std::unique_ptr<BlobDataHandle> BlobStorageContext::AddFinishedBlob(
std::unique_ptr<BlobDataBuilder> external_builder) { … }
std::unique_ptr<BlobDataHandle> BlobStorageContext::AddFinishedBlob(
const std::string& uuid,
const std::string& content_type,
const std::string& content_disposition,
std::vector<scoped_refptr<ShareableBlobDataItem>> items) { … }
std::unique_ptr<BlobDataHandle> BlobStorageContext::AddBrokenBlob(
const std::string& uuid,
const std::string& content_type,
const std::string& content_disposition,
BlobStatus reason) { … }
std::unique_ptr<BlobDataHandle> BlobStorageContext::AddFutureBlob(
const std::string& uuid,
const std::string& content_type,
const std::string& content_disposition,
BuildAbortedCallback build_aborted_callback) { … }
std::unique_ptr<BlobDataHandle> BlobStorageContext::BuildPreregisteredBlob(
std::unique_ptr<BlobDataBuilder> content,
TransportAllowedCallback transport_allowed_callback) { … }
std::unique_ptr<BlobDataHandle> BlobStorageContext::BuildBlob(
std::unique_ptr<BlobDataBuilder> content,
TransportAllowedCallback transport_allowed_callback) { … }
std::unique_ptr<BlobDataHandle> BlobStorageContext::BuildBlobInternal(
BlobEntry* entry,
std::unique_ptr<BlobDataBuilder> content,
TransportAllowedCallback transport_allowed_callback) { … }
void BlobStorageContext::CancelBuildingBlob(const std::string& uuid,
BlobStatus reason) { … }
void BlobStorageContext::NotifyTransportComplete(const std::string& uuid) { … }
void BlobStorageContext::Bind(
mojo::PendingReceiver<mojom::BlobStorageContext> receiver) { … }
void BlobStorageContext::IncrementBlobRefCount(const std::string& uuid) { … }
void BlobStorageContext::DecrementBlobRefCount(const std::string& uuid) { … }
std::unique_ptr<BlobDataSnapshot> BlobStorageContext::CreateSnapshot(
const std::string& uuid) { … }
BlobStatus BlobStorageContext::GetBlobStatus(const std::string& uuid) const { … }
void BlobStorageContext::RunOnConstructionComplete(const std::string& uuid,
BlobStatusCallback done) { … }
void BlobStorageContext::RunOnConstructionBegin(const std::string& uuid,
BlobStatusCallback done) { … }
std::unique_ptr<BlobDataHandle> BlobStorageContext::CreateHandle(
const std::string& uuid,
BlobEntry* entry) { … }
void BlobStorageContext::NotifyTransportCompleteInternal(BlobEntry* entry) { … }
void BlobStorageContext::CancelBuildingBlobInternal(BlobEntry* entry,
BlobStatus reason) { … }
void BlobStorageContext::FinishBuilding(BlobEntry* entry) { … }
void BlobStorageContext::RequestTransport(
BlobEntry* entry,
std::vector<BlobMemoryController::FileCreationInfo> files) { … }
void BlobStorageContext::OnEnoughSpaceForTransport(
const std::string& uuid,
std::vector<BlobMemoryController::FileCreationInfo> files,
bool success) { … }
void BlobStorageContext::OnEnoughSpaceForCopies(const std::string& uuid,
bool success) { … }
void BlobStorageContext::OnDependentBlobFinished(
const std::string& owning_blob_uuid,
BlobStatus status) { … }
void BlobStorageContext::ClearAndFreeMemory(BlobEntry* entry) { … }
bool BlobStorageContext::OnMemoryDump(
const base::trace_event::MemoryDumpArgs& args,
base::trace_event::ProcessMemoryDump* pmd) { … }
void BlobStorageContext::RegisterFromDataItem(
mojo::PendingReceiver<::blink::mojom::Blob> blob,
const std::string& uuid,
mojom::BlobDataItemPtr item) { … }
void BlobStorageContext::RegisterFromMemory(
mojo::PendingReceiver<::blink::mojom::Blob> blob,
const std::string& uuid,
mojo_base::BigBuffer data) { … }
void BlobStorageContext::WriteBlobToFile(
mojo::PendingRemote<::blink::mojom::Blob> pending_blob,
const base::FilePath& file_path,
bool flush_on_write,
std::optional<base::Time> last_modified,
BlobStorageContext::WriteBlobToFileCallback callback) { … }
void BlobStorageContext::Clone(
mojo::PendingReceiver<mojom::BlobStorageContext> receiver) { … }
}