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 |
7 #include <string> | 9 #include <string> |
8 | 10 |
9 #include "base/at_exit.h" | 11 #include "base/at_exit.h" |
10 #include "base/bind.h" | 12 #include "base/bind.h" |
11 #include "base/callback.h" | 13 #include "base/callback.h" |
12 #include "base/command_line.h" | 14 #include "base/command_line.h" |
13 #include "base/file_path.h" | 15 #include "base/file_path.h" |
14 #include "base/file_util.h" | 16 #include "base/file_util.h" |
| 17 #include "base/logging.h" |
15 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
16 #include "base/message_loop.h" | 19 #include "base/message_loop.h" |
17 #include "base/scoped_native_library.h" | 20 #include "base/scoped_native_library.h" |
18 #include "base/single_thread_task_runner.h" | 21 #include "base/single_thread_task_runner.h" |
19 #include "base/string_number_conversions.h" | 22 #include "base/string_number_conversions.h" |
20 #include "base/string_util.h" | 23 #include "base/string_util.h" |
21 #include "base/strings/stringize_macros.h" | 24 #include "base/strings/stringize_macros.h" |
22 #include "base/synchronization/waitable_event.h" | 25 #include "base/synchronization/waitable_event.h" |
23 #include "base/threading/thread.h" | 26 #include "base/threading/thread.h" |
24 #include "base/utf_string_conversions.h" | 27 #include "base/utf_string_conversions.h" |
(...skipping 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1040 NOTREACHED(); | 1043 NOTREACHED(); |
1041 } | 1044 } |
1042 } | 1045 } |
1043 | 1046 |
1044 void HostProcess::OnCrash(const std::string& function_name, | 1047 void HostProcess::OnCrash(const std::string& function_name, |
1045 const std::string& file_name, | 1048 const std::string& file_name, |
1046 const int& line_number) { | 1049 const int& line_number) { |
1047 CHECK(false); | 1050 CHECK(false); |
1048 } | 1051 } |
1049 | 1052 |
1050 } // namespace remoting | 1053 int HostProcessMain(int argc, char** argv) { |
1051 | |
1052 int main(int argc, char** argv) { | |
1053 #if defined(OS_MACOSX) | 1054 #if defined(OS_MACOSX) |
1054 // Needed so we don't leak objects when threads are created. | 1055 // Needed so we don't leak objects when threads are created. |
1055 base::mac::ScopedNSAutoreleasePool pool; | 1056 base::mac::ScopedNSAutoreleasePool pool; |
1056 #endif | 1057 #endif |
1057 | 1058 |
1058 CommandLine::Init(argc, argv); | 1059 CommandLine::Init(argc, argv); |
1059 | 1060 |
1060 // Initialize Breakpad as early as possible. On Windows, this happens in | 1061 // Initialize Breakpad as early as possible. On Mac the command-line needs to |
1061 // WinMain(), so it shouldn't also be done here. The command-line needs to be | 1062 // be initialized first, so that the preference for crash-reporting can be |
1062 // initialized first, so that the preference for crash-reporting can be looked | 1063 // looked up in the config file. |
1063 // up in the config file. | 1064 #if defined(OFFICIAL_BUILD) && (defined(MAC_BREAKPAD) || defined(OS_WIN)) |
1064 #if defined(MAC_BREAKPAD) | 1065 if (IsUsageStatsAllowed()) { |
1065 if (remoting::IsUsageStatsAllowed()) { | 1066 InitializeCrashReporting(); |
1066 remoting::InitializeCrashReporting(); | |
1067 } | 1067 } |
1068 #endif // MAC_BREAKPAD | 1068 #endif // defined(OFFICIAL_BUILD) && (defined(MAC_BREAKPAD) || defined(OS_WIN)) |
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 remoting::InitHostLogging(); | 1079 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) |
1080 | 1102 |
1081 #if defined(TOOLKIT_GTK) | 1103 #if defined(TOOLKIT_GTK) |
1082 // Required for any calls into GTK functions, such as the Disconnect and | 1104 // Required for any calls into GTK functions, such as the Disconnect and |
1083 // Continue windows, though these should not be used for the Me2Me case | 1105 // Continue windows, though these should not be used for the Me2Me case |
1084 // (crbug.com/104377). | 1106 // (crbug.com/104377). |
1085 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | 1107 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
1086 gfx::GtkInitFromCommandLine(*cmd_line); | 1108 gfx::GtkInitFromCommandLine(*cmd_line); |
1087 #endif // TOOLKIT_GTK | 1109 #endif // TOOLKIT_GTK |
1088 | 1110 |
1089 // Enable support for SSL server sockets, which must be done while still | 1111 // Enable support for SSL server sockets, which must be done while still |
1090 // single-threaded. | 1112 // single-threaded. |
1091 net::EnableSSLServerSockets(); | 1113 net::EnableSSLServerSockets(); |
1092 | 1114 |
1093 // Create the main message loop and start helper threads. | 1115 // Create the main message loop and start helper threads. |
1094 MessageLoop message_loop(MessageLoop::TYPE_UI); | 1116 MessageLoop message_loop(MessageLoop::TYPE_UI); |
1095 scoped_ptr<remoting::ChromotingHostContext> context = | 1117 scoped_ptr<ChromotingHostContext> context = |
1096 remoting::ChromotingHostContext::Create( | 1118 ChromotingHostContext::Create( |
1097 new remoting::AutoThreadTaskRunner(message_loop.message_loop_proxy(), | 1119 new AutoThreadTaskRunner(message_loop.message_loop_proxy(), |
1098 MessageLoop::QuitClosure())); | 1120 MessageLoop::QuitClosure())); |
1099 if (!context) | 1121 if (!context) |
1100 return remoting::kInitializationFailed; | 1122 return kInitializationFailed; |
1101 | 1123 |
1102 // Create & start the HostProcess using these threads. | 1124 // Create & start the HostProcess using these threads. |
1103 // TODO(wez): The HostProcess holds a reference to itself until Shutdown(). | 1125 // TODO(wez): The HostProcess holds a reference to itself until Shutdown(). |
1104 // Remove this hack as part of the multi-process refactoring. | 1126 // Remove this hack as part of the multi-process refactoring. |
1105 int exit_code = remoting::kSuccessExitCode; | 1127 int exit_code = kSuccessExitCode; |
1106 new remoting::HostProcess(context.Pass(), &exit_code); | 1128 new HostProcess(context.Pass(), &exit_code); |
1107 | 1129 |
1108 // Run the main (also UI) message loop until the host no longer needs it. | 1130 // Run the main (also UI) message loop until the host no longer needs it. |
1109 message_loop.Run(); | 1131 message_loop.Run(); |
1110 | 1132 |
1111 return exit_code; | 1133 return exit_code; |
1112 } | 1134 } |
1113 | 1135 |
1114 #if defined(OS_WIN) | 1136 } // namespace remoting |
1115 HMODULE g_hModule = NULL; | |
1116 | 1137 |
1117 int CALLBACK WinMain(HINSTANCE instance, | 1138 #if !defined(OS_WIN) |
1118 HINSTANCE previous_instance, | 1139 int main(int argc, char** argv) { |
1119 LPSTR command_line, | 1140 return remoting::HostProcessMain(argc, argv); |
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 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); | |
1152 } | 1141 } |
1153 | 1142 #endif // !defined(OS_WIN) |
1154 #endif // defined(OS_WIN) | |
OLD | NEW |