OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 * Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 #define NACL_LOG_MODULE_NAME "Plugin_ServiceRuntime" | 7 #define NACL_LOG_MODULE_NAME "Plugin_ServiceRuntime" |
8 | 8 |
9 #include "ppapi/native_client/src/trusted/plugin/service_runtime.h" | 9 #include "ppapi/native_client/src/trusted/plugin/service_runtime.h" |
10 | 10 |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 // (Some PPAPI actions -- like StreamAsFile -- can only run on the main thread). | 307 // (Some PPAPI actions -- like StreamAsFile -- can only run on the main thread). |
308 // OpenManifestEntry() is waiting on a condvar for this continuation to | 308 // OpenManifestEntry() is waiting on a condvar for this continuation to |
309 // complete. We Broadcast and awaken OpenManifestEntry() whenever we are done | 309 // complete. We Broadcast and awaken OpenManifestEntry() whenever we are done |
310 // either here, or in a later MainThreadContinuation step, if there are | 310 // either here, or in a later MainThreadContinuation step, if there are |
311 // multiple steps. | 311 // multiple steps. |
312 void PluginReverseInterface::OpenManifestEntry_MainThreadContinuation( | 312 void PluginReverseInterface::OpenManifestEntry_MainThreadContinuation( |
313 OpenManifestEntryResource* p, | 313 OpenManifestEntryResource* p, |
314 int32_t err) { | 314 int32_t err) { |
315 UNREFERENCED_PARAMETER(err); | 315 UNREFERENCED_PARAMETER(err); |
316 // CallOnMainThread continuations always called with err == PP_OK. | 316 // CallOnMainThread continuations always called with err == PP_OK. |
| 317 |
317 NaClLog(4, "Entered OpenManifestEntry_MainThreadContinuation\n"); | 318 NaClLog(4, "Entered OpenManifestEntry_MainThreadContinuation\n"); |
318 | 319 |
| 320 PP_Var pp_mapped_url; |
| 321 PP_PNaClOptions pnacl_options = {PP_FALSE, PP_FALSE, 2}; |
| 322 if (!GetNaClInterface()->ManifestResolveKey( |
| 323 plugin_->pp_instance(), |
| 324 PP_FromBool(!service_runtime_->main_service_runtime()), |
| 325 p->url.c_str(), |
| 326 &pp_mapped_url, |
| 327 &pnacl_options)) { |
| 328 NaClLog(4, "OpenManifestEntry_MainThreadContinuation: ResolveKey failed\n"); |
| 329 // Failed, and error_info has the details on what happened. Wake |
| 330 // up requesting thread -- we are done. |
| 331 { |
| 332 nacl::MutexLocker take(&mu_); |
| 333 *p->op_complete_ptr = true; // done... |
| 334 p->file_info->desc = -1; // but failed. |
| 335 NaClXCondVarBroadcast(&cv_); |
| 336 } |
| 337 p->MaybeRunCallback(PP_OK); |
| 338 return; |
| 339 } |
| 340 nacl::string mapped_url = pp::Var(pp_mapped_url).AsString(); |
| 341 NaClLog(4, |
| 342 "OpenManifestEntry_MainThreadContinuation: " |
| 343 "ResolveKey: %s -> %s (pnacl_translate(%d))\n", |
| 344 p->url.c_str(), mapped_url.c_str(), pnacl_options.translate); |
| 345 |
| 346 if (pnacl_options.translate) { |
| 347 // Requires PNaCl translation, but that's not supported. |
| 348 NaClLog(4, |
| 349 "OpenManifestEntry_MainThreadContinuation: " |
| 350 "Requires PNaCl translation -- not supported\n"); |
| 351 { |
| 352 nacl::MutexLocker take(&mu_); |
| 353 *p->op_complete_ptr = true; // done... |
| 354 p->file_info->desc = -1; // but failed. |
| 355 NaClXCondVarBroadcast(&cv_); |
| 356 } |
| 357 p->MaybeRunCallback(PP_OK); |
| 358 return; |
| 359 } |
| 360 |
319 // Because p is owned by the callback of this invocation, so it is necessary | 361 // Because p is owned by the callback of this invocation, so it is necessary |
320 // to create another instance. | 362 // to create another instance. |
321 OpenManifestEntryResource* open_cont = new OpenManifestEntryResource(*p); | 363 OpenManifestEntryResource* open_cont = new OpenManifestEntryResource(*p); |
| 364 open_cont->url = mapped_url; |
| 365 // Callback is now delegated from p to open_cont. So, here we manually clear |
| 366 // complete callback. |
| 367 p->callback = NULL; |
322 | 368 |
323 pp::CompletionCallback stream_cc = WeakRefNewCallback( | 369 pp::CompletionCallback stream_cc = WeakRefNewCallback( |
324 anchor_, | 370 anchor_, |
325 this, | 371 this, |
326 &PluginReverseInterface::StreamAsFile_MainThreadContinuation, | 372 &PluginReverseInterface::StreamAsFile_MainThreadContinuation, |
327 open_cont); | 373 open_cont); |
328 | 374 |
329 GetNaClInterface()->OpenManifestEntry( | 375 GetNaClInterface()->DownloadFile(plugin_->pp_instance(), |
330 plugin_->pp_instance(), | 376 mapped_url.c_str(), |
331 PP_FromBool(!service_runtime_->main_service_runtime()), | 377 &open_cont->pp_file_info, |
332 p->url.c_str(), | 378 stream_cc.pp_completion_callback()); |
333 &open_cont->pp_file_info, | |
334 stream_cc.pp_completion_callback()); | |
335 // p is deleted automatically. | 379 // p is deleted automatically. |
336 } | 380 } |
337 | 381 |
338 void PluginReverseInterface::StreamAsFile_MainThreadContinuation( | 382 void PluginReverseInterface::StreamAsFile_MainThreadContinuation( |
339 OpenManifestEntryResource* p, | 383 OpenManifestEntryResource* p, |
340 int32_t result) { | 384 int32_t result) { |
341 NaClLog(4, "Entered StreamAsFile_MainThreadContinuation\n"); | 385 NaClLog(4, "Entered StreamAsFile_MainThreadContinuation\n"); |
342 { | 386 { |
343 nacl::MutexLocker take(&mu_); | 387 nacl::MutexLocker take(&mu_); |
344 if (result == PP_OK) { | 388 if (result == PP_OK) { |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 | 772 |
729 nacl::string ServiceRuntime::GetCrashLogOutput() { | 773 nacl::string ServiceRuntime::GetCrashLogOutput() { |
730 if (NULL != subprocess_.get()) { | 774 if (NULL != subprocess_.get()) { |
731 return subprocess_->GetCrashLogOutput(); | 775 return subprocess_->GetCrashLogOutput(); |
732 } else { | 776 } else { |
733 return std::string(); | 777 return std::string(); |
734 } | 778 } |
735 } | 779 } |
736 | 780 |
737 } // namespace plugin | 781 } // namespace plugin |
OLD | NEW |