OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // TODO(port): the ifdefs in here are a first step towards trying to determine | 5 // TODO(port): the ifdefs in here are a first step towards trying to determine |
6 // the correct abstraction for all the OS functionality required at this | 6 // the correct abstraction for all the OS functionality required at this |
7 // stage of process initialization. It should not be taken as a final | 7 // stage of process initialization. It should not be taken as a final |
8 // abstraction. | 8 // abstraction. |
9 | 9 |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 | 11 |
12 #if defined(OS_WIN) | 12 #if defined(OS_WIN) |
13 #include <algorithm> | 13 #include <algorithm> |
14 #include <atlbase.h> | 14 #include <atlbase.h> |
15 #include <atlapp.h> | 15 #include <atlapp.h> |
16 #include <malloc.h> | 16 #include <malloc.h> |
17 #include <new.h> | 17 #include <new.h> |
18 #elif defined(OS_POSIX) | 18 #elif defined(OS_POSIX) |
19 #include <locale.h> | 19 #include <locale.h> |
20 #include <signal.h> | 20 #include <signal.h> |
21 #include <sys/stat.h> | 21 #include <sys/stat.h> |
22 #include <sys/types.h> | 22 #include <sys/types.h> |
23 #include <unistd.h> | 23 #include <unistd.h> |
24 #endif | 24 #endif |
25 | 25 |
26 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 26 #if defined(USE_X11) |
27 #include <gdk/gdk.h> | 27 #include <gdk/gdk.h> |
28 #include <glib.h> | 28 #include <glib.h> |
29 #include <gtk/gtk.h> | 29 #include <gtk/gtk.h> |
30 #include <stdlib.h> | 30 #include <stdlib.h> |
31 #include <string.h> | 31 #include <string.h> |
32 #endif | 32 #endif |
33 | 33 |
34 #include "app/app_paths.h" | 34 #include "app/app_paths.h" |
35 #include "app/app_switches.h" | 35 #include "app/app_switches.h" |
36 #include "app/resource_bundle.h" | 36 #include "app/resource_bundle.h" |
(...skipping 20 matching lines...) Expand all Loading... |
57 #include "chrome/common/logging_chrome.h" | 57 #include "chrome/common/logging_chrome.h" |
58 #include "chrome/common/main_function_params.h" | 58 #include "chrome/common/main_function_params.h" |
59 #include "chrome/common/sandbox_init_wrapper.h" | 59 #include "chrome/common/sandbox_init_wrapper.h" |
60 #include "chrome/common/url_constants.h" | 60 #include "chrome/common/url_constants.h" |
61 #include "ipc/ipc_switches.h" | 61 #include "ipc/ipc_switches.h" |
62 | 62 |
63 #if defined(USE_NSS) | 63 #if defined(USE_NSS) |
64 #include "base/nss_util.h" | 64 #include "base/nss_util.h" |
65 #endif | 65 #endif |
66 | 66 |
| 67 #if defined(USE_X11) |
| 68 #include "app/x11_util.h" |
| 69 #endif |
| 70 |
67 #if defined(OS_LINUX) | 71 #if defined(OS_LINUX) |
68 #include "chrome/browser/renderer_host/render_sandbox_host_linux.h" | 72 #include "chrome/browser/renderer_host/render_sandbox_host_linux.h" |
69 #include "chrome/browser/zygote_host_linux.h" | 73 #include "chrome/browser/zygote_host_linux.h" |
70 #endif | 74 #endif |
71 | 75 |
72 #if defined(OS_MACOSX) | 76 #if defined(OS_MACOSX) |
73 #include "app/l10n_util_mac.h" | 77 #include "app/l10n_util_mac.h" |
74 #include "base/mac_util.h" | 78 #include "base/mac_util.h" |
75 #include "chrome/common/chrome_paths_internal.h" | 79 #include "chrome/common/chrome_paths_internal.h" |
76 #include "chrome/app/breakpad_mac.h" | 80 #include "chrome/app/breakpad_mac.h" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 // some apps fail to properly escape arguments. | 199 // some apps fail to properly escape arguments. |
196 bool HasDeprecatedArguments(const std::wstring& command_line) { | 200 bool HasDeprecatedArguments(const std::wstring& command_line) { |
197 const wchar_t kChromeHtml[] = L"chromehtml:"; | 201 const wchar_t kChromeHtml[] = L"chromehtml:"; |
198 std::wstring command_line_lower = command_line; | 202 std::wstring command_line_lower = command_line; |
199 // We are only searching for ASCII characters so this is OK. | 203 // We are only searching for ASCII characters so this is OK. |
200 StringToLowerASCII(&command_line_lower); | 204 StringToLowerASCII(&command_line_lower); |
201 std::wstring::size_type pos = command_line_lower.find(kChromeHtml); | 205 std::wstring::size_type pos = command_line_lower.find(kChromeHtml); |
202 return (pos != std::wstring::npos); | 206 return (pos != std::wstring::npos); |
203 } | 207 } |
204 | 208 |
205 #endif // OS_WIN | 209 #endif // defined(OS_WIN) |
206 | 210 |
207 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 211 #if defined(USE_X11) |
208 static void GLibLogHandler(const gchar* log_domain, | 212 static void GLibLogHandler(const gchar* log_domain, |
209 GLogLevelFlags log_level, | 213 GLogLevelFlags log_level, |
210 const gchar* message, | 214 const gchar* message, |
211 gpointer userdata) { | 215 gpointer userdata) { |
212 if (!log_domain) | 216 if (!log_domain) |
213 log_domain = "<unknown>"; | 217 log_domain = "<unknown>"; |
214 if (!message) | 218 if (!message) |
215 message = "<no message>"; | 219 message = "<no message>"; |
216 | 220 |
217 if (strstr(message, "Loading IM context type") || | 221 if (strstr(message, "Loading IM context type") || |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 g_log_set_handler(kLogDomains[i], | 256 g_log_set_handler(kLogDomains[i], |
253 static_cast<GLogLevelFlags>(G_LOG_FLAG_RECURSION | | 257 static_cast<GLogLevelFlags>(G_LOG_FLAG_RECURSION | |
254 G_LOG_FLAG_FATAL | | 258 G_LOG_FLAG_FATAL | |
255 G_LOG_LEVEL_ERROR | | 259 G_LOG_LEVEL_ERROR | |
256 G_LOG_LEVEL_CRITICAL | | 260 G_LOG_LEVEL_CRITICAL | |
257 G_LOG_LEVEL_WARNING), | 261 G_LOG_LEVEL_WARNING), |
258 GLibLogHandler, | 262 GLibLogHandler, |
259 NULL); | 263 NULL); |
260 } | 264 } |
261 } | 265 } |
| 266 #endif // defined(USE_X11) |
262 | 267 |
| 268 #if defined(OS_LINUX) |
263 static void AdjustLinuxOOMScore(const std::string& process_type) { | 269 static void AdjustLinuxOOMScore(const std::string& process_type) { |
264 const int kMiscScore = 7; | 270 const int kMiscScore = 7; |
265 const int kPluginScore = 10; | 271 const int kPluginScore = 10; |
266 int score = -1; | 272 int score = -1; |
267 | 273 |
268 if (process_type == switches::kPluginProcess) { | 274 if (process_type == switches::kPluginProcess) { |
269 score = kPluginScore; | 275 score = kPluginScore; |
270 } else if (process_type == switches::kUtilityProcess || | 276 } else if (process_type == switches::kUtilityProcess || |
271 process_type == switches::kWorkerProcess || | 277 process_type == switches::kWorkerProcess || |
272 process_type == switches::kGpuProcess || | 278 process_type == switches::kGpuProcess || |
(...skipping 13 matching lines...) Expand all Loading... |
286 LOG(WARNING) << "process type '" << process_type << "' " | 292 LOG(WARNING) << "process type '" << process_type << "' " |
287 << "should go through the zygote."; | 293 << "should go through the zygote."; |
288 // When debugging, these process types can end up being run directly. | 294 // When debugging, these process types can end up being run directly. |
289 return; | 295 return; |
290 } else { | 296 } else { |
291 NOTREACHED() << "Unknown process type"; | 297 NOTREACHED() << "Unknown process type"; |
292 } | 298 } |
293 if (score > -1) | 299 if (score > -1) |
294 base::AdjustOOMScore(base::GetCurrentProcId(), score); | 300 base::AdjustOOMScore(base::GetCurrentProcId(), score); |
295 } | 301 } |
296 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) | 302 #endif // defined(OS_LINUX) |
297 | 303 |
298 // Register the invalid param handler and pure call handler to be able to | 304 // Register the invalid param handler and pure call handler to be able to |
299 // notify breakpad when it happens. | 305 // notify breakpad when it happens. |
300 void RegisterInvalidParamHandler() { | 306 void RegisterInvalidParamHandler() { |
301 #if defined(OS_WIN) | 307 #if defined(OS_WIN) |
302 _set_invalid_parameter_handler(InvalidParameter); | 308 _set_invalid_parameter_handler(InvalidParameter); |
303 _set_purecall_handler(PureCall); | 309 _set_purecall_handler(PureCall); |
304 // Gather allocation failure. | 310 // Gather allocation failure. |
305 std::set_new_handler(&OnNoMemory); | 311 std::set_new_handler(&OnNoMemory); |
306 // Also enable the new handler for malloc() based failures. | 312 // Also enable the new handler for malloc() based failures. |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 // sources. The language should have been passed in to us from the | 703 // sources. The language should have been passed in to us from the |
698 // browser process as a command line flag. | 704 // browser process as a command line flag. |
699 DCHECK(parsed_command_line.HasSwitch(switches::kLang) || | 705 DCHECK(parsed_command_line.HasSwitch(switches::kLang) || |
700 process_type == switches::kZygoteProcess); | 706 process_type == switches::kZygoteProcess); |
701 ResourceBundle::InitSharedInstance(std::wstring()); | 707 ResourceBundle::InitSharedInstance(std::wstring()); |
702 | 708 |
703 #if defined(OS_MACOSX) | 709 #if defined(OS_MACOSX) |
704 // Update the process name (need resources to get the strings, so | 710 // Update the process name (need resources to get the strings, so |
705 // only do this when ResourcesBundle has been initialized). | 711 // only do this when ResourcesBundle has been initialized). |
706 SetMacProcessName(process_type); | 712 SetMacProcessName(process_type); |
707 #endif // defined(OS_MACOSX) | 713 #endif // defined(OS_MACOSX) |
708 | |
709 } | 714 } |
710 | 715 |
711 if (!process_type.empty()) | 716 if (!process_type.empty()) |
712 CommonSubprocessInit(); | 717 CommonSubprocessInit(); |
713 | 718 |
714 #if defined(OS_MACOSX) | 719 #if defined(OS_MACOSX) |
715 // On OS X the renderer sandbox needs to be initialized later in the startup | 720 // On OS X the renderer sandbox needs to be initialized later in the startup |
716 // sequence in RendererMainPlatformDelegate::PlatformInitialize(). | 721 // sequence in RendererMainPlatformDelegate::PlatformInitialize(). |
717 if (process_type != switches::kRendererProcess && | 722 if (process_type != switches::kRendererProcess && |
718 process_type != switches::kExtensionProcess) { | 723 process_type != switches::kExtensionProcess) { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 g_thread_init(NULL); | 834 g_thread_init(NULL); |
830 // Glib type system initialization. Needed at least for gconf, | 835 // Glib type system initialization. Needed at least for gconf, |
831 // used in net/proxy/proxy_config_service_linux.cc. Most likely | 836 // used in net/proxy/proxy_config_service_linux.cc. Most likely |
832 // this is superfluous as gtk_init() ought to do this. It's | 837 // this is superfluous as gtk_init() ought to do this. It's |
833 // definitely harmless, so retained as a reminder of this | 838 // definitely harmless, so retained as a reminder of this |
834 // requirement for gconf. | 839 // requirement for gconf. |
835 g_type_init(); | 840 g_type_init(); |
836 // gtk_init() can change |argc| and |argv|. | 841 // gtk_init() can change |argc| and |argv|. |
837 gtk_init(&argc, &argv); | 842 gtk_init(&argc, &argv); |
838 SetUpGLibLogHandler(); | 843 SetUpGLibLogHandler(); |
| 844 |
| 845 x11_util::SetX11ErrorHandlers(); |
839 #endif // defined(OS_LINUX) | 846 #endif // defined(OS_LINUX) |
840 | 847 |
841 rv = BrowserMain(main_params); | 848 rv = BrowserMain(main_params); |
842 } else { | 849 } else { |
843 NOTREACHED() << "Unknown process type"; | 850 NOTREACHED() << "Unknown process type"; |
844 } | 851 } |
845 | 852 |
846 if (SubprocessNeedsResourceBundle(process_type)) | 853 if (SubprocessNeedsResourceBundle(process_type)) |
847 ResourceBundle::CleanupSharedInstance(); | 854 ResourceBundle::CleanupSharedInstance(); |
848 | 855 |
849 #if defined(OS_WIN) | 856 #if defined(OS_WIN) |
850 #ifdef _CRTDBG_MAP_ALLOC | 857 #ifdef _CRTDBG_MAP_ALLOC |
851 _CrtDumpMemoryLeaks(); | 858 _CrtDumpMemoryLeaks(); |
852 #endif // _CRTDBG_MAP_ALLOC | 859 #endif // _CRTDBG_MAP_ALLOC |
853 | 860 |
854 _Module.Term(); | 861 _Module.Term(); |
855 #endif | 862 #endif |
856 | 863 |
857 logging::CleanupChromeLogging(); | 864 logging::CleanupChromeLogging(); |
858 | 865 |
859 #if defined(OS_MACOSX) && defined(GOOGLE_CHROME_BUILD) | 866 #if defined(OS_MACOSX) && defined(GOOGLE_CHROME_BUILD) |
860 // TODO(mark): See the TODO(mark) above at InitCrashReporter. | 867 // TODO(mark): See the TODO(mark) above at InitCrashReporter. |
861 DestructCrashReporter(); | 868 DestructCrashReporter(); |
862 #endif // OS_MACOSX && GOOGLE_CHROME_BUILD | 869 #endif // OS_MACOSX && GOOGLE_CHROME_BUILD |
863 | 870 |
864 return rv; | 871 return rv; |
865 } | 872 } |
OLD | NEW |