| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_driver/device_info_sync_service.h" | 5 #include "components/sync_driver/device_info_sync_service.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/memory/ptr_util.h" |
| 12 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 13 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 15 #include "components/sync_driver/local_device_info_provider.h" | 16 #include "components/sync_driver/local_device_info_provider.h" |
| 16 #include "sync/api/sync_change.h" | 17 #include "sync/api/sync_change.h" |
| 17 #include "sync/protocol/sync.pb.h" | 18 #include "sync/protocol/sync.pb.h" |
| 18 #include "sync/util/time.h" | 19 #include "sync/util/time.h" |
| 19 | 20 |
| 20 namespace sync_driver { | 21 namespace sync_driver { |
| 21 | 22 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 : local_device_info_provider_(local_device_info_provider) { | 71 : local_device_info_provider_(local_device_info_provider) { |
| 71 DCHECK(local_device_info_provider); | 72 DCHECK(local_device_info_provider); |
| 72 } | 73 } |
| 73 | 74 |
| 74 DeviceInfoSyncService::~DeviceInfoSyncService() { | 75 DeviceInfoSyncService::~DeviceInfoSyncService() { |
| 75 } | 76 } |
| 76 | 77 |
| 77 SyncMergeResult DeviceInfoSyncService::MergeDataAndStartSyncing( | 78 SyncMergeResult DeviceInfoSyncService::MergeDataAndStartSyncing( |
| 78 ModelType type, | 79 ModelType type, |
| 79 const SyncDataList& initial_sync_data, | 80 const SyncDataList& initial_sync_data, |
| 80 scoped_ptr<SyncChangeProcessor> sync_processor, | 81 std::unique_ptr<SyncChangeProcessor> sync_processor, |
| 81 scoped_ptr<SyncErrorFactory> error_handler) { | 82 std::unique_ptr<SyncErrorFactory> error_handler) { |
| 82 DCHECK(sync_processor.get()); | 83 DCHECK(sync_processor.get()); |
| 83 DCHECK(error_handler.get()); | 84 DCHECK(error_handler.get()); |
| 84 DCHECK_EQ(type, syncer::DEVICE_INFO); | 85 DCHECK_EQ(type, syncer::DEVICE_INFO); |
| 85 | 86 |
| 86 DCHECK(!IsSyncing()); | 87 DCHECK(!IsSyncing()); |
| 87 | 88 |
| 88 sync_processor_ = std::move(sync_processor); | 89 sync_processor_ = std::move(sync_processor); |
| 89 error_handler_ = std::move(error_handler); | 90 error_handler_ = std::move(error_handler); |
| 90 | 91 |
| 91 // Initialization should be completed before this type is enabled | 92 // Initialization should be completed before this type is enabled |
| (...skipping 14 matching lines...) Expand all Loading... |
| 106 // Iterate over all initial sync data and copy it to the cache. | 107 // Iterate over all initial sync data and copy it to the cache. |
| 107 for (SyncDataList::const_iterator iter = initial_sync_data.begin(); | 108 for (SyncDataList::const_iterator iter = initial_sync_data.begin(); |
| 108 iter != initial_sync_data.end(); | 109 iter != initial_sync_data.end(); |
| 109 ++iter) { | 110 ++iter) { |
| 110 DCHECK_EQ(syncer::DEVICE_INFO, iter->GetDataType()); | 111 DCHECK_EQ(syncer::DEVICE_INFO, iter->GetDataType()); |
| 111 | 112 |
| 112 const std::string& id = iter->GetSpecifics().device_info().cache_guid(); | 113 const std::string& id = iter->GetSpecifics().device_info().cache_guid(); |
| 113 | 114 |
| 114 if (id == local_device_info->guid()) { | 115 if (id == local_device_info->guid()) { |
| 115 // |initial_sync_data| contains data matching the local device. | 116 // |initial_sync_data| contains data matching the local device. |
| 116 scoped_ptr<DeviceInfo> synced_local_device_info = | 117 std::unique_ptr<DeviceInfo> synced_local_device_info = |
| 117 make_scoped_ptr(CreateDeviceInfo(*iter)); | 118 base::WrapUnique(CreateDeviceInfo(*iter)); |
| 118 | 119 |
| 119 // TODO(pavely): Remove histogram once device_id mismatch is understood | 120 // TODO(pavely): Remove histogram once device_id mismatch is understood |
| 120 // (crbug/481596). | 121 // (crbug/481596). |
| 121 if (synced_local_device_info->signin_scoped_device_id() != | 122 if (synced_local_device_info->signin_scoped_device_id() != |
| 122 local_device_info->signin_scoped_device_id()) { | 123 local_device_info->signin_scoped_device_id()) { |
| 123 RecordDeviceIdChangedHistogram( | 124 RecordDeviceIdChangedHistogram( |
| 124 synced_local_device_info->signin_scoped_device_id(), | 125 synced_local_device_info->signin_scoped_device_id(), |
| 125 local_device_info->signin_scoped_device_id()); | 126 local_device_info->signin_scoped_device_id()); |
| 126 } | 127 } |
| 127 | 128 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 } | 241 } |
| 241 } | 242 } |
| 242 | 243 |
| 243 if (has_changes) { | 244 if (has_changes) { |
| 244 NotifyObservers(); | 245 NotifyObservers(); |
| 245 } | 246 } |
| 246 | 247 |
| 247 return error; | 248 return error; |
| 248 } | 249 } |
| 249 | 250 |
| 250 scoped_ptr<DeviceInfo> DeviceInfoSyncService::GetDeviceInfo( | 251 std::unique_ptr<DeviceInfo> DeviceInfoSyncService::GetDeviceInfo( |
| 251 const std::string& client_id) const { | 252 const std::string& client_id) const { |
| 252 SyncDataMap::const_iterator iter = all_data_.find(client_id); | 253 SyncDataMap::const_iterator iter = all_data_.find(client_id); |
| 253 if (iter == all_data_.end()) { | 254 if (iter == all_data_.end()) { |
| 254 return scoped_ptr<DeviceInfo>(); | 255 return std::unique_ptr<DeviceInfo>(); |
| 255 } | 256 } |
| 256 | 257 |
| 257 return make_scoped_ptr(CreateDeviceInfo(iter->second)); | 258 return base::WrapUnique(CreateDeviceInfo(iter->second)); |
| 258 } | 259 } |
| 259 | 260 |
| 260 ScopedVector<DeviceInfo> DeviceInfoSyncService::GetAllDeviceInfo() const { | 261 ScopedVector<DeviceInfo> DeviceInfoSyncService::GetAllDeviceInfo() const { |
| 261 ScopedVector<DeviceInfo> list; | 262 ScopedVector<DeviceInfo> list; |
| 262 | 263 |
| 263 for (SyncDataMap::const_iterator iter = all_data_.begin(); | 264 for (SyncDataMap::const_iterator iter = all_data_.begin(); |
| 264 iter != all_data_.end(); | 265 iter != all_data_.end(); |
| 265 ++iter) { | 266 ++iter) { |
| 266 list.push_back(CreateDeviceInfo(iter->second)); | 267 list.push_back(CreateDeviceInfo(iter->second)); |
| 267 } | 268 } |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 for (const auto& pair : all_data_) { | 400 for (const auto& pair : all_data_) { |
| 400 const TimeDelta age = GetLastUpdateAge(pair.second, now); | 401 const TimeDelta age = GetLastUpdateAge(pair.second, now); |
| 401 if (age < kStaleDeviceInfoThreshold) { | 402 if (age < kStaleDeviceInfoThreshold) { |
| 402 count++; | 403 count++; |
| 403 } | 404 } |
| 404 } | 405 } |
| 405 return count; | 406 return count; |
| 406 } | 407 } |
| 407 | 408 |
| 408 } // namespace sync_driver | 409 } // namespace sync_driver |
| OLD | NEW |