Bug 1343639 - Allow TaskFactory::NewRunnableMethod pass an arbitrary number of arguments to the runnable. r?billm draft
authorMike Conley <mconley@mozilla.com>
Mon, 06 Mar 2017 15:36:06 -0500
changeset 496819 e3ffffd11ff71f2079597fefd0eeb9a5442c60f1
parent 494684 3d341b9ba5353b6b8ab45b6ca03dcb1b2d789faa
child 496820 ce95e07210530727948271ab4b719c1c15554d51
push id48704
push usermconley@mozilla.com
push dateFri, 10 Mar 2017 18:42:06 +0000
reviewersbillm
bugs1343639
milestone55.0a1
Bug 1343639 - Allow TaskFactory::NewRunnableMethod pass an arbitrary number of arguments to the runnable. r?billm MozReview-Commit-ID: LXs6urqSxX9
ipc/glue/TaskFactory.h
--- a/ipc/glue/TaskFactory.h
+++ b/ipc/glue/TaskFactory.h
@@ -53,32 +53,26 @@ public:
   inline already_AddRefed<TaskParamType> NewTask(Args&&... args)
   {
     typedef TaskWrapper<TaskParamType> TaskWrapper;
     RefPtr<TaskWrapper> task =
       new TaskWrapper(this, mozilla::Forward<Args>(args)...);
     return task.forget();
   }
 
-  template <class Method>
-  inline already_AddRefed<Runnable> NewRunnableMethod(Method method) {
-    typedef TaskWrapper<RunnableMethod<Method, Tuple0> > TaskWrapper;
-
-    RefPtr<TaskWrapper> task = new TaskWrapper(this, object_, method,
-                                               base::MakeTuple());
+  template <class Method, typename... Args>
+  inline already_AddRefed<Runnable>
+  NewRunnableMethod(Method method, Args&&... args) {
+    typedef decltype(base::MakeTuple(mozilla::Forward<Args>(args)...)) ArgTuple;
+    typedef RunnableMethod<Method, ArgTuple> RunnableMethod;
+    typedef TaskWrapper<RunnableMethod> TaskWrapper;
 
-    return task.forget();
-  }
-
-  template <class Method, class A>
-  inline already_AddRefed<Runnable> NewRunnableMethod(Method method, const A& a) {
-    typedef TaskWrapper<RunnableMethod<Method, Tuple1<A> > > TaskWrapper;
-
-    RefPtr<TaskWrapper> task = new TaskWrapper(this, object_, method,
-                                               base::MakeTuple(a));
+    RefPtr<TaskWrapper> task =
+      new TaskWrapper(this, object_, method,
+                      base::MakeTuple(mozilla::Forward<Args>(args)...));
 
     return task.forget();
   }
 
 protected:
   template <class Method, class Params>
   class RunnableMethod : public Runnable {
    public: