download_db.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. #ifndef COMPONENTS_DOWNLOAD_DATABASE_DOWNLOAD_DB_H_
  5. #define COMPONENTS_DOWNLOAD_DATABASE_DOWNLOAD_DB_H_
  6. #include <memory>
  7. #include <string>
  8. #include <vector>
  9. #include "base/callback_forward.h"
  10. #include "components/download/database/download_namespace.h"
  11. namespace download {
  12. struct DownloadDBEntry;
  13. // A backing storage for persisting DownloadDBEntry objects.
  14. class DownloadDB {
  15. public:
  16. using LoadEntriesCallback = base::OnceCallback<void(
  17. bool success,
  18. std::unique_ptr<std::vector<DownloadDBEntry>> entries)>;
  19. using DownloadDBCallback = base::OnceCallback<void(bool success)>;
  20. DownloadDB();
  21. virtual ~DownloadDB();
  22. // Initializes this db asynchronously, callback will be run on completion.
  23. virtual void Initialize(DownloadDBCallback callback);
  24. // Adds or updates |entry| in the storage.
  25. virtual void AddOrReplace(const DownloadDBEntry& entry);
  26. // Adds or updates multiple entries in the storage.
  27. virtual void AddOrReplaceEntries(const std::vector<DownloadDBEntry>& entry,
  28. DownloadDBCallback callback);
  29. // Retrieves all entries with the given |download_namespace|.
  30. virtual void LoadEntries(LoadEntriesCallback callback);
  31. // Removes the Entry associated with |guid| from the storage.
  32. virtual void Remove(const std::string& guid);
  33. };
  34. } // namespace download
  35. #endif // COMPONENTS_DOWNLOAD_DATABASE_DOWNLOAD_DB_H_