store.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2020 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_QUERY_TILES_INTERNAL_STORE_H_
  5. #define COMPONENTS_QUERY_TILES_INTERNAL_STORE_H_
  6. #include <map>
  7. #include <memory>
  8. #include <string>
  9. #include "base/callback.h"
  10. namespace query_tiles {
  11. // Interface of query tile collection store.
  12. template <typename T>
  13. class Store {
  14. public:
  15. using KeysAndEntries = std::map<std::string, std::unique_ptr<T>>;
  16. using LoadCallback = base::OnceCallback<void(bool, KeysAndEntries)>;
  17. using UpdateCallback = base::OnceCallback<void(bool)>;
  18. using DeleteCallback = base::OnceCallback<void(bool)>;
  19. // Initializes the database and loads all entries into memory.
  20. virtual void InitAndLoad(LoadCallback callback) = 0;
  21. // Adds/Updates an existing entry.
  22. virtual void Update(const std::string& key,
  23. const T& entry,
  24. UpdateCallback callback) = 0;
  25. // Deletes an entry from database.
  26. virtual void Delete(const std::string& key, DeleteCallback callback) = 0;
  27. Store() = default;
  28. virtual ~Store() = default;
  29. Store(const Store& other) = delete;
  30. Store& operator=(const Store& other) = delete;
  31. };
  32. } // namespace query_tiles
  33. #endif // COMPONENTS_QUERY_TILES_INTERNAL_STORE_H_