ftl_host_change_notification_listener.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2019 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 REMOTING_HOST_FTL_HOST_CHANGE_NOTIFICATION_LISTENER_H_
  5. #define REMOTING_HOST_FTL_HOST_CHANGE_NOTIFICATION_LISTENER_H_
  6. #include <memory>
  7. #include <string>
  8. #include "base/memory/raw_ptr.h"
  9. #include "base/memory/weak_ptr.h"
  10. #include "remoting/signaling/signal_strategy.h"
  11. namespace remoting {
  12. // FtlHostChangeNotificationListener listens for messages from remoting backend
  13. // indicating that its host entry has been changed in the directory.
  14. // If a message is received indicating that the host was deleted, it uses the
  15. // OnHostDeleted callback to shut down the host.
  16. class FtlHostChangeNotificationListener : public SignalStrategy::Listener {
  17. public:
  18. class Listener {
  19. protected:
  20. virtual ~Listener() {}
  21. // Invoked when a notification that the host was deleted is received.
  22. public:
  23. virtual void OnHostDeleted() = 0;
  24. };
  25. // Both listener and signal_strategy are expected to outlive this object.
  26. FtlHostChangeNotificationListener(Listener* listener,
  27. SignalStrategy* signal_strategy);
  28. FtlHostChangeNotificationListener(const FtlHostChangeNotificationListener&) =
  29. delete;
  30. FtlHostChangeNotificationListener& operator=(
  31. const FtlHostChangeNotificationListener&) = delete;
  32. ~FtlHostChangeNotificationListener() override;
  33. // SignalStrategy::Listener interface.
  34. void OnSignalStrategyStateChange(SignalStrategy::State state) override;
  35. bool OnSignalStrategyIncomingStanza(
  36. const jingle_xmpp::XmlElement* stanza) override;
  37. bool OnSignalStrategyIncomingMessage(
  38. const ftl::Id& sender_id,
  39. const std::string& sender_registration_id,
  40. const ftl::ChromotingMessage& message) override;
  41. private:
  42. void OnHostDeleted();
  43. raw_ptr<Listener> listener_;
  44. raw_ptr<SignalStrategy> signal_strategy_;
  45. base::WeakPtrFactory<FtlHostChangeNotificationListener> weak_factory_{this};
  46. };
  47. } // namespace remoting
  48. #endif // REMOTING_HOST_FTL_HOST_CHANGE_NOTIFICATION_LISTENER_H_