#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "components/leveldb_proto/internal/shared_proto_database_client.h"
#include <memory>
#include <utility>
#include "base/check.h"
#include "base/check_op.h"
#include "base/notreached.h"
#include "base/strings/strcat.h"
#include "base/strings/stringprintf.h"
#include "components/leveldb_proto/internal/proto_leveldb_wrapper.h"
#include "components/leveldb_proto/internal/shared_proto_database.h"
#include "components/leveldb_proto/public/proto_database.h"
#include "components/leveldb_proto/public/shared_proto_database_client_list.h"
namespace leveldb_proto {
namespace {
const ProtoDbType* g_obsolete_client_list_for_testing = …;
class ObsoleteClientsDbHolder
: public base::RefCounted<ObsoleteClientsDbHolder> { … };
PhysicalKey MakePhysicalKey(const KeyPrefix& prefix, const LogicalKey& key) { … }
}
bool SharedProtoDatabaseClient::HasPrefix(const PhysicalKey& key,
const KeyPrefix& prefix) { … }
std::optional<LogicalKey> SharedProtoDatabaseClient::StripPrefix(
const PhysicalKey& key,
const KeyPrefix& prefix) { … }
std::unique_ptr<KeyVector> SharedProtoDatabaseClient::PrefixStrings(
std::unique_ptr<KeyVector> strings,
const KeyPrefix& prefix) { … }
bool SharedProtoDatabaseClient::KeyFilterStripPrefix(
const KeyFilter& key_filter,
const KeyPrefix& prefix,
const PhysicalKey& key) { … }
bool SharedProtoDatabaseClient::KeyStringFilterStripPrefix(
const KeyFilter& key_filter,
const KeyPrefix& prefix,
const std::string& key) { … }
Enums::KeyIteratorAction
SharedProtoDatabaseClient::KeyIteratorControllerStripPrefix(
const KeyIteratorController& controller,
const KeyPrefix& prefix,
const PhysicalKey& key) { … }
Enums::KeyIteratorAction
SharedProtoDatabaseClient::KeyStringIteratorControllerStripPrefix(
const KeyIteratorController& controller,
const KeyPrefix& prefix,
const std::string& key) { … }
void SharedProtoDatabaseClient::GetSharedDatabaseInitStatusAsync(
const std::string& client_db_id,
const scoped_refptr<SharedProtoDatabase>& shared_db,
Callbacks::InitStatusCallback callback) { … }
void SharedProtoDatabaseClient::UpdateClientMetadataAsync(
const scoped_refptr<SharedProtoDatabase>& shared_db,
const std::string& client_db_id,
SharedDBMetadataProto::MigrationStatus migration_status,
ClientCorruptCallback callback) { … }
void SharedProtoDatabaseClient::DestroyObsoleteSharedProtoDatabaseClients(
std::unique_ptr<ProtoLevelDBWrapper> db_wrapper,
Callbacks::UpdateCallback callback) { … }
void SharedProtoDatabaseClient::SetObsoleteClientListForTesting(
const ProtoDbType* list) { … }
KeyPrefix SharedProtoDatabaseClient::PrefixForDatabase(ProtoDbType db_type) { … }
SharedProtoDatabaseClient::SharedProtoDatabaseClient(
std::unique_ptr<ProtoLevelDBWrapper> db_wrapper,
ProtoDbType db_type,
const scoped_refptr<SharedProtoDatabase>& parent_db)
: … { … }
SharedProtoDatabaseClient::~SharedProtoDatabaseClient() { … }
void SharedProtoDatabaseClient::Init(const std::string& client_uma_name,
Callbacks::InitStatusCallback callback) { … }
void SharedProtoDatabaseClient::InitWithDatabase(
LevelDB* database,
const base::FilePath& database_dir,
const leveldb_env::Options& options,
bool destroy_on_corruption,
Callbacks::InitStatusCallback callback) { … }
void SharedProtoDatabaseClient::UpdateEntries(
std::unique_ptr<KeyValueVector> entries_to_save,
std::unique_ptr<KeyVector> keys_to_remove,
Callbacks::UpdateCallback callback) { … }
void SharedProtoDatabaseClient::UpdateEntriesWithRemoveFilter(
std::unique_ptr<KeyValueVector> entries_to_save,
const KeyFilter& delete_key_filter,
Callbacks::UpdateCallback callback) { … }
void SharedProtoDatabaseClient::UpdateEntriesWithRemoveFilter(
std::unique_ptr<KeyValueVector> entries_to_save,
const KeyFilter& delete_key_filter,
const std::string& target_prefix,
Callbacks::UpdateCallback callback) { … }
void SharedProtoDatabaseClient::LoadEntries(Callbacks::LoadCallback callback) { … }
void SharedProtoDatabaseClient::LoadEntriesWithFilter(
const KeyFilter& filter,
Callbacks::LoadCallback callback) { … }
void SharedProtoDatabaseClient::LoadEntriesWithFilter(
const KeyFilter& filter,
const leveldb::ReadOptions& options,
const std::string& target_prefix,
Callbacks::LoadCallback callback) { … }
void SharedProtoDatabaseClient::LoadKeys(Callbacks::LoadKeysCallback callback) { … }
void SharedProtoDatabaseClient::LoadKeys(const std::string& target_prefix,
Callbacks::LoadKeysCallback callback) { … }
void SharedProtoDatabaseClient::LoadKeysAndEntries(
Callbacks::LoadKeysAndEntriesCallback callback) { … }
void SharedProtoDatabaseClient::LoadKeysAndEntriesWithFilter(
const KeyFilter& filter,
Callbacks::LoadKeysAndEntriesCallback callback) { … }
void SharedProtoDatabaseClient::LoadKeysAndEntriesWithFilter(
const KeyFilter& filter,
const leveldb::ReadOptions& options,
const std::string& target_prefix,
Callbacks::LoadKeysAndEntriesCallback callback) { … }
void SharedProtoDatabaseClient::LoadKeysAndEntriesInRange(
const std::string& start,
const std::string& end,
Callbacks::LoadKeysAndEntriesCallback callback) { … }
void SharedProtoDatabaseClient::LoadKeysAndEntriesWhile(
const std::string& start,
const leveldb_proto::KeyIteratorController& controller,
Callbacks::LoadKeysAndEntriesCallback callback) { … }
void SharedProtoDatabaseClient::GetEntry(const std::string& key,
Callbacks::GetCallback callback) { … }
void SharedProtoDatabaseClient::Destroy(Callbacks::DestroyCallback callback) { … }
void SharedProtoDatabaseClient::UpdateClientInitMetadata(
SharedDBMetadataProto::MigrationStatus migration_status) { … }
void SharedProtoDatabaseClient::StripPrefixLoadKeysCallback(
Callbacks::LoadKeysCallback callback,
const KeyPrefix& prefix,
bool success,
std::unique_ptr<leveldb_proto::KeyVector> keys) { … }
void SharedProtoDatabaseClient::StripPrefixLoadKeysAndEntriesCallback(
Callbacks::LoadKeysAndEntriesCallback callback,
const KeyPrefix& prefix,
bool success,
std::unique_ptr<KeyValueMap> keys_entries) { … }
std::unique_ptr<KeyValueVector> SharedProtoDatabaseClient::PrefixKeyEntryVector(
std::unique_ptr<KeyValueVector> kev,
const KeyPrefix& prefix) { … }
}