invalid_connection_disconnector.h 1.8 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_INVALID_CONNECTION_DISCONNECTOR_H_
  5. #define ASH_COMPONENTS_PHONEHUB_INVALID_CONNECTION_DISCONNECTOR_H_
  6. #include "ash/services/secure_channel/public/cpp/client/connection_manager.h"
  7. namespace base {
  8. class OneShotTimer;
  9. } // namespace base
  10. namespace ash {
  11. namespace phonehub {
  12. class PhoneModel;
  13. // Disconnects the phone if the ConnectionManager is in the kConnected
  14. // state, but the PhoneStatusModel remains empty after a grace period.
  15. class InvalidConnectionDisconnector
  16. : public secure_channel::ConnectionManager::Observer {
  17. public:
  18. InvalidConnectionDisconnector(
  19. secure_channel::ConnectionManager* connection_manager,
  20. PhoneModel* phone_model);
  21. ~InvalidConnectionDisconnector() override;
  22. InvalidConnectionDisconnector(const InvalidConnectionDisconnector&) = delete;
  23. InvalidConnectionDisconnector* operator=(
  24. const InvalidConnectionDisconnector&) = delete;
  25. private:
  26. friend class InvalidConnectionDisconnectorTest;
  27. InvalidConnectionDisconnector(
  28. secure_channel::ConnectionManager* connection_manager,
  29. PhoneModel* phone_model,
  30. std::unique_ptr<base::OneShotTimer> timer);
  31. // secure_channel::ConnectionManager::Observer:
  32. void OnConnectionStatusChanged() override;
  33. void UpdateTimer();
  34. void OnTimerFired();
  35. bool IsPhoneConnected() const;
  36. bool DoesPhoneStatusModelExist() const;
  37. secure_channel::ConnectionManager* connection_manager_;
  38. PhoneModel* phone_model_;
  39. std::unique_ptr<base::OneShotTimer> timer_;
  40. };
  41. } // namespace phonehub
  42. } // namespace ash
  43. #endif // ASH_COMPONENTS_PHONEHUB_INVALID_CONNECTION_DISCONNECTOR_H_