| 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 "remoting/host/desktop_process.h" | |
| 9 | |
| 10 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
| 11 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 12 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 13 #include "base/memory/ref_counted.h" | |
| 14 #include "base/message_loop.h" | |
| 15 #include "base/run_loop.h" | |
| 16 #include "base/scoped_native_library.h" | 11 #include "base/scoped_native_library.h" |
| 17 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
| 18 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 19 #include "base/win/windows_version.h" | 14 #include "base/win/windows_version.h" |
| 20 #include "ipc/ipc_channel_proxy.h" | 15 #include "remoting/host/desktop_process.h" |
| 21 #include "remoting/base/auto_thread.h" | |
| 22 #include "remoting/base/auto_thread_task_runner.h" | |
| 23 #include "remoting/host/host_exit_codes.h" | 16 #include "remoting/host/host_exit_codes.h" |
| 24 #include "remoting/host/logging.h" | 17 #include "remoting/host/logging.h" |
| 25 #include "remoting/host/usage_stats_consent.h" | 18 #include "remoting/host/usage_stats_consent.h" |
| 26 | 19 |
| 27 #if defined(OS_MACOSX) | 20 #if defined(OS_MACOSX) |
| 28 #include "base/mac/scoped_nsautorelease_pool.h" | 21 #include "base/mac/scoped_nsautorelease_pool.h" |
| 29 #endif // defined(OS_MACOSX) | 22 #endif // defined(OS_MACOSX) |
| 30 | 23 |
| 31 #if defined(OS_WIN) | 24 #if defined(OS_WIN) |
| 32 #include <commctrl.h> | 25 #include <commctrl.h> |
| 33 #endif // defined(OS_WIN) | 26 #endif // defined(OS_WIN) |
| 34 | 27 |
| 35 namespace { | 28 namespace { |
| 36 | 29 |
| 37 // The command line switch specifying the name of the daemon IPC endpoint. | 30 // The command line switch specifying the name of the daemon IPC endpoint. |
| 38 const char kDaemonIpcSwitchName[] = "daemon-pipe"; | 31 const char kDaemonIpcSwitchName[] = "daemon-pipe"; |
| 39 | 32 |
| 40 const char kIoThreadName[] = "I/O thread"; | |
| 41 | |
| 42 // "--help" or "--?" prints the usage message. | 33 // "--help" or "--?" prints the usage message. |
| 43 const char kHelpSwitchName[] = "help"; | 34 const char kHelpSwitchName[] = "help"; |
| 44 const char kQuestionSwitchName[] = "?"; | 35 const char kQuestionSwitchName[] = "?"; |
| 45 | 36 |
| 46 const wchar_t kUsageMessage[] = | 37 const char kUsageMessage[] = |
| 47 L"\n" | 38 "\n" |
| 48 L"Usage: %ls [options]\n" | 39 "Usage: %s [options]\n" |
| 49 L"\n" | 40 "\n" |
| 50 L"Options:\n" | 41 "Options:\n" |
| 51 L" --help, --? - Print this message.\n"; | 42 " --help, --? - Print this message.\n"; |
| 52 | 43 |
| 53 void usage(const FilePath& program_name) { | 44 void Usage(const FilePath& program_name) { |
| 54 LOG(INFO) << StringPrintf(kUsageMessage, | 45 std::string display_name = UTF16ToUTF8(program_name.LossyDisplayName()); |
| 55 UTF16ToWide(program_name.value()).c_str()); | 46 LOG(INFO) << StringPrintf(kUsageMessage, display_name.c_str()); |
| 56 } | 47 } |
| 57 | 48 |
| 58 } // namespace | 49 } // namespace |
| 59 | 50 |
| 60 namespace remoting { | |
| 61 | |
| 62 DesktopProcess::DesktopProcess(const std::string& daemon_channel_name) | |
| 63 : daemon_channel_name_(daemon_channel_name) { | |
| 64 } | |
| 65 | |
| 66 DesktopProcess::~DesktopProcess() { | |
| 67 } | |
| 68 | |
| 69 bool DesktopProcess::OnMessageReceived(const IPC::Message& message) { | |
| 70 return false; | |
| 71 } | |
| 72 | |
| 73 void DesktopProcess::OnChannelConnected(int32 peer_pid) { | |
| 74 NOTIMPLEMENTED(); | |
| 75 } | |
| 76 | |
| 77 void DesktopProcess::OnChannelError() { | |
| 78 LOG(ERROR) << "Failed to connect to '" << daemon_channel_name_ << "'"; | |
| 79 daemon_channel_.reset(); | |
| 80 } | |
| 81 | |
| 82 int DesktopProcess::Run() { | |
| 83 // Create the UI message loop. | |
| 84 MessageLoop message_loop(MessageLoop::TYPE_UI); | |
| 85 | |
| 86 { | |
| 87 scoped_refptr<AutoThreadTaskRunner> ui_task_runner = | |
| 88 new remoting::AutoThreadTaskRunner(message_loop.message_loop_proxy(), | |
| 89 MessageLoop::QuitClosure()); | |
| 90 | |
| 91 // Launch the I/O thread. | |
| 92 scoped_refptr<AutoThreadTaskRunner> io_task_runner = | |
| 93 AutoThread::CreateWithType(kIoThreadName, ui_task_runner, | |
| 94 MessageLoop::TYPE_IO); | |
| 95 | |
| 96 // Connect to the daemon. | |
| 97 daemon_channel_.reset(new IPC::ChannelProxy(daemon_channel_name_, | |
| 98 IPC::Channel::MODE_CLIENT, | |
| 99 this, | |
| 100 io_task_runner)); | |
| 101 } | |
| 102 | |
| 103 // Run the UI message loop. | |
| 104 base::RunLoop run_loop; | |
| 105 run_loop.Run(); | |
| 106 return 0; | |
| 107 } | |
| 108 | |
| 109 } // namespace remoting | |
| 110 | |
| 111 int main(int argc, char** argv) { | 51 int main(int argc, char** argv) { |
| 112 #if defined(OS_MACOSX) | 52 #if defined(OS_MACOSX) |
| 113 // Needed so we don't leak objects when threads are created. | 53 // Needed so we don't leak objects when threads are created. |
| 114 base::mac::ScopedNSAutoreleasePool pool; | 54 base::mac::ScopedNSAutoreleasePool pool; |
| 115 #endif | 55 #endif |
| 116 | 56 |
| 117 CommandLine::Init(argc, argv); | 57 CommandLine::Init(argc, argv); |
| 118 | 58 |
| 119 // This object instance is required by Chrome code (for example, | 59 // This object instance is required by Chrome code (for example, |
| 120 // LazyInstance, MessageLoop). | 60 // LazyInstance, MessageLoop). |
| 121 base::AtExitManager exit_manager; | 61 base::AtExitManager exit_manager; |
| 122 | 62 |
| 123 remoting::InitHostLogging(); | 63 remoting::InitHostLogging(); |
| 124 | 64 |
| 125 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 65 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 126 if (command_line->HasSwitch(kHelpSwitchName) || | 66 if (command_line->HasSwitch(kHelpSwitchName) || |
| 127 command_line->HasSwitch(kQuestionSwitchName)) { | 67 command_line->HasSwitch(kQuestionSwitchName)) { |
| 128 usage(command_line->GetProgram()); | 68 Usage(command_line->GetProgram()); |
| 129 return remoting::kSuccessExitCode; | 69 return remoting::kSuccessExitCode; |
| 130 } | 70 } |
| 131 | 71 |
| 132 std::string channel_name = | 72 std::string channel_name = |
| 133 command_line->GetSwitchValueASCII(kDaemonIpcSwitchName); | 73 command_line->GetSwitchValueASCII(kDaemonIpcSwitchName); |
| 134 | 74 |
| 135 if (channel_name.empty()) { | 75 if (channel_name.empty()) { |
| 136 usage(command_line->GetProgram()); | 76 Usage(command_line->GetProgram()); |
| 137 return remoting::kUsageExitCode; | 77 return remoting::kUsageExitCode; |
| 138 } | 78 } |
| 139 | 79 |
| 140 remoting::DesktopProcess desktop_process(channel_name); | 80 remoting::DesktopProcess desktop_process(channel_name); |
| 141 return desktop_process.Run(); | 81 return desktop_process.Run(); |
| 142 } | 82 } |
| 143 | 83 |
| 144 #if defined(OS_WIN) | 84 #if defined(OS_WIN) |
| 145 | 85 |
| 146 int CALLBACK WinMain(HINSTANCE instance, | 86 int CALLBACK WinMain(HINSTANCE instance, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 172 user32.GetFunctionPointer("SetProcessDPIAware")); | 112 user32.GetFunctionPointer("SetProcessDPIAware")); |
| 173 set_process_dpi_aware(); | 113 set_process_dpi_aware(); |
| 174 } | 114 } |
| 175 | 115 |
| 176 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting | 116 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting |
| 177 // the command line from GetCommandLineW(), so we can safely pass NULL here. | 117 // the command line from GetCommandLineW(), so we can safely pass NULL here. |
| 178 return main(0, NULL); | 118 return main(0, NULL); |
| 179 } | 119 } |
| 180 | 120 |
| 181 #endif // defined(OS_WIN) | 121 #endif // defined(OS_WIN) |
| OLD | NEW |