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() { ...@@ -287,6 +287,7 @@ RenderViewHost* RenderFrameHostImpl::GetRenderViewHost() {
} }
ServiceRegistry* RenderFrameHostImpl::GetServiceRegistry() { ServiceRegistry* RenderFrameHostImpl::GetServiceRegistry() {
static_cast<RenderProcessHostImpl*>(GetProcess())->EnsureMojoActivated();
return &service_registry_; return &service_registry_;
} }
......
...@@ -47,7 +47,7 @@ bool MojoApplicationHost::Init() { ...@@ -47,7 +47,7 @@ bool MojoApplicationHost::Init() {
return true; return true;
} }
void MojoApplicationHost::Activate(IPC::Sender* sender, bool MojoApplicationHost::Activate(IPC::Sender* sender,
base::ProcessHandle process_handle) { base::ProcessHandle process_handle) {
DCHECK(!did_activate_); DCHECK(!did_activate_);
DCHECK(client_handle_.is_valid()); DCHECK(client_handle_.is_valid());
...@@ -56,6 +56,7 @@ void MojoApplicationHost::Activate(IPC::Sender* sender, ...@@ -56,6 +56,7 @@ void MojoApplicationHost::Activate(IPC::Sender* sender,
PlatformFileFromScopedPlatformHandle(client_handle_.Pass()); PlatformFileFromScopedPlatformHandle(client_handle_.Pass());
did_activate_ = sender->Send(new MojoMsg_Activate( did_activate_ = sender->Send(new MojoMsg_Activate(
IPC::GetFileHandleForProcess(client_file, process_handle, true))); IPC::GetFileHandleForProcess(client_file, process_handle, true)));
return did_activate_;
} }
void MojoApplicationHost::WillDestroySoon() { void MojoApplicationHost::WillDestroySoon() {
......
...@@ -30,10 +30,12 @@ class MojoApplicationHost { ...@@ -30,10 +30,12 @@ class MojoApplicationHost {
// 1- Init makes service_registry() available synchronously. // 1- Init makes service_registry() available synchronously.
// 2- Activate establishes the actual connection to the peer process. // 2- Activate establishes the actual connection to the peer process.
bool Init(); bool Init();
void Activate(IPC::Sender* sender, base::ProcessHandle process_handle); bool Activate(IPC::Sender* sender, base::ProcessHandle process_handle);
void WillDestroySoon(); void WillDestroySoon();
bool did_activate() const { return did_activate_; }
ServiceRegistry* service_registry() { return &service_registry_; } ServiceRegistry* service_registry() { return &service_registry_; }
private: private:
......
...@@ -437,6 +437,7 @@ RenderProcessHostImpl::RenderProcessHostImpl( ...@@ -437,6 +437,7 @@ RenderProcessHostImpl::RenderProcessHostImpl(
#endif #endif
pending_views_(0), pending_views_(0),
mojo_application_host_(new MojoApplicationHost), mojo_application_host_(new MojoApplicationHost),
mojo_activation_required_(false),
visible_widgets_(0), visible_widgets_(0),
backgrounded_(true), backgrounded_(true),
is_initialized_(false), is_initialized_(false),
...@@ -641,6 +642,20 @@ bool RenderProcessHostImpl::Init() { ...@@ -641,6 +642,20 @@ bool RenderProcessHostImpl::Init() {
return true; 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 { bool RenderProcessHostImpl::ShouldUseMojoChannel() const {
const base::CommandLine& command_line = const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess(); *base::CommandLine::ForCurrentProcess();
...@@ -1911,6 +1926,7 @@ void RenderProcessHostImpl::ProcessDied(bool already_dead) { ...@@ -1911,6 +1926,7 @@ void RenderProcessHostImpl::ProcessDied(bool already_dead) {
} }
mojo_application_host_.reset(new MojoApplicationHost); 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 // It's possible that one of the calls out to the observers might have caused
// this object to be no longer needed. // this object to be no longer needed.
...@@ -2077,7 +2093,7 @@ void RenderProcessHostImpl::OnProcessLaunched() { ...@@ -2077,7 +2093,7 @@ void RenderProcessHostImpl::OnProcessLaunched() {
// Allow Mojo to be setup before the renderer sees any Chrome IPC messages. // 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 // This way, Mojo can be safely used from the renderer in response to any
// Chrome IPC message. // Chrome IPC message.
mojo_application_host_->Activate(this, GetHandle()); MaybeActivateMojo();
while (!queued_messages_.empty()) { while (!queued_messages_.empty()) {
Send(queued_messages_.front()); Send(queued_messages_.front());
...@@ -2218,4 +2234,9 @@ void RenderProcessHostImpl::DecrementWorkerRefCount() { ...@@ -2218,4 +2234,9 @@ void RenderProcessHostImpl::DecrementWorkerRefCount() {
Cleanup(); Cleanup();
} }
void RenderProcessHostImpl::EnsureMojoActivated() {
mojo_activation_required_ = true;
MaybeActivateMojo();
}
} // namespace content } // namespace content
...@@ -252,6 +252,9 @@ class CONTENT_EXPORT RenderProcessHostImpl ...@@ -252,6 +252,9 @@ class CONTENT_EXPORT RenderProcessHostImpl
// immediately after receiving response headers. // immediately after receiving response headers.
void ResumeResponseDeferredAtStart(const GlobalRequestID& request_id); void ResumeResponseDeferredAtStart(const GlobalRequestID& request_id);
// Activates Mojo for this process. Does nothing if Mojo is already activated.
void EnsureMojoActivated();
protected: protected:
// A proxy for our IPC::Channel that lives on the IO thread (see // A proxy for our IPC::Channel that lives on the IO thread (see
// browser_process.h) // browser_process.h)
...@@ -276,6 +279,7 @@ class CONTENT_EXPORT RenderProcessHostImpl ...@@ -276,6 +279,7 @@ class CONTENT_EXPORT RenderProcessHostImpl
private: private:
friend class VisitRelayingRenderProcessHost; friend class VisitRelayingRenderProcessHost;
void MaybeActivateMojo();
bool ShouldUseMojoChannel() const; bool ShouldUseMojoChannel() const;
scoped_ptr<IPC::ChannelProxy> CreateChannelProxy( scoped_ptr<IPC::ChannelProxy> CreateChannelProxy(
const std::string& channel_id); const std::string& channel_id);
...@@ -323,6 +327,7 @@ class CONTENT_EXPORT RenderProcessHostImpl ...@@ -323,6 +327,7 @@ class CONTENT_EXPORT RenderProcessHostImpl
#endif #endif
scoped_ptr<MojoApplicationHost> mojo_application_host_; scoped_ptr<MojoApplicationHost> mojo_application_host_;
bool mojo_activation_required_;
// The registered IPC listener objects. When this list is empty, we should // The registered IPC listener objects. When this list is empty, we should
// delete ourselves. // 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