| 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/memory/ptr_util.h" |
| 13 #include "base/metrics/histogram_macros.h" | |
| 14 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 15 #include "components/sync_driver/device_info_util.h" | 14 #include "components/sync_driver/device_info_util.h" |
| 16 #include "components/sync_driver/local_device_info_provider.h" | 15 #include "components/sync_driver/local_device_info_provider.h" |
| 17 #include "sync/api/sync_change.h" | 16 #include "sync/api/sync_change.h" |
| 18 #include "sync/protocol/sync.pb.h" | 17 #include "sync/protocol/sync.pb.h" |
| 19 #include "sync/util/time.h" | 18 #include "sync/util/time.h" |
| 20 | 19 |
| 21 namespace sync_driver { | 20 namespace sync_driver { |
| 22 | 21 |
| 23 using base::Time; | 22 using base::Time; |
| 24 using base::TimeDelta; | 23 using base::TimeDelta; |
| 25 using syncer::ModelType; | 24 using syncer::ModelType; |
| 26 using syncer::SyncChange; | 25 using syncer::SyncChange; |
| 27 using syncer::SyncChangeList; | 26 using syncer::SyncChangeList; |
| 28 using syncer::SyncChangeProcessor; | 27 using syncer::SyncChangeProcessor; |
| 29 using syncer::SyncData; | 28 using syncer::SyncData; |
| 30 using syncer::SyncDataList; | 29 using syncer::SyncDataList; |
| 31 using syncer::SyncErrorFactory; | 30 using syncer::SyncErrorFactory; |
| 32 using syncer::SyncMergeResult; | 31 using syncer::SyncMergeResult; |
| 33 | 32 |
| 34 namespace { | |
| 35 | |
| 36 // TODO(pavely): Remove histogram once device_id mismatch is understood | |
| 37 // (crbug/481596). | |
| 38 // When signin_scoped_device_id from pref doesn't match the one in | |
| 39 // DeviceInfoSpecfics record histogram telling if sync or pref copy was empty. | |
| 40 // This will indicate how often such mismatch happens and what was the state | |
| 41 // before. | |
| 42 enum DeviceIdMismatchForHistogram { | |
| 43 DEVICE_ID_MISMATCH_BOTH_NONEMPTY = 0, | |
| 44 DEVICE_ID_MISMATCH_SYNC_EMPTY, | |
| 45 DEVICE_ID_MISMATCH_PREF_EMPTY, | |
| 46 DEVICE_ID_MISMATCH_COUNT, | |
| 47 }; | |
| 48 | |
| 49 void RecordDeviceIdChangedHistogram(const std::string& device_id_from_sync, | |
| 50 const std::string& device_id_from_pref) { | |
| 51 DCHECK(device_id_from_sync != device_id_from_pref); | |
| 52 DeviceIdMismatchForHistogram device_id_mismatch_for_histogram = | |
| 53 DEVICE_ID_MISMATCH_BOTH_NONEMPTY; | |
| 54 if (device_id_from_sync.empty()) { | |
| 55 device_id_mismatch_for_histogram = DEVICE_ID_MISMATCH_SYNC_EMPTY; | |
| 56 } else if (device_id_from_pref.empty()) { | |
| 57 device_id_mismatch_for_histogram = DEVICE_ID_MISMATCH_PREF_EMPTY; | |
| 58 } | |
| 59 UMA_HISTOGRAM_ENUMERATION("Sync.DeviceIdMismatchDetails", | |
| 60 device_id_mismatch_for_histogram, | |
| 61 DEVICE_ID_MISMATCH_COUNT); | |
| 62 } | |
| 63 | |
| 64 } // namespace | |
| 65 | |
| 66 DeviceInfoSyncService::DeviceInfoSyncService( | 33 DeviceInfoSyncService::DeviceInfoSyncService( |
| 67 LocalDeviceInfoProvider* local_device_info_provider) | 34 LocalDeviceInfoProvider* local_device_info_provider) |
| 68 : local_device_info_provider_(local_device_info_provider) { | 35 : local_device_info_provider_(local_device_info_provider) { |
| 69 DCHECK(local_device_info_provider); | 36 DCHECK(local_device_info_provider); |
| 70 } | 37 } |
| 71 | 38 |
| 72 DeviceInfoSyncService::~DeviceInfoSyncService() { | 39 DeviceInfoSyncService::~DeviceInfoSyncService() { |
| 73 } | 40 } |
| 74 | 41 |
| 75 SyncMergeResult DeviceInfoSyncService::MergeDataAndStartSyncing( | 42 SyncMergeResult DeviceInfoSyncService::MergeDataAndStartSyncing( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 ++iter) { | 74 ++iter) { |
| 108 DCHECK_EQ(syncer::DEVICE_INFO, iter->GetDataType()); | 75 DCHECK_EQ(syncer::DEVICE_INFO, iter->GetDataType()); |
| 109 | 76 |
| 110 const std::string& id = iter->GetSpecifics().device_info().cache_guid(); | 77 const std::string& id = iter->GetSpecifics().device_info().cache_guid(); |
| 111 | 78 |
| 112 if (id == local_device_info->guid()) { | 79 if (id == local_device_info->guid()) { |
| 113 // |initial_sync_data| contains data matching the local device. | 80 // |initial_sync_data| contains data matching the local device. |
| 114 std::unique_ptr<DeviceInfo> synced_local_device_info = | 81 std::unique_ptr<DeviceInfo> synced_local_device_info = |
| 115 base::WrapUnique(CreateDeviceInfo(*iter)); | 82 base::WrapUnique(CreateDeviceInfo(*iter)); |
| 116 | 83 |
| 117 // TODO(pavely): Remove histogram once device_id mismatch is understood | |
| 118 // (crbug/481596). | |
| 119 if (synced_local_device_info->signin_scoped_device_id() != | |
| 120 local_device_info->signin_scoped_device_id()) { | |
| 121 RecordDeviceIdChangedHistogram( | |
| 122 synced_local_device_info->signin_scoped_device_id(), | |
| 123 local_device_info->signin_scoped_device_id()); | |
| 124 } | |
| 125 | |
| 126 pulse_delay = DeviceInfoUtil::CalculatePulseDelay( | 84 pulse_delay = DeviceInfoUtil::CalculatePulseDelay( |
| 127 GetLastUpdateTime(*iter), Time::Now()); | 85 GetLastUpdateTime(*iter), Time::Now()); |
| 128 // Store the synced device info for the local device only if | 86 // Store the synced device info for the local device only if |
| 129 // it is the same as the local info. Otherwise store the local | 87 // it is the same as the local info. Otherwise store the local |
| 130 // device info and issue a change further below after finishing | 88 // device info and issue a change further below after finishing |
| 131 // processing the |initial_sync_data|. | 89 // processing the |initial_sync_data|. |
| 132 if (synced_local_device_info->Equals(*local_device_info) && | 90 if (synced_local_device_info->Equals(*local_device_info) && |
| 133 !pulse_delay.is_zero()) { | 91 !pulse_delay.is_zero()) { |
| 134 change_type = SyncChange::ACTION_INVALID; | 92 change_type = SyncChange::ACTION_INVALID; |
| 135 } else { | 93 } else { |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 return syncer::SyncDataRemote(device_info).GetModifiedTime(); | 333 return syncer::SyncDataRemote(device_info).GetModifiedTime(); |
| 376 } else { | 334 } else { |
| 377 // We shouldn't reach this point for remote data, so this means we're likely | 335 // We shouldn't reach this point for remote data, so this means we're likely |
| 378 // looking at the local device info. Using a long ago time is perfect, since | 336 // looking at the local device info. Using a long ago time is perfect, since |
| 379 // the desired behavior is to update/pulse our data as soon as possible. | 337 // the desired behavior is to update/pulse our data as soon as possible. |
| 380 return Time(); | 338 return Time(); |
| 381 } | 339 } |
| 382 } | 340 } |
| 383 | 341 |
| 384 } // namespace sync_driver | 342 } // namespace sync_driver |
| OLD | NEW |