Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/nacl/renderer/manifest_service_channel.h" | 5 #include "components/nacl/renderer/manifest_service_channel.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | |
| 7 #include "base/callback.h" | 8 #include "base/callback.h" |
| 8 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
| 9 #include "content/public/renderer/render_thread.h" | 10 #include "content/public/renderer/render_thread.h" |
| 10 #include "ipc/ipc_channel.h" | 11 #include "ipc/ipc_channel.h" |
| 11 #include "ipc/ipc_sync_channel.h" | 12 #include "ipc/ipc_sync_channel.h" |
| 12 #include "ppapi/c/pp_errors.h" | 13 #include "ppapi/c/pp_errors.h" |
| 13 #include "ppapi/proxy/ppapi_messages.h" | 14 #include "ppapi/proxy/ppapi_messages.h" |
| 14 | 15 |
| 15 namespace nacl { | 16 namespace nacl { |
| 16 | 17 |
| 17 ManifestServiceChannel::ManifestServiceChannel( | 18 ManifestServiceChannel::ManifestServiceChannel( |
| 19 bool pnacl_mode, | |
| 18 const IPC::ChannelHandle& handle, | 20 const IPC::ChannelHandle& handle, |
| 19 const base::Callback<void(int32_t)>& connected_callback, | 21 const base::Callback<void(int32_t)>& connected_callback, |
| 20 scoped_ptr<Delegate> delegate, | 22 scoped_ptr<Delegate> delegate, |
| 21 base::WaitableEvent* waitable_event) | 23 base::WaitableEvent* waitable_event) |
| 22 : connected_callback_(connected_callback), | 24 : pnacl_mode_(pnacl_mode), |
| 25 connected_callback_(connected_callback), | |
| 23 delegate_(delegate.Pass()), | 26 delegate_(delegate.Pass()), |
| 24 channel_(new IPC::SyncChannel( | 27 channel_(new IPC::SyncChannel( |
| 25 handle, IPC::Channel::MODE_CLIENT, this, | 28 handle, IPC::Channel::MODE_CLIENT, this, |
| 26 content::RenderThread::Get()->GetIOMessageLoopProxy(), | 29 content::RenderThread::Get()->GetIOMessageLoopProxy(), |
| 27 true, waitable_event)) { | 30 true, waitable_event)), |
| 31 weak_ptr_factory_(this) { | |
| 28 } | 32 } |
| 29 | 33 |
| 30 ManifestServiceChannel::~ManifestServiceChannel() { | 34 ManifestServiceChannel::~ManifestServiceChannel() { |
| 31 if (!connected_callback_.is_null()) | 35 if (!connected_callback_.is_null()) |
| 32 base::ResetAndReturn(&connected_callback_).Run(PP_ERROR_FAILED); | 36 base::ResetAndReturn(&connected_callback_).Run(PP_ERROR_FAILED); |
| 33 } | 37 } |
| 34 | 38 |
| 39 void ManifestServiceChannel::Send(IPC::Message* message) { | |
| 40 channel_->Send(message); | |
| 41 } | |
| 42 | |
| 35 bool ManifestServiceChannel::OnMessageReceived(const IPC::Message& message) { | 43 bool ManifestServiceChannel::OnMessageReceived(const IPC::Message& message) { |
| 36 // TODO(hidehiko): Implement OpenResource. | |
| 37 bool handled = true; | 44 bool handled = true; |
| 38 IPC_BEGIN_MESSAGE_MAP(ManifestServiceChannel, message) | 45 IPC_BEGIN_MESSAGE_MAP(ManifestServiceChannel, message) |
| 39 IPC_MESSAGE_HANDLER(PpapiHostMsg_StartupInitializationComplete, | 46 IPC_MESSAGE_HANDLER(PpapiHostMsg_StartupInitializationComplete, |
| 40 OnStartupInitializationComplete) | 47 OnStartupInitializationComplete) |
| 48 IPC_MESSAGE_HANDLER_DELAY_REPLY(PpapiHostMsg_OpenResource, | |
| 49 OnOpenResource) | |
| 41 IPC_MESSAGE_UNHANDLED(handled = false) | 50 IPC_MESSAGE_UNHANDLED(handled = false) |
| 42 IPC_END_MESSAGE_MAP() | 51 IPC_END_MESSAGE_MAP() |
| 43 return handled; | 52 return handled; |
| 44 } | 53 } |
| 45 | 54 |
| 46 void ManifestServiceChannel::OnChannelConnected(int32 peer_pid) { | 55 void ManifestServiceChannel::OnChannelConnected(int32 peer_pid) { |
| 47 if (!connected_callback_.is_null()) | 56 if (!connected_callback_.is_null()) |
| 48 base::ResetAndReturn(&connected_callback_).Run(PP_OK); | 57 base::ResetAndReturn(&connected_callback_).Run(PP_OK); |
| 49 } | 58 } |
| 50 | 59 |
| 51 void ManifestServiceChannel::OnChannelError() { | 60 void ManifestServiceChannel::OnChannelError() { |
| 52 if (!connected_callback_.is_null()) | 61 if (!connected_callback_.is_null()) |
| 53 base::ResetAndReturn(&connected_callback_).Run(PP_ERROR_FAILED); | 62 base::ResetAndReturn(&connected_callback_).Run(PP_ERROR_FAILED); |
| 54 } | 63 } |
| 55 | 64 |
| 56 void ManifestServiceChannel::OnStartupInitializationComplete() { | 65 void ManifestServiceChannel::OnStartupInitializationComplete() { |
| 57 delegate_->StartupInitializationComplete(); | 66 delegate_->StartupInitializationComplete(); |
| 58 } | 67 } |
| 59 | 68 |
| 69 void ManifestServiceChannel::OnOpenResource( | |
| 70 const std::string& key, IPC::Message* reply) { | |
| 71 if (pnacl_mode_) { | |
| 72 // OpenResource() is disabled on PNaCl. | |
| 73 PpapiHostMsg_OpenResource::WriteReplyParams( | |
| 74 reply, ppapi::proxy::SerializedHandle()); | |
| 75 Send(reply); | |
| 76 return; | |
| 77 } | |
| 78 | |
| 79 #if defined(OS_WIN) | |
| 80 // Currently this is used only for non-SFI mode, which is not supported on | |
| 81 // windows. | |
| 82 NOTREACHED(); | |
| 83 // Returns an error for Release build. | |
| 84 PpapiHostMsg_OpenResource::WriteReplyParams( | |
|
Mark Seaborn
2014/05/01 06:32:35
Could you reduce the duplication by doing:
#if !d
hidehiko
2014/05/01 13:05:40
Done.
| |
| 85 reply, ppapi::proxy::SerializedHandle()); | |
| 86 Send(reply); | |
| 87 #else | |
| 88 delegate_->OpenResource(key, | |
| 89 base::Bind(&ManifestServiceChannel::DidOpenResource, | |
| 90 weak_ptr_factory_.GetWeakPtr(), reply)); | |
| 91 #endif | |
| 92 } | |
| 93 | |
| 94 #if !defined(OS_WIN) | |
| 95 void ManifestServiceChannel::DidOpenResource( | |
| 96 IPC::Message* reply, const base::PlatformFile& platform_file) { | |
| 97 // Here, PlatformFileForTransit is alias of base::FileDescriptor. | |
| 98 PpapiHostMsg_OpenResource::WriteReplyParams( | |
| 99 reply, | |
| 100 ppapi::proxy::SerializedHandle( | |
| 101 ppapi::proxy::SerializedHandle::FILE, | |
| 102 base::FileDescriptor(platform_file, true))); | |
| 103 Send(reply); | |
| 104 } | |
| 105 #endif | |
| 106 | |
| 60 } // namespace nacl | 107 } // namespace nacl |
| OLD | NEW |