linux_aura: Disable the plugin install infobar.
[chromium-blink-merge.git] / ppapi / nacl_irt / manifest_service.cc
blob0afa217e2897a142a1dfefe555384a3c02565fec
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 "ppapi/nacl_irt/manifest_service.h"
7 #include "base/message_loop/message_loop_proxy.h"
8 #include "ipc/ipc_channel_handle.h"
9 #include "ipc/ipc_channel_proxy.h"
10 #include "ipc/ipc_sync_message_filter.h"
11 #include "native_client/src/trusted/service_runtime/include/sys/errno.h"
12 #include "ppapi/nacl_irt/irt_manifest.h"
13 #include "ppapi/nacl_irt/plugin_startup.h"
14 #include "ppapi/proxy/ppapi_messages.h"
16 namespace ppapi {
18 const char kFilePrefix[] = "files/";
20 ManifestService::ManifestService(
21 const IPC::ChannelHandle& handle,
22 scoped_refptr<base::MessageLoopProxy> io_message_loop,
23 base::WaitableEvent* shutdown_event) {
24 filter_ = new IPC::SyncMessageFilter(shutdown_event);
25 channel_.reset(new IPC::ChannelProxy(handle,
26 IPC::Channel::MODE_SERVER,
27 NULL, // Listener
28 io_message_loop));
29 channel_->AddFilter(filter_.get());
32 ManifestService::~ManifestService() {
35 void ManifestService::StartupInitializationComplete() {
36 filter_->Send(new PpapiHostMsg_StartupInitializationComplete);
39 bool ManifestService::OpenResource(const char* file, int* fd) {
40 // OpenResource will return INVALID SerializedHandle, if it is not supported.
41 // Specifically, PNaCl doesn't support open resource.
42 ppapi::proxy::SerializedHandle ipc_fd;
43 if (!filter_->Send(new PpapiHostMsg_OpenResource(
44 std::string(kFilePrefix) + file, &ipc_fd)) ||
45 !ipc_fd.is_file()) {
46 LOG(ERROR) << "ManifestService::OpenResource failed:" << file;
47 *fd = -1;
48 return false;
51 *fd = ipc_fd.descriptor().fd;
52 return true;
55 int IrtOpenResource(const char* file, int* fd) {
56 // Remove leading '/' character.
57 if (file[0] == '/')
58 ++file;
60 ManifestService* manifest_service = GetManifestService();
61 if (manifest_service == NULL ||
62 !manifest_service->OpenResource(file, fd)) {
63 return NACL_ABI_EIO;
66 return (*fd == -1) ? NACL_ABI_ENOENT : 0;
69 } // namespace ppapi