From f967b723292a0988bb3789094d5e1641caa0c2f8 Mon Sep 17 00:00:00 2001 From: "jam@chromium.org" Date: Wed, 7 Sep 2011 00:58:04 +0000 Subject: Start moving code from BrowserMain to content, so that it can be reused by all embedders of content. I've based the refactoring on the existing BrowserMainParts. This is the first step; I didn't want to do it all at the same time because it would be too big. Remaining tasks:-rename the browser_main files in chrome to chrome_browser_main-move the OS specific implementations of BrowserMainParts that are needed for content-finish splitting the remaining BrowserMain function (now that's in TemporaryContinue())BUG=90445 Review URL: http://codereview.chromium.org/7779040 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@99884 0039d316-1c4b-4281-b951-d872f2087c98 --- content/app/content_main.cc | 52 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'content/app') diff --git a/content/app/content_main.cc b/content/app/content_main.cc index 971766d..eacb2bd 100644 --- a/content/app/content_main.cc +++ b/content/app/content_main.cc @@ -12,15 +12,19 @@ #include "base/logging.h" #include "base/mac/scoped_nsautorelease_pool.h" #include "base/memory/scoped_ptr.h" +#include "base/metrics/stats_table.h" #include "base/process_util.h" #include "base/stringprintf.h" +#include "base/string_number_conversions.h" #include "content/app/content_main_delegate.h" +#include "content/common/content_constants.h" #include "content/common/content_paths.h" #include "content/common/content_switches.h" #include "content/common/main_function_params.h" #include "content/common/sandbox_init_wrapper.h" #include "content/common/set_process_title.h" #include "crypto/nss_util.h" +#include "ipc/ipc_switches.h" #include "ui/base/ui_base_switches.h" #include "ui/base/ui_base_paths.h" @@ -53,6 +57,7 @@ int tc_set_new_mode(int mode); } #endif +extern int BrowserMain(const MainFunctionParams&); extern int RendererMain(const MainFunctionParams&); extern int GpuMain(const MainFunctionParams&); extern int PluginMain(const MainFunctionParams&); @@ -184,6 +189,27 @@ void CommonSubprocessInit(const std::string& process_type) { #endif } +void InitializeStatsTable(base::ProcessId browser_pid, + const CommandLine& command_line) { + // Initialize the Stats Counters table. With this initialized, + // the StatsViewer can be utilized to read counters outside of + // Chrome. These lines can be commented out to effectively turn + // counters 'off'. The table is created and exists for the life + // of the process. It is not cleaned up. + if (command_line.HasSwitch(switches::kEnableStatsTable) || + command_line.HasSwitch(switches::kEnableBenchmarking)) { + // NOTIMPLEMENTED: we probably need to shut this down correctly to avoid + // leaking shared memory regions on posix platforms. + std::string statsfile = + base::StringPrintf("%s-%u", + content::kStatsFilename, + static_cast(browser_pid)); + base::StatsTable* stats_table = new base::StatsTable(statsfile, + content::kStatsMaxThreads, content::kStatsMaxCounters); + base::StatsTable::set_current(stats_table); + } +} + // We dispatch to a process-type-specific FooMain() based on a command-line // flag. This struct is used to build a table of (flag, main function) pairs. struct MainFunction { @@ -217,6 +243,13 @@ int RunZygote(const MainFunctionParams& main_function_params, // line so update it here with the new version. const CommandLine& command_line = *CommandLine::ForCurrentProcess(); + // The StatsTable must be initialized in each process; we already + // initialized for the browser process, now we need to initialize + // within the new processes as well. + pid_t browser_pid = base::GetParentProcessId( + base::GetParentProcessId(base::GetCurrentProcId())); + InitializeStatsTable(browser_pid, command_line); + MainFunctionParams main_params(command_line, main_function_params.sandbox_info_, main_function_params.autorelease_pool_); @@ -244,6 +277,7 @@ int RunNamedProcessTypeMain(const std::string& process_type, const MainFunctionParams& main_function_params, content::ContentMainDelegate* delegate) { static const MainFunction kMainFunctions[] = { + { "", BrowserMain }, { switches::kRendererProcess, RendererMain }, { switches::kPluginProcess, PluginMain }, { switches::kWorkerProcess, WorkerMain }, @@ -389,6 +423,24 @@ int ContentMain(int argc, CHECK(icu_util::Initialize()); + base::ProcessId browser_pid = base::GetCurrentProcId(); + if (command_line.HasSwitch(switches::kProcessChannelID)) { +#if defined(OS_WIN) || defined(OS_MACOSX) + std::string channel_name = + command_line.GetSwitchValueASCII(switches::kProcessChannelID); + + int browser_pid_int; + base::StringToInt(channel_name, &browser_pid_int); + browser_pid = static_cast(browser_pid_int); + DCHECK_NE(browser_pid_int, 0); +#elif defined(OS_POSIX) + // On linux, we're in the zygote here; so we need the parent process' id. + browser_pid = base::GetParentProcessId(base::GetCurrentProcId()); +#endif + } + + InitializeStatsTable(browser_pid, command_line); + if (delegate) delegate->PreSandboxStartup(); if (!process_type.empty()) -- cgit v1.1