Bug 1268313: Part 3 - Replace some NewCancelableRunnableMethod with NS_NewNonOwningCancelableRunnableMethod. r=froydnj

This commit is contained in:
Kyle Huey 2016-05-05 01:44:59 -07:00
Родитель 7311b10562
Коммит 7f54121b91
6 изменённых файлов: 68 добавлений и 66 удалений

Просмотреть файл

@ -112,13 +112,6 @@ static const TCHAR kPluginIgnoreSubclassProperty[] = TEXT("PluginIgnoreSubclassP
#include "PluginUtilsOSX.h"
#endif // defined(XP_MACOSX)
template<>
struct RunnableMethodTraits<PluginInstanceChild>
{
static void RetainCallee(PluginInstanceChild* obj) { }
static void ReleaseCallee(PluginInstanceChild* obj) { }
};
/**
* We can't use gfxPlatform::CreateDrawTargetForSurface() because calling
* gfxPlatform::GetPlatform() instantiates the prefs service, and that's not
@ -3299,11 +3292,8 @@ PluginInstanceChild::RecvAsyncSetWindow(const gfxSurfaceType& aSurfaceType,
// RPC call, and both Flash and Java don't expect to receive setwindow calls
// at arbitrary times.
mCurrentAsyncSetWindowTask =
NewCancelableRunnableMethod<PluginInstanceChild,
void (PluginInstanceChild::*)(const gfxSurfaceType&, const NPRemoteWindow&, bool),
const gfxSurfaceType&, const NPRemoteWindow&, bool>
(this, &PluginInstanceChild::DoAsyncSetWindow,
aSurfaceType, aWindow, true);
NS_NewNonOwningCancelableRunnableMethodWithArgs<gfxSurfaceType, NPRemoteWindow, bool>
(this, &PluginInstanceChild::DoAsyncSetWindow, aSurfaceType, aWindow, true);
RefPtr<Runnable> addrefedTask = mCurrentAsyncSetWindowTask;
MessageLoop::current()->PostTask(addrefedTask.forget());
@ -4223,7 +4213,7 @@ PluginInstanceChild::AsyncShowPluginFrame(void)
}
mCurrentInvalidateTask =
NewCancelableRunnableMethod(this, &PluginInstanceChild::InvalidateRectDelayed);
NS_NewNonOwningCancelableRunnableMethod(this, &PluginInstanceChild::InvalidateRectDelayed);
RefPtr<Runnable> addrefedTask = mCurrentInvalidateTask;
MessageLoop::current()->PostTask(addrefedTask.forget());
}

Просмотреть файл

@ -118,13 +118,6 @@ PluginInstanceParent::LookupPluginInstanceByID(uintptr_t aId)
}
#endif
template<>
struct RunnableMethodTraits<PluginInstanceParent>
{
static void RetainCallee(PluginInstanceParent* obj) { }
static void ReleaseCallee(PluginInstanceParent* obj) { }
};
PluginInstanceParent::PluginInstanceParent(PluginModuleParent* parent,
NPP npp,
const nsCString& aMimeType,
@ -1223,7 +1216,7 @@ PluginInstanceParent::ScheduleScrollCapture(int aTimeout)
}
CAPTURE_LOG("delayed scroll capture requested.");
mCaptureRefreshTask =
NewCancelableRunnableMethod(this, &PluginInstanceParent::ScheduledUpdateScrollCaptureCallback);
NS_NewNonOwningCancelableRunnableMethod(this, &PluginInstanceParent::ScheduledUpdateScrollCaptureCallback);
RefPtr<Runnable> addrefedTask = mCaptureRefreshTask;
MessageLoop::current()->PostDelayedTask(addrefedTask.forget(),
kScrollCaptureDelayMs);

Просмотреть файл

@ -68,9 +68,6 @@ public:
template<class U>
friend struct mozilla::RefPtrTraits;
template<class U>
friend struct ::RunnableMethodTraits;
template<typename U>
friend class ::mozilla::gl::RefSet;

Просмотреть файл

@ -106,8 +106,8 @@ ImageBridgeParent::ActorDestroy(ActorDestroyReason aWhy)
mSubprocess = nullptr;
}
MessageLoop::current()->PostTask(
NewRunnableMethod(this, &ImageBridgeParent::DeferredDestroy));
RefPtr<Runnable> runnable = NS_NewRunnableMethod(this, &ImageBridgeParent::DeferredDestroy);
MessageLoop::current()->PostTask(runnable.forget());
// It is very important that this method gets called at shutdown (be it a clean
// or an abnormal shutdown), because DeferredDestroy is what clears mSelfRef.

Просмотреть файл

@ -101,13 +101,6 @@ using mozilla::dom::ScriptSettingsInitialized;
using mozilla::MonitorAutoLock;
using mozilla::MonitorAutoUnlock;
template<>
struct RunnableMethodTraits<mozilla::ipc::MessageChannel>
{
static void RetainCallee(mozilla::ipc::MessageChannel* obj) { }
static void ReleaseCallee(mozilla::ipc::MessageChannel* obj) { }
};
#define IPC_ASSERT(_cond, ...) \
do { \
if (!(_cond)) \
@ -502,13 +495,13 @@ MessageChannel::MessageChannel(MessageListener *aListener)
mIsSyncWaitingOnNonMainThread = false;
#endif
mDequeueOneTask = new RefCountedTask(NewCancelableRunnableMethod(
this,
&MessageChannel::OnMaybeDequeueOne));
RefPtr<CancelableRunnable> runnable =
NS_NewNonOwningCancelableRunnableMethod(this, &MessageChannel::OnMaybeDequeueOne);
mDequeueOneTask = new RefCountedTask(runnable.forget());
mOnChannelConnectedTask = new RefCountedTask(NewCancelableRunnableMethod(
this,
&MessageChannel::DispatchOnChannelConnected));
runnable = NS_NewNonOwningCancelableRunnableMethod(this, &MessageChannel::DispatchOnChannelConnected);
mOnChannelConnectedTask = new RefCountedTask(runnable.forget());
#ifdef OS_WIN
mEvent = CreateEventW(nullptr, TRUE, FALSE, nullptr);
@ -2104,7 +2097,7 @@ MessageChannel::OnNotifyMaybeChannelError()
if (IsOnCxxStack()) {
mChannelErrorTask =
NewCancelableRunnableMethod(this, &MessageChannel::OnNotifyMaybeChannelError);
NS_NewNonOwningCancelableRunnableMethod(this, &MessageChannel::OnNotifyMaybeChannelError);
RefPtr<Runnable> task = mChannelErrorTask;
// 10 ms delay is completely arbitrary
mWorkerLoop->PostDelayedTask(task.forget(), 10);
@ -2124,7 +2117,7 @@ MessageChannel::PostErrorNotifyTask()
// This must be the last code that runs on this thread!
mChannelErrorTask =
NewCancelableRunnableMethod(this, &MessageChannel::OnNotifyMaybeChannelError);
NS_NewNonOwningCancelableRunnableMethod(this, &MessageChannel::OnNotifyMaybeChannelError);
RefPtr<Runnable> task = mChannelErrorTask;
mWorkerLoop->PostTask(task.forget());
}

Просмотреть файл

@ -283,8 +283,11 @@ nsRunnableFunction<Function>* NS_NewRunnableFunction(const Function& aFunction)
// with nsRevocableEventPtr.
template<class ClassType,
typename ReturnType = void,
bool Owning = true>
class nsRunnableMethod : public mozilla::Runnable
bool Owning = true,
bool Cancelable = false>
class nsRunnableMethod : public mozilla::Conditional<!Cancelable,
mozilla::Runnable,
mozilla::CancelableRunnable>::Type
{
public:
virtual void Revoke() = 0;
@ -328,31 +331,34 @@ struct nsRunnableMethodReceiver<ClassType, false>
void Revoke() { mObj = nullptr; }
};
template<typename Method, bool Owning> struct nsRunnableMethodTraits;
template<typename Method, bool Owning, bool Cancelable> struct nsRunnableMethodTraits;
template<class C, typename R, bool Owning, typename... As>
struct nsRunnableMethodTraits<R(C::*)(As...), Owning>
template<class C, typename R, bool Owning, bool Cancelable, typename... As>
struct nsRunnableMethodTraits<R(C::*)(As...), Owning, Cancelable>
{
typedef C class_type;
typedef R return_type;
typedef nsRunnableMethod<C, R, Owning> base_type;
typedef nsRunnableMethod<C, R, Owning, Cancelable> base_type;
static const bool can_cancel = Cancelable;
};
#ifdef NS_HAVE_STDCALL
template<class C, typename R, bool Owning, typename... As>
struct nsRunnableMethodTraits<R(__stdcall C::*)(As...), Owning>
template<class C, typename R, bool Owning, bool Cancelable, typename... As>
struct nsRunnableMethodTraits<R(__stdcall C::*)(As...), Owning, Cancelable>
{
typedef C class_type;
typedef R return_type;
typedef nsRunnableMethod<C, R, Owning> base_type;
typedef nsRunnableMethod<C, R, Owning, Cancelable> base_type;
static const bool can_cancel = Cancelable;
};
template<class C, typename R, bool Owning>
struct nsRunnableMethodTraits<R(NS_STDCALL C::*)(), Owning>
template<class C, typename R, bool Owning, bool Cancelable>
struct nsRunnableMethodTraits<R(NS_STDCALL C::*)(), Owning, Cancelable>
{
typedef C class_type;
typedef R return_type;
typedef nsRunnableMethod<C, R, Owning> base_type;
typedef nsRunnableMethod<C, R, Owning, Cancelable> base_type;
static const bool can_cancel = Cancelable;
};
#endif
@ -683,11 +689,11 @@ struct nsRunnableMethodArguments
}
};
template<typename Method, bool Owning, typename... Storages>
template<typename Method, bool Owning, bool Cancelable, typename... Storages>
class nsRunnableMethodImpl
: public nsRunnableMethodTraits<Method, Owning>::base_type
: public nsRunnableMethodTraits<Method, Owning, Cancelable>::base_type
{
typedef typename nsRunnableMethodTraits<Method, Owning>::class_type
typedef typename nsRunnableMethodTraits<Method, Owning, Cancelable>::class_type
ClassType;
nsRunnableMethodReceiver<ClassType, Owning> mReceiver;
Method mMethod;
@ -710,6 +716,11 @@ public:
}
return NS_OK;
}
nsresult Cancel() {
static_assert(Cancelable, "Don't use me!");
Revoke();
return NS_OK;
}
void Revoke() { mReceiver.Revoke(); }
};
@ -724,17 +735,24 @@ public:
// - MyClass must defined AddRef and Release methods
//
template<typename PtrType, typename Method>
typename nsRunnableMethodTraits<Method, true>::base_type*
typename nsRunnableMethodTraits<Method, true, false>::base_type*
NS_NewRunnableMethod(PtrType aPtr, Method aMethod)
{
return new nsRunnableMethodImpl<Method, true>(aPtr, aMethod);
return new nsRunnableMethodImpl<Method, true, false>(aPtr, aMethod);
}
template<typename PtrType, typename Method>
typename nsRunnableMethodTraits<Method, false>::base_type*
typename nsRunnableMethodTraits<Method, false, false>::base_type*
NS_NewNonOwningRunnableMethod(PtrType&& aPtr, Method aMethod)
{
return new nsRunnableMethodImpl<Method, false>(aPtr, aMethod);
return new nsRunnableMethodImpl<Method, false, false>(aPtr, aMethod);
}
template<typename PtrType, typename Method>
typename nsRunnableMethodTraits<Method, false, true>::base_type*
NS_NewNonOwningCancelableRunnableMethod(PtrType&& aPtr, Method aMethod)
{
return new nsRunnableMethodImpl<Method, false, true>(aPtr, aMethod);
}
// Similar to NS_NewRunnableMethod. Call like so:
@ -742,10 +760,10 @@ NS_NewNonOwningRunnableMethod(PtrType&& aPtr, Method aMethod)
// NS_NewRunnableMethodWithArg<Type>(myObject, &MyClass::HandleEvent, myArg);
// 'Type' is the stored type for the argument, see ParameterStorage for details.
template<typename Storage, typename Method, typename PtrType, typename Arg>
typename nsRunnableMethodTraits<Method, true>::base_type*
typename nsRunnableMethodTraits<Method, true, false>::base_type*
NS_NewRunnableMethodWithArg(PtrType&& aPtr, Method aMethod, Arg&& aArg)
{
return new nsRunnableMethodImpl<Method, true, Storage>(
return new nsRunnableMethodImpl<Method, true, false, Storage>(
aPtr, aMethod, mozilla::Forward<Arg>(aArg));
}
@ -754,23 +772,34 @@ NS_NewRunnableMethodWithArg(PtrType&& aPtr, Method aMethod, Arg&& aArg)
// NS_NewRunnableMethodWithArg<Types,...>(myObject, &MyClass::HandleEvent, myArg1,...);
// 'Types' are the stored type for each argument, see ParameterStorage for details.
template<typename... Storages, typename Method, typename PtrType, typename... Args>
typename nsRunnableMethodTraits<Method, true>::base_type*
typename nsRunnableMethodTraits<Method, true, false>::base_type*
NS_NewRunnableMethodWithArgs(PtrType&& aPtr, Method aMethod, Args&&... aArgs)
{
static_assert(sizeof...(Storages) == sizeof...(Args),
"<Storages...> size should be equal to number of arguments");
return new nsRunnableMethodImpl<Method, true, Storages...>(
return new nsRunnableMethodImpl<Method, true, false, Storages...>(
aPtr, aMethod, mozilla::Forward<Args>(aArgs)...);
}
template<typename... Storages, typename Method, typename PtrType, typename... Args>
typename nsRunnableMethodTraits<Method, false>::base_type*
typename nsRunnableMethodTraits<Method, false, false>::base_type*
NS_NewNonOwningRunnableMethodWithArgs(PtrType&& aPtr, Method aMethod,
Args&&... aArgs)
{
static_assert(sizeof...(Storages) == sizeof...(Args),
"<Storages...> size should be equal to number of arguments");
return new nsRunnableMethodImpl<Method, false, Storages...>(
return new nsRunnableMethodImpl<Method, false, false, Storages...>(
aPtr, aMethod, mozilla::Forward<Args>(aArgs)...);
}
template<typename... Storages, typename Method, typename PtrType, typename... Args>
typename nsRunnableMethodTraits<Method, false, true>::base_type*
NS_NewNonOwningCancelableRunnableMethodWithArgs(PtrType&& aPtr, Method aMethod,
Args&&... aArgs)
{
static_assert(sizeof...(Storages) == sizeof...(Args),
"<Storages...> size should be equal to number of arguments");
return new nsRunnableMethodImpl<Method, false, true, Storages...>(
aPtr, aMethod, mozilla::Forward<Args>(aArgs)...);
}