browser_main_gtk.cc revision 201ade2fbba22bfb27ae029f4d23fca6ded109a0
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 3// found in the LICENSE file. 4 5#include "chrome/browser/browser_main_gtk.h" 6 7#include <sys/stat.h> 8#include <sys/types.h> 9#include <unistd.h> 10 11#include "app/x11_util.h" 12#include "app/x11_util_internal.h" 13#include "base/command_line.h" 14#include "base/debug/debugger.h" 15#include "chrome/browser/browser_list.h" 16#include "chrome/browser/browser_main_gtk.h" 17#include "chrome/browser/browser_main_win.h" 18#include "chrome/browser/metrics/metrics_service.h" 19#include "chrome/browser/renderer_host/render_sandbox_host_linux.h" 20#include "chrome/browser/zygote_host_linux.h" 21#include "chrome/common/chrome_switches.h" 22#include "chrome/common/result_codes.h" 23 24#if defined(USE_NSS) 25#include "base/nss_util.h" 26#endif 27 28#if defined(USE_LINUX_BREAKPAD) 29#include "chrome/app/breakpad_linux.h" 30#endif 31 32namespace { 33 34// Indicates that we're currently responding to an IO error (by shutting down). 35bool g_in_x11_io_error_handler = false; 36 37int BrowserX11ErrorHandler(Display* d, XErrorEvent* error) { 38 if (!g_in_x11_io_error_handler) 39 LOG(ERROR) << x11_util::GetErrorEventDescription(d, error); 40 return 0; 41} 42 43int BrowserX11IOErrorHandler(Display* d) { 44 // If there's an IO error it likely means the X server has gone away 45 if (!g_in_x11_io_error_handler) { 46 g_in_x11_io_error_handler = true; 47 LOG(ERROR) << "X IO Error detected"; 48 BrowserList::SessionEnding(); 49 } 50 51 return 0; 52} 53 54} // namespace 55 56void BrowserMainPartsGtk::PreEarlyInitialization() { 57 BrowserMainPartsPosix::PreEarlyInitialization(); 58 59 SetupSandbox(); 60 61#if defined(USE_NSS) 62 // We want to be sure to init NSPR on the main thread. 63 base::EnsureNSPRInit(); 64#endif 65} 66 67void BrowserMainPartsGtk::SetupSandbox() { 68 // TODO(evanm): move this into SandboxWrapper; I'm just trying to move this 69 // code en masse out of chrome_main for now. 70 const char* sandbox_binary = NULL; 71 struct stat st; 72 73 // In Chromium branded builds, developers can set an environment variable to 74 // use the development sandbox. See 75 // http://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment 76 if (stat("/proc/self/exe", &st) == 0 && st.st_uid == getuid()) 77 sandbox_binary = getenv("CHROME_DEVEL_SANDBOX"); 78 79#if defined(LINUX_SANDBOX_PATH) 80 if (!sandbox_binary) 81 sandbox_binary = LINUX_SANDBOX_PATH; 82#endif 83 84 std::string sandbox_cmd; 85 if (sandbox_binary && !parsed_command_line().HasSwitch(switches::kNoSandbox)) 86 sandbox_cmd = sandbox_binary; 87 88 // Tickle the sandbox host and zygote host so they fork now. 89 RenderSandboxHostLinux* shost = Singleton<RenderSandboxHostLinux>::get(); 90 shost->Init(sandbox_cmd); 91 ZygoteHost* zhost = Singleton<ZygoteHost>::get(); 92 zhost->Init(sandbox_cmd); 93} 94 95void DidEndMainMessageLoop() { 96} 97 98void RecordBreakpadStatusUMA(MetricsService* metrics) { 99#if defined(USE_LINUX_BREAKPAD) 100 metrics->RecordBreakpadRegistration(IsCrashReporterEnabled()); 101#else 102 metrics->RecordBreakpadRegistration(false); 103#endif 104 metrics->RecordBreakpadHasDebugger(base::debug::BeingDebugged()); 105} 106 107void WarnAboutMinimumSystemRequirements() { 108 // Nothing to warn about on GTK right now. 109} 110 111// From browser_main_win.h, stubs until we figure out the right thing... 112 113int DoUninstallTasks(bool chrome_still_running) { 114 return ResultCodes::NORMAL_EXIT; 115} 116 117int HandleIconsCommands(const CommandLine &parsed_command_line) { 118 return 0; 119} 120 121bool CheckMachineLevelInstall() { 122 return false; 123} 124 125void PrepareRestartOnCrashEnviroment(const CommandLine &parsed_command_line) { 126} 127 128void SetBrowserX11ErrorHandlers() { 129 // Set up error handlers to make sure profile gets written if X server 130 // goes away. 131 x11_util::SetX11ErrorHandlers( 132 BrowserX11ErrorHandler, 133 BrowserX11IOErrorHandler); 134} 135 136#if !defined(OS_CHROMEOS) 137// static 138BrowserMainParts* BrowserMainParts::CreateBrowserMainParts( 139 const MainFunctionParams& parameters) { 140 return new BrowserMainPartsGtk(parameters); 141} 142#endif 143