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

Side by Side Diff: ppapi/native_client/src/trusted/plugin/plugin.cc

Issue 149403005: Pepper: Make StartSelLdr asynchronous. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CompletionCallback cleanup in service_runtime Created 6 years, 10 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifdef _MSC_VER 5 #ifdef _MSC_VER
6 // Do not warn about use of std::copy with raw pointers. 6 // Do not warn about use of std::copy with raw pointers.
7 #pragma warning(disable : 4996) 7 #pragma warning(disable : 4996)
8 #endif 8 #endif
9 9
10 #include "ppapi/native_client/src/trusted/plugin/plugin.h" 10 #include "ppapi/native_client/src/trusted/plugin/plugin.h"
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 ServiceRuntime* service_runtime = 295 ServiceRuntime* service_runtime =
296 new ServiceRuntime(this, manifest, false, 296 new ServiceRuntime(this, manifest, false,
297 pp::BlockUntilComplete(), pp::BlockUntilComplete()); 297 pp::BlockUntilComplete(), pp::BlockUntilComplete());
298 subprocess->set_service_runtime(service_runtime); 298 subprocess->set_service_runtime(service_runtime);
299 PLUGIN_PRINTF(("Plugin::LoadNaClModuleFromBackgroundThread " 299 PLUGIN_PRINTF(("Plugin::LoadNaClModuleFromBackgroundThread "
300 "(service_runtime=%p)\n", 300 "(service_runtime=%p)\n",
301 static_cast<void*>(service_runtime))); 301 static_cast<void*>(service_runtime)));
302 302
303 // Now start the SelLdr instance. This must be created on the main thread. 303 // Now start the SelLdr instance. This must be created on the main thread.
304 bool service_runtime_started; 304 bool service_runtime_started;
305 pp::CompletionCallback sel_ldr_callback =
306 callback_factory_.NewCallback(&Plugin::SignalStartSelLdrDone,
307 &service_runtime_started,
308 service_runtime);
305 pp::CompletionCallback callback = 309 pp::CompletionCallback callback =
306 callback_factory_.NewCallback(&Plugin::StartSelLdrOnMainThread, 310 callback_factory_.NewCallback(&Plugin::StartSelLdrOnMainThread,
307 service_runtime, params, 311 service_runtime, params,
308 &service_runtime_started); 312 sel_ldr_callback);
309 pp::Module::Get()->core()->CallOnMainThread(0, callback, 0); 313 pp::Module::Get()->core()->CallOnMainThread(0, callback, 0);
310 service_runtime->WaitForSelLdrStart(); 314 service_runtime->WaitForSelLdrStart();
311 PLUGIN_PRINTF(("Plugin::LoadNaClModuleFromBackgroundThread " 315 PLUGIN_PRINTF(("Plugin::LoadNaClModuleFromBackgroundThread "
312 "(service_runtime_started=%d)\n", 316 "(service_runtime_started=%d)\n",
313 service_runtime_started)); 317 service_runtime_started));
314 if (!service_runtime_started) { 318 if (!service_runtime_started) {
315 return false; 319 return false;
316 } 320 }
317 321
318 // Now actually load the nexe, which can happen on a background thread. 322 // Now actually load the nexe, which can happen on a background thread.
319 bool nexe_loaded = service_runtime->LoadNexeAndStart( 323 bool nexe_loaded = service_runtime->LoadNexeAndStart(
320 wrapper, pp::BlockUntilComplete()); 324 wrapper, pp::BlockUntilComplete());
321 PLUGIN_PRINTF(("Plugin::LoadNaClModuleFromBackgroundThread " 325 PLUGIN_PRINTF(("Plugin::LoadNaClModuleFromBackgroundThread "
322 "(nexe_loaded=%d)\n", 326 "(nexe_loaded=%d)\n",
323 nexe_loaded)); 327 nexe_loaded));
324 return nexe_loaded; 328 return nexe_loaded;
325 } 329 }
326 330
327 void Plugin::StartSelLdrOnMainThread(int32_t pp_error, 331 void Plugin::StartSelLdrOnMainThread(int32_t pp_error,
328 ServiceRuntime* service_runtime, 332 ServiceRuntime* service_runtime,
329 const SelLdrStartParams& params, 333 const SelLdrStartParams& params,
330 bool* success) { 334 pp::CompletionCallback callback) {
331 if (pp_error != PP_OK) { 335 if (pp_error != PP_OK) {
332 PLUGIN_PRINTF(("Plugin::StartSelLdrOnMainThread: non-PP_OK arg " 336 PLUGIN_PRINTF(("Plugin::StartSelLdrOnMainThread: non-PP_OK arg "
333 "-- SHOULD NOT HAPPEN\n")); 337 "-- SHOULD NOT HAPPEN\n"));
334 *success = false; 338 pp::Module::Get()->core()->CallOnMainThread(0, callback, pp_error);
335 return; 339 return;
336 } 340 }
337 *success = service_runtime->StartSelLdr(params); 341 service_runtime->StartSelLdr(params, callback);
338 // Signal outside of StartSelLdr here, so that the write to *success 342 }
339 // is done before signaling. 343
344 void Plugin::SignalStartSelLdrDone(int32_t pp_error,
345 bool* started,
346 ServiceRuntime* service_runtime) {
347 *started = (pp_error == PP_OK);
340 service_runtime->SignalStartSelLdrDone(); 348 service_runtime->SignalStartSelLdrDone();
341 } 349 }
342 350
343 void Plugin::LoadNaClModule(nacl::DescWrapper* wrapper, 351 void Plugin::LoadNaClModule(nacl::DescWrapper* wrapper,
344 bool enable_dyncode_syscalls, 352 bool enable_dyncode_syscalls,
345 bool enable_exception_handling, 353 bool enable_exception_handling,
346 bool enable_crash_throttling, 354 bool enable_crash_throttling,
347 const pp::CompletionCallback& init_done_cb, 355 const pp::CompletionCallback& init_done_cb,
348 const pp::CompletionCallback& crash_cb) { 356 const pp::CompletionCallback& crash_cb) {
357 nacl::scoped_ptr<nacl::DescWrapper> scoped_wrapper(wrapper);
349 CHECK(pp::Module::Get()->core()->IsMainThread()); 358 CHECK(pp::Module::Get()->core()->IsMainThread());
350 // Before forking a new sel_ldr process, ensure that we do not leak 359 // Before forking a new sel_ldr process, ensure that we do not leak
351 // the ServiceRuntime object for an existing subprocess, and that any 360 // the ServiceRuntime object for an existing subprocess, and that any
352 // associated listener threads do not go unjoined because if they 361 // associated listener threads do not go unjoined because if they
353 // outlive the Plugin object, they will not be memory safe. 362 // outlive the Plugin object, they will not be memory safe.
354 ShutDownSubprocesses(); 363 ShutDownSubprocesses();
355 SelLdrStartParams params(manifest_base_url(), 364 SelLdrStartParams params(manifest_base_url(),
356 true /* uses_irt */, 365 true /* uses_irt */,
357 true /* uses_ppapi */, 366 true /* uses_ppapi */,
358 enable_dev_interfaces_, 367 enable_dev_interfaces_,
359 enable_dyncode_syscalls, 368 enable_dyncode_syscalls,
360 enable_exception_handling, 369 enable_exception_handling,
361 enable_crash_throttling); 370 enable_crash_throttling);
362 ErrorInfo error_info; 371 ErrorInfo error_info;
363 ServiceRuntime* service_runtime = 372 ServiceRuntime* service_runtime =
364 new ServiceRuntime(this, manifest_.get(), true, init_done_cb, crash_cb); 373 new ServiceRuntime(this, manifest_.get(), true, init_done_cb, crash_cb);
365 main_subprocess_.set_service_runtime(service_runtime); 374 main_subprocess_.set_service_runtime(service_runtime);
366 PLUGIN_PRINTF(("Plugin::LoadNaClModule (service_runtime=%p)\n", 375 PLUGIN_PRINTF(("Plugin::LoadNaClModule (service_runtime=%p)\n",
367 static_cast<void*>(service_runtime))); 376 static_cast<void*>(service_runtime)));
368 if (NULL == service_runtime) { 377 if (NULL == service_runtime) {
369 error_info.SetReport( 378 error_info.SetReport(
370 ERROR_SEL_LDR_INIT, 379 ERROR_SEL_LDR_INIT,
371 "sel_ldr init failure " + main_subprocess_.description()); 380 "sel_ldr init failure " + main_subprocess_.description());
372 ReportLoadError(error_info); 381 ReportLoadError(error_info);
373 return; 382 return;
374 } 383 }
375 384
376 // Now start the SelLdr instance. This must be created on the main thread. 385 pp::CompletionCallback callback = callback_factory_.NewCallback(
377 bool service_runtime_started; 386 &Plugin::LoadNexeAndStart, scoped_wrapper.release(), service_runtime,
378 StartSelLdrOnMainThread(PP_OK, service_runtime, params, 387 crash_cb);
379 &service_runtime_started); 388 StartSelLdrOnMainThread(
380 PLUGIN_PRINTF(("Plugin::LoadNaClModule (service_runtime_started=%d)\n", 389 static_cast<int32_t>(PP_OK), service_runtime, params, callback);
381 service_runtime_started)); 390 }
382 if (!service_runtime_started) { 391
392 void Plugin::LoadNexeAndStart(int32_t pp_error,
393 nacl::DescWrapper* wrapper,
394 ServiceRuntime* service_runtime,
395 const pp::CompletionCallback& crash_cb) {
396 nacl::scoped_ptr<nacl::DescWrapper> scoped_wrapper(wrapper);
397 if (pp_error != PP_OK)
383 return; 398 return;
384 }
385 399
386 // Now actually load the nexe, which can happen on a background thread. 400 // Now actually load the nexe, which can happen on a background thread.
387 bool nexe_loaded = service_runtime->LoadNexeAndStart(wrapper, crash_cb); 401 bool nexe_loaded = service_runtime->LoadNexeAndStart(wrapper, crash_cb);
388 PLUGIN_PRINTF(("Plugin::LoadNaClModule (nexe_loaded=%d)\n", 402 PLUGIN_PRINTF(("Plugin::LoadNaClModule (nexe_loaded=%d)\n",
389 nexe_loaded)); 403 nexe_loaded));
390 if (nexe_loaded) { 404 if (nexe_loaded) {
391 PLUGIN_PRINTF(("Plugin::LoadNaClModule (%s)\n", 405 PLUGIN_PRINTF(("Plugin::LoadNaClModule (%s)\n",
392 main_subprocess_.detailed_description().c_str())); 406 main_subprocess_.detailed_description().c_str()));
393 } 407 }
394 } 408 }
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 nexe_downloader_.url_to_open(), 793 nexe_downloader_.url_to_open(),
780 LENGTH_IS_COMPUTABLE, 794 LENGTH_IS_COMPUTABLE,
781 nexe_bytes_read, 795 nexe_bytes_read,
782 nexe_bytes_read); 796 nexe_bytes_read);
783 797
784 load_start_ = NaClGetTimeOfDayMicroseconds(); 798 load_start_ = NaClGetTimeOfDayMicroseconds();
785 nacl::scoped_ptr<nacl::DescWrapper> 799 nacl::scoped_ptr<nacl::DescWrapper>
786 wrapper(wrapper_factory()->MakeFileDesc(file_desc_ok_to_close, O_RDONLY)); 800 wrapper(wrapper_factory()->MakeFileDesc(file_desc_ok_to_close, O_RDONLY));
787 NaClLog(4, "NexeFileDidOpen: invoking LoadNaClModule\n"); 801 NaClLog(4, "NexeFileDidOpen: invoking LoadNaClModule\n");
788 LoadNaClModule( 802 LoadNaClModule(
789 wrapper.get(), 803 wrapper.release(),
790 true, /* enable_dyncode_syscalls */ 804 true, /* enable_dyncode_syscalls */
791 true, /* enable_exception_handling */ 805 true, /* enable_exception_handling */
792 false, /* enable_crash_throttling */ 806 false, /* enable_crash_throttling */
793 callback_factory_.NewCallback(&Plugin::NexeFileDidOpenContinuation), 807 callback_factory_.NewCallback(&Plugin::NexeFileDidOpenContinuation),
794 callback_factory_.NewCallback(&Plugin::NexeDidCrash)); 808 callback_factory_.NewCallback(&Plugin::NexeDidCrash));
795 } 809 }
796 810
797 void Plugin::NexeFileDidOpenContinuation(int32_t pp_error) { 811 void Plugin::NexeFileDidOpenContinuation(int32_t pp_error) {
798 ErrorInfo error_info; 812 ErrorInfo error_info;
799 bool was_successful; 813 bool was_successful;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 if (pp_error != PP_OK) { 910 if (pp_error != PP_OK) {
897 // Error should have been reported by pnacl. Just return. 911 // Error should have been reported by pnacl. Just return.
898 PLUGIN_PRINTF(("Plugin::BitcodeDidTranslate error in Pnacl\n")); 912 PLUGIN_PRINTF(("Plugin::BitcodeDidTranslate error in Pnacl\n"));
899 return; 913 return;
900 } 914 }
901 915
902 // Inform JavaScript that we successfully translated the bitcode to a nexe. 916 // Inform JavaScript that we successfully translated the bitcode to a nexe.
903 nacl::scoped_ptr<nacl::DescWrapper> 917 nacl::scoped_ptr<nacl::DescWrapper>
904 wrapper(pnacl_coordinator_.get()->ReleaseTranslatedFD()); 918 wrapper(pnacl_coordinator_.get()->ReleaseTranslatedFD());
905 LoadNaClModule( 919 LoadNaClModule(
906 wrapper.get(), 920 wrapper.release(),
907 false, /* enable_dyncode_syscalls */ 921 false, /* enable_dyncode_syscalls */
908 false, /* enable_exception_handling */ 922 false, /* enable_exception_handling */
909 true, /* enable_crash_throttling */ 923 true, /* enable_crash_throttling */
910 callback_factory_.NewCallback(&Plugin::BitcodeDidTranslateContinuation), 924 callback_factory_.NewCallback(&Plugin::BitcodeDidTranslateContinuation),
911 callback_factory_.NewCallback(&Plugin::NexeDidCrash)); 925 callback_factory_.NewCallback(&Plugin::NexeDidCrash));
912 } 926 }
913 927
914 void Plugin::BitcodeDidTranslateContinuation(int32_t pp_error) { 928 void Plugin::BitcodeDidTranslateContinuation(int32_t pp_error) {
915 ErrorInfo error_info; 929 ErrorInfo error_info;
916 bool was_successful = LoadNaClModuleContinuationIntern(&error_info); 930 bool was_successful = LoadNaClModuleContinuationIntern(&error_info);
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after
1515 DCHECK(pp::Module::Get()->core()->IsMainThread()); 1529 DCHECK(pp::Module::Get()->core()->IsMainThread());
1516 DCHECK(nacl_interface_); 1530 DCHECK(nacl_interface_);
1517 exit_status_ = exit_status; 1531 exit_status_ = exit_status;
1518 nacl_interface_->SetReadOnlyProperty(pp_instance(), 1532 nacl_interface_->SetReadOnlyProperty(pp_instance(),
1519 pp::Var("exitStatus").pp_var(), 1533 pp::Var("exitStatus").pp_var(),
1520 pp::Var(exit_status_).pp_var()); 1534 pp::Var(exit_status_).pp_var());
1521 } 1535 }
1522 1536
1523 1537
1524 } // namespace plugin 1538 } // namespace plugin
OLDNEW
« no previous file with comments | « ppapi/native_client/src/trusted/plugin/plugin.h ('k') | ppapi/native_client/src/trusted/plugin/sel_ldr_launcher_chrome.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698