| 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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 // Allow deletion of metadata to happen before the deletion of data below. If | 237 // Allow deletion of metadata to happen before the deletion of data below. If |
| 238 // we crash after removing metadata but not regular data, then merge can | 238 // we crash after removing metadata but not regular data, then merge can |
| 239 // handle pairing everything back up. | 239 // handle pairing everything back up. |
| 240 ModelTypeSyncBridge::DisableSync(); | 240 ModelTypeSyncBridge::DisableSync(); |
| 241 | 241 |
| 242 // Remove all local data, if sync is being disabled, the user has expressed | 242 // Remove all local data, if sync is being disabled, the user has expressed |
| 243 // their desire to not have knowledge about other devices. | 243 // their desire to not have knowledge about other devices. |
| 244 if (!all_data_.empty()) { | 244 if (!all_data_.empty()) { |
| 245 std::unique_ptr<WriteBatch> batch = store_->CreateWriteBatch(); | 245 std::unique_ptr<WriteBatch> batch = store_->CreateWriteBatch(); |
| 246 for (const auto& kv : all_data_) { | 246 for (const auto& kv : all_data_) { |
| 247 store_->DeleteData(batch.get(), kv.first); | 247 batch->DeleteData(kv.first); |
| 248 } | 248 } |
| 249 store_->CommitWriteBatch( | 249 store_->CommitWriteBatch( |
| 250 std::move(batch), | 250 std::move(batch), |
| 251 base::Bind(&DeviceInfoSyncBridge::OnCommit, base::AsWeakPtr(this))); | 251 base::Bind(&DeviceInfoSyncBridge::OnCommit, base::AsWeakPtr(this))); |
| 252 | 252 |
| 253 all_data_.clear(); | 253 all_data_.clear(); |
| 254 NotifyObservers(); | 254 NotifyObservers(); |
| 255 } | 255 } |
| 256 } | 256 } |
| 257 | 257 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 | 292 |
| 293 void DeviceInfoSyncBridge::NotifyObservers() { | 293 void DeviceInfoSyncBridge::NotifyObservers() { |
| 294 for (auto& observer : observers_) | 294 for (auto& observer : observers_) |
| 295 observer.OnDeviceInfoChange(); | 295 observer.OnDeviceInfoChange(); |
| 296 } | 296 } |
| 297 | 297 |
| 298 void DeviceInfoSyncBridge::StoreSpecifics( | 298 void DeviceInfoSyncBridge::StoreSpecifics( |
| 299 std::unique_ptr<DeviceInfoSpecifics> specifics, | 299 std::unique_ptr<DeviceInfoSpecifics> specifics, |
| 300 WriteBatch* batch) { | 300 WriteBatch* batch) { |
| 301 const std::string guid = specifics->cache_guid(); | 301 const std::string guid = specifics->cache_guid(); |
| 302 store_->WriteData(batch, guid, specifics->SerializeAsString()); | 302 batch->WriteData(guid, specifics->SerializeAsString()); |
| 303 all_data_[guid] = std::move(specifics); | 303 all_data_[guid] = std::move(specifics); |
| 304 } | 304 } |
| 305 | 305 |
| 306 bool DeviceInfoSyncBridge::DeleteSpecifics(const std::string& guid, | 306 bool DeviceInfoSyncBridge::DeleteSpecifics(const std::string& guid, |
| 307 WriteBatch* batch) { | 307 WriteBatch* batch) { |
| 308 ClientIdToSpecifics::const_iterator iter = all_data_.find(guid); | 308 ClientIdToSpecifics::const_iterator iter = all_data_.find(guid); |
| 309 if (iter != all_data_.end()) { | 309 if (iter != all_data_.end()) { |
| 310 store_->DeleteData(batch, guid); | 310 batch->DeleteData(guid); |
| 311 all_data_.erase(iter); | 311 all_data_.erase(iter); |
| 312 return true; | 312 return true; |
| 313 } else { | 313 } else { |
| 314 return false; | 314 return false; |
| 315 } | 315 } |
| 316 } | 316 } |
| 317 | 317 |
| 318 void DeviceInfoSyncBridge::OnProviderInitialized() { | 318 void DeviceInfoSyncBridge::OnProviderInitialized() { |
| 319 // Now that the provider has initialized, remove the subscription. The bridge | 319 // Now that the provider has initialized, remove the subscription. The bridge |
| 320 // should only need to give the processor metadata upon initialization. If | 320 // should only need to give the processor metadata upon initialization. If |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 } | 455 } |
| 456 | 456 |
| 457 void DeviceInfoSyncBridge::ReportStartupErrorToSync(const std::string& msg) { | 457 void DeviceInfoSyncBridge::ReportStartupErrorToSync(const std::string& msg) { |
| 458 // TODO(skym): Shouldn't need to log this here, reporting should always log. | 458 // TODO(skym): Shouldn't need to log this here, reporting should always log. |
| 459 LOG(WARNING) << msg; | 459 LOG(WARNING) << msg; |
| 460 change_processor()->OnMetadataLoaded( | 460 change_processor()->OnMetadataLoaded( |
| 461 change_processor()->CreateAndUploadError(FROM_HERE, msg), nullptr); | 461 change_processor()->CreateAndUploadError(FROM_HERE, msg), nullptr); |
| 462 } | 462 } |
| 463 | 463 |
| 464 } // namespace syncer | 464 } // namespace syncer |
| OLD | NEW |