Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(279)

Unified Diff: components/leveldb_proto/core/proto_database.h

Issue 330833002: Extract protobuf database into a new 'leveldb_proto' component (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: components/ OWNERS Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/leveldb_proto/core/proto_database.h
diff --git a/components/leveldb_proto/core/proto_database.h b/components/leveldb_proto/core/proto_database.h
new file mode 100644
index 0000000000000000000000000000000000000000..b4300b031361e2740b375bef1059d0984fa29715
--- /dev/null
+++ b/components/leveldb_proto/core/proto_database.h
@@ -0,0 +1,52 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_LEVELDB_PROTO_CORE_PROTO_DATABASE_H_
+#define COMPONENTS_LEVELDB_PROTO_CORE_PROTO_DATABASE_H_
+
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "base/callback.h"
+#include "base/files/file_path.h"
+#include "base/memory/scoped_ptr.h"
+
+namespace leveldb_proto {
+
+// Interface for classes providing persistent storage of Protocol Buffer
+// entries (T must be a Proto type extending MessageLite).
+template <typename T>
+class ProtoDatabase {
+ public:
+ typedef base::Callback<void(bool success)> InitCallback;
+ typedef base::Callback<void(bool success)> UpdateCallback;
+ typedef base::Callback<void(bool success, scoped_ptr<std::vector<T> >)>
+ LoadCallback;
+ // A list of key-value (string, T) tuples.
+ typedef std::vector<std::pair<std::string, T> > KeyEntryVector;
+
+ virtual ~ProtoDatabase() {}
+
+ // Asynchronously initializes the object. |callback| will be invoked on the UI
cjhopman 2014/06/13 19:41:05 s/UI/calling and below, too
Mathieu 2014/06/13 22:07:07 Done.
+ // thread when complete.
+ virtual void Init(const base::FilePath& database_dir,
+ InitCallback callback) = 0;
+
+ // Asynchronously saves |entries_to_save| and deletes entries from
+ // |keys_to_remove| from the database. |callback| will be invoked on the UI
+ // thread when complete.
+ virtual void UpdateEntries(
+ scoped_ptr<KeyEntryVector> entries_to_save,
+ scoped_ptr<std::vector<std::string> > keys_to_remove,
+ UpdateCallback callback) = 0;
+
+ // Asynchronously loads all entries from the database and invokes |callback|
+ // when complete.
+ virtual void LoadEntries(LoadCallback callback) = 0;
+};
+
+} // namespace leveldb_proto
+
+#endif // COMPONENTS_LEVELDB_PROTO_CORE_PROTO_DATABASE_H_

Powered by Google App Engine
This is Rietveld 408576698