Index: components/sync/model_impl/sync_metadata_store_change_list.cc |
diff --git a/components/sync/model_impl/sync_metadata_store_change_list.cc b/components/sync/model_impl/sync_metadata_store_change_list.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..59f1e89ae256f26b176b416f6b432ad6924db856 |
--- /dev/null |
+++ b/components/sync/model_impl/sync_metadata_store_change_list.cc |
@@ -0,0 +1,75 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "components/sync/model_impl/sync_metadata_store_change_list.h" |
+ |
+#include "base/location.h" |
+ |
+using base::Optional; |
+using syncer::ModelError; |
+ |
+namespace syncer { |
+ |
+SyncMetadataStoreChangeList::SyncMetadataStoreChangeList( |
+ SyncMetadataStore* store, |
+ syncer::ModelType type) |
+ : store_(store), type_(type) { |
+ DCHECK(store_); |
+} |
+ |
+SyncMetadataStoreChangeList::~SyncMetadataStoreChangeList() { |
+ DCHECK(!error_); |
+} |
+ |
+void SyncMetadataStoreChangeList::UpdateModelTypeState( |
+ const sync_pb::ModelTypeState& model_type_state) { |
+ if (error_) { |
+ return; |
+ } |
+ |
+ if (!store_->UpdateModelTypeState(type_, model_type_state)) { |
+ error_ = ModelError(FROM_HERE, "Failed to update ModelTypeState."); |
+ } |
+} |
+ |
+void SyncMetadataStoreChangeList::ClearModelTypeState() { |
+ if (error_) { |
+ return; |
+ } |
+ |
+ if (!store_->ClearModelTypeState(type_)) { |
+ error_ = ModelError(FROM_HERE, "Failed to clear ModelTypeState."); |
+ } |
+} |
+ |
+void SyncMetadataStoreChangeList::UpdateMetadata( |
+ const std::string& storage_key, |
+ const sync_pb::EntityMetadata& metadata) { |
+ if (error_) { |
+ return; |
+ } |
+ |
+ if (!store_->UpdateSyncMetadata(type_, storage_key, metadata)) { |
+ error_ = ModelError(FROM_HERE, "Failed to update entity metadata."); |
+ } |
+} |
+ |
+void SyncMetadataStoreChangeList::ClearMetadata( |
+ const std::string& storage_key) { |
+ if (error_) { |
+ return; |
+ } |
+ |
+ if (!store_->ClearSyncMetadata(type_, storage_key)) { |
+ error_ = ModelError(FROM_HERE, "Failed to clear entity metadata."); |
+ } |
+} |
+ |
+Optional<ModelError> SyncMetadataStoreChangeList::TakeError() { |
+ Optional<ModelError> temp = error_; |
+ error_.reset(); |
+ return temp; |
+} |
+ |
+} // namespace syncer |