Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / components / nacl / renderer / manifest_service_channel.cc
blobcb397038f82760ea310db0e093078bca4035ea41
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
3 // found in the LICENSE file.
5 #include "components/nacl/renderer/manifest_service_channel.h"
7 #include "base/bind.h"
8 #include "base/callback.h"
9 #include "base/callback_helpers.h"
10 #include "content/public/renderer/render_thread.h"
11 #include "ipc/ipc_channel.h"
12 #include "ipc/ipc_sync_channel.h"
13 #include "ppapi/c/pp_errors.h"
14 #include "ppapi/proxy/ppapi_messages.h"
16 namespace nacl {
18 ManifestServiceChannel::ManifestServiceChannel(
19 const IPC::ChannelHandle& handle,
20 const base::Callback<void(int32_t)>& connected_callback,
21 scoped_ptr<Delegate> delegate,
22 base::WaitableEvent* waitable_event)
23 : connected_callback_(connected_callback),
24 delegate_(delegate.Pass()),
25 channel_(IPC::SyncChannel::Create(
26 handle,
27 IPC::Channel::MODE_CLIENT,
28 this,
29 content::RenderThread::Get()->GetIOMessageLoopProxy(),
30 true,
31 waitable_event)),
32 weak_ptr_factory_(this) {
35 ManifestServiceChannel::~ManifestServiceChannel() {
36 if (!connected_callback_.is_null())
37 base::ResetAndReturn(&connected_callback_).Run(PP_ERROR_FAILED);
40 void ManifestServiceChannel::Send(IPC::Message* message) {
41 channel_->Send(message);
44 bool ManifestServiceChannel::OnMessageReceived(const IPC::Message& message) {
45 bool handled = true;
46 IPC_BEGIN_MESSAGE_MAP(ManifestServiceChannel, message)
47 IPC_MESSAGE_HANDLER(PpapiHostMsg_StartupInitializationComplete,
48 OnStartupInitializationComplete)
49 IPC_MESSAGE_HANDLER_DELAY_REPLY(PpapiHostMsg_OpenResource,
50 OnOpenResource)
51 IPC_MESSAGE_UNHANDLED(handled = false)
52 IPC_END_MESSAGE_MAP()
53 return handled;
56 void ManifestServiceChannel::OnChannelConnected(int32 peer_pid) {
57 if (!connected_callback_.is_null())
58 base::ResetAndReturn(&connected_callback_).Run(PP_OK);
61 void ManifestServiceChannel::OnChannelError() {
62 if (!connected_callback_.is_null())
63 base::ResetAndReturn(&connected_callback_).Run(PP_ERROR_FAILED);
66 void ManifestServiceChannel::OnStartupInitializationComplete() {
67 delegate_->StartupInitializationComplete();
70 void ManifestServiceChannel::OnOpenResource(
71 const std::string& key, IPC::Message* reply) {
72 // Currently this is used only for non-SFI mode, which is not supported on
73 // windows.
74 #if !defined(OS_WIN)
75 delegate_->OpenResource(
76 key,
77 base::Bind(&ManifestServiceChannel::DidOpenResource,
78 weak_ptr_factory_.GetWeakPtr(), reply));
79 #else
80 PpapiHostMsg_OpenResource::WriteReplyParams(
81 reply, ppapi::proxy::SerializedHandle());
82 Send(reply);
83 #endif
86 #if !defined(OS_WIN)
87 void ManifestServiceChannel::DidOpenResource(
88 IPC::Message* reply, base::File file) {
89 // Here, PlatformFileForTransit is alias of base::FileDescriptor.
90 PpapiHostMsg_OpenResource::WriteReplyParams(
91 reply,
92 ppapi::proxy::SerializedHandle(
93 ppapi::proxy::SerializedHandle::FILE,
94 base::FileDescriptor(file.Pass())));
95 Send(reply);
97 #endif
99 } // namespace nacl