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 "ppapi/nacl_irt/manifest_service.h" | 5 #include "ppapi/nacl_irt/manifest_service.h" |
6 | 6 |
7 #include "base/message_loop/message_loop_proxy.h" | 7 #include "base/message_loop/message_loop_proxy.h" |
8 #include "ipc/ipc_channel_handle.h" | 8 #include "ipc/ipc_channel_handle.h" |
9 #include "ipc/ipc_channel_proxy.h" | 9 #include "ipc/ipc_channel_proxy.h" |
10 #include "ipc/ipc_sync_message_filter.h" | 10 #include "ipc/ipc_sync_message_filter.h" |
11 #include "native_client/src/trusted/service_runtime/include/sys/errno.h" | 11 #include "native_client/src/trusted/service_runtime/include/sys/errno.h" |
12 #include "ppapi/nacl_irt/irt_manifest.h" | 12 #include "ppapi/nacl_irt/irt_manifest.h" |
13 #include "ppapi/nacl_irt/plugin_startup.h" | 13 #include "ppapi/nacl_irt/plugin_startup.h" |
14 #include "ppapi/proxy/ppapi_messages.h" | 14 #include "ppapi/proxy/ppapi_messages.h" |
15 | 15 |
16 namespace ppapi { | 16 namespace ppapi { |
17 | 17 |
18 const char kFilePrefix[] = "files/"; | 18 const char kFilePrefix[] = "files/"; |
19 | 19 |
20 // IPC channel is asynchronously set up. So, the plugin may be try to send | |
Mark Seaborn
2014/06/13 00:34:35
Nit: "plugin" is ambiguous. Maybe say "NaCl proce
hidehiko
2014/06/13 04:37:10
Done.
| |
21 // a OpenResource message to the host before the connection is established. | |
22 // In such a case, it is necessary to wait for the set up completion. | |
23 class ManifestMessageFilter : public IPC::SyncMessageFilter { | |
24 public: | |
25 ManifestMessageFilter(base::WaitableEvent* shutdown_event) | |
26 : SyncMessageFilter(shutdown_event), | |
27 connected_event_(true, false) { // Reset manually, and init by false. | |
Mark Seaborn
2014/06/13 00:34:35
Nit: "init with" rather than "by"?
But if this is
hidehiko
2014/06/13 04:37:10
Changed the style to one which seems to be used in
| |
28 } | |
29 | |
30 virtual bool Send(IPC::Message* message) OVERRIDE { | |
31 // Wait until set up is actually done. | |
32 connected_event_.Wait(); | |
33 return SyncMessageFilter::Send(message); | |
34 } | |
35 | |
36 // When set up is done, OnFilterAdded is called on IO thread. Unblocks the | |
37 // Send(). | |
38 virtual void OnFilterAdded(IPC::Channel* channel) OVERRIDE { | |
39 SyncMessageFilter::OnFilterAdded(channel); | |
40 connected_event_.Signal(); | |
41 } | |
42 | |
43 // If an error is found, unblocks the Send(), too, to return an error. | |
44 virtual void OnChannelError() OVERRIDE { | |
45 SyncMessageFilter::OnChannelError(); | |
46 connected_event_.Signal(); | |
47 } | |
48 | |
49 // Similar to OnChannelError, unblocks the Send() on the channel closing. | |
50 virtual void OnChannelClosing() OVERRIDE { | |
51 SyncMessageFilter::OnChannelClosing(); | |
52 connected_event_.Signal(); | |
53 } | |
54 | |
55 private: | |
56 base::WaitableEvent connected_event_; | |
57 | |
58 DISALLOW_COPY_AND_ASSIGN(ManifestMessageFilter); | |
59 }; | |
60 | |
20 ManifestService::ManifestService( | 61 ManifestService::ManifestService( |
21 const IPC::ChannelHandle& handle, | 62 const IPC::ChannelHandle& handle, |
22 scoped_refptr<base::MessageLoopProxy> io_message_loop, | 63 scoped_refptr<base::MessageLoopProxy> io_message_loop, |
23 base::WaitableEvent* shutdown_event) { | 64 base::WaitableEvent* shutdown_event) { |
24 filter_ = new IPC::SyncMessageFilter(shutdown_event); | 65 filter_ = new ManifestMessageFilter(shutdown_event); |
25 channel_ = IPC::ChannelProxy::Create(handle, | 66 channel_ = IPC::ChannelProxy::Create(handle, |
26 IPC::Channel::MODE_SERVER, | 67 IPC::Channel::MODE_SERVER, |
27 NULL, // Listener | 68 NULL, // Listener |
28 io_message_loop); | 69 io_message_loop); |
29 channel_->AddFilter(filter_.get()); | 70 channel_->AddFilter(filter_.get()); |
30 } | 71 } |
31 | 72 |
32 ManifestService::~ManifestService() { | 73 ManifestService::~ManifestService() { |
33 } | 74 } |
34 | 75 |
(...skipping 25 matching lines...) Expand all Loading... | |
60 ManifestService* manifest_service = GetManifestService(); | 101 ManifestService* manifest_service = GetManifestService(); |
61 if (manifest_service == NULL || | 102 if (manifest_service == NULL || |
62 !manifest_service->OpenResource(file, fd)) { | 103 !manifest_service->OpenResource(file, fd)) { |
63 return NACL_ABI_EIO; | 104 return NACL_ABI_EIO; |
64 } | 105 } |
65 | 106 |
66 return (*fd == -1) ? NACL_ABI_ENOENT : 0; | 107 return (*fd == -1) ? NACL_ABI_ENOENT : 0; |
67 } | 108 } |
68 | 109 |
69 } // namespace ppapi | 110 } // namespace ppapi |
OLD | NEW |