| OLD | NEW |
| 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/device_info/device_info_sync_bridge.h" | 5 #include "components/sync/device_info/device_info_sync_bridge.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 | 107 |
| 108 DeviceInfoSyncBridge::~DeviceInfoSyncBridge() {} | 108 DeviceInfoSyncBridge::~DeviceInfoSyncBridge() {} |
| 109 | 109 |
| 110 std::unique_ptr<MetadataChangeList> | 110 std::unique_ptr<MetadataChangeList> |
| 111 DeviceInfoSyncBridge::CreateMetadataChangeList() { | 111 DeviceInfoSyncBridge::CreateMetadataChangeList() { |
| 112 return WriteBatch::CreateMetadataChangeList(); | 112 return WriteBatch::CreateMetadataChangeList(); |
| 113 } | 113 } |
| 114 | 114 |
| 115 base::Optional<ModelError> DeviceInfoSyncBridge::MergeSyncData( | 115 base::Optional<ModelError> DeviceInfoSyncBridge::MergeSyncData( |
| 116 std::unique_ptr<MetadataChangeList> metadata_change_list, | 116 std::unique_ptr<MetadataChangeList> metadata_change_list, |
| 117 EntityDataMap entity_data_map) { | 117 EntityChangeList entity_data) { |
| 118 DCHECK(has_provider_initialized_); | 118 DCHECK(has_provider_initialized_); |
| 119 DCHECK(change_processor()->IsTrackingMetadata()); | 119 DCHECK(change_processor()->IsTrackingMetadata()); |
| 120 const DeviceInfo* local_info = | 120 const DeviceInfo* local_info = |
| 121 local_device_info_provider_->GetLocalDeviceInfo(); | 121 local_device_info_provider_->GetLocalDeviceInfo(); |
| 122 // If our dependency was yanked out from beneath us, we cannot correctly | 122 // If our dependency was yanked out from beneath us, we cannot correctly |
| 123 // handle this request, and all our data will be deleted soon. | 123 // handle this request, and all our data will be deleted soon. |
| 124 if (local_info == nullptr) { | 124 if (local_info == nullptr) { |
| 125 return {}; | 125 return {}; |
| 126 } | 126 } |
| 127 | 127 |
| 128 // Local data should typically be near empty, with the only possible value | 128 // Local data should typically be near empty, with the only possible value |
| 129 // corresponding to this device. This is because on signout all device info | 129 // corresponding to this device. This is because on signout all device info |
| 130 // data is blown away. However, this simplification is being ignored here and | 130 // data is blown away. However, this simplification is being ignored here and |
| 131 // a full difference is going to be calculated to explore what other bridge | 131 // a full difference is going to be calculated to explore what other bridge |
| 132 // implementations may look like. | 132 // implementations may look like. |
| 133 std::set<std::string> local_guids_to_put; | 133 std::set<std::string> local_guids_to_put; |
| 134 for (const auto& kv : all_data_) { | 134 for (const auto& kv : all_data_) { |
| 135 local_guids_to_put.insert(kv.first); | 135 local_guids_to_put.insert(kv.first); |
| 136 } | 136 } |
| 137 | 137 |
| 138 bool has_changes = false; | 138 bool has_changes = false; |
| 139 std::string local_guid = local_info->guid(); | 139 std::string local_guid = local_info->guid(); |
| 140 std::unique_ptr<WriteBatch> batch = store_->CreateWriteBatch(); | 140 std::unique_ptr<WriteBatch> batch = store_->CreateWriteBatch(); |
| 141 for (const auto& kv : entity_data_map) { | 141 for (const auto& change : entity_data) { |
| 142 const DeviceInfoSpecifics& specifics = | 142 const DeviceInfoSpecifics& specifics = |
| 143 kv.second.value().specifics.device_info(); | 143 change.data().specifics.device_info(); |
| 144 DCHECK_EQ(kv.first, specifics.cache_guid()); | 144 DCHECK_EQ(change.storage_key(), specifics.cache_guid()); |
| 145 if (specifics.cache_guid() == local_guid) { | 145 if (specifics.cache_guid() == local_guid) { |
| 146 // Don't Put local data if it's the same as the remote copy. | 146 // Don't Put local data if it's the same as the remote copy. |
| 147 if (local_info->Equals(*SpecificsToModel(specifics))) { | 147 if (local_info->Equals(*SpecificsToModel(specifics))) { |
| 148 local_guids_to_put.erase(local_guid); | 148 local_guids_to_put.erase(local_guid); |
| 149 } | 149 } |
| 150 } else { | 150 } else { |
| 151 // Remote data wins conflicts. | 151 // Remote data wins conflicts. |
| 152 local_guids_to_put.erase(specifics.cache_guid()); | 152 local_guids_to_put.erase(specifics.cache_guid()); |
| 153 has_changes = true; | 153 has_changes = true; |
| 154 StoreSpecifics(base::MakeUnique<DeviceInfoSpecifics>(specifics), | 154 StoreSpecifics(base::MakeUnique<DeviceInfoSpecifics>(specifics), |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 | 472 |
| 473 int DeviceInfoSyncBridge::CountActiveDevices(const Time now) const { | 473 int DeviceInfoSyncBridge::CountActiveDevices(const Time now) const { |
| 474 return std::count_if(all_data_.begin(), all_data_.end(), | 474 return std::count_if(all_data_.begin(), all_data_.end(), |
| 475 [now](ClientIdToSpecifics::const_reference pair) { | 475 [now](ClientIdToSpecifics::const_reference pair) { |
| 476 return DeviceInfoUtil::IsActive( | 476 return DeviceInfoUtil::IsActive( |
| 477 GetLastUpdateTime(*pair.second), now); | 477 GetLastUpdateTime(*pair.second), now); |
| 478 }); | 478 }); |
| 479 } | 479 } |
| 480 | 480 |
| 481 } // namespace syncer | 481 } // namespace syncer |
| OLD | NEW |