Commit 36e91cd9 authored by dmichael's avatar dmichael Committed by Commit bot

PPAPI: Make CallWhileUnlocked more permissive.

Prior to this patch, CallWhileUnlocked required its parameters' types to
be perfect matches to the types in the function pointer it's meant to
invoke. This is counter to programmers' usual expectations for function
calls, since the compiler will usually do safe casts like add const or
promoting integral types. This just adds template params to CallWhileUnlocked
so that any call with the appropriate number of parameters will be a template
match. The compiler will still decide if there is a valid implicit conversion,
so this is still safe in the sense that mismatched params still won't
compile.

BUG=160925

Review URL: https://codereview.chromium.org/552423003

Cr-Commit-Position: refs/heads/master@{#294405}
parent c4bd497f
......@@ -688,7 +688,7 @@ void PPP_ContentDecryptor_Private_Proxy::OnMsgDecrypt(
CallWhileUnlocked(ppp_decryptor_impl_->Decrypt,
instance,
plugin_resource.get(),
const_cast<const PP_EncryptedBlockInfo*>(&block_info));
&block_info);
}
}
......@@ -713,7 +713,7 @@ void PPP_ContentDecryptor_Private_Proxy::OnMsgInitializeAudioDecoder(
CallWhileUnlocked(
ppp_decryptor_impl_->InitializeAudioDecoder,
instance,
const_cast<const PP_AudioDecoderConfig*>(&decoder_config),
&decoder_config,
plugin_resource.get());
}
}
......@@ -739,7 +739,7 @@ void PPP_ContentDecryptor_Private_Proxy::OnMsgInitializeVideoDecoder(
CallWhileUnlocked(
ppp_decryptor_impl_->InitializeVideoDecoder,
instance,
const_cast<const PP_VideoDecoderConfig*>(&decoder_config),
&decoder_config,
plugin_resource.get());
}
}
......@@ -793,7 +793,7 @@ void PPP_ContentDecryptor_Private_Proxy::OnMsgDecryptAndDecode(
instance,
decoder_type,
plugin_resource.get(),
const_cast<const PP_EncryptedBlockInfo*>(&block_info));
&block_info);
}
}
......
......@@ -167,11 +167,8 @@ void PPP_Printing_Proxy::OnPluginMsgBegin(PP_Instance instance,
return;
memcpy(&settings, &settings_string[0], sizeof(settings));
if (ppp_printing_impl_) {
*result = CallWhileUnlocked(ppp_printing_impl_->Begin,
instance,
const_cast<const PP_PrintSettings_Dev*>(&settings));
}
if (ppp_printing_impl_)
*result = CallWhileUnlocked(ppp_printing_impl_->Begin, instance, &settings);
}
void PPP_Printing_Proxy::OnPluginMsgPrintPages(
......@@ -183,7 +180,7 @@ void PPP_Printing_Proxy::OnPluginMsgPrintPages(
PP_Resource plugin_resource = CallWhileUnlocked(
ppp_printing_impl_->PrintPages,
instance, &pages[0], static_cast<uint32_t>(pages.size()));
instance, &pages[0], pages.size());
ResourceTracker* resource_tracker = PpapiGlobals::Get()->GetResourceTracker();
Resource* resource_object = resource_tracker->GetResource(plugin_resource);
if (!resource_object)
......
......@@ -166,8 +166,8 @@ void VideoCaptureResource::OnPluginMsgOnDeviceInfo(
pp_instance(),
pp_resource(),
&info,
static_cast<uint32_t>(buffers.size()),
const_cast<const PP_Resource*>(resources.get()));
buffers.size(),
resources.get());
for (size_t i = 0; i < buffers.size(); ++i)
tracker->ReleaseResource(resources[i]);
......
......@@ -117,28 +117,34 @@ ReturnType CallWhileUnlocked(ReturnType (*function)()) {
ProxyAutoUnlock unlock;
return function();
}
template <class ReturnType, class P1>
ReturnType CallWhileUnlocked(ReturnType (*function)(P1), const P1& p1) {
// Note we use 2 types for the params, even though for the most part we expect
// A1 to match P1. We let the compiler determine if P1 can convert safely to
// A1. This allows callers to avoid having to do things like
// const_cast to add const.
template <class ReturnType, class A1, class P1>
ReturnType CallWhileUnlocked(ReturnType (*function)(A1), const P1& p1) {
ProxyAutoUnlock unlock;
return function(p1);
}
template <class ReturnType, class P1, class P2>
ReturnType CallWhileUnlocked(ReturnType (*function)(P1, P2),
template <class ReturnType, class A1, class A2, class P1, class P2>
ReturnType CallWhileUnlocked(ReturnType (*function)(A1, A2),
const P1& p1,
const P2& p2) {
ProxyAutoUnlock unlock;
return function(p1, p2);
}
template <class ReturnType, class P1, class P2, class P3>
ReturnType CallWhileUnlocked(ReturnType (*function)(P1, P2, P3),
template <class ReturnType, class A1, class A2, class A3, class P1, class P2,
class P3>
ReturnType CallWhileUnlocked(ReturnType (*function)(A1, A2, A3),
const P1& p1,
const P2& p2,
const P3& p3) {
ProxyAutoUnlock unlock;
return function(p1, p2, p3);
}
template <class ReturnType, class P1, class P2, class P3, class P4>
ReturnType CallWhileUnlocked(ReturnType (*function)(P1, P2, P3, P4),
template <class ReturnType, class A1, class A2, class A3, class A4, class P1,
class P2, class P3, class P4>
ReturnType CallWhileUnlocked(ReturnType (*function)(A1, A2, A3, A4),
const P1& p1,
const P2& p2,
const P3& p3,
......@@ -146,8 +152,9 @@ ReturnType CallWhileUnlocked(ReturnType (*function)(P1, P2, P3, P4),
ProxyAutoUnlock unlock;
return function(p1, p2, p3, p4);
}
template <class ReturnType, class P1, class P2, class P3, class P4, class P5>
ReturnType CallWhileUnlocked(ReturnType (*function)(P1, P2, P3, P4, P5),
template <class ReturnType, class A1, class A2, class A3, class A4, class A5,
class P1, class P2, class P3, class P4, class P5>
ReturnType CallWhileUnlocked(ReturnType (*function)(A1, A2, A3, A4, A5),
const P1& p1,
const P2& p2,
const P3& p3,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment