OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef COMPONENTS_SYNC_CORE_IMPL_DEBUG_INFO_EVENT_LISTENER_H_ | |
6 #define COMPONENTS_SYNC_CORE_IMPL_DEBUG_INFO_EVENT_LISTENER_H_ | |
7 | |
8 #include <deque> | |
9 #include <string> | |
10 #include <vector> | |
11 | |
12 #include "base/compiler_specific.h" | |
13 #include "base/gtest_prod_util.h" | |
14 #include "base/macros.h" | |
15 #include "components/sync/base/model_type.h" | |
16 #include "components/sync/base/weak_handle.h" | |
17 #include "components/sync/core/data_type_debug_info_listener.h" | |
18 #include "components/sync/core/sync_encryption_handler.h" | |
19 #include "components/sync/core/sync_manager.h" | |
20 #include "components/sync/engine/cycle/sync_cycle_snapshot.h" | |
21 #include "components/sync/engine_impl/cycle/debug_info_getter.h" | |
22 #include "components/sync/js/js_backend.h" | |
23 #include "components/sync/protocol/sync.pb.h" | |
24 | |
25 namespace syncer { | |
26 | |
27 // In order to track datatype association results, we need at least as many | |
28 // entries as datatypes. Reserve additional space for other kinds of events that | |
29 // are likely to happen during first sync or startup. | |
30 const unsigned int kMaxEntries = MODEL_TYPE_COUNT + 10; | |
31 | |
32 // Listens to events and records them in a queue. And passes the events to | |
33 // syncer when requested. | |
34 // This class is not thread safe and should only be accessed on the sync thread. | |
35 class DebugInfoEventListener : public SyncManager::Observer, | |
36 public SyncEncryptionHandler::Observer, | |
37 public DebugInfoGetter, | |
38 public DataTypeDebugInfoListener { | |
39 public: | |
40 DebugInfoEventListener(); | |
41 ~DebugInfoEventListener() override; | |
42 | |
43 // SyncManager::Observer implementation. | |
44 void OnSyncCycleCompleted(const SyncCycleSnapshot& snapshot) override; | |
45 void OnInitializationComplete( | |
46 const WeakHandle<JsBackend>& js_backend, | |
47 const WeakHandle<DataTypeDebugInfoListener>& debug_listener, | |
48 bool success, | |
49 ModelTypeSet restored_types) override; | |
50 void OnConnectionStatusChange(ConnectionStatus connection_status) override; | |
51 void OnActionableError(const SyncProtocolError& sync_error) override; | |
52 void OnMigrationRequested(ModelTypeSet types) override; | |
53 void OnProtocolEvent(const ProtocolEvent& event) override; | |
54 | |
55 // SyncEncryptionHandler::Observer implementation. | |
56 void OnPassphraseRequired( | |
57 PassphraseRequiredReason reason, | |
58 const sync_pb::EncryptedData& pending_keys) override; | |
59 void OnPassphraseAccepted() override; | |
60 void OnBootstrapTokenUpdated(const std::string& bootstrap_token, | |
61 BootstrapTokenType type) override; | |
62 void OnEncryptedTypesChanged(ModelTypeSet encrypted_types, | |
63 bool encrypt_everything) override; | |
64 void OnEncryptionComplete() override; | |
65 void OnCryptographerStateChanged(Cryptographer* cryptographer) override; | |
66 void OnPassphraseTypeChanged(PassphraseType type, | |
67 base::Time explicit_passphrase_time) override; | |
68 void OnLocalSetPassphraseEncryption( | |
69 const SyncEncryptionHandler::NigoriState& nigori_state) override; | |
70 | |
71 // Sync manager events. | |
72 void OnNudgeFromDatatype(ModelType datatype); | |
73 | |
74 // DebugInfoGetter implementation. | |
75 void GetDebugInfo(sync_pb::DebugInfo* debug_info) override; | |
76 | |
77 // DebugInfoGetter implementation. | |
78 void ClearDebugInfo() override; | |
79 | |
80 // DataTypeDebugInfoListener implementation. | |
81 void OnDataTypeConfigureComplete( | |
82 const std::vector<DataTypeConfigurationStats>& configuration_stats) | |
83 override; | |
84 | |
85 // Returns a weak pointer to this object. | |
86 base::WeakPtr<DataTypeDebugInfoListener> GetWeakPtr(); | |
87 | |
88 private: | |
89 FRIEND_TEST_ALL_PREFIXES(DebugInfoEventListenerTest, VerifyEventsAdded); | |
90 FRIEND_TEST_ALL_PREFIXES(DebugInfoEventListenerTest, VerifyQueueSize); | |
91 FRIEND_TEST_ALL_PREFIXES(DebugInfoEventListenerTest, VerifyGetEvents); | |
92 FRIEND_TEST_ALL_PREFIXES(DebugInfoEventListenerTest, VerifyClearEvents); | |
93 | |
94 void AddEventToQueue(const sync_pb::DebugEventInfo& event_info); | |
95 void CreateAndAddEvent(sync_pb::SyncEnums::SingletonDebugEventType type); | |
96 | |
97 typedef std::deque<sync_pb::DebugEventInfo> DebugEventInfoQueue; | |
98 DebugEventInfoQueue events_; | |
99 | |
100 // True indicates we had to drop one or more events to keep our limit of | |
101 // |kMaxEntries|. | |
102 bool events_dropped_; | |
103 | |
104 // Cryptographer has keys that are not yet decrypted. | |
105 bool cryptographer_has_pending_keys_; | |
106 | |
107 // Cryptographer is initialized and does not have pending keys. | |
108 bool cryptographer_ready_; | |
109 | |
110 base::ThreadChecker thread_checker_; | |
111 | |
112 base::WeakPtrFactory<DebugInfoEventListener> weak_ptr_factory_; | |
113 | |
114 DISALLOW_COPY_AND_ASSIGN(DebugInfoEventListener); | |
115 }; | |
116 | |
117 } // namespace syncer | |
118 | |
119 #endif // COMPONENTS_SYNC_CORE_IMPL_DEBUG_INFO_EVENT_LISTENER_H_ | |
OLD | NEW |