| 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 <stdlib.h> | 7 #include <stdlib.h> |
| 8 | 8 |
| 9 #include "base/allocator/allocator_extension.h" | 9 #include "base/allocator/allocator_extension.h" |
| 10 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 // when presenting them to the user), reset the locale for numeric | 183 // when presenting them to the user), reset the locale for numeric |
| 184 // formatting. | 184 // formatting. |
| 185 // Note that this is not correct for plugin processes -- they can | 185 // Note that this is not correct for plugin processes -- they can |
| 186 // surface UI -- but it's likely they get this wrong too so why not. | 186 // surface UI -- but it's likely they get this wrong too so why not. |
| 187 setlocale(LC_NUMERIC, "C"); | 187 setlocale(LC_NUMERIC, "C"); |
| 188 #endif | 188 #endif |
| 189 } | 189 } |
| 190 | 190 |
| 191 // Only needed on Windows for creating stats tables. | 191 // Only needed on Windows for creating stats tables. |
| 192 #if defined(OS_WIN) | 192 #if defined(OS_WIN) |
| 193 static base::ProcessId GetBrowserPid(const CommandLine& command_line) { | 193 static base::ProcessId GetBrowserPid(const base::CommandLine& command_line) { |
| 194 base::ProcessId browser_pid = base::GetCurrentProcId(); | 194 base::ProcessId browser_pid = base::GetCurrentProcId(); |
| 195 if (command_line.HasSwitch(switches::kProcessChannelID)) { | 195 if (command_line.HasSwitch(switches::kProcessChannelID)) { |
| 196 std::string channel_name = | 196 std::string channel_name = |
| 197 command_line.GetSwitchValueASCII(switches::kProcessChannelID); | 197 command_line.GetSwitchValueASCII(switches::kProcessChannelID); |
| 198 | 198 |
| 199 int browser_pid_int; | 199 int browser_pid_int; |
| 200 base::StringToInt(channel_name, &browser_pid_int); | 200 base::StringToInt(channel_name, &browser_pid_int); |
| 201 browser_pid = static_cast<base::ProcessId>(browser_pid_int); | 201 browser_pid = static_cast<base::ProcessId>(browser_pid_int); |
| 202 DCHECK_NE(browser_pid_int, 0); | 202 DCHECK_NE(browser_pid_int, 0); |
| 203 } | 203 } |
| 204 return browser_pid; | 204 return browser_pid; |
| 205 } | 205 } |
| 206 #endif | 206 #endif |
| 207 | 207 |
| 208 static void InitializeStatsTable(const CommandLine& command_line) { | 208 static void InitializeStatsTable(const base::CommandLine& command_line) { |
| 209 // Initialize the Stats Counters table. With this initialized, | 209 // Initialize the Stats Counters table. With this initialized, |
| 210 // the StatsViewer can be utilized to read counters outside of | 210 // the StatsViewer can be utilized to read counters outside of |
| 211 // Chrome. These lines can be commented out to effectively turn | 211 // Chrome. These lines can be commented out to effectively turn |
| 212 // counters 'off'. The table is created and exists for the life | 212 // counters 'off'. The table is created and exists for the life |
| 213 // of the process. It is not cleaned up. | 213 // of the process. It is not cleaned up. |
| 214 if (command_line.HasSwitch(switches::kEnableStatsTable)) { | 214 if (command_line.HasSwitch(switches::kEnableStatsTable)) { |
| 215 // NOTIMPLEMENTED: we probably need to shut this down correctly to avoid | 215 // NOTIMPLEMENTED: we probably need to shut this down correctly to avoid |
| 216 // leaking shared memory regions on posix platforms. | 216 // leaking shared memory regions on posix platforms. |
| 217 #if defined(OS_POSIX) | 217 #if defined(OS_POSIX) |
| 218 // Stats table is in the global file descriptors table on Posix. | 218 // Stats table is in the global file descriptors table on Posix. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 | 251 |
| 252 #if !defined(OS_IOS) && !defined(CHROME_MULTIPLE_DLL_BROWSER) | 252 #if !defined(OS_IOS) && !defined(CHROME_MULTIPLE_DLL_BROWSER) |
| 253 if (process_type == switches::kPluginProcess || | 253 if (process_type == switches::kPluginProcess || |
| 254 process_type == switches::kPpapiPluginProcess) { | 254 process_type == switches::kPpapiPluginProcess) { |
| 255 if (delegate) | 255 if (delegate) |
| 256 content_client->plugin_ = delegate->CreateContentPluginClient(); | 256 content_client->plugin_ = delegate->CreateContentPluginClient(); |
| 257 if (!content_client->plugin_) | 257 if (!content_client->plugin_) |
| 258 content_client->plugin_ = &g_empty_content_plugin_client.Get(); | 258 content_client->plugin_ = &g_empty_content_plugin_client.Get(); |
| 259 // Single process not supported in split dll mode. | 259 // Single process not supported in split dll mode. |
| 260 } else if (process_type == switches::kRendererProcess || | 260 } else if (process_type == switches::kRendererProcess || |
| 261 CommandLine::ForCurrentProcess()->HasSwitch( | 261 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 262 switches::kSingleProcess)) { | 262 switches::kSingleProcess)) { |
| 263 if (delegate) | 263 if (delegate) |
| 264 content_client->renderer_ = delegate->CreateContentRendererClient(); | 264 content_client->renderer_ = delegate->CreateContentRendererClient(); |
| 265 if (!content_client->renderer_) | 265 if (!content_client->renderer_) |
| 266 content_client->renderer_ = &g_empty_content_renderer_client.Get(); | 266 content_client->renderer_ = &g_empty_content_renderer_client.Get(); |
| 267 } | 267 } |
| 268 | 268 |
| 269 if (process_type == switches::kUtilityProcess || | 269 if (process_type == switches::kUtilityProcess || |
| 270 CommandLine::ForCurrentProcess()->HasSwitch( | 270 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 271 switches::kSingleProcess)) { | 271 switches::kSingleProcess)) { |
| 272 if (delegate) | 272 if (delegate) |
| 273 content_client->utility_ = delegate->CreateContentUtilityClient(); | 273 content_client->utility_ = delegate->CreateContentUtilityClient(); |
| 274 // TODO(scottmg): http://crbug.com/237249 Should be in _child. | 274 // TODO(scottmg): http://crbug.com/237249 Should be in _child. |
| 275 if (!content_client->utility_) | 275 if (!content_client->utility_) |
| 276 content_client->utility_ = &g_empty_content_utility_client.Get(); | 276 content_client->utility_ = &g_empty_content_utility_client.Get(); |
| 277 } | 277 } |
| 278 #endif // !OS_IOS && !CHROME_MULTIPLE_DLL_BROWSER | 278 #endif // !OS_IOS && !CHROME_MULTIPLE_DLL_BROWSER |
| 279 } | 279 } |
| 280 }; | 280 }; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 } | 313 } |
| 314 | 314 |
| 315 // This function call can return multiple times, once per fork(). | 315 // This function call can return multiple times, once per fork(). |
| 316 if (!ZygoteMain(main_function_params, zygote_fork_delegates.Pass())) | 316 if (!ZygoteMain(main_function_params, zygote_fork_delegates.Pass())) |
| 317 return 1; | 317 return 1; |
| 318 | 318 |
| 319 if (delegate) delegate->ZygoteForked(); | 319 if (delegate) delegate->ZygoteForked(); |
| 320 | 320 |
| 321 // Zygote::HandleForkRequest may have reallocated the command | 321 // Zygote::HandleForkRequest may have reallocated the command |
| 322 // line so update it here with the new version. | 322 // line so update it here with the new version. |
| 323 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 323 const base::CommandLine& command_line = |
| 324 *base::CommandLine::ForCurrentProcess(); |
| 324 std::string process_type = | 325 std::string process_type = |
| 325 command_line.GetSwitchValueASCII(switches::kProcessType); | 326 command_line.GetSwitchValueASCII(switches::kProcessType); |
| 326 ContentClientInitializer::Set(process_type, delegate); | 327 ContentClientInitializer::Set(process_type, delegate); |
| 327 | 328 |
| 328 // The StatsTable must be initialized in each process; we already | 329 // The StatsTable must be initialized in each process; we already |
| 329 // initialized for the browser process, now we need to initialize | 330 // initialized for the browser process, now we need to initialize |
| 330 // within the new processes as well. | 331 // within the new processes as well. |
| 331 InitializeStatsTable(command_line); | 332 InitializeStatsTable(command_line); |
| 332 | 333 |
| 333 MainFunctionParams main_params(command_line); | 334 MainFunctionParams main_params(command_line); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 349 #if !defined(OS_IOS) | 350 #if !defined(OS_IOS) |
| 350 static void RegisterMainThreadFactories() { | 351 static void RegisterMainThreadFactories() { |
| 351 #if !defined(CHROME_MULTIPLE_DLL_BROWSER) | 352 #if !defined(CHROME_MULTIPLE_DLL_BROWSER) |
| 352 UtilityProcessHostImpl::RegisterUtilityMainThreadFactory( | 353 UtilityProcessHostImpl::RegisterUtilityMainThreadFactory( |
| 353 CreateInProcessUtilityThread); | 354 CreateInProcessUtilityThread); |
| 354 RenderProcessHostImpl::RegisterRendererMainThreadFactory( | 355 RenderProcessHostImpl::RegisterRendererMainThreadFactory( |
| 355 CreateInProcessRendererThread); | 356 CreateInProcessRendererThread); |
| 356 GpuProcessHost::RegisterGpuMainThreadFactory( | 357 GpuProcessHost::RegisterGpuMainThreadFactory( |
| 357 CreateInProcessGpuThread); | 358 CreateInProcessGpuThread); |
| 358 #else | 359 #else |
| 359 CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 360 base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); |
| 360 if (command_line.HasSwitch(switches::kSingleProcess)) { | 361 if (command_line.HasSwitch(switches::kSingleProcess)) { |
| 361 LOG(FATAL) << | 362 LOG(FATAL) << |
| 362 "--single-process is not supported in chrome multiple dll browser."; | 363 "--single-process is not supported in chrome multiple dll browser."; |
| 363 } | 364 } |
| 364 if (command_line.HasSwitch(switches::kInProcessGPU)) { | 365 if (command_line.HasSwitch(switches::kInProcessGPU)) { |
| 365 LOG(FATAL) << | 366 LOG(FATAL) << |
| 366 "--in-process-gpu is not supported in chrome multiple dll browser."; | 367 "--in-process-gpu is not supported in chrome multiple dll browser."; |
| 367 } | 368 } |
| 368 #endif | 369 #endif |
| 369 } | 370 } |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 // argc/argv are ignored on Windows and Android; see command_line.h for | 583 // argc/argv are ignored on Windows and Android; see command_line.h for |
| 583 // details. | 584 // details. |
| 584 int argc = 0; | 585 int argc = 0; |
| 585 const char** argv = NULL; | 586 const char** argv = NULL; |
| 586 | 587 |
| 587 #if !defined(OS_WIN) | 588 #if !defined(OS_WIN) |
| 588 argc = params.argc; | 589 argc = params.argc; |
| 589 argv = params.argv; | 590 argv = params.argv; |
| 590 #endif | 591 #endif |
| 591 | 592 |
| 592 CommandLine::Init(argc, argv); | 593 base::CommandLine::Init(argc, argv); |
| 593 | 594 |
| 594 if (!delegate_ || delegate_->ShouldEnableTerminationOnHeapCorruption()) | 595 if (!delegate_ || delegate_->ShouldEnableTerminationOnHeapCorruption()) |
| 595 base::EnableTerminationOnHeapCorruption(); | 596 base::EnableTerminationOnHeapCorruption(); |
| 596 base::EnableTerminationOnOutOfMemory(); | 597 base::EnableTerminationOnOutOfMemory(); |
| 597 | 598 |
| 598 #if !defined(OS_IOS) | 599 #if !defined(OS_IOS) |
| 599 SetProcessTitleFromCommandLine(argv); | 600 SetProcessTitleFromCommandLine(argv); |
| 600 #endif | 601 #endif |
| 601 #endif // !OS_ANDROID | 602 #endif // !OS_ANDROID |
| 602 | 603 |
| 603 int exit_code = 0; | 604 int exit_code = 0; |
| 604 if (delegate_ && delegate_->BasicStartupComplete(&exit_code)) | 605 if (delegate_ && delegate_->BasicStartupComplete(&exit_code)) |
| 605 return exit_code; | 606 return exit_code; |
| 606 | 607 |
| 607 completed_basic_startup_ = true; | 608 completed_basic_startup_ = true; |
| 608 | 609 |
| 609 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 610 const base::CommandLine& command_line = |
| 611 *base::CommandLine::ForCurrentProcess(); |
| 610 std::string process_type = | 612 std::string process_type = |
| 611 command_line.GetSwitchValueASCII(switches::kProcessType); | 613 command_line.GetSwitchValueASCII(switches::kProcessType); |
| 612 | 614 |
| 613 #if !defined(OS_IOS) | 615 #if !defined(OS_IOS) |
| 614 // Initialize mojo here so that services can be registered. | 616 // Initialize mojo here so that services can be registered. |
| 615 InitializeMojo(); | 617 InitializeMojo(); |
| 616 #endif | 618 #endif |
| 617 | 619 |
| 618 if (!GetContentClient()) | 620 if (!GetContentClient()) |
| 619 SetContentClient(&empty_content_client_); | 621 SetContentClient(&empty_content_client_); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 if (delegate_) | 740 if (delegate_) |
| 739 delegate_->SandboxInitialized(process_type); | 741 delegate_->SandboxInitialized(process_type); |
| 740 | 742 |
| 741 // Return -1 to indicate no early termination. | 743 // Return -1 to indicate no early termination. |
| 742 return -1; | 744 return -1; |
| 743 } | 745 } |
| 744 | 746 |
| 745 virtual int Run() OVERRIDE { | 747 virtual int Run() OVERRIDE { |
| 746 DCHECK(is_initialized_); | 748 DCHECK(is_initialized_); |
| 747 DCHECK(!is_shutdown_); | 749 DCHECK(!is_shutdown_); |
| 748 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 750 const base::CommandLine& command_line = |
| 751 *base::CommandLine::ForCurrentProcess(); |
| 749 std::string process_type = | 752 std::string process_type = |
| 750 command_line.GetSwitchValueASCII(switches::kProcessType); | 753 command_line.GetSwitchValueASCII(switches::kProcessType); |
| 751 | 754 |
| 752 MainFunctionParams main_params(command_line); | 755 MainFunctionParams main_params(command_line); |
| 753 main_params.ui_task = ui_task_; | 756 main_params.ui_task = ui_task_; |
| 754 #if defined(OS_WIN) | 757 #if defined(OS_WIN) |
| 755 main_params.sandbox_info = &sandbox_info_; | 758 main_params.sandbox_info = &sandbox_info_; |
| 756 #elif defined(OS_MACOSX) | 759 #elif defined(OS_MACOSX) |
| 757 main_params.autorelease_pool = autorelease_pool_.get(); | 760 main_params.autorelease_pool = autorelease_pool_.get(); |
| 758 #endif | 761 #endif |
| 759 | 762 |
| 760 #if !defined(OS_IOS) | 763 #if !defined(OS_IOS) |
| 761 return RunNamedProcessTypeMain(process_type, main_params, delegate_); | 764 return RunNamedProcessTypeMain(process_type, main_params, delegate_); |
| 762 #else | 765 #else |
| 763 return 1; | 766 return 1; |
| 764 #endif | 767 #endif |
| 765 } | 768 } |
| 766 | 769 |
| 767 virtual void Shutdown() OVERRIDE { | 770 virtual void Shutdown() OVERRIDE { |
| 768 DCHECK(is_initialized_); | 771 DCHECK(is_initialized_); |
| 769 DCHECK(!is_shutdown_); | 772 DCHECK(!is_shutdown_); |
| 770 | 773 |
| 771 if (completed_basic_startup_ && delegate_) { | 774 if (completed_basic_startup_ && delegate_) { |
| 772 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 775 const base::CommandLine& command_line = |
| 776 *base::CommandLine::ForCurrentProcess(); |
| 773 std::string process_type = | 777 std::string process_type = |
| 774 command_line.GetSwitchValueASCII(switches::kProcessType); | 778 command_line.GetSwitchValueASCII(switches::kProcessType); |
| 775 | 779 |
| 776 delegate_->ProcessExiting(process_type); | 780 delegate_->ProcessExiting(process_type); |
| 777 } | 781 } |
| 778 | 782 |
| 779 #if defined(OS_WIN) | 783 #if defined(OS_WIN) |
| 780 #ifdef _CRTDBG_MAP_ALLOC | 784 #ifdef _CRTDBG_MAP_ALLOC |
| 781 _CrtDumpMemoryLeaks(); | 785 _CrtDumpMemoryLeaks(); |
| 782 #endif // _CRTDBG_MAP_ALLOC | 786 #endif // _CRTDBG_MAP_ALLOC |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 819 | 823 |
| 820 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); | 824 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); |
| 821 }; | 825 }; |
| 822 | 826 |
| 823 // static | 827 // static |
| 824 ContentMainRunner* ContentMainRunner::Create() { | 828 ContentMainRunner* ContentMainRunner::Create() { |
| 825 return new ContentMainRunnerImpl(); | 829 return new ContentMainRunnerImpl(); |
| 826 } | 830 } |
| 827 | 831 |
| 828 } // namespace content | 832 } // namespace content |
| OLD | NEW |