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 #include "content/app/content_main.h" | 5 #include "content/public/app/content_main_runner.h" |
6 | 6 |
7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/debug/debugger.h" | 9 #include "base/debug/debugger.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
11 #include "base/i18n/icu_util.h" | 11 #include "base/i18n/icu_util.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/metrics/stats_table.h" | 14 #include "base/metrics/stats_table.h" |
15 #include "base/process_util.h" | 15 #include "base/process_util.h" |
16 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
17 #include "base/string_number_conversions.h" | 17 #include "base/string_number_conversions.h" |
18 #include "content/browser/browser_main.h" | 18 #include "content/browser/browser_main.h" |
19 #include "content/common/set_process_title.h" | 19 #include "content/common/set_process_title.h" |
20 #include "content/public/app/content_main_delegate.h" | 20 #include "content/public/app/content_main_delegate.h" |
21 #include "content/public/app/startup_helper_win.h" | 21 #include "content/public/app/startup_helper_win.h" |
22 #include "content/public/common/content_client.h" | 22 #include "content/public/common/content_client.h" |
23 #include "content/public/common/content_constants.h" | 23 #include "content/public/common/content_constants.h" |
24 #include "content/public/common/content_paths.h" | 24 #include "content/public/common/content_paths.h" |
25 #include "content/public/common/content_switches.h" | 25 #include "content/public/common/content_switches.h" |
26 #include "content/public/common/main_function_params.h" | 26 #include "content/public/common/main_function_params.h" |
27 #include "content/public/common/sandbox_init.h" | 27 #include "content/public/common/sandbox_init.h" |
28 #include "crypto/nss_util.h" | 28 #include "crypto/nss_util.h" |
29 #include "ipc/ipc_switches.h" | 29 #include "ipc/ipc_switches.h" |
30 #include "sandbox/src/sandbox_types.h" | |
30 #include "ui/base/ui_base_switches.h" | 31 #include "ui/base/ui_base_switches.h" |
31 #include "ui/base/ui_base_paths.h" | 32 #include "ui/base/ui_base_paths.h" |
32 #include "webkit/glue/webkit_glue.h" | 33 #include "webkit/glue/webkit_glue.h" |
33 | 34 |
34 #if defined(OS_WIN) | 35 #if defined(OS_WIN) |
35 #include <atlbase.h> | 36 #include <atlbase.h> |
36 #include <atlapp.h> | 37 #include <atlapp.h> |
37 #include <malloc.h> | 38 #include <malloc.h> |
38 #elif defined(OS_MACOSX) | 39 #elif defined(OS_MACOSX) |
39 #include "base/mac/scoped_nsautorelease_pool.h" | 40 #include "base/mac/scoped_nsautorelease_pool.h" |
40 #include "base/mach_ipc_mac.h" | 41 #include "base/mach_ipc_mac.h" |
41 #include "base/system_monitor/system_monitor.h" | 42 #include "base/system_monitor/system_monitor.h" |
42 #include "content/browser/mach_broker_mac.h" | 43 #include "content/browser/mach_broker_mac.h" |
43 #include "content/common/sandbox_init_mac.h" | 44 #include "content/common/sandbox_init_mac.h" |
44 #endif // OS_WIN | 45 #endif // OS_WIN |
45 | 46 |
46 #if defined(OS_POSIX) | 47 #if defined(OS_POSIX) |
47 #include <signal.h> | 48 #include <signal.h> |
48 | 49 |
49 #include "base/global_descriptors_posix.h" | 50 #include "base/global_descriptors_posix.h" |
50 #include "content/common/chrome_descriptors.h" | 51 #include "content/common/chrome_descriptors.h" |
51 | 52 |
52 #if !defined(OS_MACOSX) | 53 #if !defined(OS_MACOSX) |
53 #include "content/public/common/zygote_fork_delegate_linux.h" | 54 #include "content/public/common/zygote_fork_delegate_linux.h" |
54 #endif | 55 #endif |
(...skipping 13 matching lines...) Expand all Loading... | |
68 extern int RendererMain(const content::MainFunctionParams&); | 69 extern int RendererMain(const content::MainFunctionParams&); |
69 extern int WorkerMain(const content::MainFunctionParams&); | 70 extern int WorkerMain(const content::MainFunctionParams&); |
70 extern int UtilityMain(const content::MainFunctionParams&); | 71 extern int UtilityMain(const content::MainFunctionParams&); |
71 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 72 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
72 extern int ZygoteMain(const content::MainFunctionParams&, | 73 extern int ZygoteMain(const content::MainFunctionParams&, |
73 content::ZygoteForkDelegate* forkdelegate); | 74 content::ZygoteForkDelegate* forkdelegate); |
74 #endif | 75 #endif |
75 | 76 |
76 namespace { | 77 namespace { |
77 | 78 |
78 #if defined(OS_WIN) | 79 #if defined(OS_MACOSX) |
79 | |
80 static CAppModule _Module; | |
81 | |
82 #elif defined(OS_MACOSX) | |
83 | 80 |
84 // Completes the Mach IPC handshake by sending this process' task port to the | 81 // Completes the Mach IPC handshake by sending this process' task port to the |
85 // parent process. The parent is listening on the Mach port given by | 82 // parent process. The parent is listening on the Mach port given by |
86 // |GetMachPortName()|. The task port is used by the parent to get CPU/memory | 83 // |GetMachPortName()|. The task port is used by the parent to get CPU/memory |
87 // stats to display in the task manager. | 84 // stats to display in the task manager. |
88 void SendTaskPortToParentProcess() { | 85 void SendTaskPortToParentProcess() { |
89 const mach_msg_timeout_t kTimeoutMs = 100; | 86 const mach_msg_timeout_t kTimeoutMs = 100; |
90 const int32_t kMessageId = 0; | 87 const int32_t kMessageId = 0; |
91 std::string mach_port_name = MachBroker::GetMachPortName(); | 88 std::string mach_port_name = MachBroker::GetMachPortName(); |
92 | 89 |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
253 { switches::kRendererProcess, RendererMain }, | 250 { switches::kRendererProcess, RendererMain }, |
254 { switches::kPluginProcess, PluginMain }, | 251 { switches::kPluginProcess, PluginMain }, |
255 { switches::kWorkerProcess, WorkerMain }, | 252 { switches::kWorkerProcess, WorkerMain }, |
256 { switches::kPpapiPluginProcess, PpapiPluginMain }, | 253 { switches::kPpapiPluginProcess, PpapiPluginMain }, |
257 { switches::kPpapiBrokerProcess, PpapiBrokerMain }, | 254 { switches::kPpapiBrokerProcess, PpapiBrokerMain }, |
258 { switches::kUtilityProcess, UtilityMain }, | 255 { switches::kUtilityProcess, UtilityMain }, |
259 { switches::kGpuProcess, GpuMain }, | 256 { switches::kGpuProcess, GpuMain }, |
260 }; | 257 }; |
261 | 258 |
262 for (size_t i = 0; i < arraysize(kMainFunctions); ++i) { | 259 for (size_t i = 0; i < arraysize(kMainFunctions); ++i) { |
263 if (process_type == kMainFunctions[i].name) | 260 if (process_type == kMainFunctions[i].name) { |
261 if (delegate) { | |
262 int exit_code = delegate->RunProcess(process_type, | |
263 main_function_params); | |
264 if (exit_code >= 0) | |
265 return exit_code; | |
266 } | |
264 return kMainFunctions[i].function(main_function_params); | 267 return kMainFunctions[i].function(main_function_params); |
268 } | |
265 } | 269 } |
266 | 270 |
267 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 271 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
268 // Zygote startup is special -- see RunZygote comments above | 272 // Zygote startup is special -- see RunZygote comments above |
269 // for why we don't use ZygoteMain directly. | 273 // for why we don't use ZygoteMain directly. |
270 if (process_type == switches::kZygoteProcess) | 274 if (process_type == switches::kZygoteProcess) |
271 return RunZygote(main_function_params, delegate); | 275 return RunZygote(main_function_params, delegate); |
272 #endif | 276 #endif |
273 | 277 |
274 // If it's a process we don't know about, the embedder should know. | 278 // If it's a process we don't know about, the embedder should know. |
275 if (delegate) | 279 if (delegate) |
276 return delegate->RunProcess(process_type, main_function_params); | 280 return delegate->RunProcess(process_type, main_function_params); |
277 | 281 |
278 NOTREACHED() << "Unknown process type: " << process_type; | 282 NOTREACHED() << "Unknown process type: " << process_type; |
279 return 1; | 283 return 1; |
280 } | 284 } |
281 | 285 |
286 class ContentMainRunnerImpl : public content::ContentMainRunner { | |
287 public: | |
288 ContentMainRunnerImpl() | |
289 : is_initialized_(false), | |
290 is_shutdown_(false) { | |
291 } | |
292 | |
293 ~ContentMainRunnerImpl() { | |
294 if (is_initialized_ && !is_shutdown_) | |
295 Shutdown(); | |
296 } | |
297 | |
298 #if defined(OS_WIN) | |
299 virtual int Initialize(HINSTANCE instance, | |
300 sandbox::SandboxInterfaceInfo* sandbox_info, | |
301 content::ContentMainDelegate* delegate) OVERRIDE { | |
302 is_initialized_ = true; | |
303 | |
304 // argc/argv are ignored on Windows; see command_line.h for details. | |
305 int argc = 0; | |
306 char** argv = NULL; | |
307 | |
308 content::RegisterInvalidParamHandler(); | |
309 app_module_.reset(new CAppModule); | |
310 app_module_->Init(NULL, static_cast<HINSTANCE>(instance)); | |
311 | |
312 if (sandbox_info) | |
313 sandbox_info_ = *sandbox_info; | |
314 else | |
315 memset(&sandbox_info_, 0, sizeof(sandbox_info_)); | |
316 | |
317 #else // !OS_WIN | |
jam
2012/02/01 17:28:39
nit only two spaces before //
Marshall
2012/02/01 19:37:14
Done.
| |
318 virtual int Initialize(int argc, | |
319 const char** argv, | |
320 content::ContentMainDelegate* delegate) OVERRIDE { | |
321 is_initialized_ = true; | |
jam
2012/02/01 17:28:39
nit: just move this common line (with 302) to 339
Marshall
2012/02/01 19:37:14
Done.
| |
322 | |
323 // NOTE(willchan): One might ask why this call is done here rather than in | |
324 // process_util_linux.cc with the definition of | |
325 // EnableTerminationOnOutOfMemory(). That's because base shouldn't have a | |
326 // dependency on TCMalloc. Really, we ought to have our allocator shim code | |
327 // implement this EnableTerminationOnOutOfMemory() function. Whateverz. | |
328 // This works for now. | |
329 #if !defined(OS_MACOSX) && defined(USE_TCMALLOC) | |
330 // For tcmalloc, we need to tell it to behave like new. | |
331 tc_set_new_mode(1); | |
332 #endif | |
333 | |
334 #if !defined(OS_ANDROID) | |
335 // Set C library locale to make sure CommandLine can parse argument values | |
336 // in correct encoding. | |
337 setlocale(LC_ALL, ""); | |
338 #endif | |
339 | |
340 SetupSignalHandlers(); | |
341 | |
342 base::GlobalDescriptors* g_fds = base::GlobalDescriptors::GetInstance(); | |
343 g_fds->Set(kPrimaryIPCChannel, | |
344 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor); | |
345 #if defined(OS_LINUX) || defined(OS_OPENBSD) | |
346 g_fds->Set(kCrashDumpSignal, | |
347 kCrashDumpSignal + base::GlobalDescriptors::kBaseDescriptor); | |
348 #endif | |
349 | |
350 #endif // !OS_WIN | |
351 | |
352 delegate_ = delegate; | |
353 | |
354 base::EnableTerminationOnHeapCorruption(); | |
355 base::EnableTerminationOnOutOfMemory(); | |
356 | |
357 // The exit manager is in charge of calling the dtors of singleton objects. | |
358 exit_manager_.reset(new base::AtExitManager); | |
359 | |
360 #if defined(OS_MACOSX) | |
361 // We need this pool for all the objects created before we get to the | |
362 // event loop, but we don't want to leave them hanging around until the | |
363 // app quits. Each "main" needs to flush this pool right before it goes into | |
364 // its main event loop to get rid of the cruft. | |
365 autorelease_pool_.reset(new base::mac::ScopedNSAutoreleasePool()); | |
366 #endif | |
367 | |
368 CommandLine::Init(argc, argv); | |
369 | |
370 int exit_code; | |
371 if (delegate && delegate->BasicStartupComplete(&exit_code)) | |
372 return exit_code; | |
373 | |
374 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
375 std::string process_type = | |
376 command_line.GetSwitchValueASCII(switches::kProcessType); | |
377 | |
378 // Enable startup tracing asap to avoid early TRACE_EVENT calls being | |
379 // ignored. | |
380 if (command_line.HasSwitch(switches::kTraceStartup)) { | |
381 base::debug::TraceLog::GetInstance()->SetEnabled( | |
382 command_line.GetSwitchValueASCII(switches::kTraceStartup)); | |
383 } | |
384 | |
385 #if defined(OS_MACOSX) | |
386 // We need to allocate the IO Ports before the Sandbox is initialized or | |
387 // the first instance of SystemMonitor is created. | |
388 // It's important not to allocate the ports for processes which don't | |
389 // register with the system monitor - see crbug.com/88867. | |
390 if (process_type.empty() || | |
391 process_type == switches::kPluginProcess || | |
392 process_type == switches::kRendererProcess || | |
393 process_type == switches::kUtilityProcess || | |
394 process_type == switches::kWorkerProcess || | |
395 (delegate && | |
396 delegate->ProcessRegistersWithSystemProcess(process_type))) { | |
397 base::SystemMonitor::AllocateSystemIOPorts(); | |
398 } | |
399 | |
400 if (!process_type.empty() && | |
401 (!delegate || delegate->ShouldSendMachPort(process_type))) { | |
402 SendTaskPortToParentProcess(); | |
403 } | |
404 #elif defined(OS_WIN) | |
405 content::SetupCRT(command_line); | |
406 #endif | |
407 | |
408 #if defined(OS_POSIX) | |
409 if (!process_type.empty()) { | |
410 // When you hit Ctrl-C in a terminal running the browser | |
411 // process, a SIGINT is delivered to the entire process group. | |
412 // When debugging the browser process via gdb, gdb catches the | |
413 // SIGINT for the browser process (and dumps you back to the gdb | |
414 // console) but doesn't for the child processes, killing them. | |
415 // The fix is to have child processes ignore SIGINT; they'll die | |
416 // on their own when the browser process goes away. | |
417 // | |
418 // Note that we *can't* rely on BeingDebugged to catch this case because | |
419 // we are the child process, which is not being debugged. | |
420 // TODO(evanm): move this to some shared subprocess-init function. | |
421 if (!base::debug::BeingDebugged()) | |
422 signal(SIGINT, SIG_IGN); | |
423 } | |
424 #endif | |
425 | |
426 #if defined(USE_NSS) | |
427 crypto::EarlySetupForNSSInit(); | |
428 #endif | |
429 | |
430 ui::RegisterPathProvider(); | |
431 content::RegisterPathProvider(); | |
432 | |
433 CHECK(icu_util::Initialize()); | |
434 | |
435 base::ProcessId browser_pid = base::GetCurrentProcId(); | |
436 if (command_line.HasSwitch(switches::kProcessChannelID)) { | |
437 #if defined(OS_WIN) || defined(OS_MACOSX) | |
438 std::string channel_name = | |
439 command_line.GetSwitchValueASCII(switches::kProcessChannelID); | |
440 | |
441 int browser_pid_int; | |
442 base::StringToInt(channel_name, &browser_pid_int); | |
443 browser_pid = static_cast<base::ProcessId>(browser_pid_int); | |
444 DCHECK_NE(browser_pid_int, 0); | |
445 #elif defined(OS_POSIX) | |
446 // On linux, we're in the zygote here; so we need the parent process' id. | |
447 browser_pid = base::GetParentProcessId(base::GetCurrentProcId()); | |
448 #endif | |
449 } | |
450 | |
451 InitializeStatsTable(browser_pid, command_line); | |
452 | |
453 if (delegate) | |
454 delegate->PreSandboxStartup(); | |
455 | |
456 if (!process_type.empty()) | |
457 CommonSubprocessInit(process_type); | |
458 | |
459 #if defined(OS_WIN) | |
460 CHECK(content::InitializeSandbox(sandbox_info)); | |
461 #elif defined(OS_MACOSX) | |
462 if (process_type == switches::kRendererProcess || | |
463 process_type == switches::kPpapiPluginProcess || | |
464 (delegate && delegate->DelaySandboxInitialization(process_type))) { | |
465 // On OS X the renderer sandbox needs to be initialized later in the | |
466 // startup sequence in RendererMainPlatformDelegate::EnableSandbox(). | |
467 } else { | |
468 CHECK(content::InitializeSandbox()); | |
469 } | |
470 #endif | |
471 | |
472 if (delegate) | |
473 delegate->SandboxInitialized(process_type); | |
474 | |
475 #if defined(OS_POSIX) | |
476 SetProcessTitleFromCommandLine(argv); | |
477 #endif | |
478 | |
479 // Return -1 to indicate no early termination. | |
480 return -1; | |
481 } | |
482 | |
483 virtual int Run() OVERRIDE { | |
484 DCHECK(is_initialized_); | |
485 DCHECK(!is_shutdown_); | |
486 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
487 std::string process_type = | |
488 command_line.GetSwitchValueASCII(switches::kProcessType); | |
489 | |
490 content::MainFunctionParams main_params(command_line); | |
491 #if defined(OS_WIN) | |
492 main_params.sandbox_info = &sandbox_info_; | |
493 #elif defined(OS_MACOSX) | |
494 main_params.autorelease_pool = autorelease_pool_.get(); | |
495 #endif | |
496 | |
497 return RunNamedProcessTypeMain(process_type, main_params, delegate_); | |
498 } | |
499 | |
500 virtual void Shutdown() OVERRIDE { | |
501 DCHECK(is_initialized_); | |
502 DCHECK(!is_shutdown_); | |
503 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
504 std::string process_type = | |
505 command_line.GetSwitchValueASCII(switches::kProcessType); | |
506 | |
507 if (delegate_) | |
508 delegate_->ProcessExiting(process_type); | |
509 | |
510 #if defined(OS_WIN) | |
511 #ifdef _CRTDBG_MAP_ALLOC | |
512 _CrtDumpMemoryLeaks(); | |
513 #endif // _CRTDBG_MAP_ALLOC | |
514 | |
515 app_module_->Term(); | |
516 #endif // OS_WIN | |
517 | |
518 #if defined(OS_MACOSX) | |
519 autorelease_pool_.reset(NULL); | |
520 #endif | |
521 | |
522 exit_manager_.reset(NULL); | |
523 | |
524 #if defined(OS_WIN) | |
525 app_module_.reset(NULL); | |
526 #endif | |
527 | |
528 delegate_ = NULL; | |
529 is_shutdown_ = true; | |
530 } | |
531 | |
532 protected: | |
533 // True if the runner has been initialized. | |
534 bool is_initialized_; | |
535 | |
536 // True if the runner has been shut down. | |
537 bool is_shutdown_; | |
538 | |
539 // The delegate will outlive this object. | |
540 content::ContentMainDelegate* delegate_; | |
541 | |
542 scoped_ptr<base::AtExitManager> exit_manager_; | |
543 #if defined(OS_WIN) | |
544 sandbox::SandboxInterfaceInfo sandbox_info_; | |
545 scoped_ptr<CAppModule> app_module_; | |
546 #elif defined(OS_MACOSX) | |
547 scoped_ptr<base::mac::ScopedNSAutoreleasePool> autorelease_pool_; | |
548 #endif | |
549 | |
550 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); | |
551 }; | |
552 | |
282 } // namespace | 553 } // namespace |
283 | 554 |
284 namespace content { | 555 namespace content { |
285 | 556 |
286 #if defined(OS_WIN) | 557 // static |
287 int ContentMain(HINSTANCE instance, | 558 ContentMainRunner* ContentMainRunner::Create() { |
288 sandbox::SandboxInterfaceInfo* sandbox_info, | 559 return new ContentMainRunnerImpl(); |
289 ContentMainDelegate* delegate) { | |
290 // argc/argv are ignored on Windows; see command_line.h for details. | |
291 int argc = 0; | |
292 char** argv = NULL; | |
293 | |
294 content::RegisterInvalidParamHandler(); | |
295 _Module.Init(NULL, static_cast<HINSTANCE>(instance)); | |
296 #else | |
297 int ContentMain(int argc, | |
298 const char** argv, | |
299 ContentMainDelegate* delegate) { | |
300 // NOTE(willchan): One might ask why this call is done here rather than in | |
301 // process_util_linux.cc with the definition of | |
302 // EnableTerminationOnOutOfMemory(). That's because base shouldn't have a | |
303 // dependency on TCMalloc. Really, we ought to have our allocator shim code | |
304 // implement this EnableTerminationOnOutOfMemory() function. Whateverz. This | |
305 // works for now. | |
306 #if !defined(OS_MACOSX) && defined(USE_TCMALLOC) | |
307 // For tcmalloc, we need to tell it to behave like new. | |
308 tc_set_new_mode(1); | |
309 #endif | |
310 | |
311 #if !defined(OS_ANDROID) | |
312 // Set C library locale to make sure CommandLine can parse argument values | |
313 // in correct encoding. | |
314 setlocale(LC_ALL, ""); | |
315 #endif | |
316 | |
317 SetupSignalHandlers(); | |
318 | |
319 base::GlobalDescriptors* g_fds = base::GlobalDescriptors::GetInstance(); | |
320 g_fds->Set(kPrimaryIPCChannel, | |
321 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor); | |
322 #if defined(OS_LINUX) || defined(OS_OPENBSD) | |
323 g_fds->Set(kCrashDumpSignal, | |
324 kCrashDumpSignal + base::GlobalDescriptors::kBaseDescriptor); | |
325 #endif | |
326 | |
327 #endif // OS_WIN | |
328 | |
329 base::EnableTerminationOnHeapCorruption(); | |
330 base::EnableTerminationOnOutOfMemory(); | |
331 | |
332 // The exit manager is in charge of calling the dtors of singleton objects. | |
333 base::AtExitManager exit_manager; | |
334 | |
335 #if defined(OS_MACOSX) | |
336 // We need this pool for all the objects created before we get to the | |
337 // event loop, but we don't want to leave them hanging around until the | |
338 // app quits. Each "main" needs to flush this pool right before it goes into | |
339 // its main event loop to get rid of the cruft. | |
340 base::mac::ScopedNSAutoreleasePool autorelease_pool; | |
341 #endif | |
342 | |
343 CommandLine::Init(argc, argv); | |
344 | |
345 int exit_code; | |
346 if (delegate && delegate->BasicStartupComplete(&exit_code)) | |
347 return exit_code; | |
348 | |
349 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
350 std::string process_type = | |
351 command_line.GetSwitchValueASCII(switches::kProcessType); | |
352 | |
353 // Enable startup tracing asap to avoid early TRACE_EVENT calls being ignored. | |
354 if (command_line.HasSwitch(switches::kTraceStartup)) { | |
355 base::debug::TraceLog::GetInstance()->SetEnabled( | |
356 command_line.GetSwitchValueASCII(switches::kTraceStartup)); | |
357 } | |
358 | |
359 #if defined(OS_MACOSX) | |
360 // We need to allocate the IO Ports before the Sandbox is initialized or | |
361 // the first instance of SystemMonitor is created. | |
362 // It's important not to allocate the ports for processes which don't register | |
363 // with the system monitor - see crbug.com/88867. | |
364 if (process_type.empty() || | |
365 process_type == switches::kPluginProcess || | |
366 process_type == switches::kRendererProcess || | |
367 process_type == switches::kUtilityProcess || | |
368 process_type == switches::kWorkerProcess || | |
369 (delegate && delegate->ProcessRegistersWithSystemProcess(process_type))) { | |
370 base::SystemMonitor::AllocateSystemIOPorts(); | |
371 } | |
372 | |
373 if (!process_type.empty() && | |
374 (!delegate || delegate->ShouldSendMachPort(process_type))) { | |
375 SendTaskPortToParentProcess(); | |
376 } | |
377 #elif defined(OS_WIN) | |
378 content::SetupCRT(command_line); | |
379 #endif | |
380 | |
381 #if defined(OS_POSIX) | |
382 if (!process_type.empty()) { | |
383 // When you hit Ctrl-C in a terminal running the browser | |
384 // process, a SIGINT is delivered to the entire process group. | |
385 // When debugging the browser process via gdb, gdb catches the | |
386 // SIGINT for the browser process (and dumps you back to the gdb | |
387 // console) but doesn't for the child processes, killing them. | |
388 // The fix is to have child processes ignore SIGINT; they'll die | |
389 // on their own when the browser process goes away. | |
390 // | |
391 // Note that we *can't* rely on BeingDebugged to catch this case because we | |
392 // are the child process, which is not being debugged. | |
393 // TODO(evanm): move this to some shared subprocess-init function. | |
394 if (!base::debug::BeingDebugged()) | |
395 signal(SIGINT, SIG_IGN); | |
396 } | |
397 #endif | |
398 | |
399 #if defined(USE_NSS) | |
400 crypto::EarlySetupForNSSInit(); | |
401 #endif | |
402 | |
403 ui::RegisterPathProvider(); | |
404 content::RegisterPathProvider(); | |
405 | |
406 CHECK(icu_util::Initialize()); | |
407 | |
408 base::ProcessId browser_pid = base::GetCurrentProcId(); | |
409 if (command_line.HasSwitch(switches::kProcessChannelID)) { | |
410 #if defined(OS_WIN) || defined(OS_MACOSX) | |
411 std::string channel_name = | |
412 command_line.GetSwitchValueASCII(switches::kProcessChannelID); | |
413 | |
414 int browser_pid_int; | |
415 base::StringToInt(channel_name, &browser_pid_int); | |
416 browser_pid = static_cast<base::ProcessId>(browser_pid_int); | |
417 DCHECK_NE(browser_pid_int, 0); | |
418 #elif defined(OS_POSIX) | |
419 // On linux, we're in the zygote here; so we need the parent process' id. | |
420 browser_pid = base::GetParentProcessId(base::GetCurrentProcId()); | |
421 #endif | |
422 } | |
423 | |
424 InitializeStatsTable(browser_pid, command_line); | |
425 | |
426 if (delegate) delegate->PreSandboxStartup(); | |
427 | |
428 if (!process_type.empty()) | |
429 CommonSubprocessInit(process_type); | |
430 | |
431 #if defined(OS_WIN) | |
432 CHECK(content::InitializeSandbox(sandbox_info)); | |
433 #elif defined(OS_MACOSX) | |
434 if (process_type == switches::kRendererProcess || | |
435 process_type == switches::kPpapiPluginProcess || | |
436 (delegate && delegate->DelaySandboxInitialization(process_type))) { | |
437 // On OS X the renderer sandbox needs to be initialized later in the startup | |
438 // sequence in RendererMainPlatformDelegate::EnableSandbox(). | |
439 } else { | |
440 CHECK(content::InitializeSandbox()); | |
441 } | |
442 #endif | |
443 | |
444 if (delegate) delegate->SandboxInitialized(process_type); | |
445 | |
446 #if defined(OS_POSIX) | |
447 SetProcessTitleFromCommandLine(argv); | |
448 #endif | |
449 | |
450 content::MainFunctionParams main_params(command_line); | |
451 #if defined(OS_WIN) | |
452 main_params.sandbox_info = sandbox_info; | |
453 #elif defined(OS_MACOSX) | |
454 main_params.autorelease_pool = &autorelease_pool; | |
455 #endif | |
456 | |
457 exit_code = RunNamedProcessTypeMain(process_type, main_params, delegate); | |
458 | |
459 if (delegate) delegate->ProcessExiting(process_type); | |
460 | |
461 #if defined(OS_WIN) | |
462 #ifdef _CRTDBG_MAP_ALLOC | |
463 _CrtDumpMemoryLeaks(); | |
464 #endif // _CRTDBG_MAP_ALLOC | |
465 | |
466 _Module.Term(); | |
467 #endif // OS_WIN | |
468 | |
469 return exit_code; | |
470 } | 560 } |
471 | 561 |
472 } // namespace content | 562 } // namespace content |
OLD | NEW |