1 // Copyright 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.
5 #ifndef SYNC_INTERNAL_API_DEBUG_INFO_EVENT_LISTENER_H_
6 #define SYNC_INTERNAL_API_DEBUG_INFO_EVENT_LISTENER_H_
11 #include "base/compiler_specific.h"
12 #include "sync/base/sync_export.h"
13 #include "sync/internal_api/public/data_type_debug_info_listener.h"
14 #include "sync/internal_api/public/sessions/sync_session_snapshot.h"
15 #include "sync/internal_api/public/sync_encryption_handler.h"
16 #include "sync/internal_api/public/sync_manager.h"
17 #include "sync/internal_api/public/util/weak_handle.h"
18 #include "sync/js/js_backend.h"
19 #include "sync/protocol/sync.pb.h"
20 #include "sync/sessions/debug_info_getter.h"
24 // In order to track datatype association results, we need at least as many
25 // entries as datatypes.
26 const unsigned int kMaxEntries = 25;
28 // Listens to events and records them in a queue. And passes the events to
29 // syncer when requested.
30 // This class is not thread safe and should only be accessed on the sync thread.
31 class SYNC_EXPORT_PRIVATE DebugInfoEventListener
32 : public SyncManager::Observer,
33 public SyncEncryptionHandler::Observer,
34 public sessions::DebugInfoGetter,
35 public DataTypeDebugInfoListener {
37 DebugInfoEventListener();
38 virtual ~DebugInfoEventListener();
40 // SyncManager::Observer implementation.
41 virtual void OnSyncCycleCompleted(
42 const sessions::SyncSessionSnapshot& snapshot) OVERRIDE;
43 virtual void OnInitializationComplete(
44 const WeakHandle<JsBackend>& js_backend,
45 const WeakHandle<DataTypeDebugInfoListener>& debug_listener,
46 bool success, ModelTypeSet restored_types) OVERRIDE;
47 virtual void OnConnectionStatusChange(
48 ConnectionStatus connection_status) OVERRIDE;
49 virtual void OnStopSyncingPermanently() OVERRIDE;
50 virtual void OnActionableError(
51 const SyncProtocolError& sync_error) OVERRIDE;
53 // SyncEncryptionHandler::Observer implementation.
54 virtual void OnPassphraseRequired(
55 PassphraseRequiredReason reason,
56 const sync_pb::EncryptedData& pending_keys) OVERRIDE;
57 virtual void OnPassphraseAccepted() OVERRIDE;
58 virtual void OnBootstrapTokenUpdated(
59 const std::string& bootstrap_token,
60 BootstrapTokenType type) OVERRIDE;
61 virtual void OnEncryptedTypesChanged(
62 ModelTypeSet encrypted_types,
63 bool encrypt_everything) OVERRIDE;
64 virtual void OnEncryptionComplete() OVERRIDE;
65 virtual void OnCryptographerStateChanged(
66 Cryptographer* cryptographer) OVERRIDE;
67 virtual void OnPassphraseTypeChanged(
69 base::Time explicit_passphrase_time) OVERRIDE;
71 // Sync manager events.
72 void OnNudgeFromDatatype(ModelType datatype);
73 void OnIncomingNotification(const ObjectIdInvalidationMap& invalidations);
75 // DebugInfoGetter implementation.
76 virtual void GetAndClearDebugInfo(sync_pb::DebugInfo* debug_info) OVERRIDE;
78 // DataTypeDebugInfoListener implementation.
79 virtual void OnDataTypeConfigureComplete(
80 const std::vector<DataTypeConfigurationStats>& configuration_stats)
83 // Returns a weak pointer to this object.
84 base::WeakPtr<DataTypeDebugInfoListener> GetWeakPtr();
87 FRIEND_TEST_ALL_PREFIXES(DebugInfoEventListenerTest, VerifyEventsAdded);
88 FRIEND_TEST_ALL_PREFIXES(DebugInfoEventListenerTest, VerifyQueueSize);
89 FRIEND_TEST_ALL_PREFIXES(DebugInfoEventListenerTest, VerifyGetAndClearEvents);
91 void AddEventToQueue(const sync_pb::DebugEventInfo& event_info);
92 void CreateAndAddEvent(sync_pb::DebugEventInfo::SingletonEventType type);
93 std::queue<sync_pb::DebugEventInfo> events_;
95 // True indicates we had to drop one or more events to keep our limit of
99 // Cryptographer has keys that are not yet decrypted.
100 bool cryptographer_has_pending_keys_;
102 // Cryptographer is initialized and does not have pending keys.
103 bool cryptographer_ready_;
105 base::ThreadChecker thread_checker_;
107 base::WeakPtrFactory<DebugInfoEventListener> weak_ptr_factory_;
109 DISALLOW_COPY_AND_ASSIGN(DebugInfoEventListener);
112 } // namespace syncer
114 #endif // SYNC_INTERNAL_API_DEBUG_INFO_EVENT_LISTENER_H_