chromium/content/browser/indexed_db/indexed_db_context_impl.cc

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/browser/indexed_db/indexed_db_context_impl.h"

#include <algorithm>
#include <compare>
#include <functional>
#include <iterator>
#include <memory>
#include <ostream>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>

#include "base/barrier_callback.h"
#include "base/check.h"
#include "base/check_op.h"
#include "base/containers/contains.h"
#include "base/feature_list.h"
#include "base/files/file.h"
#include "base/files/file_enumerator.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/location.h"
#include "base/metrics/histogram_functions.h"
#include "base/not_fatal_until.h"
#include "base/numerics/clamped_math.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/bind_post_task.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/task_features.h"
#include "base/task/task_runner.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "base/time/time.h"
#include "base/trace_event/base_tracing.h"
#include "base/trace_event/common/trace_event_common.h"
#include "base/types/expected.h"
#include "base/types/strong_alias.h"
#include "build/build_config.h"
#include "components/services/storage/privileged/mojom/indexed_db_control.mojom-shared.h"
#include "components/services/storage/privileged/mojom/indexed_db_internals_types.mojom.h"
#include "components/services/storage/public/cpp/buckets/bucket_info.h"
#include "components/services/storage/public/cpp/buckets/bucket_init_params.h"
#include "components/services/storage/public/cpp/buckets/bucket_locator.h"
#include "components/services/storage/public/cpp/constants.h"
#include "components/services/storage/public/cpp/quota_error_or.h"
#include "components/services/storage/public/mojom/quota_client.mojom.h"
#include "components/services/storage/public/mojom/storage_policy_update.mojom.h"
#include "content/browser/indexed_db/file_path_util.h"
#include "content/browser/indexed_db/indexed_db_bucket_context.h"
#include "content/browser/indexed_db/indexed_db_database_error.h"
#include "content/browser/indexed_db/indexed_db_factory_client.h"
#include "content/browser/indexed_db/indexed_db_leveldb_coding.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
#include "mojo/public/cpp/bindings/pending_associated_remote.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "mojo/public/cpp/bindings/struct_ptr.h"
#include "net/base/schemeful_site.h"
#include "storage/browser/quota/quota_client_type.h"
#include "storage/browser/quota/quota_manager_proxy.h"
#include "storage/common/database/database_identifier.h"
#include "third_party/blink/public/common/storage_key/storage_key.h"
#include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom-shared.h"
#include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom.h"
#include "third_party/zlib/google/zip.h"
#include "url/origin.h"

