ftl_services_playground.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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_TEST_FTL_SERVICES_PLAYGROUND_H_
  5. #define REMOTING_TEST_FTL_SERVICES_PLAYGROUND_H_
  6. #include <memory>
  7. #include <string>
  8. #include "base/callback_forward.h"
  9. #include "base/memory/weak_ptr.h"
  10. #include "remoting/base/oauth_token_getter.h"
  11. #include "remoting/signaling/ftl_messaging_client.h"
  12. #include "remoting/signaling/ftl_registration_manager.h"
  13. namespace network {
  14. class TransitionalURLLoaderFactoryOwner;
  15. } // namespace network
  16. namespace remoting {
  17. namespace test {
  18. class TestOAuthTokenGetter;
  19. class TestTokenStorage;
  20. } // namespace test
  21. class FtlServicesPlayground {
  22. public:
  23. FtlServicesPlayground();
  24. FtlServicesPlayground(const FtlServicesPlayground&) = delete;
  25. FtlServicesPlayground& operator=(const FtlServicesPlayground&) = delete;
  26. ~FtlServicesPlayground();
  27. bool ShouldPrintHelp();
  28. void PrintHelp();
  29. void StartAndAuthenticate();
  30. private:
  31. void StartLoop();
  32. void ResetServices(base::OnceClosure on_done);
  33. void SignInGaia(base::OnceClosure on_done);
  34. void OnSignInGaiaResponse(base::OnceClosure on_done,
  35. const ProtobufHttpStatus& status);
  36. void SendMessage(base::OnceClosure on_done);
  37. void DoSendMessage(const std::string& receiver_id,
  38. const std::string& registration_id,
  39. base::OnceClosure on_done,
  40. bool should_keep_running);
  41. void OnSendMessageResponse(base::OnceCallback<void(bool)> on_continue,
  42. const ProtobufHttpStatus& status);
  43. void StartReceivingMessages(base::OnceClosure on_done);
  44. void StopReceivingMessages(base::OnceClosure on_done);
  45. void OnMessageReceived(const ftl::Id& sender_id,
  46. const std::string& sender_registration_id,
  47. const ftl::ChromotingMessage& message);
  48. void OnReceiveMessagesStreamReady();
  49. void OnReceiveMessagesStreamClosed(const ProtobufHttpStatus& status);
  50. void HandleStatusError(base::OnceClosure on_done,
  51. const ProtobufHttpStatus& status);
  52. std::unique_ptr<test::TestTokenStorage> storage_;
  53. std::unique_ptr<test::TestOAuthTokenGetter> token_getter_;
  54. std::unique_ptr<network::TransitionalURLLoaderFactoryOwner>
  55. url_loader_factory_owner_;
  56. std::unique_ptr<FtlRegistrationManager> registration_manager_;
  57. // Subscription must be deleted before |messaging_client_|.
  58. std::unique_ptr<FtlMessagingClient> messaging_client_;
  59. base::CallbackListSubscription message_subscription_;
  60. base::OnceClosure receive_messages_done_callback_;
  61. base::WeakPtrFactory<FtlServicesPlayground> weak_factory_{this};
  62. };
  63. } // namespace remoting
  64. #endif // REMOTING_TEST_FTL_SERVICES_PLAYGROUND_H_