summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/render_process.cc
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-21 08:05:28 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-21 08:05:28 +0000
commit8930d471c128ed74b11beaa78ea1b171c1ac7157 (patch)
tree5a20cb03c8e5019385709bc069e67f03488c41a1 /chrome/renderer/render_process.cc
parenta41fae8db8109bfeed047015b77b0d9227118540 (diff)
downloadchromium_src-8930d471c128ed74b11beaa78ea1b171c1ac7157.zip
chromium_src-8930d471c128ed74b11beaa78ea1b171c1ac7157.tar.gz
chromium_src-8930d471c128ed74b11beaa78ea1b171c1ac7157.tar.bz2
Refactor code from RenderThread and PluginThread and move it to ChildThread. ChildProcess now owns the ChildThread, which removes duplicate code and simplifies things.
Clean up ChildProcess, there really was no need for all the templates and statics in it and its subclasses. Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=10080 Review URL: http://codereview.chromium.org/21502 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10144 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/render_process.cc')
-rw-r--r--chrome/renderer/render_process.cc80
1 files changed, 38 insertions, 42 deletions
diff --git a/chrome/renderer/render_process.cc b/chrome/renderer/render_process.cc
index 198f854f..8cec986 100644
--- a/chrome/renderer/render_process.cc
+++ b/chrome/renderer/render_process.cc
@@ -29,34 +29,50 @@
#include "chrome/renderer/render_view.h"
#include "webkit/glue/webkit_glue.h"
-//-----------------------------------------------------------------------------
-bool RenderProcess::load_plugins_in_process_ = false;
-
-//-----------------------------------------------------------------------------
+RenderProcess::RenderProcess()
+ : ChildProcess(new RenderThread()),
+ ALLOW_THIS_IN_INITIALIZER_LIST(shared_mem_cache_cleaner_(
+ base::TimeDelta::FromSeconds(5),
+ this, &RenderProcess::ClearTransportDIBCache)),
+ sequence_number_(0) {
+ Init();
+}
RenderProcess::RenderProcess(const std::wstring& channel_name)
- : render_thread_(channel_name),
+ : ChildProcess(new RenderThread(channel_name)),
ALLOW_THIS_IN_INITIALIZER_LIST(shared_mem_cache_cleaner_(
base::TimeDelta::FromSeconds(5),
this, &RenderProcess::ClearTransportDIBCache)),
sequence_number_(0) {
- for (size_t i = 0; i < arraysize(shared_mem_cache_); ++i)
- shared_mem_cache_[i] = NULL;
+ Init();
}
RenderProcess::~RenderProcess() {
+ // TODO(port)
+ // Try and limit what we pull in for our non-Win unit test bundle
+#ifndef NDEBUG
+ // log important leaked objects
+ webkit_glue::CheckForLeaks();
+#endif
+
+ GetShutDownEvent()->Signal();
+
// We need to stop the RenderThread as the clearer_factory_
// member could be in use while the object itself is destroyed,
// as a result of the containing RenderProcess object being destroyed.
// This race condition causes a crash when the renderer process is shutting
// down.
- render_thread_.Stop();
+ child_thread()->Stop();
ClearTransportDIBCache();
}
-// static
-bool RenderProcess::GlobalInit(const std::wstring &channel_name) {
+void RenderProcess::Init() {
+ in_process_plugins_ = InProcessPlugins();
+ in_process_gears_ = false;
+ for (size_t i = 0; i < arraysize(shared_mem_cache_); ++i)
+ shared_mem_cache_[i] = NULL;
+
#if defined(OS_WIN)
// HACK: See http://b/issue?id=1024307 for rationale.
if (GetModuleHandle(L"LPK.DLL") == NULL) {
@@ -84,10 +100,6 @@ bool RenderProcess::GlobalInit(const std::wstring &channel_name) {
webkit_glue::SetRecordPlaybackMode(true);
}
- if (command_line.HasSwitch(switches::kInProcessPlugins) ||
- command_line.HasSwitch(switches::kSingleProcess))
- load_plugins_in_process_ = true;
-
if (command_line.HasSwitch(switches::kEnableWatchdog)) {
// TODO(JAR): Need to implement renderer IO msgloop watchdog.
}
@@ -98,6 +110,7 @@ bool RenderProcess::GlobalInit(const std::wstring &channel_name) {
if (command_line.HasSwitch(switches::kGearsInRenderer)) {
#if defined(OS_WIN)
+ in_process_gears_ = true;
// Load gears.dll on startup so we can access it before the sandbox
// blocks us.
std::wstring path;
@@ -113,19 +126,12 @@ bool RenderProcess::GlobalInit(const std::wstring &channel_name) {
// TODO(scherkus): check for any DLL dependencies.
webkit_glue::SetMediaPlayerAvailable(true);
}
-
- ChildProcessFactory<RenderProcess> factory;
- return ChildProcess::GlobalInit(channel_name, &factory);
-}
-
-// static
-void RenderProcess::GlobalCleanup() {
- ChildProcess::GlobalCleanup();
}
-// static
-bool RenderProcess::ShouldLoadPluginsInProcess() {
- return load_plugins_in_process_;
+bool RenderProcess::InProcessPlugins() {
+ const CommandLine& command_line = *CommandLine::ForCurrentProcess();
+ return command_line.HasSwitch(switches::kInProcessPlugins) ||
+ command_line.HasSwitch(switches::kSingleProcess);
}
// -----------------------------------------------------------------------------
@@ -155,7 +161,7 @@ TransportDIB* RenderProcess::CreateTransportDIB(size_t size) {
// get one.
IPC::Maybe<TransportDIB::Handle> mhandle;
IPC::Message* msg = new ViewHostMsg_AllocTransportDIB(size, &mhandle);
- if (!render_thread_.Send(msg))
+ if (!child_thread()->Send(msg))
return NULL;
if (!mhandle.valid)
return NULL;
@@ -171,7 +177,7 @@ void RenderProcess::FreeTransportDIB(TransportDIB* dib) {
// On Mac we need to tell the browser that it can drop a reference to the
// shared memory.
IPC::Message* msg = new ViewHostMsg_FreeTransportDIB(dib->id());
- render_thread_.Send(msg);
+ child_thread()->Send(msg);
#endif
delete dib;
@@ -180,14 +186,13 @@ void RenderProcess::FreeTransportDIB(TransportDIB* dib) {
// -----------------------------------------------------------------------------
-// static
skia::PlatformCanvas* RenderProcess::GetDrawingCanvas(
TransportDIB** memory, const gfx::Rect& rect) {
const size_t stride = skia::PlatformCanvas::StrideForWidth(rect.width());
const size_t size = stride * rect.height();
- if (!self()->GetTransportDIBFromCache(memory, size)) {
- *memory = self()->CreateTransportDIB(size);
+ if (!GetTransportDIBFromCache(memory, size)) {
+ *memory = CreateTransportDIB(size);
if (!*memory)
return false;
}
@@ -195,14 +200,13 @@ skia::PlatformCanvas* RenderProcess::GetDrawingCanvas(
return CanvasFromTransportDIB(*memory, rect);
}
-// static
void RenderProcess::ReleaseTransportDIB(TransportDIB* mem) {
- if (self()->PutSharedMemInCache(mem)) {
- self()->shared_mem_cache_cleaner_.Reset();
+ if (PutSharedMemInCache(mem)) {
+ shared_mem_cache_cleaner_.Reset();
return;
}
- self()->FreeTransportDIB(mem);
+ FreeTransportDIB(mem);
}
bool RenderProcess::GetTransportDIBFromCache(TransportDIB** mem,
@@ -266,11 +270,3 @@ void RenderProcess::ClearTransportDIBCache() {
}
}
-void RenderProcess::Cleanup() {
- // TODO(port)
- // Try and limit what we pull in for our non-Win unit test bundle
-#ifndef NDEBUG
- // log important leaked objects
- webkit_glue::CheckForLeaks();
-#endif
-}