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"
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"
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(
27 IPC::Channel::MODE_CLIENT
,
29 content::RenderThread::Get()->GetIOMessageLoopProxy(),
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
) {
46 IPC_BEGIN_MESSAGE_MAP(ManifestServiceChannel
, message
)
47 IPC_MESSAGE_HANDLER(PpapiHostMsg_StartupInitializationComplete
,
48 OnStartupInitializationComplete
)
49 IPC_MESSAGE_HANDLER_DELAY_REPLY(PpapiHostMsg_OpenResource
,
51 IPC_MESSAGE_UNHANDLED(handled
= false)
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
75 delegate_
->OpenResource(
77 base::Bind(&ManifestServiceChannel::DidOpenResource
,
78 weak_ptr_factory_
.GetWeakPtr(), reply
));
80 PpapiHostMsg_OpenResource::WriteReplyParams(
81 reply
, ppapi::proxy::SerializedHandle());
87 void ManifestServiceChannel::DidOpenResource(
88 IPC::Message
* reply
, base::File file
) {
89 // Here, PlatformFileForTransit is alias of base::FileDescriptor.
90 PpapiHostMsg_OpenResource::WriteReplyParams(
92 ppapi::proxy::SerializedHandle(
93 ppapi::proxy::SerializedHandle::FILE,
94 base::FileDescriptor(file
.Pass())));