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

Side by Side Diff: ppapi/proxy/ppb_instance_proxy.cc

Issue 10081020: PPAPI: Make blocking completion callbacks work. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: export AssertLockHeld Created 8 years, 6 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 | « ppapi/proxy/ppb_instance_proxy.h ('k') | ppapi/proxy/ppb_message_loop_proxy.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 (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 #include "ppapi/proxy/ppb_instance_proxy.h" 5 #include "ppapi/proxy/ppb_instance_proxy.h"
6 6
7 #include "ppapi/c/pp_errors.h" 7 #include "ppapi/c/pp_errors.h"
8 #include "ppapi/c/pp_time.h" 8 #include "ppapi/c/pp_time.h"
9 #include "ppapi/c/pp_var.h" 9 #include "ppapi/c/pp_var.h"
10 #include "ppapi/c/ppb_audio_config.h" 10 #include "ppapi/c/ppb_audio_config.h"
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetCursor( 430 dispatcher()->Send(new PpapiHostMsg_PPBInstance_SetCursor(
431 API_ID_PPB_INSTANCE, instance, static_cast<int32_t>(type), 431 API_ID_PPB_INSTANCE, instance, static_cast<int32_t>(type),
432 image_host_resource, hot_spot ? *hot_spot : PP_MakePoint(0, 0))); 432 image_host_resource, hot_spot ? *hot_spot : PP_MakePoint(0, 0)));
433 return PP_TRUE; 433 return PP_TRUE;
434 #else // defined(OS_NACL) 434 #else // defined(OS_NACL)
435 return PP_FALSE; 435 return PP_FALSE;
436 #endif 436 #endif
437 } 437 }
438 438
439 int32_t PPB_Instance_Proxy::LockMouse(PP_Instance instance, 439 int32_t PPB_Instance_Proxy::LockMouse(PP_Instance instance,
440 PP_CompletionCallback callback) { 440 scoped_refptr<TrackedCallback> callback) {
441 if (!callback.func)
442 return PP_ERROR_BADARGUMENT;
443
444 // Save the mouse callback on the instance data. 441 // Save the mouse callback on the instance data.
445 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())-> 442 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
446 GetInstanceData(instance); 443 GetInstanceData(instance);
447 if (!data) 444 if (!data)
448 return PP_ERROR_BADARGUMENT; 445 return PP_ERROR_BADARGUMENT;
449 if (data->mouse_lock_callback.func) 446 if (TrackedCallback::IsPending(data->mouse_lock_callback))
450 return PP_ERROR_INPROGRESS; // Already have a pending callback. 447 return PP_ERROR_INPROGRESS; // Already have a pending callback.
451 data->mouse_lock_callback = callback; 448 data->mouse_lock_callback = callback;
452 449
453 dispatcher()->Send(new PpapiHostMsg_PPBInstance_LockMouse( 450 dispatcher()->Send(new PpapiHostMsg_PPBInstance_LockMouse(
454 API_ID_PPB_INSTANCE, instance)); 451 API_ID_PPB_INSTANCE, instance));
455 return PP_OK_COMPLETIONPENDING; 452 return PP_OK_COMPLETIONPENDING;
456 } 453 }
457 454
458 void PPB_Instance_Proxy::UnlockMouse(PP_Instance instance) { 455 void PPB_Instance_Proxy::UnlockMouse(PP_Instance instance) {
459 dispatcher()->Send(new PpapiHostMsg_PPBInstance_UnlockMouse( 456 dispatcher()->Send(new PpapiHostMsg_PPBInstance_UnlockMouse(
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 // Need to be careful to always issue the callback. 644 // Need to be careful to always issue the callback.
648 pp::CompletionCallback cb = callback_factory_.NewCallback( 645 pp::CompletionCallback cb = callback_factory_.NewCallback(
649 &PPB_Instance_Proxy::MouseLockCompleteInHost, instance); 646 &PPB_Instance_Proxy::MouseLockCompleteInHost, instance);
650 647
651 EnterInstanceNoLock enter(instance); 648 EnterInstanceNoLock enter(instance);
652 if (enter.failed()) { 649 if (enter.failed()) {
653 cb.Run(PP_ERROR_BADARGUMENT); 650 cb.Run(PP_ERROR_BADARGUMENT);
654 return; 651 return;
655 } 652 }
656 int32_t result = enter.functions()->LockMouse(instance, 653 int32_t result = enter.functions()->LockMouse(instance,
657 cb.pp_completion_callback()); 654 enter.callback());
658 if (result != PP_OK_COMPLETIONPENDING) 655 if (result != PP_OK_COMPLETIONPENDING)
659 cb.Run(result); 656 cb.Run(result);
660 } 657 }
661 658
662 void PPB_Instance_Proxy::OnHostMsgUnlockMouse(PP_Instance instance) { 659 void PPB_Instance_Proxy::OnHostMsgUnlockMouse(PP_Instance instance) {
663 EnterInstanceNoLock enter(instance); 660 EnterInstanceNoLock enter(instance);
664 if (enter.succeeded()) 661 if (enter.succeeded())
665 enter.functions()->UnlockMouse(instance); 662 enter.functions()->UnlockMouse(instance);
666 } 663 }
667 664
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 } 710 }
714 711
715 void PPB_Instance_Proxy::OnHostMsgDocumentCanAccessDocument(PP_Instance active, 712 void PPB_Instance_Proxy::OnHostMsgDocumentCanAccessDocument(PP_Instance active,
716 PP_Instance target, 713 PP_Instance target,
717 PP_Bool* result) { 714 PP_Bool* result) {
718 EnterInstanceNoLock enter(active); 715 EnterInstanceNoLock enter(active);
719 if (enter.succeeded()) 716 if (enter.succeeded())
720 *result = enter.functions()->DocumentCanAccessDocument(active, target); 717 *result = enter.functions()->DocumentCanAccessDocument(active, target);
721 } 718 }
722 719
723 void PPB_Instance_Proxy::OnHostMsgGetDocumentURL(PP_Instance instance, 720 void PPB_Instance_Proxy::OnHostMsgGetDocumentURL(
724 SerializedVarReturnValue result ) { 721 PP_Instance instance,
722 SerializedVarReturnValue result) {
725 EnterInstanceNoLock enter(instance); 723 EnterInstanceNoLock enter(instance);
726 if (enter.succeeded()) { 724 if (enter.succeeded()) {
727 result.Return(dispatcher(), 725 result.Return(dispatcher(),
728 enter.functions()->GetDocumentURL(instance, NULL)); 726 enter.functions()->GetDocumentURL(instance, NULL));
729 } 727 }
730 } 728 }
731 729
732 void PPB_Instance_Proxy::OnHostMsgGetPluginInstanceURL( 730 void PPB_Instance_Proxy::OnHostMsgGetPluginInstanceURL(
733 PP_Instance instance, 731 PP_Instance instance,
734 SerializedVarReturnValue result) { 732 SerializedVarReturnValue result) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 } 785 }
788 } 786 }
789 787
790 void PPB_Instance_Proxy::OnPluginMsgMouseLockComplete(PP_Instance instance, 788 void PPB_Instance_Proxy::OnPluginMsgMouseLockComplete(PP_Instance instance,
791 int32_t result) { 789 int32_t result) {
792 // Save the mouse callback on the instance data. 790 // Save the mouse callback on the instance data.
793 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())-> 791 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
794 GetInstanceData(instance); 792 GetInstanceData(instance);
795 if (!data) 793 if (!data)
796 return; // Instance was probably deleted. 794 return; // Instance was probably deleted.
797 if (!data->mouse_lock_callback.func) { 795 if (TrackedCallback::IsPending(data->mouse_lock_callback)) {
798 NOTREACHED(); 796 NOTREACHED();
799 return; 797 return;
800 } 798 }
801 PP_RunAndClearCompletionCallback(&data->mouse_lock_callback, result); 799 TrackedCallback::ClearAndRun(&(data->mouse_lock_callback), result);
802 } 800 }
803 801
804 void PPB_Instance_Proxy::MouseLockCompleteInHost(int32_t result, 802 void PPB_Instance_Proxy::MouseLockCompleteInHost(int32_t result,
805 PP_Instance instance) { 803 PP_Instance instance) {
806 dispatcher()->Send(new PpapiMsg_PPBInstance_MouseLockComplete( 804 dispatcher()->Send(new PpapiMsg_PPBInstance_MouseLockComplete(
807 API_ID_PPB_INSTANCE, instance, result)); 805 API_ID_PPB_INSTANCE, instance, result));
808 } 806 }
809 807
810 } // namespace proxy 808 } // namespace proxy
811 } // namespace ppapi 809 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/ppb_instance_proxy.h ('k') | ppapi/proxy/ppb_message_loop_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698