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
Родитель ce113d9c26
Коммит 50c9efe1a4
7 изменённых файлов: 82 добавлений и 208 удалений

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

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

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

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

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

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

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

@ -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. // 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 // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
@ -9,6 +10,50 @@
#include "base/revocable_store.h" #include "base/revocable_store.h"
#include "base/tracked.h" #include "base/tracked.h"
#include "base/tuple.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 ------------------------------------------------------------------------ // Task ------------------------------------------------------------------------
// //
@ -110,75 +155,14 @@ class ScopedRunnableMethodFactory : public RevocableStore {
public: public:
explicit ScopedRunnableMethodFactory(T* object) : object_(object) { } explicit ScopedRunnableMethodFactory(T* object) : object_(object) { }
template <class Method> template <class Method, typename... Elements>
inline Task* NewRunnableMethod(Method method) { inline Task* NewRunnableMethod(Method method, Elements&&... elements) {
typedef typename ScopedTaskFactory<RunnableMethod< typedef mozilla::Tuple<typename mozilla::Decay<Elements>::Type...> ArgsTuple;
Method, Tuple0> >::TaskWrapper TaskWrapper; typedef RunnableMethod<Method, ArgsTuple> Runnable;
typedef typename ScopedTaskFactory<Runnable>::TaskWrapper TaskWrapper;
TaskWrapper* task = new TaskWrapper(this); TaskWrapper* task = new TaskWrapper(this);
task->Init(object_, method, base::MakeTuple()); task->Init(object_, method, mozilla::MakeTuple(mozilla::Forward<Elements>(elements)...));
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));
return task; return task;
} }
@ -188,13 +172,13 @@ class ScopedRunnableMethodFactory : public RevocableStore {
public: public:
RunnableMethod() { } RunnableMethod() { }
void Init(T* obj, Method meth, const Params& params) { void Init(T* obj, Method meth, Params&& params) {
obj_ = obj; obj_ = obj;
meth_ = meth; meth_ = meth;
params_ = params; params_ = mozilla::Forward<Params>(params);
} }
virtual void Run() { DispatchToMethod(obj_, meth_, params_); } virtual void Run() { DispatchTupleToMethod(obj_, meth_, params_); }
private: private:
T* MOZ_UNSAFE_REF("The validity of this pointer must be enforced by " 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, class RunnableMethod : public CancelableTask,
public RunnableMethodTraits<T> { public RunnableMethodTraits<T> {
public: public:
RunnableMethod(T* obj, Method meth, const Params& params) RunnableMethod(T* obj, Method meth, Params&& params)
: obj_(obj), meth_(meth), params_(params) { : obj_(obj), meth_(meth), params_(mozilla::Forward<Params>(params)) {
this->RetainCallee(obj_); this->RetainCallee(obj_);
} }
~RunnableMethod() { ~RunnableMethod() {
@ -320,7 +304,7 @@ class RunnableMethod : public CancelableTask,
virtual void Run() { virtual void Run() {
if (obj_) if (obj_)
DispatchToMethod(obj_, meth_, params_); DispatchTupleToMethod(obj_, meth_, params_);
} }
virtual void Cancel() { virtual void Cancel() {
@ -331,7 +315,7 @@ class RunnableMethod : public CancelableTask,
void ReleaseCallee() { void ReleaseCallee() {
if (obj_) { if (obj_) {
RunnableMethodTraits<T>::ReleaseCallee(obj_); RunnableMethodTraits<T>::ReleaseCallee(obj_);
obj_ = NULL; obj_ = nullptr;
} }
} }
@ -342,78 +326,11 @@ class RunnableMethod : public CancelableTask,
Params params_; Params params_;
}; };
template <class T, class Method> template <class T, class Method, typename... Args>
inline CancelableTask* NewRunnableMethod(T* object, Method method) { inline CancelableTask* NewRunnableMethod(T* object, Method method, Args&&... args) {
return new RunnableMethod<T, Method, Tuple0>(object, method, base::MakeTuple()); typedef mozilla::Tuple<typename mozilla::Decay<Args>::Type...> ArgsTuple;
} return new RunnableMethod<T, Method, ArgsTuple>(
object, method, mozilla::MakeTuple(mozilla::Forward<Args>(args)...));
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));
} }
// RunnableFunction and NewRunnableFunction implementation --------------------- // RunnableFunction and NewRunnableFunction implementation ---------------------
@ -421,8 +338,8 @@ inline CancelableTask* NewRunnableMethod(T* object, Method method,
template <class Function, class Params> template <class Function, class Params>
class RunnableFunction : public CancelableTask { class RunnableFunction : public CancelableTask {
public: public:
RunnableFunction(Function function, const Params& params) RunnableFunction(Function function, Params&& params)
: function_(function), params_(params) { : function_(function), params_(mozilla::Forward<Params>(params)) {
} }
~RunnableFunction() { ~RunnableFunction() {
@ -430,61 +347,22 @@ class RunnableFunction : public CancelableTask {
virtual void Run() { virtual void Run() {
if (function_) if (function_)
DispatchToFunction(function_, params_); DispatchTupleToFunction(function_, params_);
} }
virtual void Cancel() { virtual void Cancel() {
function_ = NULL; function_ = nullptr;
} }
private:
Function function_; Function function_;
Params params_; Params params_;
}; };
template <class Function> template <class Function, typename... Args>
inline CancelableTask* NewRunnableFunction(Function function) { inline CancelableTask* NewRunnableFunction(Function function, Args&&... args) {
return new RunnableFunction<Function, Tuple0>(function, base::MakeTuple()); typedef mozilla::Tuple<typename mozilla::Decay<Args>::Type...> ArgsTuple;
} return new RunnableFunction<Function, ArgsTuple>(
function, mozilla::MakeTuple(mozilla::Forward<Args>(args)...));
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));
} }
// Callback -------------------------------------------------------------------- // Callback --------------------------------------------------------------------

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

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

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

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

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

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