summaryrefslogtreecommitdiff
path: root/chromium/components/download/database/download_db.h
blob: 6b11d98ea59f53e51e9bf610f136236567afde59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_DOWNLOAD_DATABASE_DOWNLOAD_DB_H_
#define COMPONENTS_DOWNLOAD_DATABASE_DOWNLOAD_DB_H_

#include <memory>
#include <string>
#include <vector>

#include "base/callback_forward.h"
#include "base/optional.h"
#include "components/download/database/download_namespace.h"

namespace download {

struct DownloadDBEntry;

// A backing storage for persisting DownloadDBEntry objects.
class DownloadDB {
 public:
  using LoadEntriesCallback = base::OnceCallback<void(
      bool success,
      std::unique_ptr<std::vector<DownloadDBEntry>> entries)>;
  using DownloadDBCallback = base::OnceCallback<void(bool success)>;

  DownloadDB();
  virtual ~DownloadDB();

  // Initializes this db asynchronously, callback will be run on completion.
  virtual void Initialize(DownloadDBCallback callback);

  // Adds or updates |entry| in the storage.
  virtual void AddOrReplace(const DownloadDBEntry& entry);

  // Adds or updates multiple entries in the storage.
  virtual void AddOrReplaceEntries(const std::vector<DownloadDBEntry>& entry,
                                   DownloadDBCallback callback);

  // Retrieves all entries with the given |download_namespace|.
  virtual void LoadEntries(LoadEntriesCallback callback);

  // Removes the Entry associated with |guid| from the storage.
  virtual void Remove(const std::string& guid);
};

}  // namespace download

#endif  // COMPONENTS_DOWNLOAD_DATABASE_DOWNLOAD_DB_H_