OLD | NEW |
(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(InitCallback callback) override; |
| 38 void Update(const Entry& entry, StoreCallback callback) override; |
| 39 void Remove(const std::string& guid, StoreCallback callback) override; |
| 40 |
| 41 private: |
| 42 void OnDatabaseInited(InitCallback callback, bool success); |
| 43 void OnDatabaseLoaded(InitCallback callback, |
| 44 bool success, |
| 45 std::unique_ptr<std::vector<protodb::Entry>> protos); |
| 46 |
| 47 std::unique_ptr<leveldb_proto::ProtoDatabase<protodb::Entry>> db_; |
| 48 base::FilePath database_dir_; |
| 49 bool is_initialized_; |
| 50 |
| 51 base::WeakPtrFactory<DownloadStore> weak_factory_; |
| 52 |
| 53 DISALLOW_COPY_AND_ASSIGN(DownloadStore); |
| 54 }; |
| 55 |
| 56 } // namespace download |
| 57 |
| 58 #endif // COMPONENTS_DOWNLOAD_INTERNAL_DOWNLOAD_STORE_H_ |
OLD | NEW |