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

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

Issue 9347022: Support sharing of ContentMain and BrowserMain code with embedded use cases (try #2). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 8 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « content/app/content_main.cc ('k') | content/browser/browser_main.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/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
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
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 // argc/argv are ignored on Windows; see command_line.h for details.
303 int argc = 0;
304 char** argv = NULL;
305
306 content::RegisterInvalidParamHandler();
307 app_module_.reset(new CAppModule);
308 app_module_->Init(NULL, static_cast<HINSTANCE>(instance));
309
310 if (sandbox_info)
311 sandbox_info_ = *sandbox_info;
312 else
313 memset(&sandbox_info_, 0, sizeof(sandbox_info_));
314
315 #else // !OS_WIN
316 virtual int Initialize(int argc,
317 const char** argv,
318 content::ContentMainDelegate* delegate) OVERRIDE {
319 // NOTE(willchan): One might ask why this call is done here rather than in
320 // process_util_linux.cc with the definition of
321 // EnableTerminationOnOutOfMemory(). That's because base shouldn't have a
322 // dependency on TCMalloc. Really, we ought to have our allocator shim code
323 // implement this EnableTerminationOnOutOfMemory() function. Whateverz.
324 // This works for now.
325 #if !defined(OS_MACOSX) && defined(USE_TCMALLOC)
326 // For tcmalloc, we need to tell it to behave like new.
327 tc_set_new_mode(1);
328 #endif
329
330 #if !defined(OS_ANDROID)
331 // Set C library locale to make sure CommandLine can parse argument values
332 // in correct encoding.
333 setlocale(LC_ALL, "");
334 #endif
335
336 SetupSignalHandlers();
337
338 base::GlobalDescriptors* g_fds = base::GlobalDescriptors::GetInstance();
339 g_fds->Set(kPrimaryIPCChannel,
340 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor);
341 #if defined(OS_LINUX) || defined(OS_OPENBSD)
342 g_fds->Set(kCrashDumpSignal,
343 kCrashDumpSignal + base::GlobalDescriptors::kBaseDescriptor);
344 #endif
345
346 #endif // !OS_WIN
347
348 is_initialized_ = true;
349 delegate_ = delegate;
350
351 base::EnableTerminationOnHeapCorruption();
352 base::EnableTerminationOnOutOfMemory();
353
354 // The exit manager is in charge of calling the dtors of singleton objects.
355 exit_manager_.reset(new base::AtExitManager);
356
357 #if defined(OS_MACOSX)
358 // We need this pool for all the objects created before we get to the
359 // event loop, but we don't want to leave them hanging around until the
360 // app quits. Each "main" needs to flush this pool right before it goes into
361 // its main event loop to get rid of the cruft.
362 autorelease_pool_.reset(new base::mac::ScopedNSAutoreleasePool());
363 #endif
364
365 CommandLine::Init(argc, argv);
366
367 int exit_code;
368 if (delegate && delegate->BasicStartupComplete(&exit_code))
369 return exit_code;
370
371 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
372 std::string process_type =
373 command_line.GetSwitchValueASCII(switches::kProcessType);
374
375 // Enable startup tracing asap to avoid early TRACE_EVENT calls being
376 // ignored.
377 if (command_line.HasSwitch(switches::kTraceStartup)) {
378 base::debug::TraceLog::GetInstance()->SetEnabled(
379 command_line.GetSwitchValueASCII(switches::kTraceStartup));
380 }
381
382 #if defined(OS_MACOSX)
383 // We need to allocate the IO Ports before the Sandbox is initialized or
384 // the first instance of SystemMonitor is created.
385 // It's important not to allocate the ports for processes which don't
386 // register with the system monitor - see crbug.com/88867.
387 if (process_type.empty() ||
388 process_type == switches::kPluginProcess ||
389 process_type == switches::kRendererProcess ||
390 process_type == switches::kUtilityProcess ||
391 process_type == switches::kWorkerProcess ||
392 (delegate &&
393 delegate->ProcessRegistersWithSystemProcess(process_type))) {
394 base::SystemMonitor::AllocateSystemIOPorts();
395 }
396
397 if (!process_type.empty() &&
398 (!delegate || delegate->ShouldSendMachPort(process_type))) {
399 SendTaskPortToParentProcess();
400 }
401 #elif defined(OS_WIN)
402 content::SetupCRT(command_line);
403 #endif
404
405 #if defined(OS_POSIX)
406 if (!process_type.empty()) {
407 // When you hit Ctrl-C in a terminal running the browser
408 // process, a SIGINT is delivered to the entire process group.
409 // When debugging the browser process via gdb, gdb catches the
410 // SIGINT for the browser process (and dumps you back to the gdb
411 // console) but doesn't for the child processes, killing them.
412 // The fix is to have child processes ignore SIGINT; they'll die
413 // on their own when the browser process goes away.
414 //
415 // Note that we *can't* rely on BeingDebugged to catch this case because
416 // we are the child process, which is not being debugged.
417 // TODO(evanm): move this to some shared subprocess-init function.
418 if (!base::debug::BeingDebugged())
419 signal(SIGINT, SIG_IGN);
420 }
421 #endif
422
423 #if defined(USE_NSS)
424 crypto::EarlySetupForNSSInit();
425 #endif
426
427 ui::RegisterPathProvider();
428 content::RegisterPathProvider();
429
430 CHECK(icu_util::Initialize());
431
432 base::ProcessId browser_pid = base::GetCurrentProcId();
433 if (command_line.HasSwitch(switches::kProcessChannelID)) {
434 #if defined(OS_WIN) || defined(OS_MACOSX)
435 std::string channel_name =
436 command_line.GetSwitchValueASCII(switches::kProcessChannelID);
437
438 int browser_pid_int;
439 base::StringToInt(channel_name, &browser_pid_int);
440 browser_pid = static_cast<base::ProcessId>(browser_pid_int);
441 DCHECK_NE(browser_pid_int, 0);
442 #elif defined(OS_POSIX)
443 // On linux, we're in the zygote here; so we need the parent process' id.
444 browser_pid = base::GetParentProcessId(base::GetCurrentProcId());
445 #endif
446 }
447
448 InitializeStatsTable(browser_pid, command_line);
449
450 if (delegate)
451 delegate->PreSandboxStartup();
452
453 if (!process_type.empty())
454 CommonSubprocessInit(process_type);
455
456 #if defined(OS_WIN)
457 CHECK(content::InitializeSandbox(sandbox_info));
458 #elif defined(OS_MACOSX)
459 if (process_type == switches::kRendererProcess ||
460 process_type == switches::kPpapiPluginProcess ||
461 (delegate && delegate->DelaySandboxInitialization(process_type))) {
462 // On OS X the renderer sandbox needs to be initialized later in the
463 // startup sequence in RendererMainPlatformDelegate::EnableSandbox().
464 } else {
465 CHECK(content::InitializeSandbox());
466 }
467 #endif
468
469 if (delegate)
470 delegate->SandboxInitialized(process_type);
471
472 #if defined(OS_POSIX)
473 SetProcessTitleFromCommandLine(argv);
474 #endif
475
476 // Return -1 to indicate no early termination.
477 return -1;
478 }
479
480 virtual int Run() OVERRIDE {
481 DCHECK(is_initialized_);
482 DCHECK(!is_shutdown_);
483 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
484 std::string process_type =
485 command_line.GetSwitchValueASCII(switches::kProcessType);
486
487 content::MainFunctionParams main_params(command_line);
488 #if defined(OS_WIN)
489 main_params.sandbox_info = &sandbox_info_;
490 #elif defined(OS_MACOSX)
491 main_params.autorelease_pool = autorelease_pool_.get();
492 #endif
493
494 return RunNamedProcessTypeMain(process_type, main_params, delegate_);
495 }
496
497 virtual void Shutdown() OVERRIDE {
498 DCHECK(is_initialized_);
499 DCHECK(!is_shutdown_);
500 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
501 std::string process_type =
502 command_line.GetSwitchValueASCII(switches::kProcessType);
503
504 if (delegate_)
505 delegate_->ProcessExiting(process_type);
506
507 #if defined(OS_WIN)
508 #ifdef _CRTDBG_MAP_ALLOC
509 _CrtDumpMemoryLeaks();
510 #endif // _CRTDBG_MAP_ALLOC
511
512 app_module_->Term();
513 #endif // OS_WIN
514
515 #if defined(OS_MACOSX)
516 autorelease_pool_.reset(NULL);
517 #endif
518
519 exit_manager_.reset(NULL);
520
521 #if defined(OS_WIN)
522 app_module_.reset(NULL);
523 #endif
524
525 delegate_ = NULL;
526 is_shutdown_ = true;
527 }
528
529 protected:
530 // True if the runner has been initialized.
531 bool is_initialized_;
532
533 // True if the runner has been shut down.
534 bool is_shutdown_;
535
536 // The delegate will outlive this object.
537 content::ContentMainDelegate* delegate_;
538
539 scoped_ptr<base::AtExitManager> exit_manager_;
540 #if defined(OS_WIN)
541 sandbox::SandboxInterfaceInfo sandbox_info_;
542 scoped_ptr<CAppModule> app_module_;
543 #elif defined(OS_MACOSX)
544 scoped_ptr<base::mac::ScopedNSAutoreleasePool> autorelease_pool_;
545 #endif
546
547 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl);
548 };
549
282 } // namespace 550 } // namespace
283 551
284 namespace content { 552 namespace content {
285 553
286 #if defined(OS_WIN) 554 // static
287 int ContentMain(HINSTANCE instance, 555 ContentMainRunner* ContentMainRunner::Create() {
288 sandbox::SandboxInterfaceInfo* sandbox_info, 556 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 } 557 }
471 558
472 } // namespace content 559 } // namespace content
OLDNEW
« no previous file with comments | « content/app/content_main.cc ('k') | content/browser/browser_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698