sync_metadata_store_change_list.cc 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. #include "components/sync/model/sync_metadata_store_change_list.h"
  5. #include "components/sync/protocol/entity_metadata.pb.h"
  6. #include "base/location.h"
  7. using absl::optional;
  8. using syncer::ModelError;
  9. namespace syncer {
  10. SyncMetadataStoreChangeList::SyncMetadataStoreChangeList(
  11. SyncMetadataStore* store,
  12. syncer::ModelType type)
  13. : store_(store), type_(type) {
  14. if (!store_) {
  15. error_ = ModelError(FROM_HERE, "Invalid SyncMetadataStore");
  16. }
  17. }
  18. SyncMetadataStoreChangeList::~SyncMetadataStoreChangeList() {
  19. DCHECK(!error_);
  20. }
  21. void SyncMetadataStoreChangeList::UpdateModelTypeState(
  22. const sync_pb::ModelTypeState& model_type_state) {
  23. if (error_) {
  24. return;
  25. }
  26. if (!store_->UpdateModelTypeState(type_, model_type_state)) {
  27. error_ = ModelError(FROM_HERE, "Failed to update ModelTypeState.");
  28. }
  29. }
  30. void SyncMetadataStoreChangeList::ClearModelTypeState() {
  31. if (error_) {
  32. return;
  33. }
  34. if (!store_->ClearModelTypeState(type_)) {
  35. error_ = ModelError(FROM_HERE, "Failed to clear ModelTypeState.");
  36. }
  37. }
  38. void SyncMetadataStoreChangeList::UpdateMetadata(
  39. const std::string& storage_key,
  40. const sync_pb::EntityMetadata& metadata) {
  41. if (error_) {
  42. return;
  43. }
  44. if (!store_->UpdateSyncMetadata(type_, storage_key, metadata)) {
  45. error_ = ModelError(FROM_HERE, "Failed to update entity metadata.");
  46. }
  47. }
  48. void SyncMetadataStoreChangeList::ClearMetadata(
  49. const std::string& storage_key) {
  50. if (error_) {
  51. return;
  52. }
  53. if (!store_->ClearSyncMetadata(type_, storage_key)) {
  54. error_ = ModelError(FROM_HERE, "Failed to clear entity metadata.");
  55. }
  56. }
  57. optional<ModelError> SyncMetadataStoreChangeList::TakeError() {
  58. optional<ModelError> temp = error_;
  59. error_.reset();
  60. return temp;
  61. }
  62. const SyncMetadataStore*
  63. SyncMetadataStoreChangeList::GetMetadataStoreForTesting() const {
  64. return store_;
  65. }
  66. } // namespace syncer