| 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_service.h" | 5 #include "components/sync/device_info/device_info_service.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 } | 67 } |
| 68 | 68 |
| 69 callback.Run(base::Bind(&DeviceInfoService::OnStoreCreated, | 69 callback.Run(base::Bind(&DeviceInfoService::OnStoreCreated, |
| 70 weak_factory_.GetWeakPtr())); | 70 weak_factory_.GetWeakPtr())); |
| 71 } | 71 } |
| 72 | 72 |
| 73 DeviceInfoService::~DeviceInfoService() {} | 73 DeviceInfoService::~DeviceInfoService() {} |
| 74 | 74 |
| 75 std::unique_ptr<MetadataChangeList> | 75 std::unique_ptr<MetadataChangeList> |
| 76 DeviceInfoService::CreateMetadataChangeList() { | 76 DeviceInfoService::CreateMetadataChangeList() { |
| 77 return base::WrapUnique(new SimpleMetadataChangeList()); | 77 return base::MakeUnique<SimpleMetadataChangeList>(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 SyncError DeviceInfoService::MergeSyncData( | 80 SyncError DeviceInfoService::MergeSyncData( |
| 81 std::unique_ptr<MetadataChangeList> metadata_change_list, | 81 std::unique_ptr<MetadataChangeList> metadata_change_list, |
| 82 EntityDataMap entity_data_map) { | 82 EntityDataMap entity_data_map) { |
| 83 DCHECK(has_provider_initialized_); | 83 DCHECK(has_provider_initialized_); |
| 84 DCHECK(has_metadata_loaded_); | 84 DCHECK(has_metadata_loaded_); |
| 85 DCHECK(change_processor()); | 85 DCHECK(change_processor()); |
| 86 | 86 |
| 87 // Local data should typically be near empty, with the only possible value | 87 // Local data should typically be near empty, with the only possible value |
| (...skipping 22 matching lines...) Expand all Loading... |
| 110 } else { | 110 } else { |
| 111 // This device is valid right now and this entry is about to be | 111 // This device is valid right now and this entry is about to be |
| 112 // committed, use this as an opportunity to refresh the timestamp. | 112 // committed, use this as an opportunity to refresh the timestamp. |
| 113 all_data_[local_guid]->set_last_updated_timestamp( | 113 all_data_[local_guid]->set_last_updated_timestamp( |
| 114 syncer::TimeToProtoTime(Time::Now())); | 114 syncer::TimeToProtoTime(Time::Now())); |
| 115 } | 115 } |
| 116 } else { | 116 } else { |
| 117 // Remote data wins conflicts. | 117 // Remote data wins conflicts. |
| 118 local_guids_to_put.erase(specifics.cache_guid()); | 118 local_guids_to_put.erase(specifics.cache_guid()); |
| 119 has_changes = true; | 119 has_changes = true; |
| 120 StoreSpecifics(base::WrapUnique(new DeviceInfoSpecifics(specifics)), | 120 StoreSpecifics(base::MakeUnique<DeviceInfoSpecifics>(specifics), |
| 121 batch.get()); | 121 batch.get()); |
| 122 } | 122 } |
| 123 } | 123 } |
| 124 | 124 |
| 125 for (const std::string& guid : local_guids_to_put) { | 125 for (const std::string& guid : local_guids_to_put) { |
| 126 change_processor()->Put(guid, CopyToEntityData(*all_data_[guid]), | 126 change_processor()->Put(guid, CopyToEntityData(*all_data_[guid]), |
| 127 metadata_change_list.get()); | 127 metadata_change_list.get()); |
| 128 } | 128 } |
| 129 | 129 |
| 130 CommitAndNotify(std::move(batch), std::move(metadata_change_list), | 130 CommitAndNotify(std::move(batch), std::move(metadata_change_list), |
| (...skipping 16 matching lines...) Expand all Loading... |
| 147 if (guid == local_device_info_provider_->GetLocalDeviceInfo()->guid()) { | 147 if (guid == local_device_info_provider_->GetLocalDeviceInfo()->guid()) { |
| 148 continue; | 148 continue; |
| 149 } | 149 } |
| 150 | 150 |
| 151 if (change.type() == EntityChange::ACTION_DELETE) { | 151 if (change.type() == EntityChange::ACTION_DELETE) { |
| 152 has_changes |= DeleteSpecifics(guid, batch.get()); | 152 has_changes |= DeleteSpecifics(guid, batch.get()); |
| 153 } else { | 153 } else { |
| 154 const DeviceInfoSpecifics& specifics = | 154 const DeviceInfoSpecifics& specifics = |
| 155 change.data().specifics.device_info(); | 155 change.data().specifics.device_info(); |
| 156 DCHECK(guid == specifics.cache_guid()); | 156 DCHECK(guid == specifics.cache_guid()); |
| 157 StoreSpecifics(base::WrapUnique(new DeviceInfoSpecifics(specifics)), | 157 StoreSpecifics(base::MakeUnique<DeviceInfoSpecifics>(specifics), |
| 158 batch.get()); | 158 batch.get()); |
| 159 has_changes = true; | 159 has_changes = true; |
| 160 } | 160 } |
| 161 } | 161 } |
| 162 | 162 |
| 163 CommitAndNotify(std::move(batch), std::move(metadata_change_list), | 163 CommitAndNotify(std::move(batch), std::move(metadata_change_list), |
| 164 has_changes); | 164 has_changes); |
| 165 return SyncError(); | 165 return SyncError(); |
| 166 } | 166 } |
| 167 | 167 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 | 205 |
| 206 void DeviceInfoService::OnChangeProcessorSet() { | 206 void DeviceInfoService::OnChangeProcessorSet() { |
| 207 // We've recieved a new processor that needs metadata. If we're still in the | 207 // We've recieved a new processor that needs metadata. If we're still in the |
| 208 // process of loading data and/or metadata, then |has_metadata_loaded_| is | 208 // process of loading data and/or metadata, then |has_metadata_loaded_| is |
| 209 // false and we'll wait for those async reads to happen. If we've already | 209 // false and we'll wait for those async reads to happen. If we've already |
| 210 // loaded metadata and then subsequently we get a new processor, we must not | 210 // loaded metadata and then subsequently we get a new processor, we must not |
| 211 // have created the processor ourselves because we had no metadata. So there | 211 // have created the processor ourselves because we had no metadata. So there |
| 212 // must not be any metadata on disk. | 212 // must not be any metadata on disk. |
| 213 if (has_metadata_loaded_) { | 213 if (has_metadata_loaded_) { |
| 214 change_processor()->OnMetadataLoaded(SyncError(), | 214 change_processor()->OnMetadataLoaded(SyncError(), |
| 215 base::WrapUnique(new MetadataBatch())); | 215 base::MakeUnique<MetadataBatch>()); |
| 216 ReconcileLocalAndStored(); | 216 ReconcileLocalAndStored(); |
| 217 } | 217 } |
| 218 } | 218 } |
| 219 | 219 |
| 220 bool DeviceInfoService::IsSyncing() const { | 220 bool DeviceInfoService::IsSyncing() const { |
| 221 return !all_data_.empty(); | 221 return !all_data_.empty(); |
| 222 } | 222 } |
| 223 | 223 |
| 224 std::unique_ptr<DeviceInfo> DeviceInfoService::GetDeviceInfo( | 224 std::unique_ptr<DeviceInfo> DeviceInfoService::GetDeviceInfo( |
| 225 const std::string& client_id) const { | 225 const std::string& client_id) const { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 specifics->set_chrome_version(info.chrome_version()); | 268 specifics->set_chrome_version(info.chrome_version()); |
| 269 specifics->set_sync_user_agent(info.sync_user_agent()); | 269 specifics->set_sync_user_agent(info.sync_user_agent()); |
| 270 specifics->set_device_type(info.device_type()); | 270 specifics->set_device_type(info.device_type()); |
| 271 specifics->set_signin_scoped_device_id(info.signin_scoped_device_id()); | 271 specifics->set_signin_scoped_device_id(info.signin_scoped_device_id()); |
| 272 return specifics; | 272 return specifics; |
| 273 } | 273 } |
| 274 | 274 |
| 275 // Static. | 275 // Static. |
| 276 std::unique_ptr<DeviceInfo> DeviceInfoService::CopyToModel( | 276 std::unique_ptr<DeviceInfo> DeviceInfoService::CopyToModel( |
| 277 const DeviceInfoSpecifics& specifics) { | 277 const DeviceInfoSpecifics& specifics) { |
| 278 return base::WrapUnique(new DeviceInfo( | 278 return base::MakeUnique<DeviceInfo>( |
| 279 specifics.cache_guid(), specifics.client_name(), | 279 specifics.cache_guid(), specifics.client_name(), |
| 280 specifics.chrome_version(), specifics.sync_user_agent(), | 280 specifics.chrome_version(), specifics.sync_user_agent(), |
| 281 specifics.device_type(), specifics.signin_scoped_device_id())); | 281 specifics.device_type(), specifics.signin_scoped_device_id()); |
| 282 } | 282 } |
| 283 | 283 |
| 284 // Static. | 284 // Static. |
| 285 std::unique_ptr<EntityData> DeviceInfoService::CopyToEntityData( | 285 std::unique_ptr<EntityData> DeviceInfoService::CopyToEntityData( |
| 286 const DeviceInfoSpecifics& specifics) { | 286 const DeviceInfoSpecifics& specifics) { |
| 287 std::unique_ptr<EntityData> entity_data(new EntityData()); | 287 std::unique_ptr<EntityData> entity_data(new EntityData()); |
| 288 *entity_data->specifics.mutable_device_info() = specifics; | 288 *entity_data->specifics.mutable_device_info() = specifics; |
| 289 entity_data->non_unique_name = specifics.client_name(); | 289 entity_data->non_unique_name = specifics.client_name(); |
| 290 return entity_data; | 290 return entity_data; |
| 291 } | 291 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 void DeviceInfoService::OnReadAllData(Result result, | 335 void DeviceInfoService::OnReadAllData(Result result, |
| 336 std::unique_ptr<RecordList> record_list) { | 336 std::unique_ptr<RecordList> record_list) { |
| 337 if (result != Result::SUCCESS) { | 337 if (result != Result::SUCCESS) { |
| 338 ReportStartupErrorToSync("Initial load of data failed."); | 338 ReportStartupErrorToSync("Initial load of data failed."); |
| 339 // TODO(skym, crbug.com/582460): Handle unrecoverable initialization | 339 // TODO(skym, crbug.com/582460): Handle unrecoverable initialization |
| 340 // failure. | 340 // failure. |
| 341 return; | 341 return; |
| 342 } | 342 } |
| 343 | 343 |
| 344 for (const Record& r : *record_list.get()) { | 344 for (const Record& r : *record_list.get()) { |
| 345 std::unique_ptr<DeviceInfoSpecifics> specifics( | 345 std::unique_ptr<DeviceInfoSpecifics> specifics = |
| 346 base::WrapUnique(new DeviceInfoSpecifics())); | 346 base::MakeUnique<DeviceInfoSpecifics>(); |
| 347 if (specifics->ParseFromString(r.value)) { | 347 if (specifics->ParseFromString(r.value)) { |
| 348 all_data_[specifics->cache_guid()] = std::move(specifics); | 348 all_data_[specifics->cache_guid()] = std::move(specifics); |
| 349 } else { | 349 } else { |
| 350 ReportStartupErrorToSync("Failed to deserialize specifics."); | 350 ReportStartupErrorToSync("Failed to deserialize specifics."); |
| 351 // TODO(skym, crbug.com/582460): Handle unrecoverable initialization | 351 // TODO(skym, crbug.com/582460): Handle unrecoverable initialization |
| 352 // failure. | 352 // failure. |
| 353 } | 353 } |
| 354 } | 354 } |
| 355 | 355 |
| 356 has_data_loaded_ = true; | 356 has_data_loaded_ = true; |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 Time DeviceInfoService::GetLastUpdateTime( | 529 Time DeviceInfoService::GetLastUpdateTime( |
| 530 const DeviceInfoSpecifics& specifics) { | 530 const DeviceInfoSpecifics& specifics) { |
| 531 if (specifics.has_last_updated_timestamp()) { | 531 if (specifics.has_last_updated_timestamp()) { |
| 532 return syncer::ProtoTimeToTime(specifics.last_updated_timestamp()); | 532 return syncer::ProtoTimeToTime(specifics.last_updated_timestamp()); |
| 533 } else { | 533 } else { |
| 534 return Time(); | 534 return Time(); |
| 535 } | 535 } |
| 536 } | 536 } |
| 537 | 537 |
| 538 } // namespace sync_driver_v2 | 538 } // namespace sync_driver_v2 |
| OLD | NEW |