This source file includes following definitions.
- HandleRendererErrorTestParameters
- WillProcessTask
- DidProcessTask
- WillProcessTask
- DidProcessTask
- RendererMain
#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/debug/debugger.h"
#include "base/debug/stack_trace.h"
#include "base/debug/trace_event.h"
#include "base/i18n/rtl.h"
#include "base/memory/ref_counted.h"
#include "base/message_loop/message_loop.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/histogram.h"
#include "base/metrics/statistics_recorder.h"
#include "base/metrics/stats_counters.h"
#include "base/path_service.h"
#include "base/pending_task.h"
#include "base/strings/string_util.h"
#include "base/threading/platform_thread.h"
#include "base/time/time.h"
#include "base/timer/hi_res_timer_manager.h"
#include "content/child/child_process.h"
#include "content/child/content_child_helpers.h"
#include "content/common/content_constants_internal.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/main_function_params.h"
#include "content/public/renderer/content_renderer_client.h"
#include "content/renderer/browser_plugin/browser_plugin_manager_impl.h"
#include "content/renderer/pepper/pepper_plugin_registry.h"
#include "content/renderer/render_process_impl.h"
#include "content/renderer/render_thread_impl.h"
#include "content/renderer/renderer_main_platform_delegate.h"
#include "ui/base/ui_base_switches.h"
#if defined(OS_ANDROID)
#include "base/android/sys_utils.h"
#include "third_party/skia/include/core/SkGraphics.h"
#endif
#if defined(OS_MACOSX)
#include <Carbon/Carbon.h>
#include <signal.h>
#include <unistd.h>
#include "base/mac/mac_util.h"
#include "base/mac/scoped_nsautorelease_pool.h"
#include "base/message_loop/message_pump_mac.h"
#include "third_party/WebKit/public/web/WebView.h"
#endif
#if defined(ENABLE_WEBRTC)
#include "third_party/libjingle/overrides/init_webrtc.h"
#endif
namespace content {
namespace {
static void HandleRendererErrorTestParameters(const CommandLine& command_line) {
if (command_line.HasSwitch(switches::kWaitForDebugger))
base::debug::WaitForDebugger(60, true);
if (command_line.HasSwitch(switches::kRendererStartupDialog))
ChildProcess::WaitForDebugger("Renderer");
if (command_line.HasSwitch(switches::kRendererAssertTest)) {
DCHECK(false);
}
}
class RendererMessageLoopObserver : public base::MessageLoop::TaskObserver {
public:
RendererMessageLoopObserver()
: process_times_(base::Histogram::FactoryGet(
"Chrome.ProcMsgL RenderThread",
1, 3600000, 50, base::Histogram::kUmaTargetedHistogramFlag)) {}
virtual ~RendererMessageLoopObserver() {}
virtual void WillProcessTask(const base::PendingTask& pending_task) OVERRIDE {
begin_process_message_ = base::TimeTicks::Now();
}
virtual void DidProcessTask(const base::PendingTask& pending_task) OVERRIDE {
if (!begin_process_message_.is_null())
process_times_->AddTime(base::TimeTicks::Now() - begin_process_message_);
}
private:
base::TimeTicks begin_process_message_;
base::HistogramBase* const process_times_;
DISALLOW_COPY_AND_ASSIGN(RendererMessageLoopObserver);
};
class MemoryObserver : public base::MessageLoop::TaskObserver {
public:
MemoryObserver() {}
virtual ~MemoryObserver() {}
virtual void WillProcessTask(const base::PendingTask& pending_task) OVERRIDE {
}
virtual void DidProcessTask(const base::PendingTask& pending_task) OVERRIDE {
HISTOGRAM_MEMORY_KB("Memory.RendererUsed", GetMemoryUsageKB());
}
private:
DISALLOW_COPY_AND_ASSIGN(MemoryObserver);
};
}
int RendererMain(const MainFunctionParams& parameters) {
TRACE_EVENT_BEGIN_ETW("RendererMain", 0, "");
base::debug::TraceLog::GetInstance()->SetProcessName("Renderer");
base::debug::TraceLog::GetInstance()->SetProcessSortIndex(
kTraceEventRendererProcessSortIndex);
const CommandLine& parsed_command_line = parameters.command_line;
#if defined(OS_MACOSX)
base::mac::ScopedNSAutoreleasePool* pool = parameters.autorelease_pool;
#endif
#if defined(OS_CHROMEOS)
if (parsed_command_line.HasSwitch(switches::kLang)) {
const std::string locale =
parsed_command_line.GetSwitchValueASCII(switches::kLang);
base::i18n::SetICUDefaultLocale(locale);
}
#endif
#if defined(OS_ANDROID)
const int kMB = 1024 * 1024;
size_t font_cache_limit =
base::android::SysUtils::IsLowEndDevice() ? kMB : 8 * kMB;
SkGraphics::SetFontCacheLimit(font_cache_limit);
#endif
HandleRendererErrorTestParameters(parsed_command_line);
RendererMainPlatformDelegate platform(parameters);
base::StatsCounterTimer stats_counter_timer("Content.RendererInit");
base::StatsScope<base::StatsCounterTimer> startup_timer(stats_counter_timer);
RendererMessageLoopObserver task_observer;
#if defined(OS_MACOSX)
scoped_ptr<base::MessagePump> pump(new base::MessagePumpNSRunLoop());
base::MessageLoop main_message_loop(pump.Pass());
#else
base::MessageLoop main_message_loop;
#endif
main_message_loop.AddTaskObserver(&task_observer);
scoped_ptr<MemoryObserver> memory_observer;
if (parsed_command_line.HasSwitch(switches::kMemoryMetrics)) {
memory_observer.reset(new MemoryObserver());
main_message_loop.AddTaskObserver(memory_observer.get());
}
base::PlatformThread::SetName("CrRendererMain");
platform.PlatformInitialize();
bool no_sandbox = parsed_command_line.HasSwitch(switches::kNoSandbox);
platform.InitSandboxTests(no_sandbox);
base::StatisticsRecorder::Initialize();
base::FieldTrialList field_trial_list(NULL);
if (parsed_command_line.HasSwitch(switches::kForceFieldTrials)) {
bool result = base::FieldTrialList::CreateTrialsFromString(
parsed_command_line.GetSwitchValueASCII(switches::kForceFieldTrials),
base::FieldTrialList::ACTIVATE_TRIALS,
std::set<std::string>());
DCHECK(result);
}
#if defined(ENABLE_PLUGINS)
PepperPluginRegistry::GetInstance();
#endif
#if defined(ENABLE_WEBRTC)
InitializeWebRtcModule();
#endif
{
#if defined(OS_WIN) || defined(OS_MACOSX)
RenderProcessImpl render_process;
new RenderThreadImpl();
#endif
bool run_loop = true;
if (!no_sandbox) {
run_loop = platform.EnableSandbox();
} else {
LOG(ERROR) << "Running without renderer sandbox";
#ifndef NDEBUG
base::debug::EnableInProcessStackDumping();
#endif
}
#if defined(OS_POSIX) && !defined(OS_MACOSX)
RenderProcessImpl render_process;
new RenderThreadImpl();
#endif
base::HighResolutionTimerManager hi_res_timer_manager;
platform.RunSandboxTests(no_sandbox);
startup_timer.Stop();
if (run_loop) {
#if defined(OS_MACOSX)
if (pool)
pool->Recycle();
#endif
TRACE_EVENT_BEGIN_ETW("RendererMain.START_MSG_LOOP", 0, 0);
base::MessageLoop::current()->Run();
TRACE_EVENT_END_ETW("RendererMain.START_MSG_LOOP", 0, 0);
}
}
platform.PlatformUninitialize();
TRACE_EVENT_END_ETW("RendererMain", 0, "");
return 0;
}
}