OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/app/content_main.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/i18n/icu_util.h" | 10 #include "base/i18n/icu_util.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/mac/scoped_nsautorelease_pool.h" | |
13 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
14 #include "base/metrics/stats_table.h" | 13 #include "base/metrics/stats_table.h" |
15 #include "base/process_util.h" | 14 #include "base/process_util.h" |
16 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
17 #include "base/string_number_conversions.h" | 16 #include "base/string_number_conversions.h" |
18 #include "content/app/startup_helper_win.h" | |
19 #include "content/browser/browser_main.h" | 17 #include "content/browser/browser_main.h" |
20 #include "content/common/main_function_params.h" | 18 #include "content/common/main_function_params.h" |
21 #include "content/common/sandbox_init_wrapper.h" | |
22 #include "content/common/set_process_title.h" | 19 #include "content/common/set_process_title.h" |
23 #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" |
24 #include "content/public/common/content_client.h" | 22 #include "content/public/common/content_client.h" |
25 #include "content/public/common/content_constants.h" | 23 #include "content/public/common/content_constants.h" |
26 #include "content/public/common/content_paths.h" | 24 #include "content/public/common/content_paths.h" |
27 #include "content/public/common/content_switches.h" | 25 #include "content/public/common/content_switches.h" |
| 26 #include "content/public/common/sandbox_init.h" |
28 #include "crypto/nss_util.h" | 27 #include "crypto/nss_util.h" |
29 #include "ipc/ipc_switches.h" | 28 #include "ipc/ipc_switches.h" |
30 #include "ui/base/ui_base_switches.h" | 29 #include "ui/base/ui_base_switches.h" |
31 #include "ui/base/ui_base_paths.h" | 30 #include "ui/base/ui_base_paths.h" |
32 #include "webkit/glue/webkit_glue.h" | 31 #include "webkit/glue/webkit_glue.h" |
33 | 32 |
34 #if defined(OS_WIN) | 33 #if defined(OS_WIN) |
35 #include <atlbase.h> | 34 #include <atlbase.h> |
36 #include <atlapp.h> | 35 #include <atlapp.h> |
37 #include <malloc.h> | 36 #include <malloc.h> |
38 #elif defined(OS_MACOSX) | 37 #elif defined(OS_MACOSX) |
| 38 #include "base/mac/scoped_nsautorelease_pool.h" |
39 #include "base/mach_ipc_mac.h" | 39 #include "base/mach_ipc_mac.h" |
40 #include "base/system_monitor/system_monitor.h" | 40 #include "base/system_monitor/system_monitor.h" |
41 #include "content/browser/mach_broker_mac.h" | 41 #include "content/browser/mach_broker_mac.h" |
42 #endif // OS_WIN | 42 #endif // OS_WIN |
43 | 43 |
44 #if defined(OS_POSIX) | 44 #if defined(OS_POSIX) |
45 #include <signal.h> | 45 #include <signal.h> |
46 | 46 |
47 #include "base/global_descriptors_posix.h" | 47 #include "base/global_descriptors_posix.h" |
48 #include "content/common/chrome_descriptors.h" | 48 #include "content/common/chrome_descriptors.h" |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 std::string ua = content::GetContentClient()->GetUserAgent(&custom); | 212 std::string ua = content::GetContentClient()->GetUserAgent(&custom); |
213 if (custom) webkit_glue::SetUserAgent(ua, custom); | 213 if (custom) webkit_glue::SetUserAgent(ua, custom); |
214 | 214 |
215 // The StatsTable must be initialized in each process; we already | 215 // The StatsTable must be initialized in each process; we already |
216 // initialized for the browser process, now we need to initialize | 216 // initialized for the browser process, now we need to initialize |
217 // within the new processes as well. | 217 // within the new processes as well. |
218 pid_t browser_pid = base::GetParentProcessId( | 218 pid_t browser_pid = base::GetParentProcessId( |
219 base::GetParentProcessId(base::GetCurrentProcId())); | 219 base::GetParentProcessId(base::GetCurrentProcId())); |
220 InitializeStatsTable(browser_pid, command_line); | 220 InitializeStatsTable(browser_pid, command_line); |
221 | 221 |
222 MainFunctionParams main_params(command_line, | 222 MainFunctionParams main_params(command_line); |
223 main_function_params.sandbox_info_, | 223 |
224 main_function_params.autorelease_pool_); | |
225 // Get the new process type from the new command line. | 224 // Get the new process type from the new command line. |
226 std::string process_type = | 225 std::string process_type = |
227 command_line.GetSwitchValueASCII(switches::kProcessType); | 226 command_line.GetSwitchValueASCII(switches::kProcessType); |
228 | 227 |
229 for (size_t i = 0; i < arraysize(kMainFunctions); ++i) { | 228 for (size_t i = 0; i < arraysize(kMainFunctions); ++i) { |
230 if (process_type == kMainFunctions[i].name) | 229 if (process_type == kMainFunctions[i].name) |
231 return kMainFunctions[i].function(main_params); | 230 return kMainFunctions[i].function(main_params); |
232 } | 231 } |
233 | 232 |
234 if (delegate) | 233 if (delegate) |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 #endif | 319 #endif |
321 | 320 |
322 #endif // OS_WIN | 321 #endif // OS_WIN |
323 | 322 |
324 base::EnableTerminationOnHeapCorruption(); | 323 base::EnableTerminationOnHeapCorruption(); |
325 base::EnableTerminationOnOutOfMemory(); | 324 base::EnableTerminationOnOutOfMemory(); |
326 | 325 |
327 // The exit manager is in charge of calling the dtors of singleton objects. | 326 // The exit manager is in charge of calling the dtors of singleton objects. |
328 base::AtExitManager exit_manager; | 327 base::AtExitManager exit_manager; |
329 | 328 |
| 329 #if defined(OS_MACOSX) |
330 // We need this pool for all the objects created before we get to the | 330 // We need this pool for all the objects created before we get to the |
331 // event loop, but we don't want to leave them hanging around until the | 331 // event loop, but we don't want to leave them hanging around until the |
332 // app quits. Each "main" needs to flush this pool right before it goes into | 332 // app quits. Each "main" needs to flush this pool right before it goes into |
333 // its main event loop to get rid of the cruft. | 333 // its main event loop to get rid of the cruft. |
334 base::mac::ScopedNSAutoreleasePool autorelease_pool; | 334 base::mac::ScopedNSAutoreleasePool autorelease_pool; |
| 335 #endif |
335 | 336 |
336 CommandLine::Init(argc, argv); | 337 CommandLine::Init(argc, argv); |
337 | 338 |
338 int exit_code; | 339 int exit_code; |
339 if (delegate && delegate->BasicStartupComplete(&exit_code)) | 340 if (delegate && delegate->BasicStartupComplete(&exit_code)) |
340 return exit_code; | 341 return exit_code; |
341 | 342 |
342 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 343 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
343 std::string process_type = | 344 std::string process_type = |
344 command_line.GetSwitchValueASCII(switches::kProcessType); | 345 command_line.GetSwitchValueASCII(switches::kProcessType); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 #endif | 409 #endif |
409 } | 410 } |
410 | 411 |
411 InitializeStatsTable(browser_pid, command_line); | 412 InitializeStatsTable(browser_pid, command_line); |
412 | 413 |
413 if (delegate) delegate->PreSandboxStartup(); | 414 if (delegate) delegate->PreSandboxStartup(); |
414 | 415 |
415 if (!process_type.empty()) | 416 if (!process_type.empty()) |
416 CommonSubprocessInit(process_type); | 417 CommonSubprocessInit(process_type); |
417 | 418 |
418 // Initialize the sandbox for this process. | |
419 SandboxInitWrapper sandbox_wrapper; | |
420 bool initialize_sandbox = true; | |
421 | |
422 #if defined(OS_WIN) | 419 #if defined(OS_WIN) |
423 sandbox_wrapper.SetServices(sandbox_info); | 420 CHECK(content::InitializeSandbox(sandbox_info)); |
424 #elif defined(OS_MACOSX) | 421 #elif defined(OS_MACOSX) |
425 // On OS X the renderer sandbox needs to be initialized later in the startup | |
426 // sequence in RendererMainPlatformDelegate::EnableSandbox(). | |
427 if (process_type == switches::kRendererProcess || | 422 if (process_type == switches::kRendererProcess || |
428 process_type == switches::kPpapiPluginProcess || | 423 process_type == switches::kPpapiPluginProcess || |
429 (delegate && delegate->DelaySandboxInitialization(process_type))) { | 424 (delegate && delegate->DelaySandboxInitialization(process_type))) { |
430 initialize_sandbox = false; | 425 // On OS X the renderer sandbox needs to be initialized later in the startup |
| 426 // sequence in RendererMainPlatformDelegate::EnableSandbox(). |
| 427 } else { |
| 428 CHECK(content::InitializeSandbox()); |
431 } | 429 } |
432 #endif | 430 #endif |
433 | 431 |
434 if (initialize_sandbox) { | |
435 bool sandbox_initialized_ok = | |
436 sandbox_wrapper.InitializeSandbox(command_line, process_type); | |
437 // Die if the sandbox can't be enabled. | |
438 CHECK(sandbox_initialized_ok) << "Error initializing sandbox for " | |
439 << process_type; | |
440 } | |
441 | |
442 if (delegate) delegate->SandboxInitialized(process_type); | 432 if (delegate) delegate->SandboxInitialized(process_type); |
443 | 433 |
444 #if defined(OS_POSIX) | 434 #if defined(OS_POSIX) |
445 SetProcessTitleFromCommandLine(argv); | 435 SetProcessTitleFromCommandLine(argv); |
446 #endif | 436 #endif |
447 | 437 |
448 MainFunctionParams main_params(command_line, sandbox_wrapper, | 438 MainFunctionParams main_params(command_line); |
449 &autorelease_pool); | 439 #if defined(OS_WIN) |
| 440 main_params.sandbox_info = sandbox_info; |
| 441 #elif defined(OS_MACOSX) |
| 442 main_params.autorelease_pool = &autorelease_pool; |
| 443 #endif |
450 | 444 |
451 exit_code = RunNamedProcessTypeMain(process_type, main_params, delegate); | 445 exit_code = RunNamedProcessTypeMain(process_type, main_params, delegate); |
452 | 446 |
453 if (delegate) delegate->ProcessExiting(process_type); | 447 if (delegate) delegate->ProcessExiting(process_type); |
454 | 448 |
455 #if defined(OS_WIN) | 449 #if defined(OS_WIN) |
456 #ifdef _CRTDBG_MAP_ALLOC | 450 #ifdef _CRTDBG_MAP_ALLOC |
457 _CrtDumpMemoryLeaks(); | 451 _CrtDumpMemoryLeaks(); |
458 #endif // _CRTDBG_MAP_ALLOC | 452 #endif // _CRTDBG_MAP_ALLOC |
459 | 453 |
460 _Module.Term(); | 454 _Module.Term(); |
461 #endif // OS_WIN | 455 #endif // OS_WIN |
462 | 456 |
463 return exit_code; | 457 return exit_code; |
464 } | 458 } |
465 | 459 |
466 } // namespace content | 460 } // namespace content |
OLD | NEW |