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 8 #include <memory> 9 #include <string> 10 #include <vector> 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 DownloadDBCallback = base::OnceCallback<void(bool success)>; 27 28 DownloadDB(); 29 virtual ~DownloadDB(); 30 31 // Initializes this db asynchronously, callback will be run on completion. 32 virtual void Initialize(DownloadDBCallback callback); 33 34 // Adds or updates |entry| in the storage. 35 virtual void AddOrReplace(const DownloadDBEntry& entry); 36 37 // Adds or updates multiple entries in the storage. 38 virtual void AddOrReplaceEntries(const std::vector<DownloadDBEntry>& entry, 39 DownloadDBCallback callback); 40 41 // Retrieves all entries with the given |download_namespace|. 42 virtual void LoadEntries(LoadEntriesCallback callback); 43 44 // Removes the Entry associated with |guid| from the storage. 45 virtual void Remove(const std::string& guid); 46 }; 47 48 } // namespace download 49 50 #endif // COMPONENTS_DOWNLOAD_DATABASE_DOWNLOAD_DB_H_ 51