| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/sync/core_impl/debug_info_event_listener.h" | |
| 6 | |
| 7 #include <stddef.h> | |
| 8 | |
| 9 #include "components/sync/base/cryptographer.h" | |
| 10 | |
| 11 namespace syncer { | |
| 12 | |
| 13 DebugInfoEventListener::DebugInfoEventListener() | |
| 14 : events_dropped_(false), | |
| 15 cryptographer_has_pending_keys_(false), | |
| 16 cryptographer_ready_(false), | |
| 17 weak_ptr_factory_(this) {} | |
| 18 | |
| 19 DebugInfoEventListener::~DebugInfoEventListener() {} | |
| 20 | |
| 21 void DebugInfoEventListener::OnSyncCycleCompleted( | |
| 22 const SyncCycleSnapshot& snapshot) { | |
| 23 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 24 sync_pb::DebugEventInfo event_info; | |
| 25 sync_pb::SyncCycleCompletedEventInfo* sync_completed_event_info = | |
| 26 event_info.mutable_sync_cycle_completed_event_info(); | |
| 27 | |
| 28 sync_completed_event_info->set_num_encryption_conflicts( | |
| 29 snapshot.num_encryption_conflicts()); | |
| 30 sync_completed_event_info->set_num_hierarchy_conflicts( | |
| 31 snapshot.num_hierarchy_conflicts()); | |
| 32 sync_completed_event_info->set_num_server_conflicts( | |
| 33 snapshot.num_server_conflicts()); | |
| 34 | |
| 35 sync_completed_event_info->set_num_updates_downloaded( | |
| 36 snapshot.model_neutral_state().num_updates_downloaded_total); | |
| 37 sync_completed_event_info->set_num_reflected_updates_downloaded( | |
| 38 snapshot.model_neutral_state().num_reflected_updates_downloaded_total); | |
| 39 sync_completed_event_info->mutable_caller_info()->set_source( | |
| 40 snapshot.legacy_updates_source()); | |
| 41 sync_completed_event_info->mutable_caller_info()->set_notifications_enabled( | |
| 42 snapshot.notifications_enabled()); | |
| 43 | |
| 44 AddEventToQueue(event_info); | |
| 45 } | |
| 46 | |
| 47 void DebugInfoEventListener::OnInitializationComplete( | |
| 48 const WeakHandle<JsBackend>& js_backend, | |
| 49 const WeakHandle<DataTypeDebugInfoListener>& debug_listener, | |
| 50 bool success, | |
| 51 ModelTypeSet restored_types) { | |
| 52 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 53 CreateAndAddEvent(sync_pb::SyncEnums::INITIALIZATION_COMPLETE); | |
| 54 } | |
| 55 | |
| 56 void DebugInfoEventListener::OnConnectionStatusChange(ConnectionStatus status) { | |
| 57 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 58 CreateAndAddEvent(sync_pb::SyncEnums::CONNECTION_STATUS_CHANGE); | |
| 59 } | |
| 60 | |
| 61 void DebugInfoEventListener::OnPassphraseRequired( | |
| 62 PassphraseRequiredReason reason, | |
| 63 const sync_pb::EncryptedData& pending_keys) { | |
| 64 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 65 CreateAndAddEvent(sync_pb::SyncEnums::PASSPHRASE_REQUIRED); | |
| 66 } | |
| 67 | |
| 68 void DebugInfoEventListener::OnPassphraseAccepted() { | |
| 69 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 70 CreateAndAddEvent(sync_pb::SyncEnums::PASSPHRASE_ACCEPTED); | |
| 71 } | |
| 72 | |
| 73 void DebugInfoEventListener::OnBootstrapTokenUpdated( | |
| 74 const std::string& bootstrap_token, | |
| 75 BootstrapTokenType type) { | |
| 76 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 77 if (type == PASSPHRASE_BOOTSTRAP_TOKEN) { | |
| 78 CreateAndAddEvent(sync_pb::SyncEnums::BOOTSTRAP_TOKEN_UPDATED); | |
| 79 return; | |
| 80 } | |
| 81 DCHECK_EQ(type, KEYSTORE_BOOTSTRAP_TOKEN); | |
| 82 CreateAndAddEvent(sync_pb::SyncEnums::KEYSTORE_TOKEN_UPDATED); | |
| 83 } | |
| 84 | |
| 85 void DebugInfoEventListener::OnEncryptedTypesChanged( | |
| 86 ModelTypeSet encrypted_types, | |
| 87 bool encrypt_everything) { | |
| 88 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 89 CreateAndAddEvent(sync_pb::SyncEnums::ENCRYPTED_TYPES_CHANGED); | |
| 90 } | |
| 91 | |
| 92 void DebugInfoEventListener::OnEncryptionComplete() { | |
| 93 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 94 CreateAndAddEvent(sync_pb::SyncEnums::ENCRYPTION_COMPLETE); | |
| 95 } | |
| 96 | |
| 97 void DebugInfoEventListener::OnCryptographerStateChanged( | |
| 98 Cryptographer* cryptographer) { | |
| 99 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 100 cryptographer_has_pending_keys_ = cryptographer->has_pending_keys(); | |
| 101 cryptographer_ready_ = cryptographer->is_ready(); | |
| 102 } | |
| 103 | |
| 104 void DebugInfoEventListener::OnPassphraseTypeChanged( | |
| 105 PassphraseType type, | |
| 106 base::Time explicit_passphrase_time) { | |
| 107 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 108 CreateAndAddEvent(sync_pb::SyncEnums::PASSPHRASE_TYPE_CHANGED); | |
| 109 } | |
| 110 | |
| 111 void DebugInfoEventListener::OnLocalSetPassphraseEncryption( | |
| 112 const SyncEncryptionHandler::NigoriState& nigori_state) {} | |
| 113 | |
| 114 void DebugInfoEventListener::OnActionableError( | |
| 115 const SyncProtocolError& sync_error) { | |
| 116 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 117 CreateAndAddEvent(sync_pb::SyncEnums::ACTIONABLE_ERROR); | |
| 118 } | |
| 119 | |
| 120 void DebugInfoEventListener::OnMigrationRequested(ModelTypeSet types) {} | |
| 121 | |
| 122 void DebugInfoEventListener::OnProtocolEvent(const ProtocolEvent& event) {} | |
| 123 | |
| 124 void DebugInfoEventListener::OnNudgeFromDatatype(ModelType datatype) { | |
| 125 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 126 sync_pb::DebugEventInfo event_info; | |
| 127 event_info.set_nudging_datatype( | |
| 128 GetSpecificsFieldNumberFromModelType(datatype)); | |
| 129 AddEventToQueue(event_info); | |
| 130 } | |
| 131 | |
| 132 void DebugInfoEventListener::GetDebugInfo(sync_pb::DebugInfo* debug_info) { | |
| 133 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 134 DCHECK_LE(events_.size(), kMaxEntries); | |
| 135 | |
| 136 for (DebugEventInfoQueue::const_iterator iter = events_.begin(); | |
| 137 iter != events_.end(); ++iter) { | |
| 138 sync_pb::DebugEventInfo* event_info = debug_info->add_events(); | |
| 139 event_info->CopyFrom(*iter); | |
| 140 } | |
| 141 | |
| 142 debug_info->set_events_dropped(events_dropped_); | |
| 143 debug_info->set_cryptographer_ready(cryptographer_ready_); | |
| 144 debug_info->set_cryptographer_has_pending_keys( | |
| 145 cryptographer_has_pending_keys_); | |
| 146 } | |
| 147 | |
| 148 void DebugInfoEventListener::ClearDebugInfo() { | |
| 149 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 150 DCHECK_LE(events_.size(), kMaxEntries); | |
| 151 | |
| 152 events_.clear(); | |
| 153 events_dropped_ = false; | |
| 154 } | |
| 155 | |
| 156 base::WeakPtr<DataTypeDebugInfoListener> DebugInfoEventListener::GetWeakPtr() { | |
| 157 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 158 return weak_ptr_factory_.GetWeakPtr(); | |
| 159 } | |
| 160 | |
| 161 void DebugInfoEventListener::OnDataTypeConfigureComplete( | |
| 162 const std::vector<DataTypeConfigurationStats>& configuration_stats) { | |
| 163 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 164 | |
| 165 for (size_t i = 0; i < configuration_stats.size(); ++i) { | |
| 166 DCHECK(ProtocolTypes().Has(configuration_stats[i].model_type)); | |
| 167 const DataTypeAssociationStats& association_stats = | |
| 168 configuration_stats[i].association_stats; | |
| 169 | |
| 170 sync_pb::DebugEventInfo association_event; | |
| 171 sync_pb::DatatypeAssociationStats* datatype_stats = | |
| 172 association_event.mutable_datatype_association_stats(); | |
| 173 datatype_stats->set_data_type_id(GetSpecificsFieldNumberFromModelType( | |
| 174 configuration_stats[i].model_type)); | |
| 175 datatype_stats->set_num_local_items_before_association( | |
| 176 association_stats.num_local_items_before_association); | |
| 177 datatype_stats->set_num_sync_items_before_association( | |
| 178 association_stats.num_sync_items_before_association); | |
| 179 datatype_stats->set_num_local_items_after_association( | |
| 180 association_stats.num_local_items_after_association); | |
| 181 datatype_stats->set_num_sync_items_after_association( | |
| 182 association_stats.num_sync_items_after_association); | |
| 183 datatype_stats->set_num_local_items_added( | |
| 184 association_stats.num_local_items_added); | |
| 185 datatype_stats->set_num_local_items_deleted( | |
| 186 association_stats.num_local_items_deleted); | |
| 187 datatype_stats->set_num_local_items_modified( | |
| 188 association_stats.num_local_items_modified); | |
| 189 datatype_stats->set_num_sync_items_added( | |
| 190 association_stats.num_sync_items_added); | |
| 191 datatype_stats->set_num_sync_items_deleted( | |
| 192 association_stats.num_sync_items_deleted); | |
| 193 datatype_stats->set_num_sync_items_modified( | |
| 194 association_stats.num_sync_items_modified); | |
| 195 datatype_stats->set_local_version_pre_association( | |
| 196 association_stats.local_version_pre_association); | |
| 197 datatype_stats->set_sync_version_pre_association( | |
| 198 association_stats.sync_version_pre_association); | |
| 199 datatype_stats->set_had_error(association_stats.had_error); | |
| 200 datatype_stats->set_association_wait_time_for_same_priority_us( | |
| 201 association_stats.association_wait_time.InMicroseconds()); | |
| 202 datatype_stats->set_association_time_us( | |
| 203 association_stats.association_time.InMicroseconds()); | |
| 204 datatype_stats->set_download_wait_time_us( | |
| 205 configuration_stats[i].download_wait_time.InMicroseconds()); | |
| 206 datatype_stats->set_download_time_us( | |
| 207 configuration_stats[i].download_time.InMicroseconds()); | |
| 208 datatype_stats->set_association_wait_time_for_high_priority_us( | |
| 209 configuration_stats[i] | |
| 210 .association_wait_time_for_high_priority.InMicroseconds()); | |
| 211 | |
| 212 for (ModelTypeSet::Iterator it = | |
| 213 configuration_stats[i] | |
| 214 .high_priority_types_configured_before.First(); | |
| 215 it.Good(); it.Inc()) { | |
| 216 datatype_stats->add_high_priority_type_configured_before( | |
| 217 GetSpecificsFieldNumberFromModelType(it.Get())); | |
| 218 } | |
| 219 | |
| 220 for (ModelTypeSet::Iterator it = | |
| 221 configuration_stats[i] | |
| 222 .same_priority_types_configured_before.First(); | |
| 223 it.Good(); it.Inc()) { | |
| 224 datatype_stats->add_same_priority_type_configured_before( | |
| 225 GetSpecificsFieldNumberFromModelType(it.Get())); | |
| 226 } | |
| 227 | |
| 228 AddEventToQueue(association_event); | |
| 229 } | |
| 230 } | |
| 231 | |
| 232 void DebugInfoEventListener::CreateAndAddEvent( | |
| 233 sync_pb::SyncEnums::SingletonDebugEventType type) { | |
| 234 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 235 sync_pb::DebugEventInfo event_info; | |
| 236 event_info.set_singleton_event(type); | |
| 237 AddEventToQueue(event_info); | |
| 238 } | |
| 239 | |
| 240 void DebugInfoEventListener::AddEventToQueue( | |
| 241 const sync_pb::DebugEventInfo& event_info) { | |
| 242 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 243 if (events_.size() >= kMaxEntries) { | |
| 244 DVLOG(1) << "DebugInfoEventListener::AddEventToQueue Dropping an old event " | |
| 245 << "because of full queue"; | |
| 246 | |
| 247 events_.pop_front(); | |
| 248 events_dropped_ = true; | |
| 249 } | |
| 250 events_.push_back(event_info); | |
| 251 } | |
| 252 | |
| 253 } // namespace syncer | |
| OLD | NEW |