connection_scheduler_impl.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2020 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 ASH_COMPONENTS_PHONEHUB_CONNECTION_SCHEDULER_IMPL_H_
  5. #define ASH_COMPONENTS_PHONEHUB_CONNECTION_SCHEDULER_IMPL_H_
  6. #include "ash/components/phonehub/connection_scheduler.h"
  7. #include "ash/components/phonehub/feature_status.h"
  8. #include "ash/components/phonehub/feature_status_provider.h"
  9. // TODO(https://crbug.com/1164001): move to forward declaration.
  10. #include "ash/services/secure_channel/public/cpp/client/connection_manager.h"
  11. #include "base/memory/weak_ptr.h"
  12. #include "base/time/time.h"
  13. #include "net/base/backoff_entry.h"
  14. namespace ash {
  15. namespace phonehub {
  16. // ConnectionScheduler implementation that schedules calls to ConnectionManager
  17. // in order to establish a connection to the user's phone.
  18. class ConnectionSchedulerImpl : public ConnectionScheduler,
  19. public FeatureStatusProvider::Observer {
  20. public:
  21. ConnectionSchedulerImpl(secure_channel::ConnectionManager* connection_manager,
  22. FeatureStatusProvider* feature_status_provider);
  23. ~ConnectionSchedulerImpl() override;
  24. void ScheduleConnectionNow() override;
  25. private:
  26. friend class ConnectionSchedulerImplTest;
  27. // FeatureStatusProvider::Observer:
  28. void OnFeatureStatusChanged() override;
  29. // Invalidate all pending backoff attempts and disconnects the current
  30. // connection attempt.
  31. void DisconnectAndClearBackoffAttempts();
  32. void ClearBackoffAttempts();
  33. // Test only functions.
  34. base::TimeDelta GetCurrentBackoffDelayTimeForTesting();
  35. int GetBackoffFailureCountForTesting();
  36. secure_channel::ConnectionManager* connection_manager_;
  37. FeatureStatusProvider* feature_status_provider_;
  38. // Provides us the backoff timers for RequestConnection().
  39. net::BackoffEntry retry_backoff_;
  40. FeatureStatus current_feature_status_;
  41. base::WeakPtrFactory<ConnectionSchedulerImpl> weak_ptr_factory_{this};
  42. };
  43. } // namespace phonehub
  44. } // namespace ash
  45. #endif // ASH_COMPONENTS_PHONEHUB_CONNECTION_SCHEDULER_IMPL_H_