#ifndef COMPONENTS_DATA_SHARING_MIGRATION_INTERNAL_MIGRATION_STATE_DATABASE_IMPL_H_
#define COMPONENTS_DATA_SHARING_MIGRATION_INTERNAL_MIGRATION_STATE_DATABASE_IMPL_H_
#include <map>
#include <memory>
#include <string>
#include "base/files/file_path.h"
#include "base/memory/weak_ptr.h"
#include "base/sequence_checker.h"
#include "base/task/sequenced_task_runner.h"
#include "components/data_sharing/migration/internal/migration_state_database.h"
#include "components/data_sharing/migration/internal/protocol/migration_state.pb.h"
#include "components/data_sharing/migration/public/context_id.h"
#include "components/sqlite_proto/key_value_data.h"
#include "components/sqlite_proto/key_value_table.h"
#include "components/sqlite_proto/proto_table_manager.h"
#include "sql/database.h"
namespace data_sharing {
class MigrationStateDatabaseImpl : public MigrationStateDatabase {
public:
explicit MigrationStateDatabaseImpl(const base::FilePath& profile_dir);
~MigrationStateDatabaseImpl() override;
MigrationStateDatabaseImpl(const MigrationStateDatabaseImpl&) = delete;
MigrationStateDatabaseImpl& operator=(const MigrationStateDatabaseImpl&) =
delete;
void Init(InitCallback callback) override;
std::optional<data_sharing_pb::MigrationState> GetMigrationState(
const ContextId& context_id) const override;
void UpdateMigrationState(
const ContextId& context_id,
const data_sharing_pb::MigrationState& state) override;
void DeleteMigrationState(const ContextId& context_id) override;
private:
void OnInitialized(InitCallback callback, bool success);
const base::FilePath profile_path_;
scoped_refptr<base::SequencedTaskRunner> db_task_runner_;
std::unique_ptr<sql::Database> db_;
scoped_refptr<sqlite_proto::ProtoTableManager> proto_table_manager_;
std::unique_ptr<sqlite_proto::KeyValueTable<data_sharing_pb::MigrationState>>
migration_state_table_;
std::unique_ptr<sqlite_proto::KeyValueData<data_sharing_pb::MigrationState>>
migration_state_data_;
bool is_initialized_ = false;
SEQUENCE_CHECKER(sequence_checker_);
base::WeakPtrFactory<MigrationStateDatabaseImpl> weak_ptr_factory_{this};
};
}
#endif