| Index: components/nacl/renderer/manifest_service_channel.cc
|
| diff --git a/components/nacl/renderer/manifest_service_channel.cc b/components/nacl/renderer/manifest_service_channel.cc
|
| index f0f4adb8f940a261a4116c1f6fe9b1f292e0e4e2..6f8aa9e3b8a719199ef54fd246508dc42d61a77e 100644
|
| --- a/components/nacl/renderer/manifest_service_channel.cc
|
| +++ b/components/nacl/renderer/manifest_service_channel.cc
|
| @@ -4,6 +4,7 @@
|
|
|
| #include "components/nacl/renderer/manifest_service_channel.h"
|
|
|
| +#include "base/bind.h"
|
| #include "base/callback.h"
|
| #include "base/callback_helpers.h"
|
| #include "content/public/renderer/render_thread.h"
|
| @@ -24,20 +25,29 @@ ManifestServiceChannel::ManifestServiceChannel(
|
| channel_(new IPC::SyncChannel(
|
| handle, IPC::Channel::MODE_CLIENT, this,
|
| content::RenderThread::Get()->GetIOMessageLoopProxy(),
|
| - true, waitable_event)) {
|
| + true, waitable_event)),
|
| + peer_handle_(base::kNullProcessHandle),
|
| + weak_ptr_factory_(this) {
|
| }
|
|
|
| ManifestServiceChannel::~ManifestServiceChannel() {
|
| if (!connected_callback_.is_null())
|
| base::ResetAndReturn(&connected_callback_).Run(PP_ERROR_FAILED);
|
| + if (peer_handle_ != base::kNullProcessHandle)
|
| + base::CloseProcessHandle(peer_handle_);
|
| +}
|
| +
|
| +void ManifestServiceChannel::Send(IPC::Message* message) {
|
| + channel_->Send(message);
|
| }
|
|
|
| bool ManifestServiceChannel::OnMessageReceived(const IPC::Message& message) {
|
| - // TODO(hidehiko): Implement OpenResource.
|
| bool handled = true;
|
| IPC_BEGIN_MESSAGE_MAP(ManifestServiceChannel, message)
|
| IPC_MESSAGE_HANDLER(PpapiHostMsg_StartupInitializationComplete,
|
| OnStartupInitializationComplete)
|
| + IPC_MESSAGE_HANDLER_DELAY_REPLY(PpapiHostMsg_OpenResource,
|
| + OnOpenResource)
|
| IPC_MESSAGE_UNHANDLED(handled = false)
|
| IPC_END_MESSAGE_MAP()
|
| return handled;
|
| @@ -57,4 +67,31 @@ void ManifestServiceChannel::OnStartupInitializationComplete() {
|
| delegate_->StartupInitializationComplete();
|
| }
|
|
|
| +void ManifestServiceChannel::OnOpenResource(
|
| + const std::string& key, IPC::Message* reply) {
|
| + delegate_->OpenResource(key,
|
| + base::Bind(&ManifestServiceChannel::DidOpenResource,
|
| + weak_ptr_factory_.GetWeakPtr(), reply));
|
| +}
|
| +
|
| +void ManifestServiceChannel::DidOpenResource(
|
| + IPC::Message* reply, int32_t pp_error,
|
| + const base::PlatformFile& platform_file) {
|
| + PpapiHostMsg_OpenResource::WriteReplyParams(
|
| + reply,
|
| + ppapi::proxy::SerializedHandle(
|
| + ppapi::proxy::SerializedHandle::FILE,
|
| + IPC::GetFileHandleForProcess(
|
| + platform_file, PeerHandle(), true)));
|
| + Send(reply);
|
| +}
|
| +
|
| +base::ProcessHandle ManifestServiceChannel::PeerHandle() {
|
| + // This function is called only from DidOpenResource(), which always runs on
|
| + // a same thread.
|
| + if (peer_handle_ == base::kNullProcessHandle)
|
| + base::OpenPrivilegedProcessHandle(channel_->peer_pid(), &peer_handle_);
|
| + return peer_handle_;
|
| +}
|
| +
|
| } // namespace nacl
|
|
|