message_reception_channel.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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_MESSAGE_RECEPTION_CHANNEL_H_
  5. #define REMOTING_SIGNALING_MESSAGE_RECEPTION_CHANNEL_H_
  6. #include <memory>
  7. #include "base/callback_forward.h"
  8. #include "remoting/proto/ftl/v1/ftl_messages.pb.h"
  9. namespace remoting {
  10. class ScopedProtobufHttpRequest;
  11. class ProtobufHttpStatus;
  12. // Interface for starting or closing the server stream to receive messages from
  13. // FTL backend.
  14. class MessageReceptionChannel {
  15. public:
  16. using StreamOpener =
  17. base::RepeatingCallback<std::unique_ptr<ScopedProtobufHttpRequest>(
  18. base::OnceClosure on_channel_ready,
  19. const base::RepeatingCallback<void(
  20. std::unique_ptr<ftl::ReceiveMessagesResponse>)>& on_incoming_msg,
  21. base::OnceCallback<void(const ProtobufHttpStatus&)>
  22. on_channel_closed)>;
  23. using MessageCallback =
  24. base::RepeatingCallback<void(const ftl::InboxMessage& message)>;
  25. using DoneCallback =
  26. base::OnceCallback<void(const ProtobufHttpStatus& status)>;
  27. MessageReceptionChannel() = default;
  28. MessageReceptionChannel(const MessageReceptionChannel&) = delete;
  29. MessageReceptionChannel& operator=(const MessageReceptionChannel&) = delete;
  30. virtual ~MessageReceptionChannel() = default;
  31. virtual void Initialize(const StreamOpener& stream_opener,
  32. const MessageCallback& on_incoming_msg) = 0;
  33. // Opens a server streaming channel to the FTL API to enable message reception
  34. // over the fast path.
  35. // |on_ready| is called once the stream is successfully started.
  36. // |on_closed| is called if the stream fails to start, in which case
  37. // |on_ready| will not be called, or when the stream is closed or dropped,
  38. // in which case it is called after |on_ready| is called.
  39. virtual void StartReceivingMessages(base::OnceClosure on_ready,
  40. DoneCallback on_closed) = 0;
  41. // Closes the streaming channel. Note that |on_closed| callback will be
  42. // silently dropped.
  43. virtual void StopReceivingMessages() = 0;
  44. // Returns true if the streaming channel is open.
  45. virtual bool IsReceivingMessages() const = 0;
  46. };
  47. } // namespace remoting
  48. #endif // REMOTING_SIGNALING_MESSAGE_RECEPTION_CHANNEL_H_