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

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/irt_start.cc » ('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/manifest_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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 101
99 #if defined(OS_POSIX) 102 #if defined(OS_POSIX)
100 if (channel_handle.socket.fd == -1) { 103 if (channel_handle.socket.fd == -1) {
101 return false; 104 return false;
102 } 105 }
103 #endif 106 #endif
104 107
105 return true; 108 return true;
106 } 109 }
107 110
111 // Callback invoked when an IPC channel connection is established.
112 // As we will establish multiple IPC channels, this takes the number
113 // of expected invocations and a callback. When all channels are established,
114 // the given callback will be invoked on the main thread. Its argument will be
115 // PP_OK if all the connections are successfully established. Otherwise,
116 // the first error code will be passed, and remaining errors will be ignored.
117 // Note that PP_CompletionCallback is designed to be called exactly once.
118 class ChannelConnectedCallback {
119 public:
120 ChannelConnectedCallback(int num_expect_calls,
121 PP_CompletionCallback callback)
122 : num_remaining_calls_(num_expect_calls),
123 callback_(callback),
124 result_(PP_OK) {
125 }
126
127 ~ChannelConnectedCallback() {
128 }
129
130 void Run(int32_t result) {
131 if (result_ == PP_OK && result != PP_OK) {
132 // This is the first error, so remember it.
133 result_ = result;
134 }
135
136 --num_remaining_calls_;
137 if (num_remaining_calls_ > 0) {
138 // There still are some pending or on-going tasks. Wait for the results.
139 return;
140 }
141
142 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask(
143 FROM_HERE,
144 base::Bind(callback_.func, callback_.user_data, result_));
145 }
146
147 private:
148 int num_remaining_calls_;
149 PP_CompletionCallback callback_;
150 int32_t result_;
151
152 DISALLOW_COPY_AND_ASSIGN(ChannelConnectedCallback);
153 };
154
108 // Launch NaCl's sel_ldr process. 155 // Launch NaCl's sel_ldr process.
109 void LaunchSelLdr(PP_Instance instance, 156 void LaunchSelLdr(PP_Instance instance,
110 const char* alleged_url, 157 const char* alleged_url,
111 PP_Bool uses_irt, 158 PP_Bool uses_irt,
112 PP_Bool uses_ppapi, 159 PP_Bool uses_ppapi,
113 PP_Bool uses_nonsfi_mode, 160 PP_Bool uses_nonsfi_mode,
114 PP_Bool enable_ppapi_dev, 161 PP_Bool enable_ppapi_dev,
115 PP_Bool enable_dyncode_syscalls, 162 PP_Bool enable_dyncode_syscalls,
116 PP_Bool enable_exception_handling, 163 PP_Bool enable_exception_handling,
117 PP_Bool enable_crash_throttling, 164 PP_Bool enable_crash_throttling,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 instance_info.plugin_pid = launch_result.plugin_pid; 232 instance_info.plugin_pid = launch_result.plugin_pid;
186 instance_info.plugin_child_id = launch_result.plugin_child_id; 233 instance_info.plugin_child_id = launch_result.plugin_child_id;
187 234
188 // Don't save instance_info if channel handle is invalid. 235 // Don't save instance_info if channel handle is invalid.
189 if (IsValidChannelHandle(instance_info.channel_handle)) 236 if (IsValidChannelHandle(instance_info.channel_handle))
190 g_instance_info.Get()[instance] = instance_info; 237 g_instance_info.Get()[instance] = instance_info;
191 238
192 *(static_cast<NaClHandle*>(imc_handle)) = 239 *(static_cast<NaClHandle*>(imc_handle)) =
193 nacl::ToNativeHandle(result_socket); 240 nacl::ToNativeHandle(result_socket);
194 241
195 // TODO(hidehiko): We'll add EmbedderServiceChannel here, and it will wait 242 // Here after, we starts to establish connections for TrustedPluginChannel
196 // for the connection in parallel with TrustedPluginChannel. 243 // and ManifestServiceChannel in parallel. The invocation of the callback
197 // Thus, the callback will wait for its second invocation to run callback, 244 // is delegated to their connection completion callback.
198 // then. 245 base::Callback<void(int32_t)> connected_callback = base::Bind(
199 // Note that PP_CompletionCallback is not designed to be called twice or 246 &ChannelConnectedCallback::Run,
200 // more. Thus, it is necessary to create a function to handle multiple 247 base::Owned(new ChannelConnectedCallback(
201 // invocation. 248 2, // For TrustedPluginChannel and ManifestServiceChannel.
202 base::Callback<void(int32_t)> completion_callback = 249 callback)));
203 base::Bind(callback.func, callback.user_data); 250
204 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance); 251 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance);
205 DCHECK(load_manager); 252 DCHECK(load_manager);
206 253
207 // Stash the trusted handle as well. 254 // Stash the trusted handle as well.
208 if (load_manager && 255 if (load_manager &&
209 IsValidChannelHandle(launch_result.trusted_ipc_channel_handle)) { 256 IsValidChannelHandle(launch_result.trusted_ipc_channel_handle)) {
210 scoped_ptr<nacl::TrustedPluginChannel> trusted_plugin_channel( 257 scoped_ptr<nacl::TrustedPluginChannel> trusted_plugin_channel(
211 new nacl::TrustedPluginChannel( 258 new nacl::TrustedPluginChannel(
212 launch_result.trusted_ipc_channel_handle, 259 launch_result.trusted_ipc_channel_handle,
213 completion_callback, 260 connected_callback,
214 content::RenderThread::Get()->GetShutdownEvent())); 261 content::RenderThread::Get()->GetShutdownEvent()));
215 load_manager->set_trusted_plugin_channel(trusted_plugin_channel.Pass()); 262 load_manager->set_trusted_plugin_channel(trusted_plugin_channel.Pass());
216 } else { 263 } else {
217 completion_callback.Run(PP_ERROR_FAILED); 264 connected_callback.Run(PP_ERROR_FAILED);
265 }
266
267 // Stash the manifest service handle as well.
268 if (load_manager &&
269 IsValidChannelHandle(
270 launch_result.manifest_service_ipc_channel_handle)) {
271 scoped_ptr<nacl::ManifestServiceChannel> manifest_service_channel(
272 new nacl::ManifestServiceChannel(
273 launch_result.manifest_service_ipc_channel_handle,
274 connected_callback,
275 content::RenderThread::Get()->GetShutdownEvent()));
276 load_manager->set_manifest_service_channel(
277 manifest_service_channel.Pass());
278 } else {
279 // Currently, manifest service works only on linux/non-SFI mode.
280 // On other platforms, the socket will not be created, and thus this
281 // condition needs to be handled as success.
282 connected_callback.Run(PP_OK);
218 } 283 }
219 } 284 }
220 285
221 // Forward declaration. 286 // Forward declaration.
222 void ReportLoadError(PP_Instance instance, 287 void ReportLoadError(PP_Instance instance,
223 PP_NaClError error, 288 PP_NaClError error,
224 const char* error_message, 289 const char* error_message,
225 const char* console_message); 290 const char* console_message);
226 291
227 PP_Bool StartPpapiProxy(PP_Instance instance) { 292 PP_Bool StartPpapiProxy(PP_Instance instance) {
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 763
699 } // namespace 764 } // namespace
700 765
701 namespace nacl { 766 namespace nacl {
702 767
703 const PPB_NaCl_Private* GetNaClPrivateInterface() { 768 const PPB_NaCl_Private* GetNaClPrivateInterface() {
704 return &nacl_interface; 769 return &nacl_interface;
705 } 770 }
706 771
707 } // namespace nacl 772 } // namespace nacl
OLDNEW
« no previous file with comments | « components/nacl/renderer/nexe_load_manager.cc ('k') | ppapi/nacl_irt/irt_start.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698