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

Side by Side Diff: components/nacl/renderer/ppb_nacl_private_impl.cc

Issue 231793003: Add IPC Channel for new ManifestService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 | « components/nacl/renderer/nexe_load_manager.cc ('k') | ppapi/nacl_irt/embedder_service.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "components/nacl/renderer/ppb_nacl_private_impl.h" 5 #include "components/nacl/renderer/ppb_nacl_private_impl.h"
6 6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
7 #include "base/command_line.h" 9 #include "base/command_line.h"
8 #include "base/containers/scoped_ptr_hash_map.h" 10 #include "base/containers/scoped_ptr_hash_map.h"
9 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
10 #include "base/logging.h" 12 #include "base/logging.h"
11 #include "base/rand_util.h" 13 #include "base/rand_util.h"
12 #include "components/nacl/common/nacl_host_messages.h" 14 #include "components/nacl/common/nacl_host_messages.h"
13 #include "components/nacl/common/nacl_messages.h" 15 #include "components/nacl/common/nacl_messages.h"
14 #include "components/nacl/common/nacl_switches.h" 16 #include "components/nacl/common/nacl_switches.h"
15 #include "components/nacl/common/nacl_types.h" 17 #include "components/nacl/common/nacl_types.h"
18 #include "components/nacl/renderer/embedder_service_channel.h"
16 #include "components/nacl/renderer/nexe_load_manager.h" 19 #include "components/nacl/renderer/nexe_load_manager.h"
17 #include "components/nacl/renderer/pnacl_translation_resource_host.h" 20 #include "components/nacl/renderer/pnacl_translation_resource_host.h"
18 #include "components/nacl/renderer/sandbox_arch.h" 21 #include "components/nacl/renderer/sandbox_arch.h"
19 #include "components/nacl/renderer/trusted_plugin_channel.h" 22 #include "components/nacl/renderer/trusted_plugin_channel.h"
20 #include "content/public/common/content_client.h" 23 #include "content/public/common/content_client.h"
21 #include "content/public/common/content_switches.h" 24 #include "content/public/common/content_switches.h"
22 #include "content/public/common/sandbox_init.h" 25 #include "content/public/common/sandbox_init.h"
23 #include "content/public/renderer/pepper_plugin_instance.h" 26 #include "content/public/renderer/pepper_plugin_instance.h"
24 #include "content/public/renderer/render_thread.h" 27 #include "content/public/renderer/render_thread.h"
25 #include "content/public/renderer/render_view.h" 28 #include "content/public/renderer/render_view.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 100
98 #if defined(OS_POSIX) 101 #if defined(OS_POSIX)
99 if (channel_handle.socket.fd == -1) { 102 if (channel_handle.socket.fd == -1) {
100 return false; 103 return false;
101 } 104 }
102 #endif 105 #endif
103 106
104 return true; 107 return true;
105 } 108 }
106 109
110 // Callback invoked when an IPC channel connection is established.
111 // As we will establish multiple IPC channels, this takes the number
112 // of expected invocations and callback. When all channels are established,
dmichael (off chromium) 2014/04/10 23:14:38 nit: "a" callback here, "the given callback" below
hidehiko 2014/04/11 16:28:30 Thanks. Done.
113 // given callback will be invoked on the main thread. Its argument will be
114 // PP_OK, if all the connections are successfully establishe. Otherwise,
dmichael (off chromium) 2014/04/10 23:14:38 nit: no comma after PP_OK, also establishe->establ
hidehiko 2014/04/11 16:28:30 Done.
115 // the first error code will be passed, and remaining errors will be ignored.
116 // Note that PP_CompletionCallback is designed to be called exactly once.
117 class ChannelConnectedCallback {
118 public:
119 ChannelConnectedCallback(int num_expect_calls,
120 PP_CompletionCallback callback)
121 : num_remaining_calls_(num_expect_calls),
122 callback_(callback),
123 result_(PP_OK) {
124 }
125
126 ~ChannelConnectedCallback() {
127 }
128
129 void Run(int32_t result) {
130 if (result_ == PP_OK && result != PP_OK) {
131 // This is the first error, so remember it.
132 result_ = result;
133 }
134
135 --num_remaining_calls_;
136 if (num_remaining_calls_ > 0) {
137 // There still are some pending or on-going tasks. Wait for the results.
138 return;
139 }
140
141 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask(
142 FROM_HERE,
143 base::Bind(callback_.func, callback_.user_data, result_));
144 }
145
146 private:
147 int num_remaining_calls_;
148 PP_CompletionCallback callback_;
149 int32_t result_;
150
151 DISALLOW_COPY_AND_ASSIGN(ChannelConnectedCallback);
152 };
153
107 // Launch NaCl's sel_ldr process. 154 // Launch NaCl's sel_ldr process.
108 void LaunchSelLdr(PP_Instance instance, 155 void LaunchSelLdr(PP_Instance instance,
109 const char* alleged_url, 156 const char* alleged_url,
110 PP_Bool uses_irt, 157 PP_Bool uses_irt,
111 PP_Bool uses_ppapi, 158 PP_Bool uses_ppapi,
112 PP_Bool uses_nonsfi_mode, 159 PP_Bool uses_nonsfi_mode,
113 PP_Bool enable_ppapi_dev, 160 PP_Bool enable_ppapi_dev,
114 PP_Bool enable_dyncode_syscalls, 161 PP_Bool enable_dyncode_syscalls,
115 PP_Bool enable_exception_handling, 162 PP_Bool enable_exception_handling,
116 PP_Bool enable_crash_throttling, 163 PP_Bool enable_crash_throttling,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 instance_info.plugin_pid = launch_result.plugin_pid; 231 instance_info.plugin_pid = launch_result.plugin_pid;
185 instance_info.plugin_child_id = launch_result.plugin_child_id; 232 instance_info.plugin_child_id = launch_result.plugin_child_id;
186 233
187 // Don't save instance_info if channel handle is invalid. 234 // Don't save instance_info if channel handle is invalid.
188 if (IsValidChannelHandle(instance_info.channel_handle)) 235 if (IsValidChannelHandle(instance_info.channel_handle))
189 g_instance_info.Get()[instance] = instance_info; 236 g_instance_info.Get()[instance] = instance_info;
190 237
191 *(static_cast<NaClHandle*>(imc_handle)) = 238 *(static_cast<NaClHandle*>(imc_handle)) =
192 nacl::ToNativeHandle(result_socket); 239 nacl::ToNativeHandle(result_socket);
193 240
194 // TODO(hidehiko): We'll add EmbedderServiceChannel here, and it will wait 241 // Here after, we starts to establish connections for TrustedPluginChannel
195 // for the connection in parallel with TrustedPluginChannel. 242 // and EmbedderServiceChannel in parallel. The invocation of the callback
196 // Thus, the callback will wait for its second invocation to run callback, 243 // is delegated to their connection completion callback.
197 // then. 244 base::Callback<void(int32_t)> connected_callback = base::Bind(
198 // Note that PP_CompletionCallback is not designed to be called twice or 245 &ChannelConnectedCallback::Run,
199 // more. Thus, it is necessary to create a function to handle multiple 246 base::Owned(new ChannelConnectedCallback(
200 // invocation. 247 2, // For TrustedPluginChannel and EmbedderServiceChannel.
201 base::Callback<void(int32_t)> completion_callback = 248 callback)));
202 base::Bind(callback.func, callback.user_data); 249
203 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance); 250 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance);
204 DCHECK(load_manager); 251 DCHECK(load_manager);
205 252
206 // Stash the trusted handle as well. 253 // Stash the trusted handle as well.
207 if (load_manager && 254 if (load_manager &&
208 IsValidChannelHandle(launch_result.trusted_ipc_channel_handle)) { 255 IsValidChannelHandle(launch_result.trusted_ipc_channel_handle)) {
209 scoped_ptr<nacl::TrustedPluginChannel> trusted_plugin_channel( 256 scoped_ptr<nacl::TrustedPluginChannel> trusted_plugin_channel(
210 new nacl::TrustedPluginChannel( 257 new nacl::TrustedPluginChannel(
211 launch_result.trusted_ipc_channel_handle, 258 launch_result.trusted_ipc_channel_handle,
212 completion_callback, 259 connected_callback,
213 content::RenderThread::Get()->GetShutdownEvent())); 260 content::RenderThread::Get()->GetShutdownEvent()));
214 load_manager->set_trusted_plugin_channel(trusted_plugin_channel.Pass()); 261 load_manager->set_trusted_plugin_channel(trusted_plugin_channel.Pass());
215 } else { 262 } else {
216 completion_callback.Run(PP_ERROR_FAILED); 263 connected_callback.Run(PP_ERROR_FAILED);
264 }
265
266 // Stash the embedder service handle as well.
267 if (load_manager &&
268 IsValidChannelHandle(
269 launch_result.embedder_service_ipc_channel_handle)) {
270 scoped_ptr<nacl::EmbedderServiceChannel> embedder_service_channel(
271 new nacl::EmbedderServiceChannel(
272 launch_result.embedder_service_ipc_channel_handle,
273 connected_callback,
274 content::RenderThread::Get()->GetShutdownEvent()));
275 load_manager->set_embedder_service_channel(
276 embedder_service_channel.Pass());
277 } else {
278 // Currently, embedder service works only on linux/non-SFI mode.
279 // On other platforms, the socket will not be created, and thus this
280 // condition needs to be handled as success.
281 connected_callback.Run(PP_OK);
217 } 282 }
218 } 283 }
219 284
220 // Forward declaration. 285 // Forward declaration.
221 void ReportLoadError(PP_Instance instance, 286 void ReportLoadError(PP_Instance instance,
222 PP_NaClError error, 287 PP_NaClError error,
223 const char* error_message, 288 const char* error_message,
224 const char* console_message); 289 const char* console_message);
225 290
226 PP_Bool StartPpapiProxy(PP_Instance instance) { 291 PP_Bool StartPpapiProxy(PP_Instance instance) {
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 740
676 } // namespace 741 } // namespace
677 742
678 namespace nacl { 743 namespace nacl {
679 744
680 const PPB_NaCl_Private* GetNaClPrivateInterface() { 745 const PPB_NaCl_Private* GetNaClPrivateInterface() {
681 return &nacl_interface; 746 return &nacl_interface;
682 } 747 }
683 748
684 } // namespace nacl 749 } // namespace nacl
OLDNEW
« no previous file with comments | « components/nacl/renderer/nexe_load_manager.cc ('k') | ppapi/nacl_irt/embedder_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698