sync_metadata_store_change_list.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2017 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_SYNC_MODEL_SYNC_METADATA_STORE_CHANGE_LIST_H_
  5. #define COMPONENTS_SYNC_MODEL_SYNC_METADATA_STORE_CHANGE_LIST_H_
  6. #include <string>
  7. #include "base/memory/raw_ptr.h"
  8. #include "components/sync/base/model_type.h"
  9. #include "components/sync/model/metadata_change_list.h"
  10. #include "components/sync/model/model_error.h"
  11. #include "components/sync/model/sync_metadata_store.h"
  12. #include "components/sync/protocol/model_type_state.pb.h"
  13. #include "third_party/abseil-cpp/absl/types/optional.h"
  14. namespace sync_pb {
  15. class EntityMetadata;
  16. } // namespace sync_pb
  17. namespace syncer {
  18. // A thin wrapper around an SyncMetadataStore that implements sync's
  19. // MetadataChangeList interface. Changes are passed directly into the store and
  20. // not stored inside this object. Since the store calls can fail, |TakeError()|
  21. // must be called before this object is destroyed to check whether any
  22. // operations failed.
  23. class SyncMetadataStoreChangeList : public MetadataChangeList {
  24. public:
  25. SyncMetadataStoreChangeList(SyncMetadataStore* store, syncer::ModelType type);
  26. ~SyncMetadataStoreChangeList() override;
  27. // MetadataChangeList implementation.
  28. void UpdateModelTypeState(
  29. const sync_pb::ModelTypeState& model_type_state) override;
  30. void ClearModelTypeState() override;
  31. void UpdateMetadata(const std::string& storage_key,
  32. const sync_pb::EntityMetadata& metadata) override;
  33. void ClearMetadata(const std::string& storage_key) override;
  34. absl::optional<syncer::ModelError> TakeError();
  35. const SyncMetadataStore* GetMetadataStoreForTesting() const;
  36. private:
  37. // The metadata store to store metadata in; always outlives |this|.
  38. raw_ptr<SyncMetadataStore> store_;
  39. // The sync model type for this metadata.
  40. syncer::ModelType type_;
  41. // The first error encountered by this object, if any.
  42. absl::optional<syncer::ModelError> error_;
  43. };
  44. } // namespace syncer
  45. #endif // COMPONENTS_SYNC_MODEL_SYNC_METADATA_STORE_CHANGE_LIST_H_