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
3 // found in the LICENSE file.
5 // This file implements the Windows service controlling Me2Me host processes
6 // running within user sessions.
9 #include "base/bind_helpers.h"
10 #include "base/command_line.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/message_loop/message_loop.h"
13 #include "base/run_loop.h"
14 #include "remoting/base/auto_thread.h"
15 #include "remoting/base/auto_thread_task_runner.h"
16 #include "remoting/host/desktop_process.h"
17 #include "remoting/host/host_exit_codes.h"
18 #include "remoting/host/host_main.h"
19 #include "remoting/host/me2me_desktop_environment.h"
20 #include "remoting/host/switches.h"
21 #include "remoting/host/win/session_desktop_environment.h"
25 int DesktopProcessMain() {
26 const base::CommandLine
* command_line
=
27 base::CommandLine::ForCurrentProcess();
28 std::string channel_name
=
29 command_line
->GetSwitchValueASCII(kDaemonPipeSwitchName
);
31 if (channel_name
.empty())
32 return kUsageExitCode
;
34 base::MessageLoopForUI message_loop
;
35 base::RunLoop run_loop
;
36 scoped_refptr
<AutoThreadTaskRunner
> ui_task_runner
=
37 new AutoThreadTaskRunner(message_loop
.task_runner(),
38 run_loop
.QuitClosure());
40 // Launch the input thread.
41 scoped_refptr
<AutoThreadTaskRunner
> input_task_runner
=
42 AutoThread::CreateWithType(
43 "Input thread", ui_task_runner
, base::MessageLoop::TYPE_IO
);
45 DesktopProcess
desktop_process(ui_task_runner
,
49 // Create a platform-dependent environment factory.
50 scoped_ptr
<DesktopEnvironmentFactory
> desktop_environment_factory
;
52 desktop_environment_factory
.reset(
53 new SessionDesktopEnvironmentFactory(
57 base::Bind(&DesktopProcess::InjectSas
,
58 desktop_process
.AsWeakPtr())));
59 #else // !defined(OS_WIN)
60 desktop_environment_factory
.reset(new Me2MeDesktopEnvironmentFactory(
64 #endif // !defined(OS_WIN)
66 if (!desktop_process
.Start(desktop_environment_factory
.Pass()))
67 return kInitializationFailed
;
69 // Run the UI message loop.
70 ui_task_runner
= nullptr;
73 return kSuccessExitCode
;
76 } // namespace remoting
79 int main(int argc
, char** argv
) {
80 return remoting::HostMain(argc
, argv
);
82 #endif // !defined(OS_WIN)