Commit d0a6a8a1 authored by morrita's avatar morrita Committed by Commit bot

Revert "Always activate MojoApplicationHost"

This reverts commit bd0aa4dc.

TBR=darin@chromium.org
BUG=415059

Review URL: https://codereview.chromium.org/584173002

Cr-Commit-Position: refs/heads/master@{#295799}
parent 59126a3c
......@@ -287,6 +287,7 @@ RenderViewHost* RenderFrameHostImpl::GetRenderViewHost() {
}
ServiceRegistry* RenderFrameHostImpl::GetServiceRegistry() {
static_cast<RenderProcessHostImpl*>(GetProcess())->EnsureMojoActivated();
return &service_registry_;
}
......
......@@ -47,7 +47,7 @@ bool MojoApplicationHost::Init() {
return true;
}
void MojoApplicationHost::Activate(IPC::Sender* sender,
bool MojoApplicationHost::Activate(IPC::Sender* sender,
base::ProcessHandle process_handle) {
DCHECK(!did_activate_);
DCHECK(client_handle_.is_valid());
......@@ -56,6 +56,7 @@ void MojoApplicationHost::Activate(IPC::Sender* sender,
PlatformFileFromScopedPlatformHandle(client_handle_.Pass());
did_activate_ = sender->Send(new MojoMsg_Activate(
IPC::GetFileHandleForProcess(client_file, process_handle, true)));
return did_activate_;
}
void MojoApplicationHost::WillDestroySoon() {
......
......@@ -30,10 +30,12 @@ class MojoApplicationHost {
// 1- Init makes service_registry() available synchronously.
// 2- Activate establishes the actual connection to the peer process.
bool Init();
void Activate(IPC::Sender* sender, base::ProcessHandle process_handle);
bool Activate(IPC::Sender* sender, base::ProcessHandle process_handle);
void WillDestroySoon();
bool did_activate() const { return did_activate_; }
ServiceRegistry* service_registry() { return &service_registry_; }
private:
......
......@@ -437,6 +437,7 @@ RenderProcessHostImpl::RenderProcessHostImpl(
#endif
pending_views_(0),
mojo_application_host_(new MojoApplicationHost),
mojo_activation_required_(false),
visible_widgets_(0),
backgrounded_(true),
is_initialized_(false),
......@@ -641,6 +642,20 @@ bool RenderProcessHostImpl::Init() {
return true;
}
void RenderProcessHostImpl::MaybeActivateMojo() {
// TODO(darin): Following security review, we can unconditionally initialize
// Mojo in all renderers. We will then be able to directly call Activate()
// from OnProcessLaunched.
if (!mojo_activation_required_)
return; // Waiting on someone to require Mojo.
if (!GetHandle())
return; // Waiting on renderer startup.
if (!mojo_application_host_->did_activate())
mojo_application_host_->Activate(this, GetHandle());
}
bool RenderProcessHostImpl::ShouldUseMojoChannel() const {
const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();
......@@ -1911,6 +1926,7 @@ void RenderProcessHostImpl::ProcessDied(bool already_dead) {
}
mojo_application_host_.reset(new MojoApplicationHost);
mojo_activation_required_ = false;
// It's possible that one of the calls out to the observers might have caused
// this object to be no longer needed.
......@@ -2077,7 +2093,7 @@ void RenderProcessHostImpl::OnProcessLaunched() {
// Allow Mojo to be setup before the renderer sees any Chrome IPC messages.
// This way, Mojo can be safely used from the renderer in response to any
// Chrome IPC message.
mojo_application_host_->Activate(this, GetHandle());
MaybeActivateMojo();
while (!queued_messages_.empty()) {
Send(queued_messages_.front());
......@@ -2218,4 +2234,9 @@ void RenderProcessHostImpl::DecrementWorkerRefCount() {
Cleanup();
}
void RenderProcessHostImpl::EnsureMojoActivated() {
mojo_activation_required_ = true;
MaybeActivateMojo();
}
} // namespace content
......@@ -252,6 +252,9 @@ class CONTENT_EXPORT RenderProcessHostImpl
// immediately after receiving response headers.
void ResumeResponseDeferredAtStart(const GlobalRequestID& request_id);
// Activates Mojo for this process. Does nothing if Mojo is already activated.
void EnsureMojoActivated();
protected:
// A proxy for our IPC::Channel that lives on the IO thread (see
// browser_process.h)
......@@ -276,6 +279,7 @@ class CONTENT_EXPORT RenderProcessHostImpl
private:
friend class VisitRelayingRenderProcessHost;
void MaybeActivateMojo();
bool ShouldUseMojoChannel() const;
scoped_ptr<IPC::ChannelProxy> CreateChannelProxy(
const std::string& channel_id);
......@@ -323,6 +327,7 @@ class CONTENT_EXPORT RenderProcessHostImpl
#endif
scoped_ptr<MojoApplicationHost> mojo_application_host_;
bool mojo_activation_required_;
// The registered IPC listener objects. When this list is empty, we should
// delete ourselves.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment