blocking_model_type_store_impl.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright 2018 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_BLOCKING_MODEL_TYPE_STORE_IMPL_H_
  5. #define COMPONENTS_SYNC_MODEL_BLOCKING_MODEL_TYPE_STORE_IMPL_H_
  6. #include <memory>
  7. #include <string>
  8. #include "base/sequence_checker.h"
  9. #include "base/task/sequenced_task_runner.h"
  10. #include "components/sync/base/model_type.h"
  11. #include "components/sync/model/blocking_model_type_store.h"
  12. namespace syncer {
  13. // TODO(andreaorru): The following functions are public only
  14. // to support Lacros migration. Make them private again once
  15. // they are not needed anymore. See crbug.com/1147556 for more
  16. // context on move migration.
  17. // Formats key prefix for data records of |type|.
  18. std::string FormatDataPrefix(ModelType type);
  19. // Formats key prefix for metadata records of |type|.
  20. std::string FormatMetaPrefix(ModelType type);
  21. // Formats key for global metadata record of |type|.
  22. std::string FormatGlobalMetadataKey(ModelType type);
  23. class ModelTypeStoreBackend;
  24. class BlockingModelTypeStoreImpl : public BlockingModelTypeStore {
  25. public:
  26. // |backend| must not be null.
  27. BlockingModelTypeStoreImpl(ModelType type,
  28. scoped_refptr<ModelTypeStoreBackend> backend);
  29. BlockingModelTypeStoreImpl(const BlockingModelTypeStoreImpl&) = delete;
  30. BlockingModelTypeStoreImpl& operator=(const BlockingModelTypeStoreImpl&) =
  31. delete;
  32. ~BlockingModelTypeStoreImpl() override;
  33. // BlockingModelTypeStore implementation.
  34. absl::optional<ModelError> ReadData(const IdList& id_list,
  35. RecordList* data_records,
  36. IdList* missing_id_list) override;
  37. absl::optional<ModelError> ReadAllData(RecordList* data_records) override;
  38. absl::optional<ModelError> ReadAllMetadata(
  39. MetadataBatch* metadata_batch) override;
  40. std::unique_ptr<WriteBatch> CreateWriteBatch() override;
  41. absl::optional<ModelError> CommitWriteBatch(
  42. std::unique_ptr<WriteBatch> write_batch) override;
  43. absl::optional<ModelError> DeleteAllDataAndMetadata() override;
  44. // For advanced uses that require cross-thread batch posting. Avoid if
  45. // possible.
  46. static std::unique_ptr<WriteBatch> CreateWriteBatchForType(ModelType type);
  47. private:
  48. const ModelType type_;
  49. const scoped_refptr<ModelTypeStoreBackend> backend_;
  50. // Key prefix for data/metadata records of this model type.
  51. const std::string data_prefix_;
  52. const std::string metadata_prefix_;
  53. // Key for this type's global metadata record.
  54. const std::string global_metadata_key_;
  55. SEQUENCE_CHECKER(sequence_checker_);
  56. };
  57. } // namespace syncer
  58. #endif // COMPONENTS_SYNC_MODEL_BLOCKING_MODEL_TYPE_STORE_IMPL_H_