| 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_main.h" |
| 9 |
| 8 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
| 9 #include "base/bind.h" | 11 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 11 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 12 #include "base/file_path.h" | 14 #include "base/file_path.h" |
| 13 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
| 14 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 15 #include "base/scoped_native_library.h" | 17 #include "base/scoped_native_library.h" |
| 16 #include "base/stringprintf.h" | 18 #include "base/stringprintf.h" |
| 17 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 47 "Options:\n" | 49 "Options:\n" |
| 48 " --help, --? - Print this message.\n"; | 50 " --help, --? - Print this message.\n"; |
| 49 | 51 |
| 50 void Usage(const FilePath& program_name) { | 52 void Usage(const FilePath& program_name) { |
| 51 std::string display_name = UTF16ToUTF8(program_name.LossyDisplayName()); | 53 std::string display_name = UTF16ToUTF8(program_name.LossyDisplayName()); |
| 52 LOG(INFO) << StringPrintf(kUsageMessage, display_name.c_str()); | 54 LOG(INFO) << StringPrintf(kUsageMessage, display_name.c_str()); |
| 53 } | 55 } |
| 54 | 56 |
| 55 } // namespace | 57 } // namespace |
| 56 | 58 |
| 57 int main(int argc, char** argv) { | 59 namespace remoting { |
| 60 |
| 61 int DesktopProcessMain(int argc, char** argv) { |
| 58 #if defined(OS_MACOSX) | 62 #if defined(OS_MACOSX) |
| 59 // Needed so we don't leak objects when threads are created. | 63 // Needed so we don't leak objects when threads are created. |
| 60 base::mac::ScopedNSAutoreleasePool pool; | 64 base::mac::ScopedNSAutoreleasePool pool; |
| 61 #endif | 65 #endif |
| 62 | 66 |
| 63 CommandLine::Init(argc, argv); | 67 CommandLine::Init(argc, argv); |
| 64 | 68 |
| 69 // Initialize Breakpad as early as possible. On Mac the command-line needs to |
| 70 // be initialized first, so that the preference for crash-reporting can be |
| 71 // looked up in the config file. |
| 72 #if defined(OFFICIAL_BUILD) && (defined(MAC_BREAKPAD) || defined(OS_WIN)) |
| 73 if (IsUsageStatsAllowed()) { |
| 74 InitializeCrashReporting(); |
| 75 } |
| 76 #endif // defined(OFFICIAL_BUILD) && (defined(MAC_BREAKPAD) || defined(OS_WIN)) |
| 77 |
| 65 // This object instance is required by Chrome code (for example, | 78 // This object instance is required by Chrome code (for example, |
| 66 // LazyInstance, MessageLoop). | 79 // LazyInstance, MessageLoop). |
| 67 base::AtExitManager exit_manager; | 80 base::AtExitManager exit_manager; |
| 68 | 81 |
| 69 remoting::InitHostLogging(); | 82 InitHostLogging(); |
| 83 |
| 84 #if defined(OS_WIN) |
| 85 // Register and initialize common controls. |
| 86 INITCOMMONCONTROLSEX info; |
| 87 info.dwSize = sizeof(info); |
| 88 info.dwICC = ICC_STANDARD_CLASSES; |
| 89 InitCommonControlsEx(&info); |
| 90 |
| 91 // Mark the process as DPI-aware, so Windows won't scale coordinates in APIs. |
| 92 // N.B. This API exists on Vista and above. |
| 93 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { |
| 94 FilePath path(base::GetNativeLibraryName(UTF8ToUTF16("user32"))); |
| 95 base::ScopedNativeLibrary user32(path); |
| 96 CHECK(user32.is_valid()); |
| 97 |
| 98 typedef BOOL (WINAPI * SetProcessDPIAwareFn)(); |
| 99 SetProcessDPIAwareFn set_process_dpi_aware = |
| 100 static_cast<SetProcessDPIAwareFn>( |
| 101 user32.GetFunctionPointer("SetProcessDPIAware")); |
| 102 set_process_dpi_aware(); |
| 103 } |
| 104 #endif // defined(OS_WIN) |
| 70 | 105 |
| 71 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 106 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 72 if (command_line->HasSwitch(kHelpSwitchName) || | 107 if (command_line->HasSwitch(kHelpSwitchName) || |
| 73 command_line->HasSwitch(kQuestionSwitchName)) { | 108 command_line->HasSwitch(kQuestionSwitchName)) { |
| 74 Usage(command_line->GetProgram()); | 109 Usage(command_line->GetProgram()); |
| 75 return remoting::kSuccessExitCode; | 110 return kSuccessExitCode; |
| 76 } | 111 } |
| 77 | 112 |
| 78 std::string channel_name = | 113 std::string channel_name = |
| 79 command_line->GetSwitchValueASCII(kDaemonIpcSwitchName); | 114 command_line->GetSwitchValueASCII(kDaemonIpcSwitchName); |
| 80 | 115 |
| 81 if (channel_name.empty()) { | 116 if (channel_name.empty()) { |
| 82 Usage(command_line->GetProgram()); | 117 Usage(command_line->GetProgram()); |
| 83 return remoting::kUsageExitCode; | 118 return kUsageExitCode; |
| 84 } | 119 } |
| 85 | 120 |
| 86 MessageLoop message_loop(MessageLoop::TYPE_UI); | 121 MessageLoop message_loop(MessageLoop::TYPE_UI); |
| 87 base::RunLoop run_loop; | 122 base::RunLoop run_loop; |
| 88 base::Closure quit_ui_task_runner = base::Bind( | 123 base::Closure quit_ui_task_runner = base::Bind( |
| 89 base::IgnoreResult(&base::SingleThreadTaskRunner::PostTask), | 124 base::IgnoreResult(&base::SingleThreadTaskRunner::PostTask), |
| 90 message_loop.message_loop_proxy(), | 125 message_loop.message_loop_proxy(), |
| 91 FROM_HERE, run_loop.QuitClosure()); | 126 FROM_HERE, run_loop.QuitClosure()); |
| 92 scoped_refptr<remoting::AutoThreadTaskRunner> ui_task_runner = | 127 scoped_refptr<AutoThreadTaskRunner> ui_task_runner = |
| 93 new remoting::AutoThreadTaskRunner(message_loop.message_loop_proxy(), | 128 new AutoThreadTaskRunner(message_loop.message_loop_proxy(), |
| 94 quit_ui_task_runner); | 129 quit_ui_task_runner); |
| 95 | 130 |
| 96 remoting::DesktopProcess desktop_process(ui_task_runner, channel_name); | 131 DesktopProcess desktop_process(ui_task_runner, channel_name); |
| 97 if (!desktop_process.Start()) | 132 if (!desktop_process.Start()) |
| 98 return remoting::kInitializationFailed; | 133 return kInitializationFailed; |
| 99 | 134 |
| 100 // Run the UI message loop. | 135 // Run the UI message loop. |
| 101 ui_task_runner = NULL; | 136 ui_task_runner = NULL; |
| 102 run_loop.Run(); | 137 run_loop.Run(); |
| 103 | 138 |
| 104 return remoting::kSuccessExitCode; | 139 return kSuccessExitCode; |
| 105 } | 140 } |
| 106 | 141 |
| 107 #if defined(OS_WIN) | 142 } // namespace remoting |
| 108 | 143 |
| 109 int CALLBACK WinMain(HINSTANCE instance, | 144 #if !defined(OS_WIN) |
| 110 HINSTANCE previous_instance, | 145 int main(int argc, char** argv) { |
| 111 LPSTR raw_command_line, | 146 return remoting::DesktopProcessMain(argc, argv); |
| 112 int show_command) { | |
| 113 #ifdef OFFICIAL_BUILD | |
| 114 if (remoting::IsUsageStatsAllowed()) { | |
| 115 remoting::InitializeCrashReporting(); | |
| 116 } | |
| 117 #endif // OFFICIAL_BUILD | |
| 118 | |
| 119 // Register and initialize common controls. | |
| 120 INITCOMMONCONTROLSEX info; | |
| 121 info.dwSize = sizeof(info); | |
| 122 info.dwICC = ICC_STANDARD_CLASSES; | |
| 123 InitCommonControlsEx(&info); | |
| 124 | |
| 125 // Mark the process as DPI-aware, so Windows won't scale coordinates in APIs. | |
| 126 // N.B. This API exists on Vista and above. | |
| 127 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { | |
| 128 FilePath path(base::GetNativeLibraryName(UTF8ToUTF16("user32"))); | |
| 129 base::ScopedNativeLibrary user32(path); | |
| 130 CHECK(user32.is_valid()); | |
| 131 | |
| 132 typedef BOOL (WINAPI * SetProcessDPIAwareFn)(); | |
| 133 SetProcessDPIAwareFn set_process_dpi_aware = | |
| 134 static_cast<SetProcessDPIAwareFn>( | |
| 135 user32.GetFunctionPointer("SetProcessDPIAware")); | |
| 136 set_process_dpi_aware(); | |
| 137 } | |
| 138 | |
| 139 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting | |
| 140 // the command line from GetCommandLineW(), so we can safely pass NULL here. | |
| 141 return main(0, NULL); | |
| 142 } | 147 } |
| 143 | 148 #endif // !defined(OS_WIN) |
| 144 #endif // defined(OS_WIN) | |
| OLD | NEW |