Index: chrome/browser/sync/internal_api/debug_info_event_listener.cc |
diff --git a/chrome/browser/sync/internal_api/debug_info_event_listener.cc b/chrome/browser/sync/internal_api/debug_info_event_listener.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0377ecca2e0af1336657242ad108001e8d41befe |
--- /dev/null |
+++ b/chrome/browser/sync/internal_api/debug_info_event_listener.cc |
@@ -0,0 +1,110 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/sync/internal_api/debug_info_event_listener.h" |
+ |
+using browser_sync::sessions::SyncSessionSnapshot; |
+namespace sync_api { |
+ |
+DebugInfoEventListener::DebugInfoEventListener() { |
+} |
+ |
+DebugInfoEventListener::~DebugInfoEventListener() { |
+} |
+ |
+void DebugInfoEventListener::OnSyncCycleCompleted( |
+ const SyncSessionSnapshot* snapshot) { |
+ if (!snapshot) |
+ return; |
+ |
+ sync_pb::DebugEventInfo event_info; |
+ sync_pb::SyncCycleCompletedEventInfo* sync_completed_event_info = |
+ event_info.mutable_sync_cycle_completed_event_info(); |
tim (not reviewing)
2011/10/13 16:04:14
indent
lipalani1
2011/10/13 21:39:18
Done.
|
+ |
+ sync_completed_event_info->set_syncer_stuck( |
+ snapshot->syncer_status.syncer_stuck); |
tim (not reviewing)
2011/10/13 16:04:14
indent
lipalani1
2011/10/13 21:39:18
Done.
|
+ sync_completed_event_info->set_num_blocking_conflicts( |
+ snapshot->num_conflicting_updates); |
tim (not reviewing)
2011/10/13 16:04:14
indent
lipalani1
2011/10/13 21:39:18
Done.
|
+ sync_completed_event_info->set_num_non_blocking_conflicts( |
+ snapshot->num_blocking_conflicting_updates); |
tim (not reviewing)
2011/10/13 16:04:14
indent
lipalani1
2011/10/13 21:39:18
Done.
|
+ |
+ AddEventToQueue(event_info); |
+} |
+ |
+void DebugInfoEventListener::OnInitializationComplete( |
+ const browser_sync::WeakHandle<browser_sync::JsBackend>& js_backend, |
+ bool success) { |
+ CreateAndAddEvent(sync_pb::DebugEventInfo::INITIALIZATION_COMPLETE); |
+} |
+ |
+void DebugInfoEventListener::OnAuthError( |
+ const GoogleServiceAuthError& auth_error) { |
+ CreateAndAddEvent(sync_pb::DebugEventInfo::AUTH_ERROR); |
+} |
+ |
+void DebugInfoEventListener::OnPassphraseRequired( |
+ sync_api::PassphraseRequiredReason reason) { |
+ CreateAndAddEvent(sync_pb::DebugEventInfo::PASSPHRASE_REQUIRED); |
+} |
+ |
+void DebugInfoEventListener::OnPassphraseAccepted( |
+ const std::string& bootstrap_token) { |
+ CreateAndAddEvent(sync_pb::DebugEventInfo::PASSPHRASE_ACCEPTED); |
+} |
+ |
+void DebugInfoEventListener::OnStopSyncingPermanently() { |
+ CreateAndAddEvent(sync_pb::DebugEventInfo::STOP_SYNCING_PERMANENTLY); |
+} |
+ |
+void DebugInfoEventListener::OnUpdatedToken(const std::string& token) { |
+ CreateAndAddEvent(sync_pb::DebugEventInfo::UPDATED_TOKEN); |
+} |
+ |
+void DebugInfoEventListener::OnClearServerDataFailed() { |
+ DCHECK(false); |
tim (not reviewing)
2011/10/13 16:04:14
NOTREACHED
Although how are we guaranteed this wo
lipalani1
2011/10/13 21:39:18
Done.
|
+} |
+ |
+void DebugInfoEventListener::OnClearServerDataSucceeded() { |
+ DCHECK(false); |
tim (not reviewing)
2011/10/13 16:04:14
NOTREACHED
lipalani1
2011/10/13 21:39:18
Done.
|
+} |
+ |
+void DebugInfoEventListener::OnEncryptionComplete( |
+ const syncable::ModelTypeSet& encrypted_types) { |
+ CreateAndAddEvent(sync_pb::DebugEventInfo::ENCRYPTION_COMPLETE); |
+} |
+ |
+void DebugInfoEventListener::OnActionableError( |
+ const browser_sync::SyncProtocolError& sync_error) { |
+ CreateAndAddEvent(sync_pb::DebugEventInfo::ACTIONABLE_ERROR); |
+} |
+ |
+void DebugInfoEventListener::GetAndClearDebugInfo( |
+ sync_pb::DebugInfo* debug_info) { |
+ DCHECK(events_.size() <= kMaxEntries); |
+ while (!events_.empty()) { |
+ sync_pb::DebugEventInfo* event_info = debug_info->add_events(); |
+ const sync_pb::DebugEventInfo& debug_info = events_.front(); |
+ event_info->CopyFrom(debug_info); |
+ events_.pop(); |
+ } |
+} |
+ |
+void DebugInfoEventListener::CreateAndAddEvent( |
+ sync_pb::DebugEventInfo::EventType type) { |
+ sync_pb::DebugEventInfo event_info; |
+ event_info.set_type(type); |
+ AddEventToQueue(event_info); |
+} |
+ |
+void DebugInfoEventListener::AddEventToQueue( |
+ const sync_pb::DebugEventInfo& event_info) { |
+ if (events_.size() >= kMaxEntries) { |
+ VLOG(1) << "DebugInfoEventListener::AddEventToQueue Dropping an old event " |
+ << "because of full queue"; |
+ |
+ events_.pop(); |
+ } |
+ events_.push(event_info); |
+} |
+} // namespace sync_api |