it2me_standalone_host.cc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // Copyright 2016 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. #include "remoting/test/it2me_standalone_host.h"
  5. #include <functional>
  6. #include <iostream>
  7. #include <memory>
  8. #include <vector>
  9. #include "base/bind.h"
  10. #include "base/location.h"
  11. #include "base/memory/ptr_util.h"
  12. #include "base/memory/ref_counted.h"
  13. #include "base/threading/thread_task_runner_handle.h"
  14. #include "base/time/time.h"
  15. #include "build/build_config.h"
  16. #include "remoting/base/auto_thread_task_runner.h"
  17. #include "remoting/host/chromoting_host_context.h"
  18. #include "remoting/host/host_extension.h"
  19. #include "remoting/protocol/pairing_registry.h"
  20. #include "remoting/protocol/protocol_mock_objects.h"
  21. #include "remoting/protocol/session_config.h"
  22. namespace remoting {
  23. namespace test {
  24. namespace {
  25. void OutputFakeConnectionEventLogger(const FakeConnectionEventLogger& logger) {
  26. std::cout << logger;
  27. }
  28. constexpr char kSessionJid[] = "user@domain/rest-of-jid";
  29. } // namespace
  30. using ::remoting::protocol::MockSession;
  31. It2MeStandaloneHost::It2MeStandaloneHost()
  32. : task_environment_(
  33. base::test::SingleThreadTaskEnvironment::MainThreadType::UI),
  34. context_(ChromotingHostContext::Create(
  35. new AutoThreadTaskRunner(base::ThreadTaskRunnerHandle::Get(),
  36. run_loop_.QuitClosure()))),
  37. main_task_runner_(context_->file_task_runner()),
  38. factory_(main_task_runner_,
  39. context_->video_capture_task_runner(),
  40. context_->input_task_runner(),
  41. context_->ui_task_runner()),
  42. connection_(base::WrapUnique(new testing::NiceMock<MockSession>())),
  43. session_jid_(kSessionJid),
  44. #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
  45. // We cannot support audio capturing for linux, since a pipe name is
  46. // needed to initialize AudioCapturerLinux.
  47. config_(protocol::SessionConfig::ForTest()),
  48. #else
  49. config_(protocol::SessionConfig::ForTestWithAudio()),
  50. #endif
  51. event_logger_(&connection_) {
  52. EXPECT_CALL(*static_cast<MockSession*>(connection_.session()), jid())
  53. .WillRepeatedly(testing::ReturnRef(session_jid_));
  54. EXPECT_CALL(*static_cast<MockSession*>(connection_.session()), config())
  55. .WillRepeatedly(testing::ReturnRef(*config_));
  56. connection_.set_video_stub(event_logger_.video_stub());
  57. connection_.set_client_stub(event_logger_.client_stub());
  58. connection_.set_host_stub(event_logger_.host_stub());
  59. connection_.set_video_encode_task_runner(
  60. context_->video_encode_task_runner());
  61. }
  62. It2MeStandaloneHost::~It2MeStandaloneHost() {}
  63. void It2MeStandaloneHost::Run() {
  64. main_task_runner_->PostTask(
  65. FROM_HERE,
  66. base::BindOnce(&It2MeStandaloneHost::Connect, base::Unretained(this)));
  67. run_loop_.Run();
  68. }
  69. void It2MeStandaloneHost::StartOutputTimer() {
  70. timer_.Start(FROM_HERE, base::Seconds(1),
  71. base::BindRepeating(&OutputFakeConnectionEventLogger,
  72. std::cref(event_logger_)));
  73. }
  74. void It2MeStandaloneHost::Connect() {
  75. DesktopEnvironmentOptions options =
  76. DesktopEnvironmentOptions::CreateDefault();
  77. options.set_enable_user_interface(false);
  78. session_ = std::make_unique<ClientSession>(
  79. &handler_, std::unique_ptr<protocol::ConnectionToClient>(&connection_),
  80. &factory_, options, base::TimeDelta(),
  81. scoped_refptr<protocol::PairingRegistry>(),
  82. std::vector<HostExtension*>());
  83. session_->OnConnectionAuthenticated();
  84. session_->OnConnectionChannelsConnected();
  85. session_->CreateMediaStreams();
  86. }
  87. } // namespace test
  88. } // namespace remoting