mutable_data_batch.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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_MUTABLE_DATA_BATCH_H_
  5. #define COMPONENTS_SYNC_MODEL_MUTABLE_DATA_BATCH_H_
  6. #include <stddef.h>
  7. #include <memory>
  8. #include <string>
  9. #include <utility>
  10. #include <vector>
  11. #include "components/sync/model/data_batch.h"
  12. namespace syncer {
  13. // An implementation of DataBatch that's purpose is to transfer ownership of
  14. // EntityData objects. As soon as this batch recieves the EntityData, it owns
  15. // them until Next() is invoked, when it gives up ownerhsip. Because a vector
  16. // is used internally, this impl is unaware when duplcate storage_keys are used,
  17. // and it is the caller's job to avoid this.
  18. class MutableDataBatch : public DataBatch {
  19. public:
  20. MutableDataBatch();
  21. MutableDataBatch(const MutableDataBatch&) = delete;
  22. MutableDataBatch& operator=(const MutableDataBatch&) = delete;
  23. ~MutableDataBatch() override;
  24. // Takes ownership of the data tied to a given key used for storage. Put
  25. // should be called at most once for any given storage_key. Data will be
  26. // readable in the same order that they are put into the batch.
  27. void Put(const std::string& storage_key,
  28. std::unique_ptr<EntityData> entity_data);
  29. // DataBatch implementation.
  30. bool HasNext() const override;
  31. KeyAndData Next() override;
  32. private:
  33. std::vector<KeyAndData> key_data_pairs_;
  34. size_t read_index_ = 0;
  35. };
  36. } // namespace syncer
  37. #endif // COMPONENTS_SYNC_MODEL_MUTABLE_DATA_BATCH_H_