Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: content/app/content_main_runner.cc

Issue 1387963006: Adding error handlers to setup.exe (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix lint errors/warnings Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/app/BUILD.gn ('k') | content/app/sandbox_helper_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "content/public/app/content_main_runner.h" 5 #include "content/public/app/content_main_runner.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 8
9 #include <string>
10
9 #include "base/allocator/allocator_extension.h" 11 #include "base/allocator/allocator_extension.h"
10 #include "base/at_exit.h" 12 #include "base/at_exit.h"
11 #include "base/command_line.h" 13 #include "base/command_line.h"
12 #include "base/debug/debugger.h" 14 #include "base/debug/debugger.h"
13 #include "base/debug/stack_trace.h" 15 #include "base/debug/stack_trace.h"
14 #include "base/files/file_path.h" 16 #include "base/files/file_path.h"
15 #include "base/i18n/icu_util.h" 17 #include "base/i18n/icu_util.h"
16 #include "base/lazy_instance.h" 18 #include "base/lazy_instance.h"
17 #include "base/logging.h" 19 #include "base/logging.h"
18 #include "base/memory/scoped_ptr.h" 20 #include "base/memory/scoped_ptr.h"
(...skipping 10 matching lines...) Expand all
29 #include "base/strings/stringprintf.h" 31 #include "base/strings/stringprintf.h"
30 #include "base/trace_event/trace_event.h" 32 #include "base/trace_event/trace_event.h"
31 #include "components/tracing/trace_config_file.h" 33 #include "components/tracing/trace_config_file.h"
32 #include "components/tracing/tracing_switches.h" 34 #include "components/tracing/tracing_switches.h"
33 #include "content/browser/browser_main.h" 35 #include "content/browser/browser_main.h"
34 #include "content/common/set_process_title.h" 36 #include "content/common/set_process_title.h"
35 #include "content/common/url_schemes.h" 37 #include "content/common/url_schemes.h"
36 #include "content/gpu/in_process_gpu_thread.h" 38 #include "content/gpu/in_process_gpu_thread.h"
37 #include "content/public/app/content_main.h" 39 #include "content/public/app/content_main.h"
38 #include "content/public/app/content_main_delegate.h" 40 #include "content/public/app/content_main_delegate.h"
39 #include "content/public/app/startup_helper_win.h"
40 #include "content/public/browser/content_browser_client.h" 41 #include "content/public/browser/content_browser_client.h"
41 #include "content/public/common/content_client.h" 42 #include "content/public/common/content_client.h"
42 #include "content/public/common/content_constants.h" 43 #include "content/public/common/content_constants.h"
43 #include "content/public/common/content_paths.h" 44 #include "content/public/common/content_paths.h"
44 #include "content/public/common/content_switches.h" 45 #include "content/public/common/content_switches.h"
45 #include "content/public/common/main_function_params.h" 46 #include "content/public/common/main_function_params.h"
46 #include "content/public/common/sandbox_init.h" 47 #include "content/public/common/sandbox_init.h"
47 #include "content/renderer/in_process_renderer_thread.h" 48 #include "content/renderer/in_process_renderer_thread.h"
48 #include "content/utility/in_process_utility_thread.h" 49 #include "content/utility/in_process_utility_thread.h"
49 #include "ipc/ipc_descriptors.h" 50 #include "ipc/ipc_descriptors.h"
(...skipping 18 matching lines...) Expand all
68 #include "content/browser/utility_process_host_impl.h" 69 #include "content/browser/utility_process_host_impl.h"
69 #include "content/public/plugin/content_plugin_client.h" 70 #include "content/public/plugin/content_plugin_client.h"
70 #include "content/public/renderer/content_renderer_client.h" 71 #include "content/public/renderer/content_renderer_client.h"
71 #include "content/public/utility/content_utility_client.h" 72 #include "content/public/utility/content_utility_client.h"
72 #endif 73 #endif
73 74
74 #if defined(OS_WIN) 75 #if defined(OS_WIN)
75 #include <malloc.h> 76 #include <malloc.h>
76 #include <cstring> 77 #include <cstring>
77 78
78 #include "base/strings/string_number_conversions.h"
79 #include "base/trace_event/trace_event_etw_export_win.h" 79 #include "base/trace_event/trace_event_etw_export_win.h"
80 #include "base/win/process_startup_helper.h"
80 #include "ui/base/win/atl_module.h" 81 #include "ui/base/win/atl_module.h"
81 #include "ui/gfx/win/dpi.h" 82 #include "ui/gfx/win/dpi.h"
82 #elif defined(OS_MACOSX) 83 #elif defined(OS_MACOSX)
83 #include "base/mac/scoped_nsautorelease_pool.h" 84 #include "base/mac/scoped_nsautorelease_pool.h"
84 #if !defined(OS_IOS) 85 #if !defined(OS_IOS)
85 #include "base/power_monitor/power_monitor_device_source.h" 86 #include "base/power_monitor/power_monitor_device_source.h"
86 #include "content/app/mac/mac_init.h" 87 #include "content/app/mac/mac_init.h"
87 #include "content/browser/browser_io_surface_manager_mac.h" 88 #include "content/browser/browser_io_surface_manager_mac.h"
88 #include "content/browser/mach_broker_mac.h" 89 #include "content/browser/mach_broker_mac.h"
89 #include "content/child/child_io_surface_manager_mac.h" 90 #include "content/child/child_io_surface_manager_mac.h"
90 #include "content/common/sandbox_init_mac.h" 91 #include "content/common/sandbox_init_mac.h"
91 #endif // !OS_IOS 92 #endif // !OS_IOS
92 #endif // OS_WIN 93 #endif // OS_WIN
93 94
94 #if defined(OS_POSIX) 95 #if defined(OS_POSIX)
95 #include <signal.h> 96 #include <signal.h>
96 97
97 #include "base/posix/global_descriptors.h" 98 #include "base/posix/global_descriptors.h"
98 #include "content/public/common/content_descriptors.h" 99 #include "content/public/common/content_descriptors.h"
99 100
100 #if !defined(OS_MACOSX) 101 #if !defined(OS_MACOSX)
101 #include "content/public/common/content_descriptors.h"
102 #include "content/public/common/zygote_fork_delegate_linux.h" 102 #include "content/public/common/zygote_fork_delegate_linux.h"
103 #endif 103 #endif
104 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) 104 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
105 #include "content/zygote/zygote_main.h" 105 #include "content/zygote/zygote_main.h"
106 #endif 106 #endif
107 107
108 #endif // OS_POSIX 108 #endif // OS_POSIX
109 109
110 #if defined(USE_NSS_CERTS) 110 #if defined(USE_NSS_CERTS)
111 #include "crypto/nss_util.h" 111 #include "crypto/nss_util.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 150
151 #endif // defined(OS_WIN) 151 #endif // defined(OS_WIN)
152 152
153 #if defined(OS_POSIX) && !defined(OS_IOS) 153 #if defined(OS_POSIX) && !defined(OS_IOS)
154 154
155 // Setup signal-handling state: resanitize most signals, ignore SIGPIPE. 155 // Setup signal-handling state: resanitize most signals, ignore SIGPIPE.
156 void SetupSignalHandlers() { 156 void SetupSignalHandlers() {
157 // Sanitise our signal handling state. Signals that were ignored by our 157 // Sanitise our signal handling state. Signals that were ignored by our
158 // parent will also be ignored by us. We also inherit our parent's sigmask. 158 // parent will also be ignored by us. We also inherit our parent's sigmask.
159 sigset_t empty_signal_set; 159 sigset_t empty_signal_set;
160 CHECK(0 == sigemptyset(&empty_signal_set)); 160 CHECK_EQ(0, sigemptyset(&empty_signal_set));
161 CHECK(0 == sigprocmask(SIG_SETMASK, &empty_signal_set, NULL)); 161 CHECK_EQ(0, sigprocmask(SIG_SETMASK, &empty_signal_set, NULL));
162 162
163 struct sigaction sigact; 163 struct sigaction sigact;
164 memset(&sigact, 0, sizeof(sigact)); 164 memset(&sigact, 0, sizeof(sigact));
165 sigact.sa_handler = SIG_DFL; 165 sigact.sa_handler = SIG_DFL;
166 static const int signals_to_reset[] = 166 static const int signals_to_reset[] =
167 {SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGABRT, SIGFPE, SIGSEGV, 167 {SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGABRT, SIGFPE, SIGSEGV,
168 SIGALRM, SIGTERM, SIGCHLD, SIGBUS, SIGTRAP}; // SIGPIPE is set below. 168 SIGALRM, SIGTERM, SIGCHLD, SIGBUS, SIGTRAP}; // SIGPIPE is set below.
169 for (unsigned i = 0; i < arraysize(signals_to_reset); i++) { 169 for (unsigned i = 0; i < arraysize(signals_to_reset); i++) {
170 CHECK(0 == sigaction(signals_to_reset[i], &sigact, NULL)); 170 CHECK_EQ(0, sigaction(signals_to_reset[i], &sigact, NULL));
171 } 171 }
172 172
173 // Always ignore SIGPIPE. We check the return value of write(). 173 // Always ignore SIGPIPE. We check the return value of write().
174 CHECK(signal(SIGPIPE, SIG_IGN) != SIG_ERR); 174 CHECK_NE(SIG_ERR, signal(SIGPIPE, SIG_IGN));
175 } 175 }
176 176
177 #endif // OS_POSIX && !OS_IOS 177 #endif // OS_POSIX && !OS_IOS
178 178
179 void CommonSubprocessInit(const std::string& process_type) { 179 void CommonSubprocessInit(const std::string& process_type) {
180 #if defined(OS_WIN) 180 #if defined(OS_WIN)
181 // HACK: Let Windows know that we have started. This is needed to suppress 181 // HACK: Let Windows know that we have started. This is needed to suppress
182 // the IDC_APPSTARTING cursor from being displayed for a prolonged period 182 // the IDC_APPSTARTING cursor from being displayed for a prolonged period
183 // while a subprocess is starting. 183 // while a subprocess is starting.
184 PostThreadMessage(GetCurrentThreadId(), WM_NULL, 0, 0); 184 PostThreadMessage(GetCurrentThreadId(), WM_NULL, 0, 0);
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 static void ReleaseFreeMemoryThunk() { 436 static void ReleaseFreeMemoryThunk() {
437 MallocExtension::instance()->ReleaseFreeMemory(); 437 MallocExtension::instance()->ReleaseFreeMemory();
438 } 438 }
439 #endif 439 #endif
440 440
441 int Initialize(const ContentMainParams& params) override { 441 int Initialize(const ContentMainParams& params) override {
442 ui_task_ = params.ui_task; 442 ui_task_ = params.ui_task;
443 443
444 base::EnableTerminationOnOutOfMemory(); 444 base::EnableTerminationOnOutOfMemory();
445 #if defined(OS_WIN) 445 #if defined(OS_WIN)
446 RegisterInvalidParamHandler(); 446 base::win::RegisterInvalidParamHandler();
447 ui::win::CreateATLModuleIfNeeded(); 447 ui::win::CreateATLModuleIfNeeded();
448 448
449 sandbox_info_ = *params.sandbox_info; 449 sandbox_info_ = *params.sandbox_info;
450 #else // !OS_WIN 450 #else // !OS_WIN
451 451
452 #if defined(OS_ANDROID) 452 #if defined(OS_ANDROID)
453 // See note at the initialization of ExitManager, below; basically, 453 // See note at the initialization of ExitManager, below; basically,
454 // only Android builds have the ctor/dtor handlers set up to use 454 // only Android builds have the ctor/dtor handlers set up to use
455 // TRACE_EVENT right away. 455 // TRACE_EVENT right away.
456 TRACE_EVENT0("startup,benchmark", "ContentMainRunnerImpl::Initialize"); 456 TRACE_EVENT0("startup,benchmark", "ContentMainRunnerImpl::Initialize");
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 560
561 // TODO(yiyaoliu, vadimt): Remove this once crbug.com/453640 is fixed. 561 // TODO(yiyaoliu, vadimt): Remove this once crbug.com/453640 is fixed.
562 // Enable profiler recording right after command line is initialized so that 562 // Enable profiler recording right after command line is initialized so that
563 // browser startup can be instrumented. 563 // browser startup can be instrumented.
564 if (delegate_ && delegate_->ShouldEnableProfilerRecording()) 564 if (delegate_ && delegate_->ShouldEnableProfilerRecording())
565 tracked_objects::ScopedTracker::Enable(); 565 tracked_objects::ScopedTracker::Enable();
566 566
567 #if !defined(OS_IOS) 567 #if !defined(OS_IOS)
568 SetProcessTitleFromCommandLine(argv); 568 SetProcessTitleFromCommandLine(argv);
569 #endif 569 #endif
570 #endif // !OS_ANDROID 570 #endif // !OS_ANDROID
571 571
572 int exit_code = 0; 572 int exit_code = 0;
573 if (delegate_ && delegate_->BasicStartupComplete(&exit_code)) 573 if (delegate_ && delegate_->BasicStartupComplete(&exit_code))
574 return exit_code; 574 return exit_code;
575 575
576 completed_basic_startup_ = true; 576 completed_basic_startup_ = true;
577 577
578 const base::CommandLine& command_line = 578 const base::CommandLine& command_line =
579 *base::CommandLine::ForCurrentProcess(); 579 *base::CommandLine::ForCurrentProcess();
580 std::string process_type = 580 std::string process_type =
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 // Enable exporting of events to ETW if requested on the command line. 632 // Enable exporting of events to ETW if requested on the command line.
633 if (command_line.HasSwitch(switches::kTraceExportEventsToETW)) 633 if (command_line.HasSwitch(switches::kTraceExportEventsToETW))
634 base::trace_event::TraceEventETWExport::EnableETWExport(); 634 base::trace_event::TraceEventETWExport::EnableETWExport();
635 #endif // OS_WIN 635 #endif // OS_WIN
636 636
637 #if !defined(OS_ANDROID) 637 #if !defined(OS_ANDROID)
638 // Android tracing started at the beginning of the method. 638 // Android tracing started at the beginning of the method.
639 // Other OSes have to wait till we get here in order for all the memory 639 // Other OSes have to wait till we get here in order for all the memory
640 // management setup to be completed. 640 // management setup to be completed.
641 TRACE_EVENT0("startup,benchmark", "ContentMainRunnerImpl::Initialize"); 641 TRACE_EVENT0("startup,benchmark", "ContentMainRunnerImpl::Initialize");
642 #endif // !OS_ANDROID 642 #endif // !OS_ANDROID
643 643
644 #if defined(OS_MACOSX) && !defined(OS_IOS) 644 #if defined(OS_MACOSX) && !defined(OS_IOS)
645 // We need to allocate the IO Ports before the Sandbox is initialized or 645 // We need to allocate the IO Ports before the Sandbox is initialized or
646 // the first instance of PowerMonitor is created. 646 // the first instance of PowerMonitor is created.
647 // It's important not to allocate the ports for processes which don't 647 // It's important not to allocate the ports for processes which don't
648 // register with the power monitor - see crbug.com/88867. 648 // register with the power monitor - see crbug.com/88867.
649 if (process_type.empty() || 649 if (process_type.empty() ||
650 (delegate_ && 650 (delegate_ &&
651 delegate_->ProcessRegistersWithSystemProcess(process_type))) { 651 delegate_->ProcessRegistersWithSystemProcess(process_type))) {
652 base::PowerMonitorDeviceSource::AllocateSystemIOPorts(); 652 base::PowerMonitorDeviceSource::AllocateSystemIOPorts();
653 } 653 }
654 654
655 if (!process_type.empty() && 655 if (!process_type.empty() &&
656 (!delegate_ || delegate_->ShouldSendMachPort(process_type))) { 656 (!delegate_ || delegate_->ShouldSendMachPort(process_type))) {
657 MachBroker::ChildSendTaskPortToParent(); 657 MachBroker::ChildSendTaskPortToParent();
658 } 658 }
659 659
660 if (!command_line.HasSwitch(switches::kSingleProcess) && 660 if (!command_line.HasSwitch(switches::kSingleProcess) &&
661 !process_type.empty() && (process_type == switches::kRendererProcess || 661 !process_type.empty() && (process_type == switches::kRendererProcess ||
662 process_type == switches::kGpuProcess)) { 662 process_type == switches::kGpuProcess)) {
663 base::mac::ScopedMachSendRight service_port = 663 base::mac::ScopedMachSendRight service_port =
664 BrowserIOSurfaceManager::LookupServicePort(getppid()); 664 BrowserIOSurfaceManager::LookupServicePort(getppid());
665 if (service_port.is_valid()) { 665 if (service_port.is_valid()) {
666 ChildIOSurfaceManager::GetInstance()->set_service_port( 666 ChildIOSurfaceManager::GetInstance()->set_service_port(
667 service_port.release()); 667 service_port.release());
668 IOSurfaceManager::SetInstance(ChildIOSurfaceManager::GetInstance()); 668 IOSurfaceManager::SetInstance(ChildIOSurfaceManager::GetInstance());
669 } 669 }
670 } 670 }
671 #elif defined(OS_WIN) 671 #elif defined(OS_WIN)
672 SetupCRT(command_line); 672 base::win::SetupCRT(command_line);
673 #endif 673 #endif
674 674
675 #if defined(OS_POSIX) 675 #if defined(OS_POSIX)
676 if (!process_type.empty()) { 676 if (!process_type.empty()) {
677 // When you hit Ctrl-C in a terminal running the browser 677 // When you hit Ctrl-C in a terminal running the browser
678 // process, a SIGINT is delivered to the entire process group. 678 // process, a SIGINT is delivered to the entire process group.
679 // When debugging the browser process via gdb, gdb catches the 679 // When debugging the browser process via gdb, gdb catches the
680 // SIGINT for the browser process (and dumps you back to the gdb 680 // SIGINT for the browser process (and dumps you back to the gdb
681 // console) but doesn't for the child processes, killing them. 681 // console) but doesn't for the child processes, killing them.
682 // The fix is to have child processes ignore SIGINT; they'll die 682 // The fix is to have child processes ignore SIGINT; they'll die
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 857
858 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); 858 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl);
859 }; 859 };
860 860
861 // static 861 // static
862 ContentMainRunner* ContentMainRunner::Create() { 862 ContentMainRunner* ContentMainRunner::Create() {
863 return new ContentMainRunnerImpl(); 863 return new ContentMainRunnerImpl();
864 } 864 }
865 865
866 } // namespace content 866 } // namespace content
OLDNEW
« no previous file with comments | « content/app/BUILD.gn ('k') | content/app/sandbox_helper_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698