Chromium Code Reviews| 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 "base/metrics/histogram.h" | |
| 7 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 8 #include "components/sync_driver/local_device_info_provider.h" | 9 #include "components/sync_driver/local_device_info_provider.h" |
| 9 #include "sync/api/sync_change.h" | 10 #include "sync/api/sync_change.h" |
| 10 #include "sync/protocol/sync.pb.h" | 11 #include "sync/protocol/sync.pb.h" |
| 11 #include "sync/util/time.h" | 12 #include "sync/util/time.h" |
| 12 | 13 |
| 13 namespace sync_driver { | 14 namespace sync_driver { |
| 14 | 15 |
| 15 using syncer::ModelType; | 16 using syncer::ModelType; |
| 16 using syncer::SyncChange; | 17 using syncer::SyncChange; |
| 17 using syncer::SyncChangeList; | 18 using syncer::SyncChangeList; |
| 18 using syncer::SyncChangeProcessor; | 19 using syncer::SyncChangeProcessor; |
| 19 using syncer::SyncData; | 20 using syncer::SyncData; |
| 20 using syncer::SyncDataList; | 21 using syncer::SyncDataList; |
| 21 using syncer::SyncErrorFactory; | 22 using syncer::SyncErrorFactory; |
| 22 using syncer::SyncMergeResult; | 23 using syncer::SyncMergeResult; |
| 23 | 24 |
| 25 namespace { | |
| 26 | |
| 27 // TODO(pavely): Remove histogram once device_id mismatch is understood. | |
|
stanisc
2015/04/24 23:05:40
Perhaps mention the crbug here.
pavely
2015/04/27 18:40:35
Done.
| |
| 28 // When signin_scoped_device_id from pref doesn't match the one in | |
| 29 // DeviceInfoSpecfics record histogram telling if sync or pref copy was empty. | |
| 30 // This will indicate how often such mismatch happens and what was the state | |
| 31 // before. | |
| 32 enum DeviceIdMismatchForHistogram { | |
| 33 DEVICE_ID_MISMATCH_BOTH_NONEMPTY = 0, | |
| 34 DEVICE_ID_MISMATCH_SYNC_EMPTY, | |
| 35 DEVICE_ID_MISMATCH_PREF_EMPTY, | |
| 36 DEVICE_ID_MISMATCH_COUNT, | |
| 37 }; | |
| 38 | |
| 39 void RecordDeviceIdChangedHistogram(const std::string& device_id_from_sync, | |
| 40 const std::string& device_id_from_pref) { | |
| 41 DCHECK(device_id_from_sync != device_id_from_pref); | |
| 42 DeviceIdMismatchForHistogram device_id_mismatch_for_histogram = | |
| 43 DEVICE_ID_MISMATCH_BOTH_NONEMPTY; | |
| 44 if (device_id_from_sync.empty()) { | |
| 45 device_id_mismatch_for_histogram = DEVICE_ID_MISMATCH_SYNC_EMPTY; | |
| 46 } else if (device_id_from_pref.empty()) { | |
| 47 device_id_mismatch_for_histogram = DEVICE_ID_MISMATCH_PREF_EMPTY; | |
| 48 } | |
| 49 UMA_HISTOGRAM_ENUMERATION("Sync.DeviceIdMismatchDetails", | |
| 50 device_id_mismatch_for_histogram, | |
| 51 DEVICE_ID_MISMATCH_COUNT); | |
| 52 } | |
| 53 | |
| 54 } // namespace | |
| 55 | |
| 24 DeviceInfoSyncService::DeviceInfoSyncService( | 56 DeviceInfoSyncService::DeviceInfoSyncService( |
| 25 LocalDeviceInfoProvider* local_device_info_provider) | 57 LocalDeviceInfoProvider* local_device_info_provider) |
| 26 : local_device_backup_time_(-1), | 58 : local_device_backup_time_(-1), |
| 27 local_device_info_provider_(local_device_info_provider) { | 59 local_device_info_provider_(local_device_info_provider) { |
| 28 DCHECK(local_device_info_provider); | 60 DCHECK(local_device_info_provider); |
| 29 } | 61 } |
| 30 | 62 |
| 31 DeviceInfoSyncService::~DeviceInfoSyncService() { | 63 DeviceInfoSyncService::~DeviceInfoSyncService() { |
| 32 } | 64 } |
| 33 | 65 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 int64 synced_backup_time = | 110 int64 synced_backup_time = |
| 79 has_synced_backup_time | 111 has_synced_backup_time |
| 80 ? iter->GetSpecifics().device_info().backup_timestamp() | 112 ? iter->GetSpecifics().device_info().backup_timestamp() |
| 81 : -1; | 113 : -1; |
| 82 | 114 |
| 83 // Overwrite |local_device_backup_time_| with this value if it | 115 // Overwrite |local_device_backup_time_| with this value if it |
| 84 // hasn't been set yet. | 116 // hasn't been set yet. |
| 85 if (!has_local_device_backup_time() && has_synced_backup_time) { | 117 if (!has_local_device_backup_time() && has_synced_backup_time) { |
| 86 set_local_device_backup_time(synced_backup_time); | 118 set_local_device_backup_time(synced_backup_time); |
| 87 } | 119 } |
| 120 // TODO(pavely): Remove histogram once device_id mismatch is understood. | |
| 121 if (synced_local_device_info->signin_scoped_device_id() != | |
| 122 local_device_info->signin_scoped_device_id()) { | |
| 123 RecordDeviceIdChangedHistogram( | |
| 124 synced_local_device_info->signin_scoped_device_id(), | |
| 125 local_device_info->signin_scoped_device_id()); | |
| 126 } | |
| 88 | 127 |
| 89 // Store the synced device info for the local device only | 128 // Store the synced device info for the local device only |
| 90 // it is the same as the local info. Otherwise store the local | 129 // it is the same as the local info. Otherwise store the local |
| 91 // device info and issue a change further below after finishing | 130 // device info and issue a change further below after finishing |
| 92 // processing the |initial_sync_data|. | 131 // processing the |initial_sync_data|. |
| 93 if (synced_local_device_info->Equals(*local_device_info) && | 132 if (synced_local_device_info->Equals(*local_device_info) && |
| 94 synced_backup_time == local_device_backup_time()) { | 133 synced_backup_time == local_device_backup_time()) { |
| 95 change_type = SyncChange::ACTION_INVALID; | 134 change_type = SyncChange::ACTION_INVALID; |
| 96 } else { | 135 } else { |
| 97 num_items_updated++; | 136 num_items_updated++; |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 SyncDataMap::iterator iter = all_data_.find(client_id); | 383 SyncDataMap::iterator iter = all_data_.find(client_id); |
| 345 if (iter != all_data_.end()) { | 384 if (iter != all_data_.end()) { |
| 346 DVLOG(1) << "Deleting DEVICE_INFO for " | 385 DVLOG(1) << "Deleting DEVICE_INFO for " |
| 347 << iter->second.GetSpecifics().device_info().client_name() | 386 << iter->second.GetSpecifics().device_info().client_name() |
| 348 << " with ID " << client_id; | 387 << " with ID " << client_id; |
| 349 all_data_.erase(iter); | 388 all_data_.erase(iter); |
| 350 } | 389 } |
| 351 } | 390 } |
| 352 | 391 |
| 353 } // namespace sync_driver | 392 } // namespace sync_driver |
| OLD | NEW |