forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move Mojo channel initialization closer to IPC::Channel setup
This CL introduces two new content classes: - MojoApplicationHost encapsulates what's needed to host a Mojo App using Chrome IPC to bootstrap. - MojoApplication represents what's needed to be a Mojo App using Chrome IPC to bootstrap. The RenderProcess and RenderProcessHost interfaces are replaced with WebUISetup and WebUISetupClient interfaces. This way the interface is more specific to the service of setting up WebUI. WebUISetupClient is empty and uninteresting. RenderProcessHostImpl no longer deals with WebUI setup. That is all done directly by RenderViewHostImpl by talking to the WebUISetup service. Service names get defined in content/common/mojo/mojo_service_names.{h,cc}. TBR=sky@chromium.org, tsepez@chromium.org Originally reviewed at https://codereview.chromium.org/236813002/ Review URL: https://codereview.chromium.org/256403004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@265962 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
darin@chromium.org
committed
Apr 24, 2014
1 parent
c0b5b76
commit f68c146
Showing
41 changed files
with
487 additions
and
371 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "content/browser/mojo/mojo_application_host.h" | ||
|
||
#include "content/common/mojo/mojo_messages.h" | ||
#include "content/public/browser/browser_thread.h" | ||
#include "ipc/ipc_sender.h" | ||
#include "mojo/embedder/platform_channel_pair.h" | ||
|
||
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 | ||
} | ||
|
||
} // namespace | ||
|
||
MojoApplicationHost::MojoApplicationHost() : did_activate_(false) { | ||
} | ||
|
||
MojoApplicationHost::~MojoApplicationHost() { | ||
} | ||
|
||
bool MojoApplicationHost::Init() { | ||
DCHECK(shell_client_.is_null()) << "Already initialized!"; | ||
|
||
mojo::embedder::PlatformChannelPair channel_pair; | ||
|
||
mojo::ScopedMessagePipeHandle message_pipe = channel_init_.Init( | ||
PlatformFileFromScopedPlatformHandle(channel_pair.PassServerHandle()), | ||
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); | ||
if (!message_pipe.is_valid()) | ||
return false; | ||
|
||
// Forward this to the client once we know its process handle. | ||
client_handle_ = channel_pair.PassClientHandle(); | ||
|
||
// TODO(darin): Provide a Shell implementation | ||
shell_client_.reset( | ||
mojo::ScopedShellClientHandle::From(message_pipe.Pass()), NULL); | ||
|
||
return true; | ||
} | ||
|
||
bool MojoApplicationHost::Activate(IPC::Sender* sender, | ||
base::ProcessHandle process_handle) { | ||
DCHECK(!did_activate_); | ||
DCHECK(client_handle_.is_valid()); | ||
|
||
base::PlatformFile client_file = | ||
PlatformFileFromScopedPlatformHandle(client_handle_.Pass()); | ||
did_activate_ = sender->Send(new MojoMsg_Activate( | ||
IPC::GetFileHandleForProcess(client_file, process_handle, true))); | ||
return did_activate_; | ||
} | ||
|
||
} // namespace content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CONTENT_BROWSER_MOJO_MOJO_APPLICATION_HOST_H_ | ||
#define CONTENT_BROWSER_MOJO_MOJO_APPLICATION_HOST_H_ | ||
|
||
#include "base/process/process_handle.h" | ||
#include "mojo/common/channel_init.h" | ||
#include "mojo/embedder/scoped_platform_handle.h" | ||
#include "mojo/public/cpp/bindings/remote_ptr.h" | ||
#include "mojo/public/interfaces/shell/shell.mojom.h" | ||
|
||
namespace IPC { | ||
class Sender; | ||
} | ||
|
||
namespace content { | ||
|
||
// MojoApplicationHost represents the code needed on the browser side to setup | ||
// a child process as a Mojo application via Chrome IPC. The child process | ||
// should use MojoApplication to handle messages generated by an instance of | ||
// MojoApplicationHost. MojoApplicationHost makes the mojo::ShellClient | ||
// interface available so that child-provided services can be invoked. | ||
class MojoApplicationHost { | ||
public: | ||
MojoApplicationHost(); | ||
~MojoApplicationHost(); | ||
|
||
// Two-phase initialization: | ||
// 1- Init makes the shell_client() available synchronously. | ||
// 2- Activate establishes the actual connection to the peer process. | ||
bool Init(); | ||
bool Activate(IPC::Sender* sender, base::ProcessHandle process_handle); | ||
|
||
bool did_activate() const { return did_activate_; } | ||
|
||
mojo::ShellClient* shell_client() { return shell_client_.get(); } | ||
|
||
private: | ||
mojo::common::ChannelInit channel_init_; | ||
mojo::embedder::ScopedPlatformHandle client_handle_; | ||
mojo::RemotePtr<mojo::ShellClient> shell_client_; | ||
bool did_activate_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(MojoApplicationHost); | ||
}; | ||
|
||
} // namespace content | ||
|
||
#endif // CONTENT_BROWSER_MOJO_MOJO_APPLICATION_HOST_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.