| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 using Record = ModelTypeStore::Record; | 32 using Record = ModelTypeStore::Record; |
| 33 using RecordList = ModelTypeStore::RecordList; | 33 using RecordList = ModelTypeStore::RecordList; |
| 34 using Result = ModelTypeStore::Result; | 34 using Result = ModelTypeStore::Result; |
| 35 using WriteBatch = ModelTypeStore::WriteBatch; | 35 using WriteBatch = ModelTypeStore::WriteBatch; |
| 36 | 36 |
| 37 DeviceInfoService::DeviceInfoService( | 37 DeviceInfoService::DeviceInfoService( |
| 38 LocalDeviceInfoProvider* local_device_info_provider, | 38 LocalDeviceInfoProvider* local_device_info_provider, |
| 39 const StoreFactoryFunction& callback, | 39 const StoreFactoryFunction& callback, |
| 40 const ChangeProcessorFactory& change_processor_factory) | 40 const ChangeProcessorFactory& change_processor_factory) |
| 41 : ModelTypeService(change_processor_factory, DEVICE_INFO), | 41 : ModelTypeSyncBridge(change_processor_factory, DEVICE_INFO), |
| 42 local_device_info_provider_(local_device_info_provider) { | 42 local_device_info_provider_(local_device_info_provider) { |
| 43 DCHECK(local_device_info_provider); | 43 DCHECK(local_device_info_provider); |
| 44 | 44 |
| 45 // This is not threadsafe, but presuably the provider initializes on the same | 45 // This is not threadsafe, but presuably the provider initializes on the same |
| 46 // thread as us so we're okay. | 46 // thread as us so we're okay. |
| 47 if (local_device_info_provider->GetLocalDeviceInfo()) { | 47 if (local_device_info_provider->GetLocalDeviceInfo()) { |
| 48 OnProviderInitialized(); | 48 OnProviderInitialized(); |
| 49 } else { | 49 } else { |
| 50 subscription_ = | 50 subscription_ = |
| 51 local_device_info_provider->RegisterOnInitializedCallback(base::Bind( | 51 local_device_info_provider->RegisterOnInitializedCallback(base::Bind( |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 return entity_data.specifics.device_info().cache_guid(); | 180 return entity_data.specifics.device_info().cache_guid(); |
| 181 } | 181 } |
| 182 | 182 |
| 183 void DeviceInfoService::DisableSync() { | 183 void DeviceInfoService::DisableSync() { |
| 184 // TODO(skym, crbug.com/659263): Would it be reasonable to pulse_timer_.Stop() | 184 // TODO(skym, crbug.com/659263): Would it be reasonable to pulse_timer_.Stop() |
| 185 // or subscription_.reset() here? | 185 // or subscription_.reset() here? |
| 186 | 186 |
| 187 // Allow deletion of metadata to happen before the deletion of data below. If | 187 // Allow deletion of metadata to happen before the deletion of data below. If |
| 188 // we crash after removing metadata but not regular data, then merge can | 188 // we crash after removing metadata but not regular data, then merge can |
| 189 // handle pairing everything back up. | 189 // handle pairing everything back up. |
| 190 ModelTypeService::DisableSync(); | 190 ModelTypeSyncBridge::DisableSync(); |
| 191 | 191 |
| 192 // Remove all local data, if sync is being disabled, the user has expressed | 192 // Remove all local data, if sync is being disabled, the user has expressed |
| 193 // their desire to not have knowledge about other devices. | 193 // their desire to not have knowledge about other devices. |
| 194 if (!all_data_.empty()) { | 194 if (!all_data_.empty()) { |
| 195 std::unique_ptr<WriteBatch> batch = store_->CreateWriteBatch(); | 195 std::unique_ptr<WriteBatch> batch = store_->CreateWriteBatch(); |
| 196 for (const auto& kv : all_data_) { | 196 for (const auto& kv : all_data_) { |
| 197 store_->DeleteData(batch.get(), kv.first); | 197 store_->DeleteData(batch.get(), kv.first); |
| 198 } | 198 } |
| 199 store_->CommitWriteBatch( | 199 store_->CommitWriteBatch( |
| 200 std::move(batch), | 200 std::move(batch), |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 Time DeviceInfoService::GetLastUpdateTime( | 496 Time DeviceInfoService::GetLastUpdateTime( |
| 497 const DeviceInfoSpecifics& specifics) { | 497 const DeviceInfoSpecifics& specifics) { |
| 498 if (specifics.has_last_updated_timestamp()) { | 498 if (specifics.has_last_updated_timestamp()) { |
| 499 return ProtoTimeToTime(specifics.last_updated_timestamp()); | 499 return ProtoTimeToTime(specifics.last_updated_timestamp()); |
| 500 } else { | 500 } else { |
| 501 return Time(); | 501 return Time(); |
| 502 } | 502 } |
| 503 } | 503 } |
| 504 | 504 |
| 505 } // namespace syncer | 505 } // namespace syncer |
| OLD | NEW |