blob: 90b8040fd8c43e87a3100cc457f9802269b88898 [file] [log] [blame]
Min Qin826f29b2018-05-26 06:36:191// 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 Pazf96614b2018-07-27 10:49:318#include <memory>
Min Qin826f29b2018-05-26 06:36:199#include <string>
Xing Liua04f4d02018-07-27 18:51:4710#include <vector>
Min Qin826f29b2018-05-26 06:36:1911
12#include "base/callback_forward.h"
Min Qin826f29b2018-05-26 06:36:1913#include "components/download/database/download_namespace.h"
Anton Bikineev1156b5f2021-05-15 22:35:3614#include "third_party/abseil-cpp/absl/types/optional.h"
Min Qin826f29b2018-05-26 06:36:1915
16namespace download {
17
18struct DownloadDBEntry;
19
20// A backing storage for persisting DownloadDBEntry objects.
21class DownloadDB {
22 public:
23 using LoadEntriesCallback = base::OnceCallback<void(
24 bool success,
25 std::unique_ptr<std::vector<DownloadDBEntry>> entries)>;
Min Qin246ef152018-08-07 21:32:4426 using DownloadDBCallback = base::OnceCallback<void(bool success)>;
Min Qin826f29b2018-05-26 06:36:1927
Min Qindc243952018-07-25 18:46:0828 DownloadDB();
29 virtual ~DownloadDB();
Min Qin826f29b2018-05-26 06:36:1930
31 // Initializes this db asynchronously, callback will be run on completion.
Min Qin246ef152018-08-07 21:32:4432 virtual void Initialize(DownloadDBCallback callback);
Min Qin826f29b2018-05-26 06:36:1933
Min Qinc8592cc2018-06-22 19:37:0834 // Adds or updates |entry| in the storage.
Min Qindc243952018-07-25 18:46:0835 virtual void AddOrReplace(const DownloadDBEntry& entry);
Min Qin826f29b2018-05-26 06:36:1936
Min Qinc8592cc2018-06-22 19:37:0837 // Adds or updates multiple entries in the storage.
Min Qin246ef152018-08-07 21:32:4438 virtual void AddOrReplaceEntries(const std::vector<DownloadDBEntry>& entry,
39 DownloadDBCallback callback);
Min Qinc8592cc2018-06-22 19:37:0840
Min Qin826f29b2018-05-26 06:36:1941 // Retrieves all entries with the given |download_namespace|.
Min Qindc243952018-07-25 18:46:0842 virtual void LoadEntries(LoadEntriesCallback callback);
Min Qin826f29b2018-05-26 06:36:1943
44 // Removes the Entry associated with |guid| from the storage.
Min Qindc243952018-07-25 18:46:0845 virtual void Remove(const std::string& guid);
Min Qin826f29b2018-05-26 06:36:1946};
47
48} // namespace download
49
50#endif // COMPONENTS_DOWNLOAD_DATABASE_DOWNLOAD_DB_H_