Bug 1221371 - Switch chromium IPC code to use mozilla::Tuple (r=jld,cpearce,kats)

This commit is contained in:
Bill McCloskey 2015-11-02 16:50:45 -08:00
parent 99aa2b1506
commit 068553a3b2
8 changed files with 84 additions and 209 deletions

View File

@ -61,7 +61,7 @@ GMPDecryptorChild::CallOnGMPThread(MethodType aMethod, ParamType&&... aParams)
// Use const reference when we have to.
auto m = &GMPDecryptorChild::CallMethod<
decltype(aMethod), typename AddConstReference<ParamType>::Type...>;
auto t = NewRunnableMethod(this, m, aMethod, aParams...);
auto t = NewRunnableMethod(this, m, aMethod, Forward<ParamType>(aParams)...);
mPlugin->GMPMessageLoop()->PostTask(FROM_HERE, t);
}
}
@ -116,7 +116,7 @@ GMPDecryptorChild::SessionMessage(const char* aSessionId,
msg.AppendElements(aMessage, aMessageLength);
CALL_ON_GMP_THREAD(SendSessionMessage,
nsAutoCString(aSessionId, aSessionIdLength),
aMessageType, msg);
aMessageType, Move(msg));
}
void

View File

@ -2564,7 +2564,7 @@ PluginInstanceChild::RecvAsyncSetWindow(const gfxSurfaceType& aSurfaceType,
mCurrentAsyncSetWindowTask =
NewRunnableMethod<PluginInstanceChild,
void (PluginInstanceChild::*)(const gfxSurfaceType&, const NPRemoteWindow&, bool),
gfxSurfaceType, NPRemoteWindow, bool>
const gfxSurfaceType&, const NPRemoteWindow&, bool>
(this, &PluginInstanceChild::DoAsyncSetWindow,
aSurfaceType, aWindow, true);
MessageLoop::current()->PostTask(FROM_HERE, mCurrentAsyncSetWindowTask);

View File

@ -458,7 +458,7 @@ void ImageBridgeChild::DispatchReleaseTextureClient(TextureClient* aClient)
NewRunnableFunction(&ReleaseTextureClientNow, aClient));
}
static void UpdateImageClientNow(ImageClient* aClient, ImageContainer* aContainer)
static void UpdateImageClientNow(ImageClient* aClient, RefPtr<ImageContainer>&& aContainer)
{
if (!ImageBridgeChild::IsCreated()) {
NS_WARNING("Something is holding on to graphics resources after the shutdown"
@ -491,10 +491,7 @@ void ImageBridgeChild::DispatchImageClientUpdate(ImageClient* aClient,
}
sImageBridgeChildSingleton->GetMessageLoop()->PostTask(
FROM_HERE,
NewRunnableFunction<
void (*)(ImageClient*, ImageContainer*),
ImageClient*,
RefPtr<ImageContainer> >(&UpdateImageClientNow, aClient, aContainer));
NewRunnableFunction(&UpdateImageClientNow, aClient, RefPtr<ImageContainer>(aContainer)));
}
static void UpdateAsyncCanvasRendererSync(AsyncCanvasRenderer* aWrapper,
@ -543,7 +540,7 @@ void ImageBridgeChild::UpdateAsyncCanvasRendererNow(AsyncCanvasRenderer* aWrappe
}
static void FlushAllImagesSync(ImageClient* aClient, ImageContainer* aContainer,
AsyncTransactionWaiter* aWaiter)
RefPtr<AsyncTransactionWaiter>&& aWaiter)
{
if (!ImageBridgeChild::IsCreated()) {
// How sad. If we get into this branch it means that the ImageBridge

View File

@ -1,3 +1,4 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
// Copyright (c) 2006-2008 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.
@ -9,6 +10,50 @@
#include "base/revocable_store.h"
#include "base/tracked.h"
#include "base/tuple.h"
#include "mozilla/IndexSequence.h"
#include "mozilla/Tuple.h"
// Helper functions so that we can call a function a pass it arguments that come
// from a Tuple.
namespace details {
// Call the given method on the given object. Arguments are passed by move
// semantics from the given tuple. If the tuple has length N, the sequence must
// be IndexSequence<0, 1, ..., N-1>.
template<size_t... Indices, class ObjT, class Method, typename... Args>
void CallMethod(mozilla::IndexSequence<Indices...>, ObjT* obj, Method method,
mozilla::Tuple<Args...>& arg)
{
(obj->*method)(mozilla::Move(mozilla::Get<Indices>(arg))...);
}
// Same as above, but call a function.
template<size_t... Indices, typename Function, typename... Args>
void CallFunction(mozilla::IndexSequence<Indices...>, Function function,
mozilla::Tuple<Args...>& arg)
{
(*function)(mozilla::Move(mozilla::Get<Indices>(arg))...);
}
} // namespace details
// Call a method on the given object. Arguments are passed by move semantics
// from the given tuple.
template<class ObjT, class Method, typename... Args>
void DispatchTupleToMethod(ObjT* obj, Method method, mozilla::Tuple<Args...>& arg)
{
details::CallMethod(typename mozilla::IndexSequenceFor<Args...>::Type(),
obj, method, arg);
}
// Same as above, but call a function.
template<typename Function, typename... Args>
void DispatchTupleToFunction(Function function, mozilla::Tuple<Args...>& arg)
{
details::CallFunction(typename mozilla::IndexSequenceFor<Args...>::Type(),
function, arg);
}
// Task ------------------------------------------------------------------------
//
@ -110,75 +155,14 @@ class ScopedRunnableMethodFactory : public RevocableStore {
public:
explicit ScopedRunnableMethodFactory(T* object) : object_(object) { }
template <class Method>
inline Task* NewRunnableMethod(Method method) {
typedef typename ScopedTaskFactory<RunnableMethod<
Method, Tuple0> >::TaskWrapper TaskWrapper;
template <class Method, typename... Elements>
inline Task* NewRunnableMethod(Method method, Elements&&... elements) {
typedef mozilla::Tuple<typename mozilla::Decay<Elements>::Type...> ArgsTuple;
typedef RunnableMethod<Method, ArgsTuple> Runnable;
typedef typename ScopedTaskFactory<Runnable>::TaskWrapper TaskWrapper;
TaskWrapper* task = new TaskWrapper(this);
task->Init(object_, method, base::MakeTuple());
return task;
}
template <class Method, class A>
inline Task* NewRunnableMethod(Method method, const A& a) {
typedef typename ScopedTaskFactory<RunnableMethod<
Method, Tuple1<A> > >::TaskWrapper TaskWrapper;
TaskWrapper* task = new TaskWrapper(this);
task->Init(object_, method, base::MakeTuple(a));
return task;
}
template <class Method, class A, class B>
inline Task* NewRunnableMethod(Method method, const A& a, const B& b) {
typedef typename ScopedTaskFactory<RunnableMethod<
Method, Tuple2<A, B> > >::TaskWrapper TaskWrapper;
TaskWrapper* task = new TaskWrapper(this);
task->Init(object_, method, base::MakeTuple(a, b));
return task;
}
template <class Method, class A, class B, class C>
inline Task* NewRunnableMethod(Method method,
const A& a,
const B& b,
const C& c) {
typedef typename ScopedTaskFactory<RunnableMethod<
Method, Tuple3<A, B, C> > >::TaskWrapper TaskWrapper;
TaskWrapper* task = new TaskWrapper(this);
task->Init(object_, method, base::MakeTuple(a, b, c));
return task;
}
template <class Method, class A, class B, class C, class D>
inline Task* NewRunnableMethod(Method method,
const A& a,
const B& b,
const C& c,
const D& d) {
typedef typename ScopedTaskFactory<RunnableMethod<
Method, Tuple4<A, B, C, D> > >::TaskWrapper TaskWrapper;
TaskWrapper* task = new TaskWrapper(this);
task->Init(object_, method, base::MakeTuple(a, b, c, d));
return task;
}
template <class Method, class A, class B, class C, class D, class E>
inline Task* NewRunnableMethod(Method method,
const A& a,
const B& b,
const C& c,
const D& d,
const E& e) {
typedef typename ScopedTaskFactory<RunnableMethod<
Method, Tuple5<A, B, C, D, E> > >::TaskWrapper TaskWrapper;
TaskWrapper* task = new TaskWrapper(this);
task->Init(object_, method, base::MakeTuple(a, b, c, d, e));
task->Init(object_, method, mozilla::MakeTuple(mozilla::Forward<Elements>(elements)...));
return task;
}
@ -188,13 +172,13 @@ class ScopedRunnableMethodFactory : public RevocableStore {
public:
RunnableMethod() { }
void Init(T* obj, Method meth, const Params& params) {
void Init(T* obj, Method meth, Params&& params) {
obj_ = obj;
meth_ = meth;
params_ = params;
params_ = mozilla::Forward<Params>(params);
}
virtual void Run() { DispatchToMethod(obj_, meth_, params_); }
virtual void Run() { DispatchTupleToMethod(obj_, meth_, params_); }
private:
T* MOZ_UNSAFE_REF("The validity of this pointer must be enforced by "
@ -310,8 +294,8 @@ template <class T, class Method, class Params>
class RunnableMethod : public CancelableTask,
public RunnableMethodTraits<T> {
public:
RunnableMethod(T* obj, Method meth, const Params& params)
: obj_(obj), meth_(meth), params_(params) {
RunnableMethod(T* obj, Method meth, Params&& params)
: obj_(obj), meth_(meth), params_(mozilla::Forward<Params>(params)) {
this->RetainCallee(obj_);
}
~RunnableMethod() {
@ -320,7 +304,7 @@ class RunnableMethod : public CancelableTask,
virtual void Run() {
if (obj_)
DispatchToMethod(obj_, meth_, params_);
DispatchTupleToMethod(obj_, meth_, params_);
}
virtual void Cancel() {
@ -331,7 +315,7 @@ class RunnableMethod : public CancelableTask,
void ReleaseCallee() {
if (obj_) {
RunnableMethodTraits<T>::ReleaseCallee(obj_);
obj_ = NULL;
obj_ = nullptr;
}
}
@ -342,78 +326,11 @@ class RunnableMethod : public CancelableTask,
Params params_;
};
template <class T, class Method>
inline CancelableTask* NewRunnableMethod(T* object, Method method) {
return new RunnableMethod<T, Method, Tuple0>(object, method, base::MakeTuple());
}
template <class T, class Method, class A>
inline CancelableTask* NewRunnableMethod(T* object, Method method, const A& a) {
return new RunnableMethod<T, Method, Tuple1<A> >(object,
method,
base::MakeTuple(a));
}
template <class T, class Method, class A, class B>
inline CancelableTask* NewRunnableMethod(T* object, Method method,
const A& a, const B& b) {
return new RunnableMethod<T, Method, Tuple2<A, B> >(object, method,
base::MakeTuple(a, b));
}
template <class T, class Method, class A, class B, class C>
inline CancelableTask* NewRunnableMethod(T* object, Method method,
const A& a, const B& b, const C& c) {
return new RunnableMethod<T, Method, Tuple3<A, B, C> >(object, method,
base::MakeTuple(a, b, c));
}
template <class T, class Method, class A, class B, class C, class D>
inline CancelableTask* NewRunnableMethod(T* object, Method method,
const A& a, const B& b,
const C& c, const D& d) {
return new RunnableMethod<T, Method, Tuple4<A, B, C, D> >(object, method,
base::MakeTuple(a, b,
c, d));
}
template <class T, class Method, class A, class B, class C, class D, class E>
inline CancelableTask* NewRunnableMethod(T* object, Method method,
const A& a, const B& b,
const C& c, const D& d, const E& e) {
return new RunnableMethod<T,
Method,
Tuple5<A, B, C, D, E> >(object,
method,
base::MakeTuple(a, b, c, d, e));
}
template <class T, class Method, class A, class B, class C, class D, class E,
class F>
inline CancelableTask* NewRunnableMethod(T* object, Method method,
const A& a, const B& b,
const C& c, const D& d, const E& e,
const F& f) {
return new RunnableMethod<T,
Method,
Tuple6<A, B, C, D, E, F> >(object,
method,
base::MakeTuple(a, b, c, d, e,
f));
}
template <class T, class Method, class A, class B, class C, class D, class E,
class F, class G>
inline CancelableTask* NewRunnableMethod(T* object, Method method,
const A& a, const B& b,
const C& c, const D& d, const E& e,
const F& f, const G& g) {
return new RunnableMethod<T,
Method,
Tuple7<A, B, C, D, E, F, G> >(object,
method,
base::MakeTuple(a, b, c, d,
e, f, g));
template <class T, class Method, typename... Args>
inline CancelableTask* NewRunnableMethod(T* object, Method method, Args&&... args) {
typedef mozilla::Tuple<typename mozilla::Decay<Args>::Type...> ArgsTuple;
return new RunnableMethod<T, Method, ArgsTuple>(
object, method, mozilla::MakeTuple(mozilla::Forward<Args>(args)...));
}
// RunnableFunction and NewRunnableFunction implementation ---------------------
@ -421,8 +338,8 @@ inline CancelableTask* NewRunnableMethod(T* object, Method method,
template <class Function, class Params>
class RunnableFunction : public CancelableTask {
public:
RunnableFunction(Function function, const Params& params)
: function_(function), params_(params) {
RunnableFunction(Function function, Params&& params)
: function_(function), params_(mozilla::Forward<Params>(params)) {
}
~RunnableFunction() {
@ -430,61 +347,22 @@ class RunnableFunction : public CancelableTask {
virtual void Run() {
if (function_)
DispatchToFunction(function_, params_);
DispatchTupleToFunction(function_, params_);
}
virtual void Cancel() {
function_ = NULL;
function_ = nullptr;
}
private:
Function function_;
Params params_;
};
template <class Function>
inline CancelableTask* NewRunnableFunction(Function function) {
return new RunnableFunction<Function, Tuple0>(function, base::MakeTuple());
}
template <class Function, class A>
inline CancelableTask* NewRunnableFunction(Function function, const A& a) {
return new RunnableFunction<Function, Tuple1<A> >(function, base::MakeTuple(a));
}
template <class Function, class A, class B>
inline CancelableTask* NewRunnableFunction(Function function,
const A& a, const B& b) {
return new RunnableFunction<Function, Tuple2<A, B> >(function,
base::MakeTuple(a, b));
}
template <class Function, class A, class B, class C>
inline CancelableTask* NewRunnableFunction(Function function,
const A& a, const B& b,
const C& c) {
return new RunnableFunction<Function, Tuple3<A, B, C> >(function,
base::MakeTuple(a, b, c));
}
template <class Function, class A, class B, class C, class D>
inline CancelableTask* NewRunnableFunction(Function function,
const A& a, const B& b,
const C& c, const D& d) {
return new RunnableFunction<Function, Tuple4<A, B, C, D> >(function,
base::MakeTuple(a, b,
c, d));
}
template <class Function, class A, class B, class C, class D, class E>
inline CancelableTask* NewRunnableFunction(Function function,
const A& a, const B& b,
const C& c, const D& d,
const E& e) {
return new RunnableFunction<Function, Tuple5<A, B, C, D, E> >(function,
base::MakeTuple(a, b,
c, d,
e));
template <class Function, typename... Args>
inline CancelableTask* NewRunnableFunction(Function function, Args&&... args) {
typedef mozilla::Tuple<typename mozilla::Decay<Args>::Type...> ArgsTuple;
return new RunnableFunction<Function, ArgsTuple>(
function, mozilla::MakeTuple(mozilla::Forward<Args>(args)...));
}
// Callback --------------------------------------------------------------------

View File

@ -12,7 +12,6 @@
#include "base/file_path.h"
#include "base/string_util.h"
#include "base/string16.h"
#include "base/tuple.h"
#include "base/time.h"
#if defined(OS_POSIX)

View File

@ -567,7 +567,7 @@ RenderFrameParent::SetTargetAPZC(uint64_t aInputBlockId,
= &APZCTreeManager::SetTargetAPZC;
APZThreadUtils::RunOnControllerThread(NewRunnableMethod(
GetApzcTreeManager(), setTargetApzcFunc,
aInputBlockId, aTargets));
aInputBlockId, nsTArray<ScrollableLayerGuid>(aTargets)));
}
}
@ -578,7 +578,7 @@ RenderFrameParent::SetAllowedTouchBehavior(uint64_t aInputBlockId,
if (GetApzcTreeManager()) {
APZThreadUtils::RunOnControllerThread(NewRunnableMethod(
GetApzcTreeManager(), &APZCTreeManager::SetAllowedTouchBehavior,
aInputBlockId, aFlags));
aInputBlockId, nsTArray<TouchBehaviorFlags>(aFlags)));
}
}

View File

@ -440,7 +440,8 @@ nsScreenGonk::GetEGLSurface()
}
static void
UpdateMirroringWidgetSync(nsScreenGonk* aScreen, nsWindow* aWindow) {
UpdateMirroringWidgetSync(RefPtr<nsScreenGonk>&& aScreen, nsWindow* aWindow)
{
MOZ_ASSERT(CompositorParent::IsInCompositorThread());
already_AddRefed<nsWindow> window(aWindow);
aScreen->UpdateMirroringWidget(window);

View File

@ -902,7 +902,7 @@ void nsBaseWidget::ConfigureAPZCTreeManager()
MOZ_ASSERT(NS_IsMainThread());
APZThreadUtils::RunOnControllerThread(NewRunnableMethod(
treeManager.get(), &APZCTreeManager::SetAllowedTouchBehavior,
aInputBlockId, aFlags));
aInputBlockId, nsTArray<TouchBehaviorFlags>(aFlags)));
};
RefPtr<GeckoContentController> controller = CreateRootContentController();
@ -934,7 +934,7 @@ nsBaseWidget::SetConfirmedTargetAPZC(uint64_t aInputBlockId,
void (APZCTreeManager::*setTargetApzcFunc)(uint64_t, const nsTArray<ScrollableLayerGuid>&)
= &APZCTreeManager::SetTargetAPZC;
APZThreadUtils::RunOnControllerThread(NewRunnableMethod(
mAPZC.get(), setTargetApzcFunc, aInputBlockId, mozilla::Move(aTargets)));
mAPZC.get(), setTargetApzcFunc, aInputBlockId, nsTArray<ScrollableLayerGuid>(aTargets)));
}
void