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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_DOWNLOAD_INTERNAL_DOWNLOAD_STORE_H_
6 #define COMPONENTS_DOWNLOAD_INTERNAL_DOWNLOAD_STORE_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/files/file_path.h"
12 #include "base/macros.h"
13 #include "base/memory/weak_ptr.h"
14 #include "components/download/internal/store.h"
15 #include "components/leveldb_proto/proto_database.h"
16
17 namespace protodb {
18 class Entry;
19
20 } // namespace
21
22 namespace download {
23
24 // DownloadStore provides a layer around a LevelDB proto database that persists
25 // the download request, scheduling params and metadata to the disk. The data is
26 // read during initialization and presented to the caller after converting to
27 // Entry entries.
28 class DownloadStore : public Store {
29 public:
30 DownloadStore(
31 const base::FilePath& database_dir,
32 std::unique_ptr<leveldb_proto::ProtoDatabase<protodb::Entry>> db);
33 ~DownloadStore() override;
34
35 // Store implementation.
36 bool IsInitialized() override;
37 void Initialize(const InitCallback& callback) override;
38 void Destroy(const StoreCallback& callback) override;
39 void Update(const Entry& entry, const StoreCallback& callback) override;
40 void Remove(const std::string& guid, const StoreCallback& callback) override;
41
42 private:
43 void OnDatabaseInited(const InitCallback& callback, bool success);
44 void OnDatabaseLoaded(const InitCallback& callback,
45 bool success,
46 std::unique_ptr<std::vector<protodb::Entry>> protos);
47
48 std::unique_ptr<leveldb_proto::ProtoDatabase<protodb::Entry>> db_;
49 base::FilePath database_dir_;
50 bool is_initialized_;
51
52 base::WeakPtrFactory<DownloadStore> weak_factory_;
53
54 DISALLOW_COPY_AND_ASSIGN(DownloadStore);
55 };
56
57 } // namespace download
58
59 #endif // COMPONENTS_DOWNLOAD_INTERNAL_DOWNLOAD_STORE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698