#ifndef COMPONENTS_LEVELDB_PROTO_INTERNAL_PROTO_DATABASE_IMPL_H_
#define COMPONENTS_LEVELDB_PROTO_INTERNAL_PROTO_DATABASE_IMPL_H_
#include <map>
#include <memory>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/task/sequenced_task_runner.h"
#include "components/leveldb_proto/internal/proto_database_selector.h"
#include "components/leveldb_proto/internal/shared_proto_database.h"
#include "components/leveldb_proto/internal/shared_proto_database_provider.h"
#include "components/leveldb_proto/public/proto_database.h"
#include "components/leveldb_proto/public/shared_proto_database_client_list.h"
namespace google {
namespace protobuf {
class MessageLite;
}
}
namespace leveldb_proto {
void COMPONENT_EXPORT(LEVELDB_PROTO) RunUpdateCallback(
scoped_refptr<base::SequencedTaskRunner> callback_task_runner,
Callbacks::UpdateCallback callback,
bool success);
void COMPONENT_EXPORT(LEVELDB_PROTO) RunLoadKeysCallback(
scoped_refptr<base::SequencedTaskRunner> callback_task_runner,
Callbacks::LoadKeysCallback callback,
bool success,
std::unique_ptr<KeyVector> keys);
void COMPONENT_EXPORT(LEVELDB_PROTO) RunDestroyCallback(
scoped_refptr<base::SequencedTaskRunner> callback_task_runner,
Callbacks::DestroyCallback callback,
bool success);
template <typename P, typename T = P>
class ProtoDatabaseImpl : public ProtoDatabase<P, T> { … };
namespace {
template <typename P,
typename T,
std::enable_if_t<std::is_base_of<google::protobuf::MessageLite,
T>::value>* = nullptr>
std::string SerializeAsString(T* entry) { … }
template <typename P,
typename T,
std::enable_if_t<!std::is_base_of<google::protobuf::MessageLite,
T>::value>* = nullptr>
std::string SerializeAsString(T* entry) { … }
template <typename P>
bool ParseToProto(const std::string& serialized_entry, P* proto) { … }
template <typename P,
typename T,
std::enable_if_t<std::is_base_of<google::protobuf::MessageLite,
T>::value>* = nullptr>
bool ParseToClientType(const std::string& serialized_entry, T* output) { … }
template <typename P,
typename T,
std::enable_if_t<!std::is_base_of<google::protobuf::MessageLite,
T>::value>* = nullptr>
bool ParseToClientType(const std::string& serialized_entry, T* entry) { … }
template <typename P, typename T>
void UpdateEntriesFromTaskRunner(
std::unique_ptr<typename Util::Internal<T>::KeyEntryVector> entries_to_save,
std::unique_ptr<KeyVector> keys_to_remove,
scoped_refptr<ProtoDatabaseSelector> db,
Callbacks::UpdateCallback callback) { … }
template <typename P, typename T>
void UpdateEntriesWithRemoveFilterFromTaskRunner(
std::unique_ptr<typename ProtoDatabase<T>::KeyEntryVector> entries_to_save,
const KeyFilter& delete_key_filter,
scoped_refptr<ProtoDatabaseSelector> db,
Callbacks::UpdateCallback callback) { … }
template <typename P, typename T>
void ParseLoadedEntries(
scoped_refptr<base::SequencedTaskRunner> callback_task_runner,
typename Callbacks::Internal<T>::LoadCallback callback,
bool success,
std::unique_ptr<ValueVector> loaded_entries) { … }
template <typename P, typename T>
void ParseLoadedKeysAndEntries(
scoped_refptr<base::SequencedTaskRunner> callback_task_runner,
typename Callbacks::Internal<T>::LoadKeysAndEntriesCallback callback,
bool success,
std::unique_ptr<KeyValueMap> loaded_entries) { … }
template <typename P, typename T>
void ParseLoadedEntry(
scoped_refptr<base::SequencedTaskRunner> callback_task_runner,
typename Callbacks::Internal<T>::GetCallback callback,
bool success,
std::unique_ptr<std::string> serialized_entry) { … }
}
template <typename P, typename T>
ProtoDatabaseImpl<P, T>::ProtoDatabaseImpl(
ProtoDbType db_type,
const base::FilePath& db_dir,
const scoped_refptr<base::SequencedTaskRunner>& task_runner)
: … { … }
template <typename P, typename T>
ProtoDatabaseImpl<P, T>::ProtoDatabaseImpl(
ProtoDbType db_type,
const base::FilePath& db_dir,
const scoped_refptr<base::SequencedTaskRunner>& task_runner,
std::unique_ptr<SharedProtoDatabaseProvider> db_provider)
: … { … }
template <typename P, typename T>
void ProtoDatabaseImpl<P, T>::Init(
typename Callbacks::InitStatusCallback callback) { … }
template <typename P, typename T>
void ProtoDatabaseImpl<P, T>::Init(
const leveldb_env::Options& unique_db_options,
typename Callbacks::InitStatusCallback callback) { … }
template <typename P, typename T>
void ProtoDatabaseImpl<P, T>::InitInternal(
const std::string& client_name,
const leveldb_env::Options& unique_db_options,
bool use_shared_db,
Callbacks::InitStatusCallback callback) { … }
template <typename P, typename T>
void ProtoDatabaseImpl<P, T>::InitWithDatabase(
LevelDB* database,
const base::FilePath& database_dir,
const leveldb_env::Options& options,
Callbacks::InitStatusCallback callback) { … }
template <typename P, typename T>
void ProtoDatabaseImpl<P, T>::UpdateEntries(
std::unique_ptr<typename ProtoDatabase<T>::KeyEntryVector> entries_to_save,
std::unique_ptr<KeyVector> keys_to_remove,
Callbacks::UpdateCallback callback) { … }
template <typename P, typename T>
void ProtoDatabaseImpl<P, T>::UpdateEntriesWithRemoveFilter(
std::unique_ptr<typename ProtoDatabase<T>::KeyEntryVector> entries_to_save,
const KeyFilter& delete_key_filter,
Callbacks::UpdateCallback callback) { … }
template <typename P, typename T>
void ProtoDatabaseImpl<P, T>::LoadEntries(
typename Callbacks::Internal<T>::LoadCallback callback) { … }
template <typename P, typename T>
void ProtoDatabaseImpl<P, T>::LoadEntriesWithFilter(
const KeyFilter& filter,
typename Callbacks::Internal<T>::LoadCallback callback) { … }
template <typename P, typename T>
void ProtoDatabaseImpl<P, T>::LoadEntriesWithFilter(
const KeyFilter& key_filter,
const leveldb::ReadOptions& options,
const std::string& target_prefix,
typename Callbacks::Internal<T>::LoadCallback callback) { … }
template <typename P, typename T>
void ProtoDatabaseImpl<P, T>::LoadKeysAndEntries(
typename Callbacks::Internal<T>::LoadKeysAndEntriesCallback callback) { … }
template <typename P, typename T>
void ProtoDatabaseImpl<P, T>::LoadKeysAndEntriesWithFilter(
const KeyFilter& filter,
typename Callbacks::Internal<T>::LoadKeysAndEntriesCallback callback) { … }
template <typename P, typename T>
void ProtoDatabaseImpl<P, T>::LoadKeysAndEntriesWithFilter(
const KeyFilter& filter,
const leveldb::ReadOptions& options,
const std::string& target_prefix,
typename Callbacks::Internal<T>::LoadKeysAndEntriesCallback callback) { … }
template <typename P, typename T>
void ProtoDatabaseImpl<P, T>::LoadKeysAndEntriesInRange(
const std::string& start,
const std::string& end,
typename Callbacks::Internal<T>::LoadKeysAndEntriesCallback callback) { … }
template <typename P, typename T>
void ProtoDatabaseImpl<P, T>::LoadKeysAndEntriesWhile(
const std::string& start,
const KeyIteratorController& controller,
typename Callbacks::Internal<T>::LoadKeysAndEntriesCallback callback) { … }
template <typename P, typename T>
void ProtoDatabaseImpl<P, T>::LoadKeys(Callbacks::LoadKeysCallback callback) { … }
template <typename P, typename T>
void ProtoDatabaseImpl<P, T>::GetEntry(
const std::string& key,
typename Callbacks::Internal<T>::GetCallback callback) { … }
template <typename P, typename T>
void ProtoDatabaseImpl<P, T>::Destroy(Callbacks::DestroyCallback callback) { … }
template <typename P, typename T>
void ProtoDatabaseImpl<P, T>::RemoveKeysForTesting(
const KeyFilter& key_filter,
const std::string& target_prefix,
Callbacks::UpdateCallback callback) { … }
template <typename P, typename T>
void ProtoDatabaseImpl<P, T>::PostTransaction(base::OnceClosure task) { … }
}
#endif