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/public/app/content_main_runner.h" | 5 #include "content/public/app/content_main_runner.h" |
6 | 6 |
7 #include "base/allocator/allocator_extension.h" | 7 #include "base/allocator/allocator_extension.h" |
8 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/debugger.h" | 10 #include "base/debug/debugger.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 } | 72 } |
73 #endif | 73 #endif |
74 | 74 |
75 extern int GpuMain(const content::MainFunctionParams&); | 75 extern int GpuMain(const content::MainFunctionParams&); |
76 extern int PluginMain(const content::MainFunctionParams&); | 76 extern int PluginMain(const content::MainFunctionParams&); |
77 extern int PpapiPluginMain(const content::MainFunctionParams&); | 77 extern int PpapiPluginMain(const content::MainFunctionParams&); |
78 extern int PpapiBrokerMain(const content::MainFunctionParams&); | 78 extern int PpapiBrokerMain(const content::MainFunctionParams&); |
79 extern int RendererMain(const content::MainFunctionParams&); | 79 extern int RendererMain(const content::MainFunctionParams&); |
80 extern int WorkerMain(const content::MainFunctionParams&); | 80 extern int WorkerMain(const content::MainFunctionParams&); |
81 extern int UtilityMain(const content::MainFunctionParams&); | 81 extern int UtilityMain(const content::MainFunctionParams&); |
82 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 82 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
83 namespace content { | 83 namespace content { |
84 extern int ZygoteMain(const content::MainFunctionParams&, | 84 extern int ZygoteMain(const content::MainFunctionParams&, |
85 content::ZygoteForkDelegate* forkdelegate); | 85 content::ZygoteForkDelegate* forkdelegate); |
86 } // namespace content | 86 } // namespace content |
87 #endif | 87 #endif |
88 | 88 |
89 namespace { | 89 namespace { |
90 | 90 |
91 #if defined(OS_WIN) | 91 #if defined(OS_WIN) |
92 | 92 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 } | 187 } |
188 } | 188 } |
189 | 189 |
190 // We dispatch to a process-type-specific FooMain() based on a command-line | 190 // We dispatch to a process-type-specific FooMain() based on a command-line |
191 // flag. This struct is used to build a table of (flag, main function) pairs. | 191 // flag. This struct is used to build a table of (flag, main function) pairs. |
192 struct MainFunction { | 192 struct MainFunction { |
193 const char* name; | 193 const char* name; |
194 int (*function)(const content::MainFunctionParams&); | 194 int (*function)(const content::MainFunctionParams&); |
195 }; | 195 }; |
196 | 196 |
197 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 197 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
198 // On platforms that use the zygote, we have a special subset of | 198 // On platforms that use the zygote, we have a special subset of |
199 // subprocesses that are launched via the zygote. This function | 199 // subprocesses that are launched via the zygote. This function |
200 // fills in some process-launching bits around ZygoteMain(). | 200 // fills in some process-launching bits around ZygoteMain(). |
201 // Returns the exit code of the subprocess. | 201 // Returns the exit code of the subprocess. |
202 int RunZygote(const content::MainFunctionParams& main_function_params, | 202 int RunZygote(const content::MainFunctionParams& main_function_params, |
203 content::ContentMainDelegate* delegate) { | 203 content::ContentMainDelegate* delegate) { |
204 static const MainFunction kMainFunctions[] = { | 204 static const MainFunction kMainFunctions[] = { |
205 { switches::kRendererProcess, RendererMain }, | 205 { switches::kRendererProcess, RendererMain }, |
206 { switches::kWorkerProcess, WorkerMain }, | 206 { switches::kWorkerProcess, WorkerMain }, |
207 { switches::kPpapiPluginProcess, PpapiPluginMain }, | 207 { switches::kPpapiPluginProcess, PpapiPluginMain }, |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 if (delegate) { | 286 if (delegate) { |
287 int exit_code = delegate->RunProcess(process_type, | 287 int exit_code = delegate->RunProcess(process_type, |
288 main_function_params); | 288 main_function_params); |
289 if (exit_code >= 0) | 289 if (exit_code >= 0) |
290 return exit_code; | 290 return exit_code; |
291 } | 291 } |
292 return kMainFunctions[i].function(main_function_params); | 292 return kMainFunctions[i].function(main_function_params); |
293 } | 293 } |
294 } | 294 } |
295 | 295 |
296 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 296 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
297 // Zygote startup is special -- see RunZygote comments above | 297 // Zygote startup is special -- see RunZygote comments above |
298 // for why we don't use ZygoteMain directly. | 298 // for why we don't use ZygoteMain directly. |
299 if (process_type == switches::kZygoteProcess) | 299 if (process_type == switches::kZygoteProcess) |
300 return RunZygote(main_function_params, delegate); | 300 return RunZygote(main_function_params, delegate); |
301 #endif | 301 #endif |
302 | 302 |
303 // If it's a process we don't know about, the embedder should know. | 303 // If it's a process we don't know about, the embedder should know. |
304 if (delegate) | 304 if (delegate) |
305 return delegate->RunProcess(process_type, main_function_params); | 305 return delegate->RunProcess(process_type, main_function_params); |
306 | 306 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 | 345 |
346 if (sandbox_info) | 346 if (sandbox_info) |
347 sandbox_info_ = *sandbox_info; | 347 sandbox_info_ = *sandbox_info; |
348 else | 348 else |
349 memset(&sandbox_info_, 0, sizeof(sandbox_info_)); | 349 memset(&sandbox_info_, 0, sizeof(sandbox_info_)); |
350 | 350 |
351 #else // !OS_WIN | 351 #else // !OS_WIN |
352 virtual int Initialize(int argc, | 352 virtual int Initialize(int argc, |
353 const char** argv, | 353 const char** argv, |
354 content::ContentMainDelegate* delegate) OVERRIDE { | 354 content::ContentMainDelegate* delegate) OVERRIDE { |
| 355 |
355 // NOTE(willchan): One might ask why this call is done here rather than in | 356 // NOTE(willchan): One might ask why this call is done here rather than in |
356 // process_util_linux.cc with the definition of | 357 // process_util_linux.cc with the definition of |
357 // EnableTerminationOnOutOfMemory(). That's because base shouldn't have a | 358 // EnableTerminationOnOutOfMemory(). That's because base shouldn't have a |
358 // dependency on TCMalloc. Really, we ought to have our allocator shim code | 359 // dependency on TCMalloc. Really, we ought to have our allocator shim code |
359 // implement this EnableTerminationOnOutOfMemory() function. Whateverz. | 360 // implement this EnableTerminationOnOutOfMemory() function. Whateverz. |
360 // This works for now. | 361 // This works for now. |
361 #if !defined(OS_MACOSX) && defined(USE_TCMALLOC) | 362 #if !defined(OS_MACOSX) && defined(USE_TCMALLOC) |
362 // For tcmalloc, we need to tell it to behave like new. | 363 // For tcmalloc, we need to tell it to behave like new. |
363 tc_set_new_mode(1); | 364 tc_set_new_mode(1); |
364 | 365 |
365 // On windows, we've already set these thunks up in _heap_init() | 366 // On windows, we've already set these thunks up in _heap_init() |
366 base::allocator::SetGetStatsFunction(GetStatsThunk); | 367 base::allocator::SetGetStatsFunction(GetStatsThunk); |
367 base::allocator::SetReleaseFreeMemoryFunction(ReleaseFreeMemoryThunk); | 368 base::allocator::SetReleaseFreeMemoryFunction(ReleaseFreeMemoryThunk); |
368 #endif | 369 #endif |
369 | 370 |
| 371 // On Android, |
| 372 // - setlocale() is not supported. |
| 373 // - We do not override the signal handlers so that we can get |
| 374 // stack trace when crashing. |
| 375 // - The ipc_fd is passed through the Java service. |
| 376 // Thus, these are all disabled. |
370 #if !defined(OS_ANDROID) | 377 #if !defined(OS_ANDROID) |
371 // Set C library locale to make sure CommandLine can parse argument values | 378 // Set C library locale to make sure CommandLine can parse argument values |
372 // in correct encoding. | 379 // in correct encoding. |
373 setlocale(LC_ALL, ""); | 380 setlocale(LC_ALL, ""); |
374 #endif | |
375 | 381 |
376 SetupSignalHandlers(); | 382 SetupSignalHandlers(); |
377 | 383 |
378 base::GlobalDescriptors* g_fds = base::GlobalDescriptors::GetInstance(); | 384 base::GlobalDescriptors* g_fds = base::GlobalDescriptors::GetInstance(); |
379 g_fds->Set(kPrimaryIPCChannel, | 385 g_fds->Set(kPrimaryIPCChannel, |
380 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor); | 386 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor); |
| 387 #endif |
| 388 |
381 #if defined(OS_LINUX) || defined(OS_OPENBSD) | 389 #if defined(OS_LINUX) || defined(OS_OPENBSD) |
382 g_fds->Set(kCrashDumpSignal, | 390 g_fds->Set(kCrashDumpSignal, |
383 kCrashDumpSignal + base::GlobalDescriptors::kBaseDescriptor); | 391 kCrashDumpSignal + base::GlobalDescriptors::kBaseDescriptor); |
384 #endif | 392 #endif |
385 | 393 |
386 #endif // !OS_WIN | 394 #endif // !OS_WIN |
387 | 395 |
388 is_initialized_ = true; | 396 is_initialized_ = true; |
389 delegate_ = delegate; | 397 delegate_ = delegate; |
390 | 398 |
391 base::EnableTerminationOnHeapCorruption(); | 399 base::EnableTerminationOnHeapCorruption(); |
392 base::EnableTerminationOnOutOfMemory(); | 400 base::EnableTerminationOnOutOfMemory(); |
393 | 401 |
| 402 // On Android, AtExitManager is set up when library is loaded. |
| 403 #if !defined(OS_ANDROID) |
394 // The exit manager is in charge of calling the dtors of singleton objects. | 404 // The exit manager is in charge of calling the dtors of singleton objects. |
395 exit_manager_.reset(new base::AtExitManager); | 405 exit_manager_.reset(new base::AtExitManager); |
| 406 #endif |
396 | 407 |
397 #if defined(OS_MACOSX) | 408 #if defined(OS_MACOSX) |
398 // We need this pool for all the objects created before we get to the | 409 // We need this pool for all the objects created before we get to the |
399 // event loop, but we don't want to leave them hanging around until the | 410 // event loop, but we don't want to leave them hanging around until the |
400 // app quits. Each "main" needs to flush this pool right before it goes into | 411 // app quits. Each "main" needs to flush this pool right before it goes into |
401 // its main event loop to get rid of the cruft. | 412 // its main event loop to get rid of the cruft. |
402 autorelease_pool_.reset(new base::mac::ScopedNSAutoreleasePool()); | 413 autorelease_pool_.reset(new base::mac::ScopedNSAutoreleasePool()); |
403 #endif | 414 #endif |
404 | 415 |
| 416 // On Android, the command line is initialized when library is loaded. |
| 417 // (But *is* initialized here for content shell bringup) |
| 418 #if !defined(OS_ANDROID) || defined(ANDROID_UPSTREAM_BRINGUP) |
405 CommandLine::Init(argc, argv); | 419 CommandLine::Init(argc, argv); |
| 420 #endif |
406 | 421 |
407 int exit_code; | 422 int exit_code; |
408 if (delegate && delegate->BasicStartupComplete(&exit_code)) | 423 if (delegate && delegate->BasicStartupComplete(&exit_code)) |
409 return exit_code; | 424 return exit_code; |
410 DCHECK(!delegate || content::GetContentClient()) << | 425 DCHECK(!delegate || content::GetContentClient()) << |
411 "BasicStartupComplete didn't set the content client"; | 426 "BasicStartupComplete didn't set the content client"; |
412 | 427 |
413 completed_basic_startup_ = true; | 428 completed_basic_startup_ = true; |
414 | 429 |
415 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 430 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 signal(SIGINT, SIG_IGN); | 481 signal(SIGINT, SIG_IGN); |
467 } | 482 } |
468 #endif | 483 #endif |
469 | 484 |
470 #if defined(USE_NSS) | 485 #if defined(USE_NSS) |
471 crypto::EarlySetupForNSSInit(); | 486 crypto::EarlySetupForNSSInit(); |
472 #endif | 487 #endif |
473 | 488 |
474 ui::RegisterPathProvider(); | 489 ui::RegisterPathProvider(); |
475 content::RegisterPathProvider(); | 490 content::RegisterPathProvider(); |
| 491 |
| 492 // TODO(jrg): "up to here" is how far we get without crashing on |
| 493 // content shell bringup. |
| 494 #if defined(ANDROID_UPSTREAM_BRINGUP) |
| 495 return 0; |
| 496 #endif |
476 content::RegisterContentSchemes(true); | 497 content::RegisterContentSchemes(true); |
477 | 498 |
478 CHECK(icu_util::Initialize()); | 499 CHECK(icu_util::Initialize()); |
479 | 500 |
480 base::ProcessId browser_pid = base::GetCurrentProcId(); | 501 base::ProcessId browser_pid = base::GetCurrentProcId(); |
481 if (command_line.HasSwitch(switches::kProcessChannelID)) { | 502 if (command_line.HasSwitch(switches::kProcessChannelID)) { |
482 #if defined(OS_WIN) || defined(OS_MACOSX) | 503 #if defined(OS_WIN) || defined(OS_MACOSX) |
483 std::string channel_name = | 504 std::string channel_name = |
484 command_line.GetSwitchValueASCII(switches::kProcessChannelID); | 505 command_line.GetSwitchValueASCII(switches::kProcessChannelID); |
485 | 506 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 } // namespace | 627 } // namespace |
607 | 628 |
608 namespace content { | 629 namespace content { |
609 | 630 |
610 // static | 631 // static |
611 ContentMainRunner* ContentMainRunner::Create() { | 632 ContentMainRunner* ContentMainRunner::Create() { |
612 return new ContentMainRunnerImpl(); | 633 return new ContentMainRunnerImpl(); |
613 } | 634 } |
614 | 635 |
615 } // namespace content | 636 } // namespace content |
OLD | NEW |