Chromium Code Reviews| Index: ppapi/proxy/output_protection_resource.cc |
| diff --git a/ppapi/proxy/output_protection_resource.cc b/ppapi/proxy/output_protection_resource.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..33b2cb72938bcc2259a44c82cd1d1d01467c964e |
| --- /dev/null |
| +++ b/ppapi/proxy/output_protection_resource.cc |
| @@ -0,0 +1,104 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ppapi/proxy/output_protection_resource.h" |
| + |
| +#include "base/logging.h" |
| +#include "ppapi/proxy/plugin_globals.h" |
| +#include "ppapi/proxy/plugin_resource_tracker.h" |
| +#include "ppapi/proxy/ppapi_messages.h" |
| +#include "ppapi/shared_impl/proxy_lock.h" |
| +#include "ppapi/shared_impl/resource_tracker.h" |
| +#include "ppapi/shared_impl/tracked_callback.h" |
| +#include "ppapi/thunk/enter.h" |
| +#include "ppapi/thunk/ppb_output_protection_api.h" |
| + |
| +namespace ppapi { |
| +namespace proxy { |
| + |
| +OutputProtectionResource::OutputProtectionResource( |
| + Connection connection, |
| + PP_Instance instance) |
| + : 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.
|
| + SendCreate(BROWSER, PpapiHostMsg_OutputProtection_Create()); |
| +} |
| + |
| +OutputProtectionResource::~OutputProtectionResource() { |
| + if (TrackedCallback::IsPending(query_status_callback_)) |
| + query_status_callback_->PostAbort(); |
| + if (TrackedCallback::IsPending(enable_protection_callback_)) |
| + enable_protection_callback_->PostAbort(); |
| +} |
| + |
| +thunk::PPB_OutputProtection_API* |
| + OutputProtectionResource::AsPPB_OutputProtection_API() { |
| + return this; |
| +} |
| + |
| +int32_t OutputProtectionResource::QueryStatus( |
| + uint32_t* link_mask, |
| + uint32_t* protection_mask, |
| + scoped_refptr<TrackedCallback> callback) { |
| + if (!link_mask || !protection_mask) |
| + return PP_ERROR_BADARGUMENT; |
| + if (TrackedCallback::IsPending(query_status_callback_)) |
| + 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.
|
| + |
| + link_mask_ = link_mask; |
| + protection_mask_ = protection_mask; |
| + query_status_callback_ = callback; |
| + |
| + Call<PpapiPluginMsg_OutputProtection_QueryStatusReply>( |
| + BROWSER, |
| + PpapiHostMsg_OutputProtection_QueryStatus(), |
| + base::Bind(&OutputProtectionResource::OnPluginMsgQueryStatusReply, |
| + base::Unretained(this))); |
| + return PP_OK_COMPLETIONPENDING; |
| +} |
| + |
| +void OutputProtectionResource::OnPluginMsgQueryStatusReply( |
| + const ResourceMessageReplyParams& params, |
| + uint32_t link_mask, |
| + uint32_t protection_mask) { |
| + // The callback may have been aborted. |
| + if (!TrackedCallback::IsPending(query_status_callback_)) |
| + return; |
| + 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.
|
| + return; |
| + |
| + int32_t result = params.result(); |
| + |
| + if (result == PP_OK) { |
| + *link_mask_ = link_mask; |
| + *protection_mask_ = protection_mask; |
| + } |
| + link_mask_ = NULL; |
| + protection_mask_ = NULL; |
| + query_status_callback_->Run(result); |
| +} |
| + |
| +int32_t OutputProtectionResource::EnableProtection(uint32_t desired_method_mask, |
| + scoped_refptr<TrackedCallback> callback) { |
| + if (TrackedCallback::IsPending(enable_protection_callback_)) |
| + return PP_ERROR_INPROGRESS; |
| + |
| + enable_protection_callback_ = callback; |
| + |
| + Call<PpapiPluginMsg_OutputProtection_EnableProtectionReply>( |
| + BROWSER, |
| + PpapiHostMsg_OutputProtection_EnableProtection(desired_method_mask), |
| + base::Bind(&OutputProtectionResource::OnPluginMsgEnableProtectionReply, |
| + base::Unretained(this))); |
| + return PP_OK_COMPLETIONPENDING; |
| +} |
| + |
| +void OutputProtectionResource::OnPluginMsgEnableProtectionReply( |
| + const ResourceMessageReplyParams& params) { |
| + // The callback may have been aborted. |
| + if (TrackedCallback::IsPending(enable_protection_callback_)) |
| + enable_protection_callback_->Run(params.result()); |
| +} |
| + |
| +} // namespace proxy |
| +} // namespace ppapi |