Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ppapi/proxy/output_protection_resource.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "ppapi/proxy/plugin_globals.h" | |
| 9 #include "ppapi/proxy/plugin_resource_tracker.h" | |
| 10 #include "ppapi/proxy/ppapi_messages.h" | |
| 11 #include "ppapi/shared_impl/proxy_lock.h" | |
| 12 #include "ppapi/shared_impl/resource_tracker.h" | |
| 13 #include "ppapi/shared_impl/tracked_callback.h" | |
| 14 #include "ppapi/thunk/enter.h" | |
| 15 #include "ppapi/thunk/ppb_output_protection_api.h" | |
| 16 | |
| 17 namespace ppapi { | |
| 18 namespace proxy { | |
| 19 | |
| 20 OutputProtectionResource::OutputProtectionResource( | |
| 21 Connection connection, | |
| 22 PP_Instance instance) | |
| 23 : PluginResource(connection, instance) { | |
|
dmichael (off chromium)
2013/09/09 20:37:15
please initialize link_mask_ and protection_mask_
kcwu
2013/09/10 12:50:21
Done.
| |
| 24 SendCreate(BROWSER, PpapiHostMsg_OutputProtection_Create()); | |
| 25 } | |
| 26 | |
| 27 OutputProtectionResource::~OutputProtectionResource() { | |
| 28 if (TrackedCallback::IsPending(query_status_callback_)) | |
| 29 query_status_callback_->PostAbort(); | |
| 30 if (TrackedCallback::IsPending(enable_protection_callback_)) | |
| 31 enable_protection_callback_->PostAbort(); | |
| 32 } | |
| 33 | |
| 34 thunk::PPB_OutputProtection_API* | |
| 35 OutputProtectionResource::AsPPB_OutputProtection_API() { | |
| 36 return this; | |
| 37 } | |
| 38 | |
| 39 int32_t OutputProtectionResource::QueryStatus( | |
| 40 uint32_t* link_mask, | |
| 41 uint32_t* protection_mask, | |
| 42 scoped_refptr<TrackedCallback> callback) { | |
| 43 if (!link_mask || !protection_mask) | |
| 44 return PP_ERROR_BADARGUMENT; | |
| 45 if (TrackedCallback::IsPending(query_status_callback_)) | |
| 46 return PP_ERROR_INPROGRESS; | |
|
dmichael (off chromium)
2013/09/09 20:37:15
Suggestion:
You could instead use Bind to bind |li
kcwu
2013/09/10 12:50:21
If so, do I still need to check IsPending() at the
dmichael (off chromium)
2013/09/11 18:22:45
Yes, it may still be aborted via the CallbackTrack
kcwu
2013/09/12 18:22:08
I will address this tomorrow.
| |
| 47 | |
| 48 link_mask_ = link_mask; | |
| 49 protection_mask_ = protection_mask; | |
| 50 query_status_callback_ = callback; | |
| 51 | |
| 52 Call<PpapiPluginMsg_OutputProtection_QueryStatusReply>( | |
| 53 BROWSER, | |
| 54 PpapiHostMsg_OutputProtection_QueryStatus(), | |
| 55 base::Bind(&OutputProtectionResource::OnPluginMsgQueryStatusReply, | |
| 56 base::Unretained(this))); | |
| 57 return PP_OK_COMPLETIONPENDING; | |
| 58 } | |
| 59 | |
| 60 void OutputProtectionResource::OnPluginMsgQueryStatusReply( | |
| 61 const ResourceMessageReplyParams& params, | |
| 62 uint32_t link_mask, | |
| 63 uint32_t protection_mask) { | |
| 64 // The callback may have been aborted. | |
| 65 if (!TrackedCallback::IsPending(query_status_callback_)) | |
| 66 return; | |
| 67 if (link_mask_ == NULL || protection_mask_ == NULL) | |
|
dmichael (off chromium)
2013/09/09 20:37:15
NOTREACHED()?
kcwu
2013/09/10 12:50:21
Done.
| |
| 68 return; | |
| 69 | |
| 70 int32_t result = params.result(); | |
| 71 | |
| 72 if (result == PP_OK) { | |
| 73 *link_mask_ = link_mask; | |
| 74 *protection_mask_ = protection_mask; | |
| 75 } | |
| 76 link_mask_ = NULL; | |
| 77 protection_mask_ = NULL; | |
| 78 query_status_callback_->Run(result); | |
| 79 } | |
| 80 | |
| 81 int32_t OutputProtectionResource::EnableProtection(uint32_t desired_method_mask, | |
| 82 scoped_refptr<TrackedCallback> callback) { | |
| 83 if (TrackedCallback::IsPending(enable_protection_callback_)) | |
| 84 return PP_ERROR_INPROGRESS; | |
| 85 | |
| 86 enable_protection_callback_ = callback; | |
| 87 | |
| 88 Call<PpapiPluginMsg_OutputProtection_EnableProtectionReply>( | |
| 89 BROWSER, | |
| 90 PpapiHostMsg_OutputProtection_EnableProtection(desired_method_mask), | |
| 91 base::Bind(&OutputProtectionResource::OnPluginMsgEnableProtectionReply, | |
| 92 base::Unretained(this))); | |
| 93 return PP_OK_COMPLETIONPENDING; | |
| 94 } | |
| 95 | |
| 96 void OutputProtectionResource::OnPluginMsgEnableProtectionReply( | |
| 97 const ResourceMessageReplyParams& params) { | |
| 98 // The callback may have been aborted. | |
| 99 if (TrackedCallback::IsPending(enable_protection_callback_)) | |
| 100 enable_protection_callback_->Run(params.result()); | |
| 101 } | |
| 102 | |
| 103 } // namespace proxy | |
| 104 } // namespace ppapi | |
| OLD | NEW |