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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 { switches::kRendererProcess, RendererMain }, | 254 { switches::kRendererProcess, RendererMain }, |
254 { switches::kPluginProcess, PluginMain }, | 255 { switches::kPluginProcess, PluginMain }, |
255 { switches::kWorkerProcess, WorkerMain }, | 256 { switches::kWorkerProcess, WorkerMain }, |
256 { switches::kPpapiPluginProcess, PpapiPluginMain }, | 257 { switches::kPpapiPluginProcess, PpapiPluginMain }, |
257 { switches::kPpapiBrokerProcess, PpapiBrokerMain }, | 258 { switches::kPpapiBrokerProcess, PpapiBrokerMain }, |
258 { switches::kUtilityProcess, UtilityMain }, | 259 { switches::kUtilityProcess, UtilityMain }, |
259 { switches::kGpuProcess, GpuMain }, | 260 { switches::kGpuProcess, GpuMain }, |
260 }; | 261 }; |
261 | 262 |
262 for (size_t i = 0; i < arraysize(kMainFunctions); ++i) { | 263 for (size_t i = 0; i < arraysize(kMainFunctions); ++i) { |
263 if (process_type == kMainFunctions[i].name) | 264 if (process_type == kMainFunctions[i].name) { |
| 265 if (delegate) { |
| 266 int exit_code = delegate->RunProcess(process_type, |
| 267 main_function_params); |
| 268 if (exit_code >= 0) |
| 269 return exit_code; |
| 270 } |
264 return kMainFunctions[i].function(main_function_params); | 271 return kMainFunctions[i].function(main_function_params); |
| 272 } |
265 } | 273 } |
266 | 274 |
267 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 275 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
268 // Zygote startup is special -- see RunZygote comments above | 276 // Zygote startup is special -- see RunZygote comments above |
269 // for why we don't use ZygoteMain directly. | 277 // for why we don't use ZygoteMain directly. |
270 if (process_type == switches::kZygoteProcess) | 278 if (process_type == switches::kZygoteProcess) |
271 return RunZygote(main_function_params, delegate); | 279 return RunZygote(main_function_params, delegate); |
272 #endif | 280 #endif |
273 | 281 |
274 // If it's a process we don't know about, the embedder should know. | 282 // If it's a process we don't know about, the embedder should know. |
275 if (delegate) | 283 if (delegate) |
276 return delegate->RunProcess(process_type, main_function_params); | 284 return delegate->RunProcess(process_type, main_function_params); |
277 | 285 |
278 NOTREACHED() << "Unknown process type: " << process_type; | 286 NOTREACHED() << "Unknown process type: " << process_type; |
279 return 1; | 287 return 1; |
280 } | 288 } |
281 | 289 |
| 290 class ContentMainRunnerImpl : public content::ContentMainRunner { |
| 291 public: |
| 292 ContentMainRunnerImpl() |
| 293 : is_initialized_(false), |
| 294 is_shutdown_(false) { |
| 295 } |
| 296 |
| 297 ~ContentMainRunnerImpl() { |
| 298 if (is_initialized_ && !is_shutdown_) |
| 299 Shutdown(); |
| 300 } |
| 301 |
| 302 #if defined(OS_WIN) |
| 303 virtual int Initialize(HINSTANCE instance, |
| 304 sandbox::SandboxInterfaceInfo* sandbox_info, |
| 305 content::ContentMainDelegate* delegate) OVERRIDE { |
| 306 // argc/argv are ignored on Windows; see command_line.h for details. |
| 307 int argc = 0; |
| 308 char** argv = NULL; |
| 309 |
| 310 content::RegisterInvalidParamHandler(); |
| 311 _Module.Init(NULL, static_cast<HINSTANCE>(instance)); |
| 312 |
| 313 if (sandbox_info) |
| 314 sandbox_info_ = *sandbox_info; |
| 315 else |
| 316 memset(&sandbox_info_, 0, sizeof(sandbox_info_)); |
| 317 |
| 318 #else // !OS_WIN |
| 319 virtual int Initialize(int argc, |
| 320 const char** argv, |
| 321 content::ContentMainDelegate* delegate) OVERRIDE { |
| 322 // NOTE(willchan): One might ask why this call is done here rather than in |
| 323 // process_util_linux.cc with the definition of |
| 324 // EnableTerminationOnOutOfMemory(). That's because base shouldn't have a |
| 325 // dependency on TCMalloc. Really, we ought to have our allocator shim code |
| 326 // implement this EnableTerminationOnOutOfMemory() function. Whateverz. |
| 327 // This works for now. |
| 328 #if !defined(OS_MACOSX) && defined(USE_TCMALLOC) |
| 329 // For tcmalloc, we need to tell it to behave like new. |
| 330 tc_set_new_mode(1); |
| 331 #endif |
| 332 |
| 333 #if !defined(OS_ANDROID) |
| 334 // Set C library locale to make sure CommandLine can parse argument values |
| 335 // in correct encoding. |
| 336 setlocale(LC_ALL, ""); |
| 337 #endif |
| 338 |
| 339 SetupSignalHandlers(); |
| 340 |
| 341 base::GlobalDescriptors* g_fds = base::GlobalDescriptors::GetInstance(); |
| 342 g_fds->Set(kPrimaryIPCChannel, |
| 343 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor); |
| 344 #if defined(OS_LINUX) || defined(OS_OPENBSD) |
| 345 g_fds->Set(kCrashDumpSignal, |
| 346 kCrashDumpSignal + base::GlobalDescriptors::kBaseDescriptor); |
| 347 #endif |
| 348 |
| 349 #endif // !OS_WIN |
| 350 |
| 351 is_initialized_ = true; |
| 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 _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 delegate_ = NULL; |
| 525 is_shutdown_ = true; |
| 526 } |
| 527 |
| 528 protected: |
| 529 // True if the runner has been initialized. |
| 530 bool is_initialized_; |
| 531 |
| 532 // True if the runner has been shut down. |
| 533 bool is_shutdown_; |
| 534 |
| 535 // The delegate will outlive this object. |
| 536 content::ContentMainDelegate* delegate_; |
| 537 |
| 538 scoped_ptr<base::AtExitManager> exit_manager_; |
| 539 #if defined(OS_WIN) |
| 540 sandbox::SandboxInterfaceInfo sandbox_info_; |
| 541 #elif defined(OS_MACOSX) |
| 542 scoped_ptr<base::mac::ScopedNSAutoreleasePool> autorelease_pool_; |
| 543 #endif |
| 544 |
| 545 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); |
| 546 }; |
| 547 |
282 } // namespace | 548 } // namespace |
283 | 549 |
284 namespace content { | 550 namespace content { |
285 | 551 |
286 #if defined(OS_WIN) | 552 // static |
287 int ContentMain(HINSTANCE instance, | 553 ContentMainRunner* ContentMainRunner::Create() { |
288 sandbox::SandboxInterfaceInfo* sandbox_info, | 554 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 } | 555 } |
471 | 556 |
472 } // namespace content | 557 } // namespace content |
OLD | NEW |