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

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

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

Powered by Google App Engine
This is Rietveld 408576698