OLD | NEW |
1 // Copyright 2017 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 "chrome/browser/chromeos/printing/printers_sync_bridge.h" | 5 #include "chrome/browser/chromeos/printing/printers_sync_bridge.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 | 176 |
177 PrintersSyncBridge::~PrintersSyncBridge() {} | 177 PrintersSyncBridge::~PrintersSyncBridge() {} |
178 | 178 |
179 std::unique_ptr<MetadataChangeList> | 179 std::unique_ptr<MetadataChangeList> |
180 PrintersSyncBridge::CreateMetadataChangeList() { | 180 PrintersSyncBridge::CreateMetadataChangeList() { |
181 return ModelTypeStore::WriteBatch::CreateMetadataChangeList(); | 181 return ModelTypeStore::WriteBatch::CreateMetadataChangeList(); |
182 } | 182 } |
183 | 183 |
184 base::Optional<syncer::ModelError> PrintersSyncBridge::MergeSyncData( | 184 base::Optional<syncer::ModelError> PrintersSyncBridge::MergeSyncData( |
185 std::unique_ptr<MetadataChangeList> metadata_change_list, | 185 std::unique_ptr<MetadataChangeList> metadata_change_list, |
186 syncer::EntityDataMap entity_data_map) { | 186 syncer::EntityChangeList entity_data) { |
187 DCHECK(change_processor()->IsTrackingMetadata()); | 187 DCHECK(change_processor()->IsTrackingMetadata()); |
188 | 188 |
189 std::unique_ptr<ModelTypeStore::WriteBatch> batch = | 189 std::unique_ptr<ModelTypeStore::WriteBatch> batch = |
190 store_delegate_->CreateWriteBatch(); | 190 store_delegate_->CreateWriteBatch(); |
191 for (const auto& entry : entity_data_map) { | 191 std::set<std::string> sync_entity_ids; |
| 192 for (const auto& change : entity_data) { |
192 const sync_pb::PrinterSpecifics& specifics = | 193 const sync_pb::PrinterSpecifics& specifics = |
193 entry.second.value().specifics.printer(); | 194 change.data().specifics.printer(); |
194 | 195 |
195 DCHECK_EQ(entry.first, specifics.id()); | 196 DCHECK_EQ(change.storage_key(), specifics.id()); |
| 197 sync_entity_ids.insert(specifics.id()); |
196 | 198 |
197 // Write the update to local storage even if we already have it. | 199 // Write the update to local storage even if we already have it. |
198 StoreSpecifics(base::MakeUnique<sync_pb::PrinterSpecifics>(specifics), | 200 StoreSpecifics(base::MakeUnique<sync_pb::PrinterSpecifics>(specifics), |
199 &all_data_, batch.get()); | 201 &all_data_, batch.get()); |
200 } | 202 } |
201 | 203 |
202 // Inform the change processor of the new local entities and generate | 204 // Inform the change processor of the new local entities and generate |
203 // appropriate metadata. | 205 // appropriate metadata. |
204 for (const auto& entry : all_data_) { | 206 for (const auto& entry : all_data_) { |
205 const std::string& local_entity_id = entry.first; | 207 const std::string& local_entity_id = entry.first; |
206 if (!base::ContainsKey(entity_data_map, local_entity_id)) { | 208 if (!base::ContainsKey(sync_entity_ids, local_entity_id)) { |
207 // Only local objects which were not updated are uploaded. Objects for | 209 // Only local objects which were not updated are uploaded. Objects for |
208 // which there was a remote copy are overwritten. | 210 // which there was a remote copy are overwritten. |
209 change_processor()->Put(local_entity_id, CopyToEntityData(*entry.second), | 211 change_processor()->Put(local_entity_id, CopyToEntityData(*entry.second), |
210 metadata_change_list.get()); | 212 metadata_change_list.get()); |
211 } | 213 } |
212 } | 214 } |
213 | 215 |
214 batch->TransferMetadataChanges(std::move(metadata_change_list)); | 216 batch->TransferMetadataChanges(std::move(metadata_change_list)); |
215 store_delegate_->Commit(std::move(batch)); | 217 store_delegate_->Commit(std::move(batch)); |
216 return {}; | 218 return {}; |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 const std::string& id) const { | 351 const std::string& id) const { |
350 auto iter = all_data_.find(id); | 352 auto iter = all_data_.find(id); |
351 if (iter == all_data_.end()) { | 353 if (iter == all_data_.end()) { |
352 return {}; | 354 return {}; |
353 } | 355 } |
354 | 356 |
355 return {*iter->second}; | 357 return {*iter->second}; |
356 } | 358 } |
357 | 359 |
358 } // namespace chromeos | 360 } // namespace chromeos |
OLD | NEW |