Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(570)

Side by Side Diff: sync/internal_api/debug_info_event_listener.cc

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

Powered by Google App Engine
This is Rietveld 408576698