#include "components/leveldb_proto/internal/shared_proto_database.h"
#include <memory>
#include <utility>
#include "base/functional/callback_helpers.h"
#include "base/memory/ptr_util.h"
#include "base/synchronization/lock.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/thread_pool.h"
#include "components/leveldb_proto/internal/leveldb_database.h"
#include "components/leveldb_proto/internal/proto_database_selector.h"
#include "components/leveldb_proto/internal/proto_leveldb_wrapper.h"
#include "components/leveldb_proto/public/proto_database.h"
#include "components/leveldb_proto/public/proto_database_provider.h"
#include "components/leveldb_proto/public/shared_proto_database_client_list.h"
namespace leveldb_proto {
namespace {
const base::FilePath::CharType kMetadataDatabasePath[] = …);
const int kMaxInitMetaDatabaseAttempts = …;
const int kMaxSharedDbFailuresBeforeDestroy = …;
const char kGlobalMetadataKey[] = …;
const char kSharedProtoDatabaseUmaName[] = …;
}
inline void RunInitStatusCallbackOnCallingSequence(
SharedProtoDatabase::SharedClientInitCallback callback,
scoped_refptr<base::SequencedTaskRunner> callback_task_runner,
Enums::InitStatus status,
SharedDBMetadataProto::MigrationStatus migration_status,
ProtoDatabaseSelector::ProtoDatabaseInitState metric) { … }
SharedProtoDatabase::InitRequest::InitRequest(
SharedClientInitCallback callback,
const scoped_refptr<base::SequencedTaskRunner>& task_runner,
const std::string& client_db_id)
: … { … }
SharedProtoDatabase::InitRequest::~InitRequest() = default;
SharedProtoDatabase::SharedProtoDatabase(const std::string& client_db_id,
const base::FilePath& db_dir)
: … { … }
void SharedProtoDatabase::GetDatabaseInitStatusAsync(
const std::string& client_db_id,
Callbacks::InitStatusCallback callback) { … }
void SharedProtoDatabase::RunInitCallback(
Callbacks::InitStatusCallback callback,
scoped_refptr<base::SequencedTaskRunner> callback_task_runner) { … }
void SharedProtoDatabase::UpdateClientMetadataAsync(
const std::string& client_db_id,
SharedDBMetadataProto::MigrationStatus migration_status,
base::OnceCallback<void(bool)> callback) { … }
void SharedProtoDatabase::GetClientMetadataAsync(
const std::string& client_db_id,
SharedClientInitCallback callback,
scoped_refptr<base::SequencedTaskRunner> callback_task_runner) { … }
void SharedProtoDatabase::OnGetClientMetadata(
const std::string& client_db_id,
SharedClientInitCallback callback,
scoped_refptr<base::SequencedTaskRunner> callback_task_runner,
bool success,
std::unique_ptr<SharedDBMetadataProto> proto) { … }
void SharedProtoDatabase::CheckCorruptionAndRunInitCallback(
const std::string& client_db_id,
SharedClientInitCallback callback,
scoped_refptr<base::SequencedTaskRunner> callback_task_runner,
Enums::InitStatus status) { … }
void SharedProtoDatabase::Init(
bool create_if_missing,
const std::string& client_db_id,
SharedClientInitCallback callback,
scoped_refptr<base::SequencedTaskRunner> callback_task_runner) { … }
void SharedProtoDatabase::ProcessInitRequests(Enums::InitStatus status) { … }
void SharedProtoDatabase::InitMetadataDatabase(int attempt, bool corruption) { … }
void SharedProtoDatabase::OnMetadataInitComplete(
int attempt,
bool corruption,
leveldb_proto::Enums::InitStatus status) { … }
void SharedProtoDatabase::OnGetGlobalMetadata(
bool corruption,
bool success,
std::unique_ptr<SharedDBMetadataProto> proto) { … }
void SharedProtoDatabase::OnWriteMetadataAtInit(bool success) { … }
void SharedProtoDatabase::OnDestroySharedDatabase(bool success) { … }
void SharedProtoDatabase::InitDatabase() { … }
void SharedProtoDatabase::OnDatabaseInit(bool create_if_missing,
Enums::InitStatus status) { … }
void SharedProtoDatabase::Shutdown() { … }
void SharedProtoDatabase::OnUpdateCorruptionCountAtInit(bool success) { … }
void SharedProtoDatabase::CommitUpdatedGlobalMetadata(
Callbacks::UpdateCallback callback) { … }
SharedProtoDatabase::~SharedProtoDatabase() { … }
void GetClientInitCallback(
base::OnceCallback<void(std::unique_ptr<SharedProtoDatabaseClient>,
Enums::InitStatus)> callback,
std::unique_ptr<SharedProtoDatabaseClient> client,
Enums::InitStatus status,
SharedDBMetadataProto::MigrationStatus migration_status) { … }
void SharedProtoDatabase::GetClientAsync(
ProtoDbType db_type,
bool create_if_missing,
base::OnceCallback<void(std::unique_ptr<SharedProtoDatabaseClient>,
Enums::InitStatus)> callback) { … }
std::unique_ptr<SharedProtoDatabaseClient>
SharedProtoDatabase::GetClientForTesting(ProtoDbType db_type,
bool create_if_missing,
SharedClientInitCallback callback) { … }
std::unique_ptr<SharedProtoDatabaseClient>
SharedProtoDatabase::GetClientInternal(ProtoDbType db_type) { … }
void SharedProtoDatabase::DestroyObsoleteSharedProtoDatabaseClients(
Callbacks::UpdateCallback done) { … }
void SharedProtoDatabase::SetDeleteObsoleteDelayForTesting(
base::TimeDelta delay) { … }
LevelDB* SharedProtoDatabase::GetLevelDBForTesting() const { … }
}