metadata_batch.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2015 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_METADATA_BATCH_H_
  5. #define COMPONENTS_SYNC_MODEL_METADATA_BATCH_H_
  6. #include <map>
  7. #include <memory>
  8. #include <string>
  9. #include "components/sync/protocol/model_type_state.pb.h"
  10. namespace sync_pb {
  11. class EntityMetadata;
  12. } // namespace sync_pb
  13. namespace syncer {
  14. // Map of storage keys to EntityMetadata proto.
  15. using EntityMetadataMap =
  16. std::map<std::string, std::unique_ptr<sync_pb::EntityMetadata>>;
  17. // Container used to pass sync metadata from services to their processor.
  18. class MetadataBatch {
  19. public:
  20. MetadataBatch();
  21. MetadataBatch(MetadataBatch&&);
  22. ~MetadataBatch();
  23. MetadataBatch(const MetadataBatch&) = delete;
  24. // Read-only access to the entire metadata map.
  25. const EntityMetadataMap& GetAllMetadata() const;
  26. // Allows the caller to take ownership of the entire metadata map. This is
  27. // done because the caller will probably swap out all the EntityMetadata
  28. // protos from the map for performance reasons.
  29. EntityMetadataMap TakeAllMetadata();
  30. // Add |metadata| for |storage_key| to the batch.
  31. void AddMetadata(const std::string& storage_key,
  32. std::unique_ptr<sync_pb::EntityMetadata> metadata);
  33. // Get the ModelTypeState for this batch.
  34. const sync_pb::ModelTypeState& GetModelTypeState() const;
  35. // Set the ModelTypeState for this batch.
  36. void SetModelTypeState(const sync_pb::ModelTypeState& state);
  37. private:
  38. EntityMetadataMap metadata_map_;
  39. sync_pb::ModelTypeState state_;
  40. };
  41. } // namespace syncer
  42. #endif // COMPONENTS_SYNC_MODEL_METADATA_BATCH_H_