| 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 | |
| 318 NaClLog(4, "Entered OpenManifestEntry_MainThreadContinuation\n"); | 317 NaClLog(4, "Entered OpenManifestEntry_MainThreadContinuation\n"); |
| 319 | 318 |
| 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 | |
| 361 // Because p is owned by the callback of this invocation, so it is necessary | 319 // Because p is owned by the callback of this invocation, so it is necessary |
| 362 // to create another instance. | 320 // to create another instance. |
| 363 OpenManifestEntryResource* open_cont = new OpenManifestEntryResource(*p); | 321 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; | |
| 368 | 322 |
| 369 pp::CompletionCallback stream_cc = WeakRefNewCallback( | 323 pp::CompletionCallback stream_cc = WeakRefNewCallback( |
| 370 anchor_, | 324 anchor_, |
| 371 this, | 325 this, |
| 372 &PluginReverseInterface::StreamAsFile_MainThreadContinuation, | 326 &PluginReverseInterface::StreamAsFile_MainThreadContinuation, |
| 373 open_cont); | 327 open_cont); |
| 374 | 328 |
| 375 GetNaClInterface()->DownloadFile(plugin_->pp_instance(), | 329 GetNaClInterface()->OpenManifestEntry( |
| 376 mapped_url.c_str(), | 330 plugin_->pp_instance(), |
| 377 &open_cont->pp_file_info, | 331 PP_FromBool(!service_runtime_->main_service_runtime()), |
| 378 stream_cc.pp_completion_callback()); | 332 p->url.c_str(), |
| 333 &open_cont->pp_file_info, |
| 334 stream_cc.pp_completion_callback()); |
| 379 // p is deleted automatically. | 335 // p is deleted automatically. |
| 380 } | 336 } |
| 381 | 337 |
| 382 void PluginReverseInterface::StreamAsFile_MainThreadContinuation( | 338 void PluginReverseInterface::StreamAsFile_MainThreadContinuation( |
| 383 OpenManifestEntryResource* p, | 339 OpenManifestEntryResource* p, |
| 384 int32_t result) { | 340 int32_t result) { |
| 385 NaClLog(4, "Entered StreamAsFile_MainThreadContinuation\n"); | 341 NaClLog(4, "Entered StreamAsFile_MainThreadContinuation\n"); |
| 386 { | 342 { |
| 387 nacl::MutexLocker take(&mu_); | 343 nacl::MutexLocker take(&mu_); |
| 388 if (result == PP_OK) { | 344 if (result == PP_OK) { |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 | 728 |
| 773 nacl::string ServiceRuntime::GetCrashLogOutput() { | 729 nacl::string ServiceRuntime::GetCrashLogOutput() { |
| 774 if (NULL != subprocess_.get()) { | 730 if (NULL != subprocess_.get()) { |
| 775 return subprocess_->GetCrashLogOutput(); | 731 return subprocess_->GetCrashLogOutput(); |
| 776 } else { | 732 } else { |
| 777 return std::string(); | 733 return std::string(); |
| 778 } | 734 } |
| 779 } | 735 } |
| 780 | 736 |
| 781 } // namespace plugin | 737 } // namespace plugin |
| OLD | NEW |