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