chromium/components/leveldb_proto/public/proto_database.h

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_LEVELDB_PROTO_PUBLIC_PROTO_DATABASE_H_
#define COMPONENTS_LEVELDB_PROTO_PUBLIC_PROTO_DATABASE_H_

#include <map>
#include <vector>

#include "base/component_export.h"
#include "base/task/sequenced_task_runner.h"
#include "base/threading/thread_checker.h"
#include "third_party/leveldatabase/env_chromium.h"

namespace leveldb_proto {

class ProtoLevelDBWrapper;

class Enums {};

class Callbacks {};

class Util {};

//  When used to filter keys, a key is skipped skipped if the callback returns
//  `false`. When used to control a while loop, the loop is stopped if the
//  callback returns `false`.
KeyFilter;

// Callback choosing the next action when scanning the database.
KeyIteratorController;

// Interface for classes providing persistent storage of Protocol Buffer
// entries. P must be a proto type extending MessageLite. T is optional and
// defaults to P and there is then no additional requirements for clients.
// If T is set to something else, the client must provide these functions
// (note the namespace requirement):
//    namespace leveldb_proto {
//    void DataToProto(const T& data, P* proto);
//    void ProtoToData(const P& proto, T* data);
//    }  // namespace leveldb_proto
//
// The P type will be stored in the database, and the T type will be required
// as input and will be provided as output for all API calls. The backend will
// invoke the methods above for all conversions between the two types.
//
// For retrieving a database of proto type ClientProto, use:
//    auto db = ProtoDatabaseProviderFactory::GetForBrowserContext(...)
//        -> GetDB<ClientProto>(...);
//
// For automatically converting to a different data type, use:
//    auto db = ProtoDatabaseProviderFactory::GetForBrowserContext(...)
//        -> GetDB<ClientProto, ClientStruct>(...);
template <typename P, typename T = P>
class ProtoDatabase {};

// Return a new instance of Options, but with two additions:
// 1) create_if_missing = true
// 2) max_open_files = 0
leveldb_env::Options COMPONENT_EXPORT(LEVELDB_PROTO) CreateSimpleOptions();

}  // namespace leveldb_proto

#endif  // COMPONENTS_LEVELDB_PROTO_PUBLIC_PROTO_DATABASE_H_