Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(558)

Side by Side Diff: ppapi/nacl_irt/manifest_service.cc

Issue 1262253004: Let IPC::SyncMessageFilter take advantage of thread-safe Send. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/single_thread_task_runner.h" 7 #include "base/single_thread_task_runner.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_sync_channel.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 #if !defined(OS_NACL_SFI) 16 #if !defined(OS_NACL_SFI)
17 #include <pthread.h> 17 #include <pthread.h>
18 #include <map> 18 #include <map>
19 #include <string> 19 #include <string>
20 #endif 20 #endif
21 21
22 namespace ppapi { 22 namespace ppapi {
23 23
24 // IPC channel is asynchronously set up. So, the NaCl process may try to
25 // send a OpenResource message to the host before the connection is
26 // established. In such a case, it is necessary to wait for the set up
27 // completion.
28 class ManifestMessageFilter : public IPC::SyncMessageFilter {
29 public:
30 ManifestMessageFilter(base::WaitableEvent* shutdown_event)
31 : SyncMessageFilter(shutdown_event),
32 connected_event_(
33 true /* manual_reset */, false /* initially_signaled */) {
34 }
35
36 bool Send(IPC::Message* message) override {
37 // Wait until set up is actually done.
38 connected_event_.Wait();
39 return SyncMessageFilter::Send(message);
40 }
41
42 // When set up is done, OnFilterAdded is called on IO thread. Unblocks the
43 // Send().
44 void OnFilterAdded(IPC::Sender* sender) override {
45 SyncMessageFilter::OnFilterAdded(sender);
46 connected_event_.Signal();
47 }
48
49 // If an error is found, unblocks the Send(), too, to return an error.
50 void OnChannelError() override {
51 SyncMessageFilter::OnChannelError();
52 connected_event_.Signal();
53 }
54
55 // Similar to OnChannelError, unblocks the Send() on the channel closing.
56 void OnChannelClosing() override {
57 SyncMessageFilter::OnChannelClosing();
58 connected_event_.Signal();
59 }
60
61 private:
62 base::WaitableEvent connected_event_;
63
64 DISALLOW_COPY_AND_ASSIGN(ManifestMessageFilter);
65 };
66
67 ManifestService::ManifestService( 24 ManifestService::ManifestService(
68 const IPC::ChannelHandle& handle, 25 const IPC::ChannelHandle& handle,
69 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, 26 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
70 base::WaitableEvent* shutdown_event) { 27 base::WaitableEvent* shutdown_event) {
71 filter_ = new ManifestMessageFilter(shutdown_event); 28 channel_ = IPC::SyncChannel::Create(handle, IPC::Channel::MODE_SERVER,
72 channel_ = IPC::ChannelProxy::Create(handle, IPC::Channel::MODE_SERVER, 29 nullptr /* listener */,
73 NULL, // Listener 30 io_task_runner.get(),
74 io_task_runner.get()); 31 false /* create_pipe_now */,
75 channel_->AddFilter(filter_.get()); 32 shutdown_event);
33 filter_ = channel_->AddNewSyncMessageFilter();
76 } 34 }
77 35
78 ManifestService::~ManifestService() { 36 ManifestService::~ManifestService() {
79 } 37 }
80 38
81 void ManifestService::StartupInitializationComplete() { 39 void ManifestService::StartupInitializationComplete() {
82 filter_->Send(new PpapiHostMsg_StartupInitializationComplete); 40 filter_->Send(new PpapiHostMsg_StartupInitializationComplete);
83 } 41 }
84 42
85 bool ManifestService::OpenResource(const char* file, int* fd) { 43 bool ManifestService::OpenResource(const char* file, int* fd) {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 120
163 ManifestService* manifest_service = GetManifestService(); 121 ManifestService* manifest_service = GetManifestService();
164 if (manifest_service == NULL || 122 if (manifest_service == NULL ||
165 !manifest_service->OpenResource(file, fd)) { 123 !manifest_service->OpenResource(file, fd)) {
166 return NACL_ABI_EIO; 124 return NACL_ABI_EIO;
167 } 125 }
168 return (*fd == -1) ? NACL_ABI_ENOENT : 0; 126 return (*fd == -1) ? NACL_ABI_ENOENT : 0;
169 } 127 }
170 128
171 } // namespace ppapi 129 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698