namespace content {

StorageKey;
BucketLocator;

namespace {

// Creates a task runner suitable for use either as the main IDB thread or for a
// backing store. See https://crbug.com/329221141 for notes on task priority.
scoped_refptr<base::SequencedTaskRunner> CreateTaskRunner() {}

bool IsAllowedPath(const std::vector<base::FilePath>& allowed_paths,
                   const base::FilePath& candidate_path) {}

// Used to field IDBFactory requests when the quota system failed to
// find/return a bucket.
class MissingBucketErrorEndpoint : public blink::mojom::IDBFactory {};

// Getting all the bucket details requires multiple asynchronous steps.
// `IndexedDBContextImpl::ContinueGetAllBucketsDetails` is invoked after
// asynchronously retrieving buckets from the quota manager, whereas
// `FinishGetAllBucketsDetails` is invoked after retrieving details from
// individual bucket contexts.
void FinishGetAllBucketsDetails(
    base::OnceCallback<void(std::vector<storage::mojom::IdbOriginMetadataPtr>)>
        callback,
    std::vector<storage::mojom::IdbBucketMetadataPtr> infos) {}

}  // namespace

IndexedDBContextImpl::IndexedDBContextImpl(
    const base::FilePath& base_data_path,
    scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy,
    mojo::PendingRemote<storage::mojom::BlobStorageContext>
        blob_storage_context,
    mojo::PendingRemote<storage::mojom::FileSystemAccessContext>
        file_system_access_context,
    scoped_refptr<base::SequencedTaskRunner> io_task_runner,
    scoped_refptr<base::SequencedTaskRunner> custom_task_runner)
    :{}

void IndexedDBContextImpl::BindPipesOnIDBSequence(
    mojo::PendingReceiver<storage::mojom::QuotaClient>
        pending_quota_client_receiver,
    mojo::PendingRemote<storage::mojom::BlobStorageContext>
        pending_blob_storage_context,
    mojo::PendingRemote<storage::mojom::FileSystemAccessContext>
        pending_file_system_access_context) {}

void IndexedDBContextImpl::BindControlOnIDBSequence(
    mojo::PendingReceiver<storage::mojom::IndexedDBControl> control) {}

void IndexedDBContextImpl::BindControl(
    mojo::PendingReceiver<storage::mojom::IndexedDBControl> control) {}

void IndexedDBContextImpl::BindIndexedDB(
    const BucketLocator& bucket_locator,
    const storage::BucketClientInfo& client_info,
    mojo::PendingRemote<storage::mojom::IndexedDBClientStateChecker>
        client_state_checker_remote,
    mojo::PendingReceiver<blink::mojom::IDBFactory> receiver) {}

void IndexedDBContextImpl::BindIndexedDBImpl(
    const storage::BucketClientInfo& client_info,
    mojo::PendingRemote<storage::mojom::IndexedDBClientStateChecker>
        client_state_checker_remote,
    mojo::PendingReceiver<blink::mojom::IDBFactory> pending_receiver,
    storage::QuotaErrorOr<storage::BucketInfo> bucket_info) {}

void IndexedDBContextImpl::DeleteBucketData(const BucketLocator& bucket_locator,
                                            DeleteBucketDataCallback callback) {}

void IndexedDBContextImpl::DidForceCloseForDeleteBucketData(
    const storage::BucketLocator& bucket_locator,
    DeleteBucketDataCallback callback) {}

void IndexedDBContextImpl::ForceClose(storage::BucketId bucket_id,
                                      storage::mojom::ForceCloseReason reason,
                                      base::OnceClosure closure) {}

void IndexedDBContextImpl::StartMetadataRecording(
    storage::BucketId bucket_id,
    StartMetadataRecordingCallback callback) {}

void IndexedDBContextImpl::StopMetadataRecording(
    storage::BucketId bucket_id,
    StopMetadataRecordingCallback callback) {}

void IndexedDBContextImpl::DownloadBucketData(
    storage::BucketId bucket_id,
    DownloadBucketDataCallback callback) {}

void IndexedDBContextImpl::GetAllBucketsDetails(
    GetAllBucketsDetailsCallback callback) {}

void IndexedDBContextImpl::ContinueGetAllBucketsDetails(
    GetAllBucketsDetailsCallback callback,
    std::vector<storage::QuotaErrorOr<storage::BucketInfo>> bucket_infos) {}

void IndexedDBContextImpl::SetForceKeepSessionState() {}

void IndexedDBContextImpl::ApplyPolicyUpdates(
    std::vector<storage::mojom::StoragePolicyUpdatePtr> policy_updates) {}

void IndexedDBContextImpl::BindTestInterface(
    mojo::PendingReceiver<storage::mojom::IndexedDBControlTest> receiver) {}

void IndexedDBContextImpl::AddObserver(
    mojo::PendingRemote<storage::mojom::IndexedDBObserver> observer) {}

void IndexedDBContextImpl::GetBaseDataPathForTesting(
    GetBaseDataPathForTestingCallback callback) {}

void IndexedDBContextImpl::GetFilePathForTesting(
    const BucketLocator& bucket_locator,
    GetFilePathForTestingCallback callback) {}

void IndexedDBContextImpl::ResetCachesForTesting(base::OnceClosure callback) {}

void IndexedDBContextImpl::WriteToIndexedDBForTesting(
    const BucketLocator& bucket_locator,
    const std::string& key,
    const std::string& value,
    base::OnceClosure callback) {}

void IndexedDBContextImpl::GetPathForBlobForTesting(
    const BucketLocator& bucket_locator,
    int64_t database_id,
    int64_t blob_number,
    GetPathForBlobForTestingCallback callback) {}

void IndexedDBContextImpl::CompactBackingStoreForTesting(
    const BucketLocator& bucket_locator,
    base::OnceClosure callback) {}

void IndexedDBContextImpl::GetUsageForTesting(
    GetUsageForTestingCallback callback) {}

void IndexedDBContextImpl::BindMockFailureSingletonForTesting(
    mojo::PendingReceiver<storage::mojom::MockFailureInjector> receiver) {}

void IndexedDBContextImpl::GetDatabaseKeysForTesting(
    GetDatabaseKeysForTestingCallback callback) {}

std::optional<BucketLocator> IndexedDBContextImpl::LookUpBucket(
    storage::BucketId bucket_id) {}

int64_t IndexedDBContextImpl::GetBucketDiskUsage(
    const BucketLocator& bucket_locator) {}

base::Time IndexedDBContextImpl::GetBucketLastModified(
    const BucketLocator& bucket_locator) {}

std::vector<base::FilePath> IndexedDBContextImpl::GetStoragePaths(
    const BucketLocator& bucket_locator) const {}

base::FilePath IndexedDBContextImpl::GetDataPath(
    const BucketLocator& bucket_locator) const {}

const base::FilePath IndexedDBContextImpl::GetLegacyDataPath() const {}

const base::FilePath IndexedDBContextImpl::GetFirstPartyDataPathForTesting()
    const {}

void IndexedDBContextImpl::OnFilesWritten(const BucketLocator& bucket_locator,
                                          bool flushed) {}

void IndexedDBContextImpl::NotifyIndexedDBContentChanged(
    const BucketLocator& bucket_locator,
    const std::u16string& database_name,
    const std::u16string& object_store_name) {}

IndexedDBContextImpl::~IndexedDBContextImpl() {}

void IndexedDBContextImpl::ShutdownOnIDBSequence(base::TimeTicks start_time) {}

// static
void IndexedDBContextImpl::Shutdown(
    std::unique_ptr<IndexedDBContextImpl> context) {}

base::FilePath IndexedDBContextImpl::GetBlobStorePath(
    const BucketLocator& bucket_locator) const {}

base::FilePath IndexedDBContextImpl::GetLevelDBPath(
    const BucketLocator& bucket_locator) const {}

int64_t IndexedDBContextImpl::ReadUsageFromDisk(
    const BucketLocator& bucket_locator,
    bool write_in_progress) const {}

void IndexedDBContextImpl::NotifyOfBucketModification(
    const BucketLocator& bucket_locator) {}

void IndexedDBContextImpl::InitializeFromFilesIfNeeded(
    base::OnceClosure callback) {}

void IndexedDBContextImpl::ForceInitializeFromFilesForTesting(
    ForceInitializeFromFilesForTestingCallback callback) {}

std::map<StorageKey, base::FilePath>
IndexedDBContextImpl::FindLegacyIndexedDBFiles() const {}

std::map<storage::BucketId, base::FilePath>
IndexedDBContextImpl::FindIndexedDBFiles() const {}

void IndexedDBContextImpl::ForEachBucketContext(
    IndexedDBBucketContext::InstanceClosure callback) {}

void IndexedDBContextImpl::GetInMemorySize(
    storage::BucketId bucket_id,
    base::OnceCallback<void(int64_t)> on_got_size) const {}

std::vector<storage::BucketId>
IndexedDBContextImpl::GetOpenBucketIdsForTesting() const {}

base::SequenceBound<IndexedDBBucketContext>*
IndexedDBContextImpl::GetBucketContextForTesting(const storage::BucketId& id) {}

void IndexedDBContextImpl::FillInBucketMetadata(
    storage::mojom::IdbBucketMetadataPtr info,
    base::OnceCallback<void(storage::mojom::IdbBucketMetadataPtr)> result) {}

void IndexedDBContextImpl::DestroyBucketContext(storage::BucketId bucket_id) {}

void IndexedDBContextImpl::EnsureBucketContext(
    const storage::BucketInfo& bucket,
    const base::FilePath& data_directory) {}

void IndexedDBContextImpl::GetBucketUsage(const BucketLocator& bucket,
                                          GetBucketUsageCallback callback) {}

void IndexedDBContextImpl::GetStorageKeysForType(
    blink::mojom::StorageType type,
    GetStorageKeysForTypeCallback callback) {}

void IndexedDBContextImpl::PerformStorageCleanup(
    blink::mojom::StorageType type,
    PerformStorageCleanupCallback callback) {}

bool IndexedDBContextImpl::BucketContextExists(storage::BucketId bucket_id) {}

}  // namespace content