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

Unified Diff: content/browser/renderer_host/render_process_host_impl.cc

Issue 236813002: Move Mojo channel initialization closer to IPC::Channel setup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/render_process_host_impl.cc
diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc
index a1fb9f888cb71d3ae2f3d4634843fc2a2ac517bf..9474f58ce481045ba62b5dc54744d442218da73d 100644
--- a/content/browser/renderer_host/render_process_host_impl.cc
+++ b/content/browser/renderer_host/render_process_host_impl.cc
@@ -87,7 +87,6 @@
#include "content/browser/renderer_host/pepper/pepper_message_filter.h"
#include "content/browser/renderer_host/pepper/pepper_renderer_connection.h"
#include "content/browser/renderer_host/render_message_filter.h"
-#include "content/browser/renderer_host/render_process_host_mojo_impl.h"
#include "content/browser/renderer_host/render_view_host_delegate.h"
#include "content/browser/renderer_host/render_view_host_impl.h"
#include "content/browser/renderer_host/render_widget_helper.h"
@@ -113,6 +112,8 @@
#include "content/common/child_process_messages.h"
#include "content/common/content_switches_internal.h"
#include "content/common/gpu/gpu_messages.h"
+#include "content/common/mojo/mojo_channel_init.h"
+#include "content/common/mojo/mojo_messages.h"
#include "content/common/resource_messages.h"
#include "content/common/view_messages.h"
#include "content/port/browser/render_widget_host_view_frame_subscriber.h"
@@ -138,6 +139,7 @@
#include "ipc/ipc_logging.h"
#include "ipc/ipc_switches.h"
#include "media/base/media_switches.h"
+#include "mojo/embedder/platform_channel_pair.h"
#include "net/url_request/url_request_context_getter.h"
#include "ppapi/shared_impl/ppapi_switches.h"
#include "third_party/skia/include/core/SkBitmap.h"
@@ -169,6 +171,15 @@ static const char* kSiteProcessMapKeyName = "content_site_process_map";
namespace content {
namespace {
+base::PlatformFile PlatformFileFromScopedPlatformHandle(
+ mojo::embedder::ScopedPlatformHandle handle) {
+#if defined(OS_POSIX)
+ return handle.release().fd;
+#elif defined(OS_WIN)
+ return handle.release().handle;
+#endif
+}
+
void CacheShaderInfo(int32 id, base::FilePath path) {
ShaderCacheFactory::GetInstance()->SetCacheInfo(id, path);
}
@@ -548,6 +559,7 @@ bool RenderProcessHostImpl::Init() {
this,
BrowserThread::GetMessageLoopProxyForThread(
BrowserThread::IO).get()));
+ InitializeMojo();
// Call the embedder first so that their IPC filters have priority.
GetContentClient()->browser()->RenderProcessWillLaunch(this);
@@ -608,6 +620,31 @@ bool RenderProcessHostImpl::Init() {
return true;
}
+void RenderProcessHostImpl::InitializeMojo() {
+ mojo::embedder::PlatformChannelPair channel_pair;
+ mojo_channel_init_.reset(new MojoChannelInit);
+
+ mojo::ScopedMessagePipeHandle message_pipe = mojo_channel_init_->Init(
+ PlatformFileFromScopedPlatformHandle(channel_pair.PassServerHandle()),
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
+ DCHECK(message_pipe.is_valid());
+
+ // The render_process_ is ready to use at this point, but all calls will be
+ // queued until the client-side is connected. See ActivateMojo.
+ render_process_.reset(
+ ScopedIRenderProcessHandle::From(message_pipe.Pass()), this);
+
+ // Forward this to the client once we know its process handle.
+ mojo_client_handle_ = channel_pair.PassClientHandle();
+}
+
+void RenderProcessHostImpl::ActivateMojo() {
+ base::PlatformFile client_file =
+ PlatformFileFromScopedPlatformHandle(mojo_client_handle_.Pass());
+ Send(new MojoMsg_Activate(
+ IPC::GetFileHandleForProcess(client_file, GetHandle(), true)));
+}
+
void RenderProcessHostImpl::CreateMessageFilters() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
AddFilter(new ResourceSchedulerFilter(GetID()));
@@ -1917,7 +1954,8 @@ void RenderProcessHostImpl::ProcessDied(bool already_dead) {
ClearTransportDIBCache();
- render_process_host_mojo_.reset();
+ render_process_.reset();
+ mojo_channel_init_.reset();
// It's possible that one of the calls out to the observers might have caused
// this object to be no longer needed.
@@ -2052,6 +2090,10 @@ void RenderProcessHostImpl::OnProcessLaunched() {
Source<RenderProcessHost>(this),
NotificationService::NoDetails());
+ // Let the Mojo system get setup on the child process side before any other
+ // IPCs arrive. This way those may safely generate Mojo-related RPCs.
+ ActivateMojo();
+
while (!queued_messages_.empty()) {
Send(queued_messages_.front());
queued_messages_.pop();
@@ -2061,9 +2103,6 @@ void RenderProcessHostImpl::OnProcessLaunched() {
if (WebRTCInternals::GetInstance()->aec_dump_enabled())
EnableAecDump(WebRTCInternals::GetInstance()->aec_dump_file_path());
#endif
-
- if (render_process_host_mojo_.get())
- render_process_host_mojo_->OnProcessLaunched();
}
scoped_refptr<AudioRendererHost>
@@ -2140,9 +2179,8 @@ void RenderProcessHostImpl::DecrementWorkerRefCount() {
void RenderProcessHostImpl::SetWebUIHandle(
int32 view_routing_id,
mojo::ScopedMessagePipeHandle handle) {
- if (!render_process_host_mojo_)
- render_process_host_mojo_.reset(new RenderProcessHostMojoImpl(this));
- render_process_host_mojo_->SetWebUIHandle(view_routing_id, handle.Pass());
+ DCHECK(!render_process_.is_null());
+ render_process_->SetWebUIHandle(view_routing_id, handle.Pass());
}
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698