#include "storage/browser/database/database_tracker.h"
#include <stddef.h>
#include <stdint.h>
#include <algorithm>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "base/containers/contains.h"
#include "base/files/file_enumerator.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/location.h"
#include "base/memory/scoped_refptr.h"
#include "base/metrics/user_metrics.h"
#include "base/not_fatal_until.h"
#include "base/observer_list.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/thread_pool.h"
#include "base/time/time.h"
#include "base/types/pass_key.h"
#include "components/services/storage/public/cpp/quota_client_callback_wrapper.h"
#include "components/services/storage/public/mojom/quota_client.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "net/base/net_errors.h"
#include "sql/database.h"
#include "sql/meta_table.h"
#include "sql/transaction.h"
#include "storage/browser/database/database_quota_client.h"
#include "storage/browser/database/database_util.h"
#include "storage/browser/database/databases_table.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/quota/quota_types.mojom.h"
#include "third_party/sqlite/sqlite3.h"
#include "url/gurl.h"
#include "url/origin.h"
namespace storage {
const base::FilePath::CharType kDatabaseDirectoryName[] = …);
const base::FilePath::CharType kIncognitoDatabaseDirectoryName[] = …);
const base::FilePath::CharType kTrackerDatabaseFileName[] = …);
static const int kDatabaseTrackerCurrentSchemaVersion = …;
static const int kDatabaseTrackerCompatibleVersion = …;
const base::FilePath::CharType kTemporaryDirectoryPrefix[] = …);
const base::FilePath::CharType kTemporaryDirectoryPattern[] = …);
OriginInfo::OriginInfo()
: … { … }
OriginInfo::OriginInfo(const OriginInfo& origin_info) = default;
OriginInfo::~OriginInfo() = default;
int64_t OriginInfo::GetDatabaseSize(const std::u16string& database_name) const { … }
OriginInfo::OriginInfo(const std::string& origin_identifier, int64_t total_size)
: … { … }
scoped_refptr<DatabaseTracker> DatabaseTracker::Create(
const base::FilePath& profile_path,
bool is_incognito,
scoped_refptr<QuotaManagerProxy> quota_manager_proxy) { … }
DatabaseTracker::DatabaseTracker(
const base::FilePath& profile_path,
bool is_incognito,
scoped_refptr<QuotaManagerProxy> quota_manager_proxy,
base::PassKey<DatabaseTracker>)
: … { … }
DatabaseTracker::~DatabaseTracker() { … }
void DatabaseTracker::RegisterQuotaClient() { … }
void DatabaseTracker::DatabaseOpened(const std::string& origin_identifier,
const std::u16string& database_name,
const std::u16string& database_description,
int64_t* database_size) { … }
void DatabaseTracker::DatabaseModified(const std::string& origin_identifier,
const std::u16string& database_name) { … }
void DatabaseTracker::DatabaseClosed(const std::string& origin_identifier,
const std::u16string& database_name) { … }
void DatabaseTracker::HandleSqliteError(const std::string& origin_identifier,
const std::u16string& database_name,
int error) { … }
void DatabaseTracker::CloseDatabases(const DatabaseConnections& connections) { … }
void DatabaseTracker::DeleteDatabaseIfNeeded(
const std::string& origin_identifier,
const std::u16string& database_name) { … }
void DatabaseTracker::AddObserver(Observer* observer) { … }
void DatabaseTracker::RemoveObserver(Observer* observer) { … }
void DatabaseTracker::CloseTrackerDatabaseAndClearCaches() { … }
base::FilePath DatabaseTracker::GetOriginDirectory(
const std::string& origin_identifier) { … }
base::FilePath DatabaseTracker::GetFullDBFilePath(
const std::string& origin_identifier,
const std::u16string& database_name) { … }
bool DatabaseTracker::GetOriginInfo(const std::string& origin_identifier,
OriginInfo* info) { … }
bool DatabaseTracker::GetAllOriginIdentifiers(
std::vector<std::string>* origin_identifiers) { … }
bool DatabaseTracker::GetAllOriginsInfo(
std::vector<OriginInfo>* origins_info) { … }
bool DatabaseTracker::DeleteClosedDatabase(
const std::string& origin_identifier,
const std::u16string& database_name) { … }
bool DatabaseTracker::DeleteOrigin(const std::string& origin_identifier,
bool force) { … }
bool DatabaseTracker::IsDatabaseScheduledForDeletion(
const std::string& origin_identifier,
const std::u16string& database_name) { … }
bool DatabaseTracker::LazyInit() { … }
bool DatabaseTracker::UpgradeToCurrentVersion() { … }
void DatabaseTracker::InsertOrUpdateDatabaseDetails(
const std::string& origin_identifier,
const std::u16string& database_name,
const std::u16string& database_description) { … }
void DatabaseTracker::ClearAllCachedOriginInfo() { … }
DatabaseTracker::CachedOriginInfo* DatabaseTracker::MaybeGetCachedOriginInfo(
const std::string& origin_identifier, bool create_if_needed) { … }
int64_t DatabaseTracker::GetDBFileSize(const std::string& origin_identifier,
const std::u16string& database_name) { … }
int64_t DatabaseTracker::SeedOpenDatabaseInfo(
const std::string& origin_id,
const std::u16string& name,
const std::u16string& description) { … }
int64_t DatabaseTracker::UpdateOpenDatabaseInfoAndNotify(
const std::string& origin_id,
const std::u16string& name,
const std::u16string* opt_description) { … }
void DatabaseTracker::ScheduleDatabaseForDeletion(
const std::string& origin_identifier,
const std::u16string& database_name) { … }
void DatabaseTracker::ScheduleDatabasesForDeletion(
const DatabaseSet& databases,
net::CompletionOnceCallback callback) { … }
void DatabaseTracker::DeleteDatabase(const std::string& origin_identifier,
const std::u16string& database_name,
net::CompletionOnceCallback callback) { … }
void DatabaseTracker::DeleteDataModifiedSince(
const base::Time& cutoff,
net::CompletionOnceCallback callback) { … }
void DatabaseTracker::DeleteDataForOrigin(
const url::Origin& origin,
net::CompletionOnceCallback callback) { … }
const base::File* DatabaseTracker::GetIncognitoFile(
const std::u16string& vfs_file_name) const { … }
const base::File* DatabaseTracker::SaveIncognitoFile(
const std::u16string& vfs_file_name,
base::File file) { … }
void DatabaseTracker::CloseIncognitoFileHandle(
const std::u16string& vfs_file_name) { … }
bool DatabaseTracker::HasSavedIncognitoFileHandle(
const std::u16string& vfs_file_name) const { … }
void DatabaseTracker::DeleteIncognitoDBDirectory() { … }
void DatabaseTracker::Shutdown() { … }
}