OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // This file implements the Windows service controlling Me2Me host processes | 5 // This file implements the Windows service controlling Me2Me host processes |
6 // running within user sessions. | 6 // running within user sessions. |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 17 #include "mojo/edk/embedder/embedder.h" |
| 18 #include "mojo/edk/embedder/named_platform_channel_pair.h" |
| 19 #include "mojo/edk/embedder/platform_channel_pair.h" |
| 20 #include "mojo/edk/embedder/scoped_ipc_support.h" |
17 #include "remoting/base/auto_thread.h" | 21 #include "remoting/base/auto_thread.h" |
18 #include "remoting/base/auto_thread_task_runner.h" | 22 #include "remoting/base/auto_thread_task_runner.h" |
19 #include "remoting/host/desktop_process.h" | 23 #include "remoting/host/desktop_process.h" |
20 #include "remoting/host/host_exit_codes.h" | 24 #include "remoting/host/host_exit_codes.h" |
21 #include "remoting/host/host_main.h" | 25 #include "remoting/host/host_main.h" |
22 #include "remoting/host/me2me_desktop_environment.h" | 26 #include "remoting/host/me2me_desktop_environment.h" |
23 #include "remoting/host/switches.h" | 27 #include "remoting/host/switches.h" |
24 #include "remoting/host/win/session_desktop_environment.h" | 28 #include "remoting/host/win/session_desktop_environment.h" |
25 | 29 |
26 namespace remoting { | 30 namespace remoting { |
27 | 31 |
28 int DesktopProcessMain() { | 32 int DesktopProcessMain() { |
29 const base::CommandLine* command_line = | 33 const base::CommandLine* command_line = |
30 base::CommandLine::ForCurrentProcess(); | 34 base::CommandLine::ForCurrentProcess(); |
31 std::string channel_name = | |
32 command_line->GetSwitchValueASCII(kDaemonPipeSwitchName); | |
33 | |
34 if (channel_name.empty()) | |
35 return kInvalidCommandLineExitCode; | |
36 | |
37 base::MessageLoopForUI message_loop; | 35 base::MessageLoopForUI message_loop; |
38 base::RunLoop run_loop; | 36 base::RunLoop run_loop; |
39 scoped_refptr<AutoThreadTaskRunner> ui_task_runner = | 37 scoped_refptr<AutoThreadTaskRunner> ui_task_runner = |
40 new AutoThreadTaskRunner(message_loop.task_runner(), | 38 new AutoThreadTaskRunner(message_loop.task_runner(), |
41 run_loop.QuitClosure()); | 39 run_loop.QuitClosure()); |
42 | 40 |
43 // Launch the video capture thread. | 41 // Launch the video capture thread. |
44 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner = | 42 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner = |
45 AutoThread::Create("Video capture thread", ui_task_runner); | 43 AutoThread::Create("Video capture thread", ui_task_runner); |
46 | 44 |
47 // Launch the input thread. | 45 // Launch the input thread. |
48 scoped_refptr<AutoThreadTaskRunner> input_task_runner = | 46 scoped_refptr<AutoThreadTaskRunner> input_task_runner = |
49 AutoThread::CreateWithType( | 47 AutoThread::CreateWithType( |
50 "Input thread", ui_task_runner, base::MessageLoop::TYPE_IO); | 48 "Input thread", ui_task_runner, base::MessageLoop::TYPE_IO); |
51 | 49 |
52 DesktopProcess desktop_process(ui_task_runner, | 50 // Launch the I/O thread. |
53 input_task_runner, | 51 scoped_refptr<AutoThreadTaskRunner> io_task_runner = |
54 channel_name); | 52 AutoThread::CreateWithType("I/O thread", ui_task_runner, |
| 53 base::MessageLoop::TYPE_IO); |
| 54 |
| 55 mojo::edk::ScopedIPCSupport ipc_support(io_task_runner->task_runner()); |
| 56 mojo::edk::ScopedPlatformHandle parent_pipe = |
| 57 mojo::edk::PlatformChannelPair::PassClientHandleFromParentProcess( |
| 58 *command_line); |
| 59 if (!parent_pipe.is_valid()) { |
| 60 parent_pipe = |
| 61 mojo::edk::NamedPlatformChannelPair::PassClientHandleFromParentProcess( |
| 62 *command_line); |
| 63 } |
| 64 if (!parent_pipe.is_valid()) { |
| 65 return kInvalidCommandLineExitCode; |
| 66 } |
| 67 mojo::edk::SetParentPipeHandle(std::move(parent_pipe)); |
| 68 mojo::ScopedMessagePipeHandle message_pipe = |
| 69 mojo::edk::CreateChildMessagePipe( |
| 70 command_line->GetSwitchValueASCII(kMojoPipeToken)); |
| 71 DesktopProcess desktop_process(ui_task_runner, input_task_runner, |
| 72 io_task_runner, std::move(message_pipe)); |
55 | 73 |
56 // Create a platform-dependent environment factory. | 74 // Create a platform-dependent environment factory. |
57 std::unique_ptr<DesktopEnvironmentFactory> desktop_environment_factory; | 75 std::unique_ptr<DesktopEnvironmentFactory> desktop_environment_factory; |
58 #if defined(OS_WIN) | 76 #if defined(OS_WIN) |
59 desktop_environment_factory.reset(new SessionDesktopEnvironmentFactory( | 77 desktop_environment_factory.reset(new SessionDesktopEnvironmentFactory( |
60 ui_task_runner, video_capture_task_runner, input_task_runner, | 78 ui_task_runner, video_capture_task_runner, input_task_runner, |
61 ui_task_runner, | 79 ui_task_runner, |
62 base::Bind(&DesktopProcess::InjectSas, desktop_process.AsWeakPtr()), | 80 base::Bind(&DesktopProcess::InjectSas, desktop_process.AsWeakPtr()), |
63 base::Bind(&DesktopProcess::LockWorkStation, | 81 base::Bind(&DesktopProcess::LockWorkStation, |
64 desktop_process.AsWeakPtr()))); | 82 desktop_process.AsWeakPtr()))); |
(...skipping 13 matching lines...) Expand all Loading... |
78 return kSuccessExitCode; | 96 return kSuccessExitCode; |
79 } | 97 } |
80 | 98 |
81 } // namespace remoting | 99 } // namespace remoting |
82 | 100 |
83 #if !defined(OS_WIN) | 101 #if !defined(OS_WIN) |
84 int main(int argc, char** argv) { | 102 int main(int argc, char** argv) { |
85 return remoting::HostMain(argc, argv); | 103 return remoting::HostMain(argc, argv); |
86 } | 104 } |
87 #endif // !defined(OS_WIN) | 105 #endif // !defined(OS_WIN) |
OLD | NEW |