reading_list_model_storage.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright 2016 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_READING_LIST_CORE_READING_LIST_MODEL_STORAGE_H_
  5. #define COMPONENTS_READING_LIST_CORE_READING_LIST_MODEL_STORAGE_H_
  6. #include <memory>
  7. #include "components/reading_list/core/reading_list_entry.h"
  8. #include "components/sync/base/model_type.h"
  9. #include "components/sync/model/model_type_sync_bridge.h"
  10. class ReadingListModel;
  11. class ReadingListStoreDelegate;
  12. namespace base {
  13. class Clock;
  14. }
  15. namespace syncer {
  16. class ModelTypeChangeProcessor;
  17. }
  18. // Interface for a persistence layer for reading list.
  19. // All interface methods have to be called on main thread.
  20. class ReadingListModelStorage : public syncer::ModelTypeSyncBridge {
  21. public:
  22. class ScopedBatchUpdate;
  23. ReadingListModelStorage(
  24. std::unique_ptr<syncer::ModelTypeChangeProcessor> change_processor);
  25. ReadingListModelStorage(const ReadingListModelStorage&) = delete;
  26. ReadingListModelStorage& operator=(const ReadingListModelStorage&) = delete;
  27. ~ReadingListModelStorage() override;
  28. // Sets the model the Storage is backing.
  29. // This will trigger store initalization and load persistent entries.
  30. // Pass the |clock| from the |model| to ensure synchroization when loading
  31. // entries. Must be called no more than once.
  32. virtual void SetReadingListModel(ReadingListModel* model,
  33. ReadingListStoreDelegate* delegate,
  34. base::Clock* clock) = 0;
  35. // Starts a transaction. All Save/Remove entry will be delayed until the
  36. // transaction is commited.
  37. // Multiple transaction can be started at the same time. Commit will happen
  38. // when the last transaction is commited.
  39. // Returns a scoped batch update object that should be retained while the
  40. // batch update is performed. Deallocating this object will inform model that
  41. // the batch update has completed.
  42. virtual std::unique_ptr<ScopedBatchUpdate> EnsureBatchCreated() = 0;
  43. // Saves or updates an entry. If the entry is not yet in the database, it is
  44. // created.
  45. virtual void SaveEntry(const ReadingListEntry& entry) = 0;
  46. // Removed an entry from the storage.
  47. virtual void RemoveEntry(const ReadingListEntry& entry) = 0;
  48. class ScopedBatchUpdate {
  49. public:
  50. ScopedBatchUpdate() {}
  51. ScopedBatchUpdate(const ScopedBatchUpdate&) = delete;
  52. ScopedBatchUpdate& operator=(const ScopedBatchUpdate&) = delete;
  53. virtual ~ScopedBatchUpdate() {}
  54. };
  55. };
  56. #endif // COMPONENTS_READING_LIST_CORE_READING_LIST_MODEL_STORAGE_H_