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 a standalone host process for Me2Me. | 5 // This file implements a standalone host process for Me2Me. |
6 | 6 |
7 #include "remoting/host/remoting_me2me_host.h" | |
8 | |
9 #include <string> | 7 #include <string> |
10 | 8 |
11 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
12 #include "base/bind.h" | 10 #include "base/bind.h" |
13 #include "base/callback.h" | 11 #include "base/callback.h" |
14 #include "base/command_line.h" | 12 #include "base/command_line.h" |
15 #include "base/file_path.h" | 13 #include "base/file_path.h" |
16 #include "base/file_util.h" | 14 #include "base/file_util.h" |
17 #include "base/logging.h" | |
18 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
19 #include "base/message_loop.h" | 16 #include "base/message_loop.h" |
20 #include "base/scoped_native_library.h" | 17 #include "base/scoped_native_library.h" |
21 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
22 #include "base/string_number_conversions.h" | 19 #include "base/string_number_conversions.h" |
23 #include "base/string_util.h" | 20 #include "base/string_util.h" |
24 #include "base/strings/stringize_macros.h" | 21 #include "base/strings/stringize_macros.h" |
25 #include "base/synchronization/waitable_event.h" | 22 #include "base/synchronization/waitable_event.h" |
26 #include "base/threading/thread.h" | 23 #include "base/threading/thread.h" |
27 #include "base/utf_string_conversions.h" | 24 #include "base/utf_string_conversions.h" |
(...skipping 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1043 NOTREACHED(); | 1040 NOTREACHED(); |
1044 } | 1041 } |
1045 } | 1042 } |
1046 | 1043 |
1047 void HostProcess::OnCrash(const std::string& function_name, | 1044 void HostProcess::OnCrash(const std::string& function_name, |
1048 const std::string& file_name, | 1045 const std::string& file_name, |
1049 const int& line_number) { | 1046 const int& line_number) { |
1050 CHECK(false); | 1047 CHECK(false); |
1051 } | 1048 } |
1052 | 1049 |
1053 int HostProcessMain(int argc, char** argv) { | 1050 } // namespace remoting |
| 1051 |
| 1052 int main(int argc, char** argv) { |
1054 #if defined(OS_MACOSX) | 1053 #if defined(OS_MACOSX) |
1055 // Needed so we don't leak objects when threads are created. | 1054 // Needed so we don't leak objects when threads are created. |
1056 base::mac::ScopedNSAutoreleasePool pool; | 1055 base::mac::ScopedNSAutoreleasePool pool; |
1057 #endif | 1056 #endif |
1058 | 1057 |
1059 CommandLine::Init(argc, argv); | 1058 CommandLine::Init(argc, argv); |
1060 | 1059 |
1061 // Initialize Breakpad as early as possible. On Mac the command-line needs to | 1060 // Initialize Breakpad as early as possible. On Windows, this happens in |
1062 // be initialized first, so that the preference for crash-reporting can be | 1061 // WinMain(), so it shouldn't also be done here. The command-line needs to be |
1063 // looked up in the config file. | 1062 // initialized first, so that the preference for crash-reporting can be looked |
1064 #if defined(OFFICIAL_BUILD) && (defined(MAC_BREAKPAD) || defined(OS_WIN)) | 1063 // up in the config file. |
1065 if (IsUsageStatsAllowed()) { | 1064 #if defined(MAC_BREAKPAD) |
1066 InitializeCrashReporting(); | 1065 if (remoting::IsUsageStatsAllowed()) { |
| 1066 remoting::InitializeCrashReporting(); |
1067 } | 1067 } |
1068 #endif // defined(OFFICIAL_BUILD) && (defined(MAC_BREAKPAD) || defined(OS_WIN)) | 1068 #endif // MAC_BREAKPAD |
1069 | 1069 |
1070 // This object instance is required by Chrome code (for example, | 1070 // This object instance is required by Chrome code (for example, |
1071 // LazyInstance, MessageLoop). | 1071 // LazyInstance, MessageLoop). |
1072 base::AtExitManager exit_manager; | 1072 base::AtExitManager exit_manager; |
1073 | 1073 |
1074 if (CommandLine::ForCurrentProcess()->HasSwitch(kVersionSwitchName)) { | 1074 if (CommandLine::ForCurrentProcess()->HasSwitch(kVersionSwitchName)) { |
1075 printf("%s\n", STRINGIZE(VERSION)); | 1075 printf("%s\n", STRINGIZE(VERSION)); |
1076 return 0; | 1076 return 0; |
1077 } | 1077 } |
1078 | 1078 |
1079 InitHostLogging(); | 1079 remoting::InitHostLogging(); |
1080 | |
1081 #if defined(OS_WIN) | |
1082 // Register and initialize common controls. | |
1083 INITCOMMONCONTROLSEX info; | |
1084 info.dwSize = sizeof(info); | |
1085 info.dwICC = ICC_STANDARD_CLASSES; | |
1086 InitCommonControlsEx(&info); | |
1087 | |
1088 // Mark the process as DPI-aware, so Windows won't scale coordinates in APIs. | |
1089 // N.B. This API exists on Vista and above. | |
1090 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { | |
1091 FilePath path(base::GetNativeLibraryName(UTF8ToUTF16("user32"))); | |
1092 base::ScopedNativeLibrary user32(path); | |
1093 CHECK(user32.is_valid()); | |
1094 | |
1095 typedef BOOL (WINAPI * SetProcessDPIAwareFn)(); | |
1096 SetProcessDPIAwareFn set_process_dpi_aware = | |
1097 static_cast<SetProcessDPIAwareFn>( | |
1098 user32.GetFunctionPointer("SetProcessDPIAware")); | |
1099 set_process_dpi_aware(); | |
1100 } | |
1101 #endif // defined(OS_WIN) | |
1102 | 1080 |
1103 #if defined(TOOLKIT_GTK) | 1081 #if defined(TOOLKIT_GTK) |
1104 // Required for any calls into GTK functions, such as the Disconnect and | 1082 // Required for any calls into GTK functions, such as the Disconnect and |
1105 // Continue windows, though these should not be used for the Me2Me case | 1083 // Continue windows, though these should not be used for the Me2Me case |
1106 // (crbug.com/104377). | 1084 // (crbug.com/104377). |
1107 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | 1085 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
1108 gfx::GtkInitFromCommandLine(*cmd_line); | 1086 gfx::GtkInitFromCommandLine(*cmd_line); |
1109 #endif // TOOLKIT_GTK | 1087 #endif // TOOLKIT_GTK |
1110 | 1088 |
1111 // Enable support for SSL server sockets, which must be done while still | 1089 // Enable support for SSL server sockets, which must be done while still |
1112 // single-threaded. | 1090 // single-threaded. |
1113 net::EnableSSLServerSockets(); | 1091 net::EnableSSLServerSockets(); |
1114 | 1092 |
1115 // Create the main message loop and start helper threads. | 1093 // Create the main message loop and start helper threads. |
1116 MessageLoop message_loop(MessageLoop::TYPE_UI); | 1094 MessageLoop message_loop(MessageLoop::TYPE_UI); |
1117 scoped_ptr<ChromotingHostContext> context = | 1095 scoped_ptr<remoting::ChromotingHostContext> context = |
1118 ChromotingHostContext::Create( | 1096 remoting::ChromotingHostContext::Create( |
1119 new AutoThreadTaskRunner(message_loop.message_loop_proxy(), | 1097 new remoting::AutoThreadTaskRunner(message_loop.message_loop_proxy(), |
1120 MessageLoop::QuitClosure())); | 1098 MessageLoop::QuitClosure())); |
1121 if (!context) | 1099 if (!context) |
1122 return kInitializationFailed; | 1100 return remoting::kInitializationFailed; |
1123 | 1101 |
1124 // Create & start the HostProcess using these threads. | 1102 // Create & start the HostProcess using these threads. |
1125 // TODO(wez): The HostProcess holds a reference to itself until Shutdown(). | 1103 // TODO(wez): The HostProcess holds a reference to itself until Shutdown(). |
1126 // Remove this hack as part of the multi-process refactoring. | 1104 // Remove this hack as part of the multi-process refactoring. |
1127 int exit_code = kSuccessExitCode; | 1105 int exit_code = remoting::kSuccessExitCode; |
1128 new HostProcess(context.Pass(), &exit_code); | 1106 new remoting::HostProcess(context.Pass(), &exit_code); |
1129 | 1107 |
1130 // Run the main (also UI) message loop until the host no longer needs it. | 1108 // Run the main (also UI) message loop until the host no longer needs it. |
1131 message_loop.Run(); | 1109 message_loop.Run(); |
1132 | 1110 |
1133 return exit_code; | 1111 return exit_code; |
1134 } | 1112 } |
1135 | 1113 |
1136 } // namespace remoting | 1114 #if defined(OS_WIN) |
| 1115 HMODULE g_hModule = NULL; |
1137 | 1116 |
1138 #if !defined(OS_WIN) | 1117 int CALLBACK WinMain(HINSTANCE instance, |
1139 int main(int argc, char** argv) { | 1118 HINSTANCE previous_instance, |
1140 return remoting::HostProcessMain(argc, argv); | 1119 LPSTR command_line, |
| 1120 int show_command) { |
| 1121 #if defined(OFFICIAL_BUILD) |
| 1122 if (remoting::IsUsageStatsAllowed()) { |
| 1123 remoting::InitializeCrashReporting(); |
| 1124 } |
| 1125 #endif // OFFICIAL_BUILD |
| 1126 |
| 1127 g_hModule = instance; |
| 1128 |
| 1129 // Register and initialize common controls. |
| 1130 INITCOMMONCONTROLSEX info; |
| 1131 info.dwSize = sizeof(info); |
| 1132 info.dwICC = ICC_STANDARD_CLASSES; |
| 1133 InitCommonControlsEx(&info); |
| 1134 |
| 1135 // Mark the process as DPI-aware, so Windows won't scale coordinates in APIs. |
| 1136 // N.B. This API exists on Vista and above. |
| 1137 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { |
| 1138 base::FilePath path(base::GetNativeLibraryName(UTF8ToUTF16("user32"))); |
| 1139 base::ScopedNativeLibrary user32(path); |
| 1140 CHECK(user32.is_valid()); |
| 1141 |
| 1142 typedef BOOL (WINAPI * SetProcessDPIAwareFn)(); |
| 1143 SetProcessDPIAwareFn set_process_dpi_aware = |
| 1144 static_cast<SetProcessDPIAwareFn>( |
| 1145 user32.GetFunctionPointer("SetProcessDPIAware")); |
| 1146 set_process_dpi_aware(); |
| 1147 } |
| 1148 |
| 1149 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting |
| 1150 // the command line from GetCommandLineW(), so we can safely pass NULL here. |
| 1151 return main(0, NULL); |
1141 } | 1152 } |
1142 #endif // !defined(OS_WIN) | 1153 |
| 1154 #endif // defined(OS_WIN) |
OLD | NEW |