Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Side by Side Diff: components/sync/model/model_type_sync_bridge.cc

Issue 2923363004: [Sync] Migrate bridge implementations to change list based MergeSyncData (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/sync/model/model_type_sync_bridge.h" 5 #include "components/sync/model/model_type_sync_bridge.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "components/sync/model/metadata_batch.h" 10 #include "components/sync/model/metadata_batch.h"
11 #include "components/sync/model/metadata_change_list.h" 11 #include "components/sync/model/metadata_change_list.h"
12 12
13 namespace syncer { 13 namespace syncer {
14 14
15 ModelTypeSyncBridge::ModelTypeSyncBridge( 15 ModelTypeSyncBridge::ModelTypeSyncBridge(
16 const ChangeProcessorFactory& change_processor_factory, 16 const ChangeProcessorFactory& change_processor_factory,
17 ModelType type) 17 ModelType type)
18 : type_(type), 18 : type_(type),
19 change_processor_factory_(change_processor_factory), 19 change_processor_factory_(change_processor_factory),
20 change_processor_(change_processor_factory_.Run(type_, this)) {} 20 change_processor_(change_processor_factory_.Run(type_, this)) {}
21 21
22 ModelTypeSyncBridge::~ModelTypeSyncBridge() {} 22 ModelTypeSyncBridge::~ModelTypeSyncBridge() {}
23 23
24 base::Optional<ModelError> ModelTypeSyncBridge::MergeSyncData(
25 std::unique_ptr<MetadataChangeList> metadata_change_list,
26 EntityChangeList entity_data) {
27 EntityDataMap entity_data_map;
28 for (const auto& change : entity_data) {
29 DCHECK_EQ(EntityChange::ACTION_ADD, change.type());
30 DCHECK(!change.storage_key().empty());
31 DCHECK(entity_data_map.find(change.storage_key()) == entity_data_map.end());
32 entity_data_map.emplace(change.storage_key(), change.data_ptr());
33 }
34 return MergeSyncData(std::move(metadata_change_list), entity_data_map);
35 }
36
37 bool ModelTypeSyncBridge::SupportsGetStorageKey() const { 24 bool ModelTypeSyncBridge::SupportsGetStorageKey() const {
38 return true; 25 return true;
39 } 26 }
40 27
41 ConflictResolution ModelTypeSyncBridge::ResolveConflict( 28 ConflictResolution ModelTypeSyncBridge::ResolveConflict(
42 const EntityData& local_data, 29 const EntityData& local_data,
43 const EntityData& remote_data) const { 30 const EntityData& remote_data) const {
44 if (remote_data.is_deleted()) { 31 if (remote_data.is_deleted()) {
45 DCHECK(!local_data.is_deleted()); 32 DCHECK(!local_data.is_deleted());
46 return ConflictResolution::UseLocal(); 33 return ConflictResolution::UseLocal();
(...skipping 16 matching lines...) Expand all
63 // while the models are loading, aka before the service has finished loading 50 // while the models are loading, aka before the service has finished loading
64 // the initial metadata. 51 // the initial metadata.
65 change_processor_->ModelReadyToSync(base::MakeUnique<MetadataBatch>()); 52 change_processor_->ModelReadyToSync(base::MakeUnique<MetadataBatch>());
66 } 53 }
67 54
68 ModelTypeChangeProcessor* ModelTypeSyncBridge::change_processor() const { 55 ModelTypeChangeProcessor* ModelTypeSyncBridge::change_processor() const {
69 return change_processor_.get(); 56 return change_processor_.get();
70 } 57 }
71 58
72 } // namespace syncer 59 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/model/model_type_sync_bridge.h ('k') | components/sync/model/stub_model_type_sync_bridge.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698