From 068553a3b254a429c620f094d32709d7df58e9e5 Mon Sep 17 00:00:00 2001 From: Bill McCloskey Date: Mon, 2 Nov 2015 16:50:45 -0800 Subject: [PATCH] Bug 1221371 - Switch chromium IPC code to use mozilla::Tuple (r=jld,cpearce,kats) --- dom/media/gmp/GMPDecryptorChild.cpp | 4 +- dom/plugins/ipc/PluginInstanceChild.cpp | 2 +- gfx/layers/ipc/ImageBridgeChild.cpp | 9 +- ipc/chromium/src/base/task.h | 266 +++++------------- .../src/chrome/common/ipc_message_utils.h | 1 - layout/ipc/RenderFrameParent.cpp | 4 +- widget/gonk/nsScreenManagerGonk.cpp | 3 +- widget/nsBaseWidget.cpp | 4 +- 8 files changed, 84 insertions(+), 209 deletions(-) diff --git a/dom/media/gmp/GMPDecryptorChild.cpp b/dom/media/gmp/GMPDecryptorChild.cpp index 590f2fc544d..fa3a57ae9a9 100644 --- a/dom/media/gmp/GMPDecryptorChild.cpp +++ b/dom/media/gmp/GMPDecryptorChild.cpp @@ -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::Type...>; - auto t = NewRunnableMethod(this, m, aMethod, aParams...); + auto t = NewRunnableMethod(this, m, aMethod, Forward(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 diff --git a/dom/plugins/ipc/PluginInstanceChild.cpp b/dom/plugins/ipc/PluginInstanceChild.cpp index 2534e5ff6bf..540138087b5 100644 --- a/dom/plugins/ipc/PluginInstanceChild.cpp +++ b/dom/plugins/ipc/PluginInstanceChild.cpp @@ -2564,7 +2564,7 @@ PluginInstanceChild::RecvAsyncSetWindow(const gfxSurfaceType& aSurfaceType, mCurrentAsyncSetWindowTask = NewRunnableMethod + const gfxSurfaceType&, const NPRemoteWindow&, bool> (this, &PluginInstanceChild::DoAsyncSetWindow, aSurfaceType, aWindow, true); MessageLoop::current()->PostTask(FROM_HERE, mCurrentAsyncSetWindowTask); diff --git a/gfx/layers/ipc/ImageBridgeChild.cpp b/gfx/layers/ipc/ImageBridgeChild.cpp index 6c9042a7360..cd959807782 100644 --- a/gfx/layers/ipc/ImageBridgeChild.cpp +++ b/gfx/layers/ipc/ImageBridgeChild.cpp @@ -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&& 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 >(&UpdateImageClientNow, aClient, aContainer)); + NewRunnableFunction(&UpdateImageClientNow, aClient, RefPtr(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&& aWaiter) { if (!ImageBridgeChild::IsCreated()) { // How sad. If we get into this branch it means that the ImageBridge diff --git a/ipc/chromium/src/base/task.h b/ipc/chromium/src/base/task.h index eabb04dc3ee..d908361a0d8 100644 --- a/ipc/chromium/src/base/task.h +++ b/ipc/chromium/src/base/task.h @@ -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 +void CallMethod(mozilla::IndexSequence, ObjT* obj, Method method, + mozilla::Tuple& arg) +{ + (obj->*method)(mozilla::Move(mozilla::Get(arg))...); +} + +// Same as above, but call a function. +template +void CallFunction(mozilla::IndexSequence, Function function, + mozilla::Tuple& arg) +{ + (*function)(mozilla::Move(mozilla::Get(arg))...); +} + +} // namespace details + +// Call a method on the given object. Arguments are passed by move semantics +// from the given tuple. +template +void DispatchTupleToMethod(ObjT* obj, Method method, mozilla::Tuple& arg) +{ + details::CallMethod(typename mozilla::IndexSequenceFor::Type(), + obj, method, arg); +} + +// Same as above, but call a function. +template +void DispatchTupleToFunction(Function function, mozilla::Tuple& arg) +{ + details::CallFunction(typename mozilla::IndexSequenceFor::Type(), + function, arg); +} // Task ------------------------------------------------------------------------ // @@ -110,75 +155,14 @@ class ScopedRunnableMethodFactory : public RevocableStore { public: explicit ScopedRunnableMethodFactory(T* object) : object_(object) { } - template - inline Task* NewRunnableMethod(Method method) { - typedef typename ScopedTaskFactory >::TaskWrapper TaskWrapper; + template + inline Task* NewRunnableMethod(Method method, Elements&&... elements) { + typedef mozilla::Tuple::Type...> ArgsTuple; + typedef RunnableMethod Runnable; + typedef typename ScopedTaskFactory::TaskWrapper TaskWrapper; TaskWrapper* task = new TaskWrapper(this); - task->Init(object_, method, base::MakeTuple()); - return task; - } - - template - inline Task* NewRunnableMethod(Method method, const A& a) { - typedef typename ScopedTaskFactory > >::TaskWrapper TaskWrapper; - - TaskWrapper* task = new TaskWrapper(this); - task->Init(object_, method, base::MakeTuple(a)); - return task; - } - - template - inline Task* NewRunnableMethod(Method method, const A& a, const B& b) { - typedef typename ScopedTaskFactory > >::TaskWrapper TaskWrapper; - - TaskWrapper* task = new TaskWrapper(this); - task->Init(object_, method, base::MakeTuple(a, b)); - return task; - } - - template - inline Task* NewRunnableMethod(Method method, - const A& a, - const B& b, - const C& c) { - typedef typename ScopedTaskFactory > >::TaskWrapper TaskWrapper; - - TaskWrapper* task = new TaskWrapper(this); - task->Init(object_, method, base::MakeTuple(a, b, c)); - return task; - } - - template - inline Task* NewRunnableMethod(Method method, - const A& a, - const B& b, - const C& c, - const D& d) { - typedef typename ScopedTaskFactory > >::TaskWrapper TaskWrapper; - - TaskWrapper* task = new TaskWrapper(this); - task->Init(object_, method, base::MakeTuple(a, b, c, d)); - return task; - } - - template - inline Task* NewRunnableMethod(Method method, - const A& a, - const B& b, - const C& c, - const D& d, - const E& e) { - typedef typename ScopedTaskFactory > >::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)...)); 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); } - 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 RunnableMethod : public CancelableTask, public RunnableMethodTraits { 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)) { 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::ReleaseCallee(obj_); - obj_ = NULL; + obj_ = nullptr; } } @@ -342,78 +326,11 @@ class RunnableMethod : public CancelableTask, Params params_; }; -template -inline CancelableTask* NewRunnableMethod(T* object, Method method) { - return new RunnableMethod(object, method, base::MakeTuple()); -} - -template -inline CancelableTask* NewRunnableMethod(T* object, Method method, const A& a) { - return new RunnableMethod >(object, - method, - base::MakeTuple(a)); -} - -template -inline CancelableTask* NewRunnableMethod(T* object, Method method, -const A& a, const B& b) { - return new RunnableMethod >(object, method, - base::MakeTuple(a, b)); -} - -template -inline CancelableTask* NewRunnableMethod(T* object, Method method, - const A& a, const B& b, const C& c) { - return new RunnableMethod >(object, method, - base::MakeTuple(a, b, c)); -} - -template -inline CancelableTask* NewRunnableMethod(T* object, Method method, - const A& a, const B& b, - const C& c, const D& d) { - return new RunnableMethod >(object, method, - base::MakeTuple(a, b, - c, d)); -} - -template -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 >(object, - method, - base::MakeTuple(a, b, c, d, e)); -} - -template -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 >(object, - method, - base::MakeTuple(a, b, c, d, e, - f)); -} - -template -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 >(object, - method, - base::MakeTuple(a, b, c, d, - e, f, g)); +template +inline CancelableTask* NewRunnableMethod(T* object, Method method, Args&&... args) { + typedef mozilla::Tuple::Type...> ArgsTuple; + return new RunnableMethod( + object, method, mozilla::MakeTuple(mozilla::Forward(args)...)); } // RunnableFunction and NewRunnableFunction implementation --------------------- @@ -421,8 +338,8 @@ inline CancelableTask* NewRunnableMethod(T* object, Method method, template 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)) { } ~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 -inline CancelableTask* NewRunnableFunction(Function function) { - return new RunnableFunction(function, base::MakeTuple()); -} - -template -inline CancelableTask* NewRunnableFunction(Function function, const A& a) { - return new RunnableFunction >(function, base::MakeTuple(a)); -} - -template -inline CancelableTask* NewRunnableFunction(Function function, - const A& a, const B& b) { - return new RunnableFunction >(function, - base::MakeTuple(a, b)); -} - -template -inline CancelableTask* NewRunnableFunction(Function function, - const A& a, const B& b, - const C& c) { - return new RunnableFunction >(function, - base::MakeTuple(a, b, c)); -} - -template -inline CancelableTask* NewRunnableFunction(Function function, - const A& a, const B& b, - const C& c, const D& d) { - return new RunnableFunction >(function, - base::MakeTuple(a, b, - c, d)); -} - -template -inline CancelableTask* NewRunnableFunction(Function function, - const A& a, const B& b, - const C& c, const D& d, - const E& e) { - return new RunnableFunction >(function, - base::MakeTuple(a, b, - c, d, - e)); +template +inline CancelableTask* NewRunnableFunction(Function function, Args&&... args) { + typedef mozilla::Tuple::Type...> ArgsTuple; + return new RunnableFunction( + function, mozilla::MakeTuple(mozilla::Forward(args)...)); } // Callback -------------------------------------------------------------------- diff --git a/ipc/chromium/src/chrome/common/ipc_message_utils.h b/ipc/chromium/src/chrome/common/ipc_message_utils.h index 44e3b8276a8..e3373b8a3e6 100644 --- a/ipc/chromium/src/chrome/common/ipc_message_utils.h +++ b/ipc/chromium/src/chrome/common/ipc_message_utils.h @@ -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) diff --git a/layout/ipc/RenderFrameParent.cpp b/layout/ipc/RenderFrameParent.cpp index 4f1b07faa1e..cbccf9fda67 100644 --- a/layout/ipc/RenderFrameParent.cpp +++ b/layout/ipc/RenderFrameParent.cpp @@ -567,7 +567,7 @@ RenderFrameParent::SetTargetAPZC(uint64_t aInputBlockId, = &APZCTreeManager::SetTargetAPZC; APZThreadUtils::RunOnControllerThread(NewRunnableMethod( GetApzcTreeManager(), setTargetApzcFunc, - aInputBlockId, aTargets)); + aInputBlockId, nsTArray(aTargets))); } } @@ -578,7 +578,7 @@ RenderFrameParent::SetAllowedTouchBehavior(uint64_t aInputBlockId, if (GetApzcTreeManager()) { APZThreadUtils::RunOnControllerThread(NewRunnableMethod( GetApzcTreeManager(), &APZCTreeManager::SetAllowedTouchBehavior, - aInputBlockId, aFlags)); + aInputBlockId, nsTArray(aFlags))); } } diff --git a/widget/gonk/nsScreenManagerGonk.cpp b/widget/gonk/nsScreenManagerGonk.cpp index 78e89e037f7..4bd79e76ee1 100644 --- a/widget/gonk/nsScreenManagerGonk.cpp +++ b/widget/gonk/nsScreenManagerGonk.cpp @@ -440,7 +440,8 @@ nsScreenGonk::GetEGLSurface() } static void -UpdateMirroringWidgetSync(nsScreenGonk* aScreen, nsWindow* aWindow) { +UpdateMirroringWidgetSync(RefPtr&& aScreen, nsWindow* aWindow) +{ MOZ_ASSERT(CompositorParent::IsInCompositorThread()); already_AddRefed window(aWindow); aScreen->UpdateMirroringWidget(window); diff --git a/widget/nsBaseWidget.cpp b/widget/nsBaseWidget.cpp index 747d4595d7b..a7cad89c05c 100644 --- a/widget/nsBaseWidget.cpp +++ b/widget/nsBaseWidget.cpp @@ -902,7 +902,7 @@ void nsBaseWidget::ConfigureAPZCTreeManager() MOZ_ASSERT(NS_IsMainThread()); APZThreadUtils::RunOnControllerThread(NewRunnableMethod( treeManager.get(), &APZCTreeManager::SetAllowedTouchBehavior, - aInputBlockId, aFlags)); + aInputBlockId, nsTArray(aFlags))); }; RefPtr controller = CreateRootContentController(); @@ -934,7 +934,7 @@ nsBaseWidget::SetConfirmedTargetAPZC(uint64_t aInputBlockId, void (APZCTreeManager::*setTargetApzcFunc)(uint64_t, const nsTArray&) = &APZCTreeManager::SetTargetAPZC; APZThreadUtils::RunOnControllerThread(NewRunnableMethod( - mAPZC.get(), setTargetApzcFunc, aInputBlockId, mozilla::Move(aTargets))); + mAPZC.get(), setTargetApzcFunc, aInputBlockId, nsTArray(aTargets))); } void