Min Qin | 826f29b | 2018-05-26 06:36:19 | [diff] [blame] | 1 | // Copyright 2018 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_DATABASE_DOWNLOAD_DB_H_ |
| 6 | #define COMPONENTS_DOWNLOAD_DATABASE_DOWNLOAD_DB_H_ |
| 7 | |
Jose Dapena Paz | f96614b | 2018-07-27 10:49:31 | [diff] [blame] | 8 | #include <memory> |
Min Qin | 826f29b | 2018-05-26 06:36:19 | [diff] [blame] | 9 | #include <string> |
Xing Liu | a04f4d0 | 2018-07-27 18:51:47 | [diff] [blame^] | 10 | #include <vector> |
Min Qin | 826f29b | 2018-05-26 06:36:19 | [diff] [blame] | 11 | |
| 12 | #include "base/callback_forward.h" |
| 13 | #include "base/optional.h" |
| 14 | #include "components/download/database/download_namespace.h" |
| 15 | |
| 16 | namespace download { |
| 17 | |
| 18 | struct DownloadDBEntry; |
| 19 | |
| 20 | // A backing storage for persisting DownloadDBEntry objects. |
| 21 | class DownloadDB { |
| 22 | public: |
| 23 | using LoadEntriesCallback = base::OnceCallback<void( |
| 24 | bool success, |
| 25 | std::unique_ptr<std::vector<DownloadDBEntry>> entries)>; |
| 26 | using InitializeCallback = base::OnceCallback<void(bool success)>; |
| 27 | |
Min Qin | dc24395 | 2018-07-25 18:46:08 | [diff] [blame] | 28 | DownloadDB(); |
| 29 | virtual ~DownloadDB(); |
Min Qin | 826f29b | 2018-05-26 06:36:19 | [diff] [blame] | 30 | |
| 31 | // Initializes this db asynchronously, callback will be run on completion. |
Min Qin | dc24395 | 2018-07-25 18:46:08 | [diff] [blame] | 32 | virtual void Initialize(InitializeCallback callback); |
Min Qin | 826f29b | 2018-05-26 06:36:19 | [diff] [blame] | 33 | |
Min Qin | c8592cc | 2018-06-22 19:37:08 | [diff] [blame] | 34 | // Adds or updates |entry| in the storage. |
Min Qin | dc24395 | 2018-07-25 18:46:08 | [diff] [blame] | 35 | virtual void AddOrReplace(const DownloadDBEntry& entry); |
Min Qin | 826f29b | 2018-05-26 06:36:19 | [diff] [blame] | 36 | |
Min Qin | c8592cc | 2018-06-22 19:37:08 | [diff] [blame] | 37 | // Adds or updates multiple entries in the storage. |
Min Qin | dc24395 | 2018-07-25 18:46:08 | [diff] [blame] | 38 | virtual void AddOrReplaceEntries(const std::vector<DownloadDBEntry>& entry); |
Min Qin | c8592cc | 2018-06-22 19:37:08 | [diff] [blame] | 39 | |
Min Qin | 826f29b | 2018-05-26 06:36:19 | [diff] [blame] | 40 | // Retrieves all entries with the given |download_namespace|. |
Min Qin | dc24395 | 2018-07-25 18:46:08 | [diff] [blame] | 41 | virtual void LoadEntries(LoadEntriesCallback callback); |
Min Qin | 826f29b | 2018-05-26 06:36:19 | [diff] [blame] | 42 | |
| 43 | // Removes the Entry associated with |guid| from the storage. |
Min Qin | dc24395 | 2018-07-25 18:46:08 | [diff] [blame] | 44 | virtual void Remove(const std::string& guid); |
Min Qin | 826f29b | 2018-05-26 06:36:19 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | } // namespace download |
| 48 | |
| 49 | #endif // COMPONENTS_DOWNLOAD_DATABASE_DOWNLOAD_DB_H_ |