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