| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/autofill/core/browser/webdata/autofill_metadata_change_list
.h" | 5 #include "components/sync/model_impl/on_disk_metadata_change_list.h" |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 | 8 |
| 9 using base::Optional; | 9 using base::Optional; |
| 10 using syncer::ModelError; | 10 using syncer::ModelError; |
| 11 | 11 |
| 12 namespace autofill { | 12 namespace syncer { |
| 13 | 13 |
| 14 AutofillMetadataChangeList::AutofillMetadataChangeList(AutofillTable* table, | 14 OnDiskMetadataChangeList::OnDiskMetadataChangeList(MetadataTable* table, |
| 15 syncer::ModelType type) | 15 syncer::ModelType type) |
| 16 : table_(table), type_(type) { | 16 : table_(table), type_(type) { |
| 17 DCHECK(table_); | 17 DCHECK(table_); |
| 18 // This should be changed as new autofill types are converted to USS. | |
| 19 DCHECK_EQ(syncer::AUTOFILL, type_); | |
| 20 } | 18 } |
| 21 | 19 |
| 22 AutofillMetadataChangeList::~AutofillMetadataChangeList() { | 20 OnDiskMetadataChangeList::~OnDiskMetadataChangeList() { |
| 23 DCHECK(!error_); | 21 DCHECK(!error_); |
| 24 } | 22 } |
| 25 | 23 |
| 26 void AutofillMetadataChangeList::UpdateModelTypeState( | 24 void OnDiskMetadataChangeList::UpdateModelTypeState( |
| 27 const sync_pb::ModelTypeState& model_type_state) { | 25 const sync_pb::ModelTypeState& model_type_state) { |
| 28 if (error_) { | 26 if (error_) { |
| 29 return; | 27 return; |
| 30 } | 28 } |
| 31 | 29 |
| 32 if (!table_->UpdateModelTypeState(type_, model_type_state)) { | 30 if (!table_->UpdateModelTypeState(type_, model_type_state)) { |
| 33 error_ = ModelError(FROM_HERE, "Failed to update ModelTypeState."); | 31 error_ = ModelError(FROM_HERE, "Failed to update ModelTypeState."); |
| 34 } | 32 } |
| 35 } | 33 } |
| 36 | 34 |
| 37 void AutofillMetadataChangeList::ClearModelTypeState() { | 35 void OnDiskMetadataChangeList::ClearModelTypeState() { |
| 38 if (error_) { | 36 if (error_) { |
| 39 return; | 37 return; |
| 40 } | 38 } |
| 41 | 39 |
| 42 if (!table_->ClearModelTypeState(type_)) { | 40 if (!table_->ClearModelTypeState(type_)) { |
| 43 error_ = ModelError(FROM_HERE, "Failed to clear ModelTypeState."); | 41 error_ = ModelError(FROM_HERE, "Failed to clear ModelTypeState."); |
| 44 } | 42 } |
| 45 } | 43 } |
| 46 | 44 |
| 47 void AutofillMetadataChangeList::UpdateMetadata( | 45 void OnDiskMetadataChangeList::UpdateMetadata( |
| 48 const std::string& storage_key, | 46 const std::string& storage_key, |
| 49 const sync_pb::EntityMetadata& metadata) { | 47 const sync_pb::EntityMetadata& metadata) { |
| 50 if (error_) { | 48 if (error_) { |
| 51 return; | 49 return; |
| 52 } | 50 } |
| 53 | 51 |
| 54 if (!table_->UpdateSyncMetadata(type_, storage_key, metadata)) { | 52 if (!table_->UpdateSyncMetadata(type_, storage_key, metadata)) { |
| 55 error_ = ModelError(FROM_HERE, "Failed to update entity metadata."); | 53 error_ = ModelError(FROM_HERE, "Failed to update entity metadata."); |
| 56 } | 54 } |
| 57 } | 55 } |
| 58 | 56 |
| 59 void AutofillMetadataChangeList::ClearMetadata(const std::string& storage_key) { | 57 void OnDiskMetadataChangeList::ClearMetadata(const std::string& storage_key) { |
| 60 if (error_) { | 58 if (error_) { |
| 61 return; | 59 return; |
| 62 } | 60 } |
| 63 | 61 |
| 64 if (!table_->ClearSyncMetadata(type_, storage_key)) { | 62 if (!table_->ClearSyncMetadata(type_, storage_key)) { |
| 65 error_ = ModelError(FROM_HERE, "Failed to clear entity metadata."); | 63 error_ = ModelError(FROM_HERE, "Failed to clear entity metadata."); |
| 66 } | 64 } |
| 67 } | 65 } |
| 68 | 66 |
| 69 Optional<ModelError> AutofillMetadataChangeList::TakeError() { | 67 Optional<ModelError> OnDiskMetadataChangeList::TakeError() { |
| 70 Optional<ModelError> temp = error_; | 68 Optional<ModelError> temp = error_; |
| 71 error_.reset(); | 69 error_.reset(); |
| 72 return temp; | 70 return temp; |
| 73 } | 71 } |
| 74 | 72 |
| 75 } // namespace autofill | 73 } // namespace syncer |
| OLD | NEW |