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

Unified Diff: components/download/internal/download_store.h

Issue 2881173003: Download Service : Added leveldb proto layer (Closed)
Patch Set: More unittests Created 3 years, 7 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/download/internal/download_store.h
diff --git a/components/download/internal/download_store.h b/components/download/internal/download_store.h
new file mode 100644
index 0000000000000000000000000000000000000000..c2babae85ec167e5e8d0129b84c349e9e7d9dc78
--- /dev/null
+++ b/components/download/internal/download_store.h
@@ -0,0 +1,59 @@
+// Copyright 2017 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_DOWNLOAD_INTERNAL_DOWNLOAD_STORE_H_
+#define COMPONENTS_DOWNLOAD_INTERNAL_DOWNLOAD_STORE_H_
+
+#include <string>
+#include <vector>
+
+#include "base/files/file_path.h"
+#include "base/macros.h"
+#include "base/memory/weak_ptr.h"
+#include "components/download/internal/store.h"
+#include "components/leveldb_proto/proto_database.h"
+
+namespace protodb {
+class Entry;
+
+} // namespace
+
+namespace download {
+
+// DownloadStore provides a layer around a LevelDB proto database that persists
+// the download request, scheduling params and metadata to the disk. The data is
+// read during initialization and presented to the caller after converting to
+// Entry entries.
+class DownloadStore : public Store {
+ public:
+ DownloadStore(
+ const base::FilePath& database_dir,
+ std::unique_ptr<leveldb_proto::ProtoDatabase<protodb::Entry>> db);
+ ~DownloadStore() override;
+
+ // Store implementation.
+ bool IsInitialized() override;
+ void Initialize(const InitCallback& callback) override;
+ void Destroy(const StoreCallback& callback) override;
+ void Update(const Entry& entry, const StoreCallback& callback) override;
+ void Remove(const std::string& guid, const StoreCallback& callback) override;
+
+ private:
+ void OnDatabaseInited(const InitCallback& callback, bool success);
+ void OnDatabaseLoaded(const InitCallback& callback,
+ bool success,
+ std::unique_ptr<std::vector<protodb::Entry>> protos);
+
+ std::unique_ptr<leveldb_proto::ProtoDatabase<protodb::Entry>> db_;
+ base::FilePath database_dir_;
+ bool is_initialized_;
+
+ base::WeakPtrFactory<DownloadStore> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(DownloadStore);
+};
+
+} // namespace download
+
+#endif // COMPONENTS_DOWNLOAD_INTERNAL_DOWNLOAD_STORE_H_

Powered by Google App Engine
This is Rietveld 408576698