Bug 1160298: Modify TaskFactory::NewTask to support variadic templates; r=gfritzsche
authorAaron Klotz <aklotz@mozilla.com>
Thu, 30 Apr 2015 14:23:24 -0600
changeset 273959 aa884bc76a9d644bf82ef9410022e50d70eb0d2e
parent 273958 b7ed296c05adfa33ea8fc3aa29a28d96ce05a267
child 273960 3d2d5ade77a2382d0a8b128dc95a963de28ef88e
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgfritzsche
bugs1160298
milestone40.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1160298: Modify TaskFactory::NewTask to support variadic templates; r=gfritzsche
dom/plugins/ipc/TaskFactory.h
--- a/dom/plugins/ipc/TaskFactory.h
+++ b/dom/plugins/ipc/TaskFactory.h
@@ -2,16 +2,18 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_plugins_TaskFactory_h
 #define mozilla_plugins_TaskFactory_h
 
 #include <base/task.h>
 
+#include "mozilla/Move.h"
+
 /*
  * This is based on the ScopedRunnableMethodFactory from ipc/chromium/src/base/task.h
  * Chromium's factories assert if tasks are created and run on different threads,
  * which is something we need to do in PluginModuleParent (hang UI vs. main thread).
  * TaskFactory just provides cancellable tasks that don't assert this.
  * This version also allows both ScopedMethod and regular Tasks to be generated
  * by the same Factory object.
  */
@@ -22,35 +24,40 @@ namespace plugins {
 template<class T>
 class TaskFactory : public RevocableStore
 {
 private:
   template<class TaskType>
   class TaskWrapper : public TaskType
   {
   public:
-    explicit TaskWrapper(RevocableStore* store) : revocable_(store) { }
+    template<typename... Args>
+    explicit TaskWrapper(RevocableStore* store, Args&&... args)
+      : TaskType(mozilla::Forward<Args>(args)...)
+      , revocable_(store)
+    {
+    }
 
     virtual void Run() {
       if (!revocable_.revoked())
         TaskType::Run();
     }
 
   private:
     Revocable revocable_;
   };
 
 public:
   explicit TaskFactory(T* object) : object_(object) { }
 
-  template <class TaskParamType>
-  inline TaskParamType* NewTask()
+  template <typename TaskParamType, typename... Args>
+  inline TaskParamType* NewTask(Args&&... args)
   {
     typedef TaskWrapper<TaskParamType> TaskWrapper;
-    TaskWrapper* task = new TaskWrapper(this);
+    TaskWrapper* task = new TaskWrapper(this, mozilla::Forward<Args>(args)...);
     return task;
   }
 
   template <class Method>
   inline Task* NewRunnableMethod(Method method) {
     typedef TaskWrapper<RunnableMethod<Method, Tuple0> > TaskWrapper;
 
     TaskWrapper* task = new TaskWrapper(this);