it2me_cli_host.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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_IT2ME_CLI_HOST_H_
  5. #define REMOTING_TEST_IT2ME_CLI_HOST_H_
  6. #include <memory>
  7. #include <string>
  8. #include "base/memory/scoped_refptr.h"
  9. #include "base/memory/weak_ptr.h"
  10. #include "base/values.h"
  11. #include "extensions/browser/api/messaging/native_message_host.h"
  12. #include "remoting/base/oauth_token_getter.h"
  13. namespace remoting {
  14. namespace test {
  15. class TestOAuthTokenGetter;
  16. class TestTokenStorage;
  17. } // namespace test
  18. class AutoThreadTaskRunner;
  19. class It2MeCliHost final : public extensions::NativeMessageHost::Client {
  20. public:
  21. static bool ShouldPrintHelp();
  22. static void PrintHelp();
  23. It2MeCliHost();
  24. It2MeCliHost(const It2MeCliHost&) = delete;
  25. It2MeCliHost& operator=(const It2MeCliHost&) = delete;
  26. ~It2MeCliHost() override;
  27. void Start();
  28. private:
  29. // extensions::NativeMessageHost::Client:
  30. // Invoked when native host sends a message
  31. void PostMessageFromNativeHost(const std::string& message) override;
  32. void CloseChannel(const std::string& error_message) override;
  33. // Sends message to host in separate task.
  34. void SendMessageToHost(const std::string& type, base::Value params);
  35. // Actually sends message to host.
  36. void DoSendMessage(const std::string& json);
  37. void OnProtocolBroken(const std::string& message);
  38. void StartCRDHostAndGetCode(OAuthTokenGetter::Status status,
  39. const std::string& user_email,
  40. const std::string& access_token);
  41. // Shuts down host in a separate task.
  42. void ShutdownHost();
  43. // Actually shuts down a host.
  44. void DoShutdownHost();
  45. // Handlers for messages from host
  46. void OnHelloResponse();
  47. void OnDisconnectResponse();
  48. void OnStateError(const std::string& error_state, const base::Value& message);
  49. void OnStateRemoteConnected(const base::Value& message);
  50. void OnStateRemoteDisconnected();
  51. void OnStateReceivedAccessCode(const base::Value& message);
  52. std::unique_ptr<test::TestTokenStorage> storage_;
  53. std::unique_ptr<test::TestOAuthTokenGetter> token_getter_;
  54. scoped_refptr<AutoThreadTaskRunner> ui_task_runner_;
  55. std::unique_ptr<extensions::NativeMessageHost> host_;
  56. // Filled structure with parameters for "connect" message.
  57. base::Value connect_params_;
  58. // Determines actions when receiving messages from CRD host,
  59. // if command is still running (no error / access code), then
  60. // callbacks have to be called.
  61. bool command_awaiting_crd_access_code_;
  62. // True if remote session was established.
  63. bool remote_connected_;
  64. base::WeakPtrFactory<It2MeCliHost> weak_factory_{this};
  65. };
  66. } // namespace remoting
  67. #endif // REMOTING_TEST_IT2ME_CLI_HOST_H_