blob: 77fdd532193cdf47f1aa8c6c3ca88df83e51e53e [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"
13#include "base/optional.h"
14#include "components/download/database/download_namespace.h"
15
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)>;
26 using InitializeCallback = base::OnceCallback<void(bool success)>;
27
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 Qindc243952018-07-25 18:46:0832 virtual void Initialize(InitializeCallback 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 Qindc243952018-07-25 18:46:0838 virtual void AddOrReplaceEntries(const std::vector<DownloadDBEntry>& entry);
Min Qinc8592cc2018-06-22 19:37:0839
Min Qin826f29b2018-05-26 06:36:1940 // Retrieves all entries with the given |download_namespace|.
Min Qindc243952018-07-25 18:46:0841 virtual void LoadEntries(LoadEntriesCallback callback);
Min Qin826f29b2018-05-26 06:36:1942
43 // Removes the Entry associated with |guid| from the storage.
Min Qindc243952018-07-25 18:46:0844 virtual void Remove(const std::string& guid);
Min Qin826f29b2018-05-26 06:36:1945};
46
47} // namespace download
48
49#endif // COMPONENTS_DOWNLOAD_DATABASE_DOWNLOAD_DB_H_