chromium/storage/browser/quota/quota_database.cc

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

#include "storage/browser/quota/quota_database.h"

#include <stddef.h>
#include <stdint.h>

#include <memory>
#include <tuple>
#include <vector>

#include "base/auto_reset.h"
#include "base/containers/contains.h"
#include "base/dcheck_is_on.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/metrics/histogram_functions.h"
#include "base/sequence_checker.h"
#include "base/time/clock.h"
#include "components/services/storage/public/cpp/buckets/constants.h"
#include "components/services/storage/public/cpp/quota_error_or.h"
#include "sql/database.h"
#include "sql/error_delegate_util.h"
#include "sql/meta_table.h"
#include "sql/recovery.h"
#include "sql/statement.h"
#include "sql/transaction.h"
#include "storage/browser/quota/quota_database_migrations.h"
#include "storage/browser/quota/quota_features.h"
#include "storage/browser/quota/quota_internals.mojom.h"
#include "storage/browser/quota/special_storage_policy.h"
#include "url/gurl.h"

StorageKey;
StorageType;

namespace storage {
namespace {

static const int kDaysInTenYears =;

// Version number of the database schema.
//
// We support migrating the database schema from versions that are at most 2
// years old. Older versions are unsupported, and will cause the database to get
// razed.
//
// Version 1 - 2011-03-17 - http://crrev.com/78521 (unsupported)
// Version 2 - 2011-04-25 - http://crrev.com/82847 (unsupported)
// Version 3 - 2011-07-08 - http://crrev.com/91835 (unsupported)
// Version 4 - 2011-10-17 - http://crrev.com/105822 (unsupported)
// Version 5 - 2015-10-19 - https://crrev.com/354932 (unsupported)
// Version 6 - 2021-04-27 - https://crrev.com/c/2757450 (unsupported)
// Version 7 - 2021-05-20 - https://crrev.com/c/2910136
// Version 8 - 2021-09-01 - https://crrev.com/c/3119831
// Version 9 - 2022-05-13 - https://crrev.com/c/3601253
// Version 10 - 2023-04-10 - https://crrev.com/c/4412082
const int kQuotaDatabaseCurrentSchemaVersion =;
const int kQuotaDatabaseCompatibleVersion =;

// Definitions for database schema.
const char kBucketTable[] =;

// Flag to ensure that all existing data for storage keys have been
// registered into the buckets table. Introduced 2022-05 (crrev.com/c/3594211).
const char kBucketsTableBootstrapped[] =;

const int kCommitIntervalMs =;

base::Clock* g_clock_for_testing =;

void RecordDatabaseResetHistogram(const DatabaseResetReason reason) {}

// SQL statement fragment for inserting fields into the buckets table.
#define BUCKETS_FIELDS_INSERTER

void BindBucketInitParamsToInsertStatement(const BucketInitParams& params,
                                           StorageType type,
                                           int use_count,
                                           const base::Time& last_accessed,
                                           const base::Time& last_modified,
                                           sql::Statement& statement) {}

// Fields to be retrieved from the database and stored in a
// `BucketTableEntryPtr`.
#define BUCKET_TABLE_ENTRY_FIELDS_SELECTOR

mojom::BucketTableEntryPtr BucketTableEntryFromSqlStatement(
    sql::Statement& statement) {}

// Fields to be retrieved from the database and stored in a `BucketInfo`.
#define BUCKET_INFO_FIELDS_SELECTOR

QuotaErrorOr<BucketInfo> BucketInfoFromSqlStatement(sql::Statement& statement) {}

std::set<BucketInfo> BucketInfosFromSqlStatement(sql::Statement& statement) {}

}  // anonymous namespace

const QuotaDatabase::TableSchema QuotaDatabase::kTables[] =;
const size_t QuotaDatabase::kTableCount =;

// static
const QuotaDatabase::IndexSchema QuotaDatabase::kIndexes[] =;
const size_t QuotaDatabase::kIndexCount =;

// QuotaDatabase ------------------------------------------------------------
QuotaDatabase::QuotaDatabase(const base::FilePath& profile_path)
    :{}

QuotaDatabase::~QuotaDatabase() {}

constexpr char QuotaDatabase::kDatabaseName[];

QuotaErrorOr<BucketInfo> QuotaDatabase::UpdateOrCreateBucket(
    const BucketInitParams& params,
    int max_bucket_count) {}

QuotaErrorOr<BucketInfo> QuotaDatabase::GetOrCreateBucketDeprecated(
    const BucketInitParams& params,
    StorageType type) {}

QuotaErrorOr<BucketInfo> QuotaDatabase::CreateBucketForTesting(
    const StorageKey& storage_key,
    const std::string& bucket_name,
    StorageType storage_type) {}

QuotaErrorOr<BucketInfo> QuotaDatabase::GetBucket(
    const StorageKey& storage_key,
    const std::string& bucket_name,
    blink::mojom::StorageType storage_type) {}

QuotaErrorOr<BucketInfo> QuotaDatabase::UpdateBucketExpiration(
    BucketId bucket,
    const base::Time& expiration) {}

QuotaErrorOr<BucketInfo> QuotaDatabase::UpdateBucketPersistence(
    BucketId bucket,
    bool persistent) {}

QuotaErrorOr<BucketInfo> QuotaDatabase::GetBucketById(BucketId bucket_id) {}

QuotaErrorOr<std::set<BucketInfo>> QuotaDatabase::GetBucketsForType(
    StorageType type) {}

QuotaErrorOr<std::set<BucketInfo>> QuotaDatabase::GetBucketsForHost(
    const std::string& host,
    StorageType type) {}

QuotaErrorOr<std::set<BucketInfo>> QuotaDatabase::GetBucketsForStorageKey(
    const StorageKey& storage_key,
    StorageType type) {}

QuotaError QuotaDatabase::SetStorageKeyLastAccessTime(
    const StorageKey& storage_key,
    StorageType type,
    base::Time last_accessed) {}

QuotaError QuotaDatabase::SetBucketLastAccessTime(BucketId bucket_id,
                                                  base::Time last_accessed) {}

QuotaError QuotaDatabase::SetBucketLastModifiedTime(BucketId bucket_id,
                                                    base::Time last_modified) {}

QuotaError QuotaDatabase::RegisterInitialStorageKeyInfo(
    base::flat_map<StorageType, std::set<StorageKey>> storage_keys_by_type) {}

QuotaErrorOr<mojom::BucketTableEntryPtr> QuotaDatabase::GetBucketInfoForTest(
    BucketId bucket_id) {}

QuotaErrorOr<mojom::BucketTableEntryPtr> QuotaDatabase::DeleteBucketData(
    const BucketLocator& bucket) {}

QuotaErrorOr<std::set<BucketLocator>> QuotaDatabase::GetBucketsForEviction(
    StorageType type,
    int64_t target_usage,
    const std::map<BucketLocator, int64_t>& usage_map,
    const std::set<BucketId>& bucket_exceptions,
    SpecialStoragePolicy* special_storage_policy) {}

QuotaErrorOr<std::set<StorageKey>> QuotaDatabase::GetStorageKeysForType(
    StorageType type) {}

QuotaErrorOr<std::set<BucketLocator>> QuotaDatabase::GetBucketsModifiedBetween(
    StorageType type,
    base::Time begin,
    base::Time end) {}

QuotaErrorOr<std::set<BucketInfo>> QuotaDatabase::GetExpiredBuckets(
    SpecialStoragePolicy* special_storage_policy) {}

bool QuotaDatabase::IsBootstrapped() {}

QuotaError QuotaDatabase::SetIsBootstrapped(bool bootstrap_flag) {}

bool QuotaDatabase::RecoverOrRaze(int error_code) {}

QuotaError QuotaDatabase::CorruptForTesting(
    base::OnceCallback<void(const base::FilePath&)> corrupter) {}

void QuotaDatabase::SetDisabledForTesting(bool disable) {}

// static
base::Time QuotaDatabase::GetNow() {}

// static
void QuotaDatabase::SetClockForTesting(base::Clock* clock) {}

void QuotaDatabase::SetAlreadyEvictedStaleStorageForTesting(
    bool already_evicted_stale_storage) {}

void QuotaDatabase::CommitNow() {}

void QuotaDatabase::Commit() {}

void QuotaDatabase::ScheduleCommit() {}

QuotaError QuotaDatabase::EnsureOpened() {}

void QuotaDatabase::OnSqliteError(int sqlite_error_code,
                                  sql::Statement* statement) {}

bool QuotaDatabase::MoveLegacyDatabase() {}

bool QuotaDatabase::OpenDatabase() {}

bool QuotaDatabase::EnsureDatabaseVersion() {}

bool QuotaDatabase::CreateSchema() {}

bool QuotaDatabase::CreateTable(const TableSchema& table) {}

bool QuotaDatabase::CreateIndex(const IndexSchema& index) {}

bool QuotaDatabase::ResetStorage() {}

QuotaError QuotaDatabase::DumpBucketTable(const BucketTableCallback& callback) {}

QuotaErrorOr<BucketInfo> QuotaDatabase::CreateBucketInternal(
    const BucketInitParams& params,
    StorageType type,
    int max_bucket_count) {}

void QuotaDatabase::SetDbErrorCallback(
    const base::RepeatingCallback<void(int)>& db_error_callback) {}

}  // namespace storage