 Chromium Code Reviews
 Chromium Code Reviews Issue 10377059:
  Android content shell bringup.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 10377059:
  Android content shell bringup.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| 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 | 
| 370 #if !defined(OS_ANDROID) | 371 #if !defined(OS_ANDROID) | 
| 
Avi (use Gerrit)
2012/05/09 19:57:18
Not what I meant. On line 401, the comment about h
 | |
| 371 // Set C library locale to make sure CommandLine can parse argument values | 372 // Set C library locale to make sure CommandLine can parse argument values | 
| 372 // in correct encoding. | 373 // in correct encoding. | 
| 374 // Disabled on Android where it isn't supported. | |
| 373 setlocale(LC_ALL, ""); | 375 setlocale(LC_ALL, ""); | 
| 374 #endif | |
| 375 | 376 | 
| 377 // Disabled on Android. We do not override the signal | |
| 378 // handlers so that we can get stack trace when crashing. | |
| 376 SetupSignalHandlers(); | 379 SetupSignalHandlers(); | 
| 377 | 380 | 
| 381 // Android passes the ipc_fd through the Java service, so the next | |
| 382 // lines are disabled as well. | |
| 378 base::GlobalDescriptors* g_fds = base::GlobalDescriptors::GetInstance(); | 383 base::GlobalDescriptors* g_fds = base::GlobalDescriptors::GetInstance(); | 
| 379 g_fds->Set(kPrimaryIPCChannel, | 384 g_fds->Set(kPrimaryIPCChannel, | 
| 380 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor); | 385 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor); | 
| 386 #endif | |
| 387 | |
| 381 #if defined(OS_LINUX) || defined(OS_OPENBSD) | 388 #if defined(OS_LINUX) || defined(OS_OPENBSD) | 
| 382 g_fds->Set(kCrashDumpSignal, | 389 g_fds->Set(kCrashDumpSignal, | 
| 383 kCrashDumpSignal + base::GlobalDescriptors::kBaseDescriptor); | 390 kCrashDumpSignal + base::GlobalDescriptors::kBaseDescriptor); | 
| 384 #endif | 391 #endif | 
| 385 | 392 | 
| 386 #endif // !OS_WIN | 393 #endif // !OS_WIN | 
| 387 | 394 | 
| 388 is_initialized_ = true; | 395 is_initialized_ = true; | 
| 389 delegate_ = delegate; | 396 delegate_ = delegate; | 
| 390 | 397 | 
| 391 base::EnableTerminationOnHeapCorruption(); | 398 base::EnableTerminationOnHeapCorruption(); | 
| 392 base::EnableTerminationOnOutOfMemory(); | 399 base::EnableTerminationOnOutOfMemory(); | 
| 393 | 400 | 
| 401 // On Android, AtExitManager is set up when library is loaded. | |
| 402 #if !defined(OS_ANDROID) | |
| 394 // The exit manager is in charge of calling the dtors of singleton objects. | 403 // The exit manager is in charge of calling the dtors of singleton objects. | 
| 395 exit_manager_.reset(new base::AtExitManager); | 404 exit_manager_.reset(new base::AtExitManager); | 
| 405 #endif | |
| 396 | 406 | 
| 397 #if defined(OS_MACOSX) | 407 #if defined(OS_MACOSX) | 
| 398 // We need this pool for all the objects created before we get to the | 408 // 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 | 409 // 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 | 410 // 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. | 411 // its main event loop to get rid of the cruft. | 
| 402 autorelease_pool_.reset(new base::mac::ScopedNSAutoreleasePool()); | 412 autorelease_pool_.reset(new base::mac::ScopedNSAutoreleasePool()); | 
| 403 #endif | 413 #endif | 
| 404 | 414 | 
| 415 // On Android, the command line is initialized when library is loaded. | |
| 416 // (But *is* initialized here for content shell bringup) | |
| 417 #if !defined(OS_ANDROID) || defined(ANDROID_UPSTREAM_BRINGUP) | |
| 405 CommandLine::Init(argc, argv); | 418 CommandLine::Init(argc, argv); | 
| 419 #endif | |
| 406 | 420 | 
| 407 int exit_code; | 421 int exit_code; | 
| 408 if (delegate && delegate->BasicStartupComplete(&exit_code)) | 422 if (delegate && delegate->BasicStartupComplete(&exit_code)) | 
| 409 return exit_code; | 423 return exit_code; | 
| 410 DCHECK(!delegate || content::GetContentClient()) << | 424 DCHECK(!delegate || content::GetContentClient()) << | 
| 411 "BasicStartupComplete didn't set the content client"; | 425 "BasicStartupComplete didn't set the content client"; | 
| 412 | 426 | 
| 413 completed_basic_startup_ = true; | 427 completed_basic_startup_ = true; | 
| 414 | 428 | 
| 415 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 429 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 466 signal(SIGINT, SIG_IGN); | 480 signal(SIGINT, SIG_IGN); | 
| 467 } | 481 } | 
| 468 #endif | 482 #endif | 
| 469 | 483 | 
| 470 #if defined(USE_NSS) | 484 #if defined(USE_NSS) | 
| 471 crypto::EarlySetupForNSSInit(); | 485 crypto::EarlySetupForNSSInit(); | 
| 472 #endif | 486 #endif | 
| 473 | 487 | 
| 474 ui::RegisterPathProvider(); | 488 ui::RegisterPathProvider(); | 
| 475 content::RegisterPathProvider(); | 489 content::RegisterPathProvider(); | 
| 490 | |
| 491 // TODO(jrg): "up to here" is how far we get without crashing on | |
| 492 // content shell bringup. | |
| 493 #if defined(ANDROID_UPSTREAM_BRINGUP) | |
| 494 return 0; | |
| 495 #endif | |
| 476 content::RegisterContentSchemes(true); | 496 content::RegisterContentSchemes(true); | 
| 477 | 497 | 
| 478 CHECK(icu_util::Initialize()); | 498 CHECK(icu_util::Initialize()); | 
| 479 | 499 | 
| 480 base::ProcessId browser_pid = base::GetCurrentProcId(); | 500 base::ProcessId browser_pid = base::GetCurrentProcId(); | 
| 481 if (command_line.HasSwitch(switches::kProcessChannelID)) { | 501 if (command_line.HasSwitch(switches::kProcessChannelID)) { | 
| 482 #if defined(OS_WIN) || defined(OS_MACOSX) | 502 #if defined(OS_WIN) || defined(OS_MACOSX) | 
| 483 std::string channel_name = | 503 std::string channel_name = | 
| 484 command_line.GetSwitchValueASCII(switches::kProcessChannelID); | 504 command_line.GetSwitchValueASCII(switches::kProcessChannelID); | 
| 485 | 505 | 
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 606 } // namespace | 626 } // namespace | 
| 607 | 627 | 
| 608 namespace content { | 628 namespace content { | 
| 609 | 629 | 
| 610 // static | 630 // static | 
| 611 ContentMainRunner* ContentMainRunner::Create() { | 631 ContentMainRunner* ContentMainRunner::Create() { | 
| 612 return new ContentMainRunnerImpl(); | 632 return new ContentMainRunnerImpl(); | 
| 613 } | 633 } | 
| 614 | 634 | 
| 615 } // namespace content | 635 } // namespace content | 
| OLD | NEW |