debug_info_event_listener.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. #ifndef COMPONENTS_SYNC_ENGINE_DEBUG_INFO_EVENT_LISTENER_H_
  5. #define COMPONENTS_SYNC_ENGINE_DEBUG_INFO_EVENT_LISTENER_H_
  6. #include "base/containers/circular_deque.h"
  7. #include "base/gtest_prod_util.h"
  8. #include "base/sequence_checker.h"
  9. #include "components/sync/base/model_type.h"
  10. #include "components/sync/engine/cycle/debug_info_getter.h"
  11. #include "components/sync/engine/cycle/sync_cycle_snapshot.h"
  12. #include "components/sync/engine/sync_encryption_handler.h"
  13. #include "components/sync/engine/sync_manager.h"
  14. #include "components/sync/protocol/client_debug_info.pb.h"
  15. #include "components/sync/protocol/sync_enums.pb.h"
  16. namespace sync_pb {
  17. class EncryptedData;
  18. }
  19. namespace syncer {
  20. // In order to track datatype association results, we need at least as many
  21. // entries as datatypes. Reserve additional space for other kinds of events that
  22. // are likely to happen during first sync or startup.
  23. const unsigned int kMaxEntries = GetNumModelTypes() + 10;
  24. // Listens to events and records them in a queue. And passes the events to
  25. // syncer when requested.
  26. // This class is not thread safe and should only be accessed on the sync thread.
  27. class DebugInfoEventListener : public SyncManager::Observer,
  28. public SyncEncryptionHandler::Observer,
  29. public DebugInfoGetter {
  30. public:
  31. DebugInfoEventListener();
  32. DebugInfoEventListener(const DebugInfoEventListener&) = delete;
  33. DebugInfoEventListener& operator=(const DebugInfoEventListener&) = delete;
  34. ~DebugInfoEventListener() override;
  35. void InitializationComplete();
  36. // SyncManager::Observer implementation.
  37. void OnSyncCycleCompleted(const SyncCycleSnapshot& snapshot) override;
  38. void OnConnectionStatusChange(ConnectionStatus connection_status) override;
  39. void OnActionableError(const SyncProtocolError& sync_error) override;
  40. void OnMigrationRequested(ModelTypeSet types) override;
  41. void OnProtocolEvent(const ProtocolEvent& event) override;
  42. void OnSyncStatusChanged(const SyncStatus& status) override;
  43. // SyncEncryptionHandler::Observer implementation.
  44. void OnPassphraseRequired(
  45. const KeyDerivationParams& key_derivation_params,
  46. const sync_pb::EncryptedData& pending_keys) override;
  47. void OnPassphraseAccepted() override;
  48. void OnTrustedVaultKeyRequired() override;
  49. void OnTrustedVaultKeyAccepted() override;
  50. void OnEncryptedTypesChanged(ModelTypeSet encrypted_types,
  51. bool encrypt_everything) override;
  52. void OnCryptographerStateChanged(Cryptographer* cryptographer,
  53. bool has_pending_keys) override;
  54. void OnPassphraseTypeChanged(PassphraseType type,
  55. base::Time explicit_passphrase_time) override;
  56. // Sync manager events.
  57. void OnNudgeFromDatatype(ModelType datatype);
  58. // DebugInfoGetter implementation.
  59. sync_pb::DebugInfo GetDebugInfo() const override;
  60. // DebugInfoGetter implementation.
  61. void ClearDebugInfo() override;
  62. private:
  63. FRIEND_TEST_ALL_PREFIXES(DebugInfoEventListenerTest, VerifyEventsAdded);
  64. FRIEND_TEST_ALL_PREFIXES(DebugInfoEventListenerTest, VerifyQueueSize);
  65. FRIEND_TEST_ALL_PREFIXES(DebugInfoEventListenerTest, VerifyGetEvents);
  66. FRIEND_TEST_ALL_PREFIXES(DebugInfoEventListenerTest, VerifyClearEvents);
  67. void AddEventToQueue(const sync_pb::DebugEventInfo& event_info);
  68. void CreateAndAddEvent(sync_pb::SyncEnums::SingletonDebugEventType type);
  69. using DebugEventInfoQueue = base::circular_deque<sync_pb::DebugEventInfo>;
  70. DebugEventInfoQueue events_;
  71. // True indicates we had to drop one or more events to keep our limit of
  72. // |kMaxEntries|.
  73. bool events_dropped_;
  74. // Cryptographer has keys that are not yet decrypted.
  75. bool cryptographer_has_pending_keys_;
  76. // Cryptographer is able to encrypt data, which usually means it's initialized
  77. // and does not have pending keys.
  78. bool cryptographer_can_encrypt_;
  79. SEQUENCE_CHECKER(sequence_checker_);
  80. };
  81. } // namespace syncer
  82. #endif // COMPONENTS_SYNC_ENGINE_DEBUG_INFO_EVENT_LISTENER_H_