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

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

Issue 334593004: Fix race condition on ManifestService initialization. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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 NaCl process may try to
21 // send a OpenResource message to the host before the connection is
22 // established. In such a case, it is necessary to wait for the set up
23 // completion.
24 class ManifestMessageFilter : public IPC::SyncMessageFilter {
25 public:
26 ManifestMessageFilter(base::WaitableEvent* shutdown_event)
27 : SyncMessageFilter(shutdown_event),
28 connected_event_(
29 true /* manual_reset */, false /* initially_signaled */) {
30 }
31
32 virtual bool Send(IPC::Message* message) OVERRIDE {
33 // Wait until set up is actually done.
34 connected_event_.Wait();
35 return SyncMessageFilter::Send(message);
36 }
37
38 // When set up is done, OnFilterAdded is called on IO thread. Unblocks the
39 // Send().
40 virtual void OnFilterAdded(IPC::Sender* sender) OVERRIDE {
41 SyncMessageFilter::OnFilterAdded(sender);
42 connected_event_.Signal();
43 }
44
45 // If an error is found, unblocks the Send(), too, to return an error.
46 virtual void OnChannelError() OVERRIDE {
47 SyncMessageFilter::OnChannelError();
48 connected_event_.Signal();
49 }
50
51 // Similar to OnChannelError, unblocks the Send() on the channel closing.
52 virtual void OnChannelClosing() OVERRIDE {
53 SyncMessageFilter::OnChannelClosing();
54 connected_event_.Signal();
55 }
56
57 private:
58 base::WaitableEvent connected_event_;
59
60 DISALLOW_COPY_AND_ASSIGN(ManifestMessageFilter);
61 };
62
20 ManifestService::ManifestService( 63 ManifestService::ManifestService(
21 const IPC::ChannelHandle& handle, 64 const IPC::ChannelHandle& handle,
22 scoped_refptr<base::MessageLoopProxy> io_message_loop, 65 scoped_refptr<base::MessageLoopProxy> io_message_loop,
23 base::WaitableEvent* shutdown_event) { 66 base::WaitableEvent* shutdown_event) {
24 filter_ = new IPC::SyncMessageFilter(shutdown_event); 67 filter_ = new ManifestMessageFilter(shutdown_event);
25 channel_ = IPC::ChannelProxy::Create(handle, 68 channel_ = IPC::ChannelProxy::Create(handle,
26 IPC::Channel::MODE_SERVER, 69 IPC::Channel::MODE_SERVER,
27 NULL, // Listener 70 NULL, // Listener
28 io_message_loop); 71 io_message_loop);
29 channel_->AddFilter(filter_.get()); 72 channel_->AddFilter(filter_.get());
30 } 73 }
31 74
32 ManifestService::~ManifestService() { 75 ManifestService::~ManifestService() {
33 } 76 }
34 77
(...skipping 25 matching lines...) Expand all
60 ManifestService* manifest_service = GetManifestService(); 103 ManifestService* manifest_service = GetManifestService();
61 if (manifest_service == NULL || 104 if (manifest_service == NULL ||
62 !manifest_service->OpenResource(file, fd)) { 105 !manifest_service->OpenResource(file, fd)) {
63 return NACL_ABI_EIO; 106 return NACL_ABI_EIO;
64 } 107 }
65 108
66 return (*fd == -1) ? NACL_ABI_ENOENT : 0; 109 return (*fd == -1) ? NACL_ABI_ENOENT : 0;
67 } 110 }
68 111
69 } // namespace ppapi 112 } // namespace ppapi
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698