Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / components / nacl / renderer / trusted_plugin_channel.cc
index c553e3a..7ce3d84 100644 (file)
@@ -4,26 +4,28 @@
 
 #include "components/nacl/renderer/trusted_plugin_channel.h"
 
-#include "base/debug/stack_trace.h"
+#include "base/callback_helpers.h"
 #include "content/public/renderer/render_thread.h"
-#include "ppapi/c/pp_completion_callback.h"
+#include "ipc/ipc_channel.h"
+#include "ipc/ipc_sync_channel.h"
 #include "ppapi/c/pp_errors.h"
-#include "ppapi/shared_impl/ppapi_globals.h"
 
 namespace nacl {
 
 TrustedPluginChannel::TrustedPluginChannel(
     const IPC::ChannelHandle& handle,
-    PP_CompletionCallback connected_callback,
+    const base::Callback<void(int32_t)>& connected_callback,
     base::WaitableEvent* waitable_event)
-    : connected_callback_(connected_callback) {
-  channel_.reset(new IPC::SyncChannel(
-      handle, IPC::Channel::MODE_CLIENT, this,
-      content::RenderThread::Get()->GetIOMessageLoopProxy(), true,
-      waitable_event));
+    : connected_callback_(connected_callback),
+      channel_(new IPC::SyncChannel(
+          handle, IPC::Channel::MODE_CLIENT, this,
+          content::RenderThread::Get()->GetIOMessageLoopProxy(), true,
+          waitable_event)) {
 }
 
 TrustedPluginChannel::~TrustedPluginChannel() {
+  if (!connected_callback_.is_null())
+    base::ResetAndReturn(&connected_callback_).Run(PP_ERROR_FAILED);
 }
 
 bool TrustedPluginChannel::Send(IPC::Message* message) {
@@ -35,13 +37,13 @@ bool TrustedPluginChannel::OnMessageReceived(const IPC::Message& message) {
 }
 
 void TrustedPluginChannel::OnChannelConnected(int32 peer_pid) {
-  if (connected_callback_.func)
-    PP_RunAndClearCompletionCallback(&connected_callback_, PP_OK);
+  if (!connected_callback_.is_null())
+    base::ResetAndReturn(&connected_callback_).Run(PP_OK);
 }
 
 void TrustedPluginChannel::OnChannelError() {
-  if (connected_callback_.func)
-    PP_RunAndClearCompletionCallback(&connected_callback_, PP_ERROR_FAILED);
+  if (!connected_callback_.is_null())
+    base::ResetAndReturn(&connected_callback_).Run(PP_ERROR_FAILED);
 }
 
 }  // namespace nacl