| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/host/ipc_desktop_environment.h" | 5 #include "remoting/host/ipc_desktop_environment.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
| 18 #include "base/process/process.h" | 18 #include "base/process/process.h" |
| 19 #include "base/process/process_handle.h" | 19 #include "base/process/process_handle.h" |
| 20 #include "base/run_loop.h" | 20 #include "base/run_loop.h" |
| 21 #include "base/single_thread_task_runner.h" | 21 #include "base/single_thread_task_runner.h" |
| 22 #include "build/build_config.h" | 22 #include "build/build_config.h" |
| 23 #include "ipc/attachment_broker_privileged.h" | |
| 24 #include "ipc/ipc_channel.h" | 23 #include "ipc/ipc_channel.h" |
| 25 #include "ipc/ipc_channel_proxy.h" | 24 #include "ipc/ipc_channel_proxy.h" |
| 26 #include "ipc/ipc_listener.h" | 25 #include "ipc/ipc_listener.h" |
| 27 #include "ipc/ipc_message.h" | 26 #include "ipc/ipc_message.h" |
| 28 #include "ipc/ipc_platform_file.h" | 27 #include "ipc/ipc_platform_file.h" |
| 29 #include "remoting/base/auto_thread.h" | 28 #include "remoting/base/auto_thread.h" |
| 30 #include "remoting/base/auto_thread_task_runner.h" | 29 #include "remoting/base/auto_thread_task_runner.h" |
| 31 #include "remoting/base/constants.h" | 30 #include "remoting/base/constants.h" |
| 32 #include "remoting/host/chromoting_messages.h" | 31 #include "remoting/host/chromoting_messages.h" |
| 33 #include "remoting/host/desktop_process.h" | 32 #include "remoting/host/desktop_process.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 }; | 98 }; |
| 100 | 99 |
| 101 // Receives messages sent from the desktop process to the daemon. | 100 // Receives messages sent from the desktop process to the daemon. |
| 102 class MockDaemonListener : public IPC::Listener { | 101 class MockDaemonListener : public IPC::Listener { |
| 103 public: | 102 public: |
| 104 MockDaemonListener() {} | 103 MockDaemonListener() {} |
| 105 ~MockDaemonListener() override {} | 104 ~MockDaemonListener() override {} |
| 106 | 105 |
| 107 bool OnMessageReceived(const IPC::Message& message) override; | 106 bool OnMessageReceived(const IPC::Message& message) override; |
| 108 | 107 |
| 109 MOCK_METHOD1(OnDesktopAttached, void(IPC::PlatformFileForTransit)); | 108 MOCK_METHOD1(OnDesktopAttached, void(const IPC::ChannelHandle&)); |
| 110 MOCK_METHOD1(OnChannelConnected, void(int32_t)); | 109 MOCK_METHOD1(OnChannelConnected, void(int32_t)); |
| 111 MOCK_METHOD0(OnChannelError, void()); | 110 MOCK_METHOD0(OnChannelError, void()); |
| 112 | 111 |
| 113 private: | 112 private: |
| 114 DISALLOW_COPY_AND_ASSIGN(MockDaemonListener); | 113 DISALLOW_COPY_AND_ASSIGN(MockDaemonListener); |
| 115 }; | 114 }; |
| 116 | 115 |
| 117 bool FakeDaemonSender::Send(IPC::Message* message) { | 116 bool FakeDaemonSender::Send(IPC::Message* message) { |
| 118 OnMessageReceived(*message); | 117 OnMessageReceived(*message); |
| 119 delete message; | 118 delete message; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 // Creates and starts an instance of desktop process object. | 186 // Creates and starts an instance of desktop process object. |
| 188 void CreateDesktopProcess(); | 187 void CreateDesktopProcess(); |
| 189 | 188 |
| 190 // Destroys the desktop process object created by CreateDesktopProcess(). | 189 // Destroys the desktop process object created by CreateDesktopProcess(). |
| 191 void DestoyDesktopProcess(); | 190 void DestoyDesktopProcess(); |
| 192 | 191 |
| 193 void OnDisconnectCallback(); | 192 void OnDisconnectCallback(); |
| 194 | 193 |
| 195 // Invoked when ChromotingDesktopDaemonMsg_DesktopAttached message is | 194 // Invoked when ChromotingDesktopDaemonMsg_DesktopAttached message is |
| 196 // received. | 195 // received. |
| 197 void OnDesktopAttached(IPC::PlatformFileForTransit desktop_pipe); | 196 void OnDesktopAttached(const IPC::ChannelHandle& desktop_pipe); |
| 198 | 197 |
| 199 void RunMainLoopUntilDone(); | 198 void RunMainLoopUntilDone(); |
| 200 | 199 |
| 201 // The main message loop. | 200 // The main message loop. |
| 202 base::MessageLoopForUI message_loop_; | 201 base::MessageLoopForUI message_loop_; |
| 203 | 202 |
| 204 // Runs until |desktop_session_proxy_| is connected to the desktop. | 203 // Runs until |desktop_session_proxy_| is connected to the desktop. |
| 205 std::unique_ptr<base::RunLoop> setup_run_loop_; | 204 std::unique_ptr<base::RunLoop> setup_run_loop_; |
| 206 | 205 |
| 207 scoped_refptr<AutoThreadTaskRunner> task_runner_; | 206 scoped_refptr<AutoThreadTaskRunner> task_runner_; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 // Runs until there are references to |task_runner_|. | 249 // Runs until there are references to |task_runner_|. |
| 251 base::RunLoop main_run_loop_; | 250 base::RunLoop main_run_loop_; |
| 252 }; | 251 }; |
| 253 | 252 |
| 254 IpcDesktopEnvironmentTest::IpcDesktopEnvironmentTest() | 253 IpcDesktopEnvironmentTest::IpcDesktopEnvironmentTest() |
| 255 : client_jid_("user@domain/rest-of-jid"), | 254 : client_jid_("user@domain/rest-of-jid"), |
| 256 clipboard_stub_(nullptr), | 255 clipboard_stub_(nullptr), |
| 257 remote_input_injector_(nullptr), | 256 remote_input_injector_(nullptr), |
| 258 terminal_id_(-1), | 257 terminal_id_(-1), |
| 259 client_session_control_factory_(&client_session_control_) { | 258 client_session_control_factory_(&client_session_control_) { |
| 260 IPC::AttachmentBrokerPrivileged::CreateBrokerForSingleProcessTests(); | |
| 261 } | 259 } |
| 262 | 260 |
| 263 IpcDesktopEnvironmentTest::~IpcDesktopEnvironmentTest() { | 261 IpcDesktopEnvironmentTest::~IpcDesktopEnvironmentTest() { |
| 264 } | 262 } |
| 265 | 263 |
| 266 void IpcDesktopEnvironmentTest::SetUp() { | 264 void IpcDesktopEnvironmentTest::SetUp() { |
| 267 // Arrange to run |message_loop_| until no components depend on it. | 265 // Arrange to run |message_loop_| until no components depend on it. |
| 268 task_runner_ = new AutoThreadTaskRunner( | 266 task_runner_ = new AutoThreadTaskRunner( |
| 269 message_loop_.task_runner(), main_run_loop_.QuitClosure()); | 267 message_loop_.task_runner(), main_run_loop_.QuitClosure()); |
| 270 | 268 |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 desktop_process_.reset(); | 441 desktop_process_.reset(); |
| 444 } | 442 } |
| 445 remote_input_injector_ = nullptr; | 443 remote_input_injector_ = nullptr; |
| 446 } | 444 } |
| 447 | 445 |
| 448 void IpcDesktopEnvironmentTest::OnDisconnectCallback() { | 446 void IpcDesktopEnvironmentTest::OnDisconnectCallback() { |
| 449 DeleteDesktopEnvironment(); | 447 DeleteDesktopEnvironment(); |
| 450 } | 448 } |
| 451 | 449 |
| 452 void IpcDesktopEnvironmentTest::OnDesktopAttached( | 450 void IpcDesktopEnvironmentTest::OnDesktopAttached( |
| 453 IPC::PlatformFileForTransit desktop_pipe) { | 451 const IPC::ChannelHandle& desktop_pipe) { |
| 454 | |
| 455 base::ProcessHandle process_handle = base::GetCurrentProcessHandle(); | |
| 456 #if defined(OS_WIN) | |
| 457 ASSERT_NE(FALSE, ::DuplicateHandle(GetCurrentProcess(), process_handle, | |
| 458 GetCurrentProcess(), &process_handle, | |
| 459 0, FALSE, DUPLICATE_SAME_ACCESS)); | |
| 460 #endif | |
| 461 | |
| 462 // Instruct DesktopSessionProxy to connect to the network-to-desktop pipe. | 452 // Instruct DesktopSessionProxy to connect to the network-to-desktop pipe. |
| 463 desktop_environment_factory_->OnDesktopSessionAgentAttached( | 453 desktop_environment_factory_->OnDesktopSessionAgentAttached( |
| 464 terminal_id_, process_handle, desktop_pipe); | 454 terminal_id_, desktop_pipe); |
| 465 } | 455 } |
| 466 | 456 |
| 467 void IpcDesktopEnvironmentTest::RunMainLoopUntilDone() { | 457 void IpcDesktopEnvironmentTest::RunMainLoopUntilDone() { |
| 468 task_runner_ = nullptr; | 458 task_runner_ = nullptr; |
| 469 io_task_runner_ = nullptr; | 459 io_task_runner_ = nullptr; |
| 470 main_run_loop_.Run(); | 460 main_run_loop_.Run(); |
| 471 } | 461 } |
| 472 | 462 |
| 473 // Runs until the desktop is attached and exits immediately after that. | 463 // Runs until the desktop is attached and exits immediately after that. |
| 474 TEST_F(IpcDesktopEnvironmentTest, Basic) { | 464 TEST_F(IpcDesktopEnvironmentTest, Basic) { |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 .WillOnce(InvokeWithoutArgs( | 725 .WillOnce(InvokeWithoutArgs( |
| 736 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)); | 726 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)); |
| 737 | 727 |
| 738 // Change the desktop resolution. | 728 // Change the desktop resolution. |
| 739 screen_controls_->SetScreenResolution(ScreenResolution( | 729 screen_controls_->SetScreenResolution(ScreenResolution( |
| 740 webrtc::DesktopSize(100, 100), | 730 webrtc::DesktopSize(100, 100), |
| 741 webrtc::DesktopVector(96, 96))); | 731 webrtc::DesktopVector(96, 96))); |
| 742 } | 732 } |
| 743 | 733 |
| 744 } // namespace remoting | 734 } // namespace remoting |
| OLD | NEW |