sync_status_tracker.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. #ifndef COMPONENTS_SYNC_ENGINE_SYNC_STATUS_TRACKER_H_
  5. #define COMPONENTS_SYNC_ENGINE_SYNC_STATUS_TRACKER_H_
  6. #include <map>
  7. #include <string>
  8. #include "base/callback.h"
  9. #include "base/compiler_specific.h"
  10. #include "base/sequence_checker.h"
  11. #include "components/sync/base/model_type.h"
  12. #include "components/sync/engine/sync_engine_event_listener.h"
  13. #include "components/sync/engine/sync_status.h"
  14. #include "components/sync/protocol/nigori_specifics.pb.h"
  15. namespace syncer {
  16. struct SyncCycleEvent;
  17. // This class watches various sync engine components, updating its internal
  18. // state upon change and firing the callback injected on construction.
  19. //
  20. // Most of this data ends up on the chrome://sync-internals page. But the page
  21. // is only 'pinged' to update itself at the end of a sync cycle. A user could
  22. // refresh manually, but unless their timing is excellent it's unlikely that a
  23. // user will see any state in mid-sync cycle. We have no plans to change this.
  24. // However, we will continue to collect data and update state mid-sync-cycle in
  25. // case we need to debug slow or stuck sync cycles.
  26. class SyncStatusTracker : public SyncEngineEventListener {
  27. public:
  28. explicit SyncStatusTracker(
  29. const base::RepeatingCallback<void(const SyncStatus&)>&
  30. status_changed_callback);
  31. ~SyncStatusTracker() override;
  32. SyncStatusTracker(const SyncStatusTracker&) = delete;
  33. SyncStatusTracker& operator=(const SyncStatusTracker&) = delete;
  34. // SyncEngineEventListener implementation.
  35. void OnSyncCycleEvent(const SyncCycleEvent& event) override;
  36. void OnActionableError(const SyncProtocolError& error) override;
  37. void OnRetryTimeChanged(base::Time retry_time) override;
  38. void OnThrottledTypesChanged(ModelTypeSet throttled_types) override;
  39. void OnBackedOffTypesChanged(ModelTypeSet backed_off_types) override;
  40. void OnMigrationRequested(ModelTypeSet types) override;
  41. void OnProtocolEvent(const ProtocolEvent& event) override;
  42. void SetNotificationsEnabled(bool notifications_enabled);
  43. void IncrementNotificationsReceived();
  44. void SetEncryptedTypes(ModelTypeSet types);
  45. void SetCryptographerCanEncrypt(bool can_encrypt);
  46. void SetCryptoHasPendingKeys(bool has_pending_keys);
  47. void SetPassphraseType(PassphraseType type);
  48. void SetHasKeystoreKey(bool has_keystore_key);
  49. void SetKeystoreMigrationTime(const base::Time& migration_time);
  50. void SetTrustedVaultDebugInfo(
  51. const sync_pb::NigoriSpecifics::TrustedVaultDebugInfo&
  52. trusted_vault_debug_info);
  53. void SetCacheGuid(const std::string& cache_guid);
  54. void SetInvalidatorClientId(const std::string& invalidator_client_id);
  55. void SetLocalBackendFolder(const std::string& folder);
  56. protected:
  57. // Examines syncer to calculate syncing and the unsynced count,
  58. // and returns a Status with new values.
  59. SyncStatus CalcSyncing(const SyncCycleEvent& event) const;
  60. SyncStatus CreateBlankStatus() const;
  61. SyncStatus status_;
  62. private:
  63. const base::RepeatingCallback<void(const SyncStatus&)>
  64. status_changed_callback_;
  65. SEQUENCE_CHECKER(sequence_checker_);
  66. };
  67. } // namespace syncer
  68. #endif // COMPONENTS_SYNC_ENGINE_SYNC_STATUS_TRACKER_H_