ftl_signal_strategy.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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_SIGNALING_FTL_SIGNAL_STRATEGY_H_
  5. #define REMOTING_SIGNALING_FTL_SIGNAL_STRATEGY_H_
  6. #include <memory>
  7. #include "base/memory/scoped_refptr.h"
  8. #include "remoting/signaling/signal_strategy.h"
  9. namespace network {
  10. class SharedURLLoaderFactory;
  11. } // namespace network
  12. namespace remoting {
  13. class FtlDeviceIdProvider;
  14. class MessagingClient;
  15. class RegistrationManager;
  16. class SignalingTracker;
  17. class OAuthTokenGetter;
  18. // FtlSignalStrategy implements SignalStrategy using the FTL messaging service.
  19. // This class can be created on a different sequence from the one it is used
  20. // (when Connect() is called).
  21. class FtlSignalStrategy : public SignalStrategy {
  22. public:
  23. // We take unique_ptr<OAuthTokenGetter> here so that we still have a chance to
  24. // send out pending requests after the instance is deleted.
  25. // |signaling_tracker| is nullable; if it's non-null, it must outlive |this|.
  26. FtlSignalStrategy(
  27. std::unique_ptr<OAuthTokenGetter> oauth_token_getter,
  28. scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
  29. std::unique_ptr<FtlDeviceIdProvider> device_id_provider,
  30. SignalingTracker* signaling_tracker = nullptr);
  31. FtlSignalStrategy(const FtlSignalStrategy&) = delete;
  32. FtlSignalStrategy& operator=(const FtlSignalStrategy&) = delete;
  33. // Note that pending outgoing messages will be silently dropped when the
  34. // signal strategy is being deleted. If you want to send last minute messages,
  35. // consider calling Disconnect() then posting a delayed task to delete the
  36. // strategy.
  37. ~FtlSignalStrategy() override;
  38. // SignalStrategy interface.
  39. void Connect() override;
  40. void Disconnect() override;
  41. State GetState() const override;
  42. Error GetError() const override;
  43. const SignalingAddress& GetLocalAddress() const override;
  44. void AddListener(Listener* listener) override;
  45. void RemoveListener(Listener* listener) override;
  46. bool SendStanza(std::unique_ptr<jingle_xmpp::XmlElement> stanza) override;
  47. bool SendMessage(const SignalingAddress& destination_address,
  48. const ftl::ChromotingMessage& message) override;
  49. std::string GetNextId() override;
  50. bool IsSignInError() const override;
  51. private:
  52. friend class FtlSignalStrategyTest;
  53. FtlSignalStrategy(std::unique_ptr<OAuthTokenGetter> oauth_token_getter,
  54. std::unique_ptr<RegistrationManager> registration_manager,
  55. std::unique_ptr<MessagingClient> messaging_client);
  56. void CreateCore(std::unique_ptr<OAuthTokenGetter> oauth_token_getter,
  57. std::unique_ptr<RegistrationManager> registration_manager,
  58. std::unique_ptr<MessagingClient> messaging_client);
  59. // This ensures that even if a Listener deletes the current instance during
  60. // OnSignalStrategyIncomingStanza(), we can delete |core_| asynchronously.
  61. class Core;
  62. std::unique_ptr<Core> core_;
  63. };
  64. } // namespace remoting
  65. #endif // REMOTING_SIGNALING_FTL_SIGNAL_STRATEGY_H_