Home | History | Annotate | Download | only in host
      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.
      4 //
      5 // This file implements the Windows service controlling Me2Me host processes
      6 // running within user sessions.
      7 
      8 #include "base/bind.h"
      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/ipc_constants.h"
     20 #include "remoting/host/me2me_desktop_environment.h"
     21 #include "remoting/host/win/session_desktop_environment.h"
     22 
     23 namespace remoting {
     24 
     25 int DesktopProcessMain() {
     26   const CommandLine* command_line = CommandLine::ForCurrentProcess();
     27   std::string channel_name =
     28       command_line->GetSwitchValueASCII(kDaemonPipeSwitchName);
     29 
     30   if (channel_name.empty())
     31     return kUsageExitCode;
     32 
     33   base::MessageLoop message_loop(base::MessageLoop::TYPE_UI);
     34   base::RunLoop run_loop;
     35   scoped_refptr<AutoThreadTaskRunner> ui_task_runner =
     36       new AutoThreadTaskRunner(message_loop.message_loop_proxy(),
     37                                run_loop.QuitClosure());
     38 
     39   // Launch the input thread.
     40   scoped_refptr<AutoThreadTaskRunner> input_task_runner =
     41       AutoThread::CreateWithType(
     42           "Input thread", ui_task_runner, base::MessageLoop::TYPE_IO);
     43 
     44   DesktopProcess desktop_process(ui_task_runner,
     45                                  input_task_runner,
     46                                  channel_name);
     47 
     48   // Create a platform-dependent environment factory.
     49   scoped_ptr<DesktopEnvironmentFactory> desktop_environment_factory;
     50 #if defined(OS_WIN)
     51   desktop_environment_factory.reset(
     52       new SessionDesktopEnvironmentFactory(
     53           ui_task_runner,
     54           input_task_runner,
     55           ui_task_runner,
     56           base::Bind(&DesktopProcess::InjectSas,
     57                      desktop_process.AsWeakPtr())));
     58 #else  // !defined(OS_WIN)
     59   desktop_environment_factory.reset(new Me2MeDesktopEnvironmentFactory(
     60       ui_task_runner,
     61       input_task_runner,
     62       ui_task_runner));
     63 #endif  // !defined(OS_WIN)
     64 
     65   if (!desktop_process.Start(desktop_environment_factory.Pass()))
     66     return kInitializationFailed;
     67 
     68   // Run the UI message loop.
     69   ui_task_runner = NULL;
     70   run_loop.Run();
     71 
     72   return kSuccessExitCode;
     73 }
     74 
     75 }  // namespace remoting
     76 
     77 #if !defined(OS_WIN)
     78 int main(int argc, char** argv) {
     79   return remoting::HostMain(argc, argv);
     80 }
     81 #endif  // !defined(OS_WIN)
     82