Bug 1281626 - part 1 - move nsRunnableMethod* into mozilla::detail and rename them; r=khuey
authorNathan Froyd <froydnj@gmail.com>
Tue, 28 Jun 2016 22:24:54 -0400
changeset 382168 14345389a69aa48c7352e44b587d7c11a3095396
parent 382167 93ac933f0d64016f38154cc67cbaa91f91fd9ef4
child 382169 5e317ff236ec5074411a14a7859c0624c90101ba
push id21645
push userbmo:gasolin@mozilla.com
push dateWed, 29 Jun 2016 04:02:20 +0000
reviewerskhuey
bugs1281626
milestone50.0a1
Bug 1281626 - part 1 - move nsRunnableMethod* into mozilla::detail and rename them; r=khuey Less ns-prefixing is more better. Also, this renaming makes clearer that these classes are private implementation details, which is good, because we're going to take advantage of that fact in a bit.
xpcom/glue/nsThreadUtils.h
--- a/xpcom/glue/nsThreadUtils.h
+++ b/xpcom/glue/nsThreadUtils.h
@@ -699,59 +699,62 @@ template<typename T>
 struct ParameterStorage
   : mozilla::Conditional<IsParameterStorageClass<T>::value,
                          T,
                          typename NonParameterStorageClass<T>::Type>
 {};
 
 } /* namespace detail */
 
+namespace mozilla {
+
+namespace detail {
+
 // struct used to store arguments and later apply them to a method.
 template <typename... Ts>
-struct nsRunnableMethodArguments
+struct RunnableMethodArguments
 {
-  mozilla::Tuple<typename ::detail::ParameterStorage<Ts>::Type...> mArguments;
+  Tuple<typename ::detail::ParameterStorage<Ts>::Type...> mArguments;
   template <typename... As>
-  explicit nsRunnableMethodArguments(As&&... aArguments)
-    : mArguments(mozilla::Forward<As>(aArguments)...)
+  explicit RunnableMethodArguments(As&&... aArguments)
+    : mArguments(Forward<As>(aArguments)...)
   {}
   template<typename C, typename M, typename... Args, size_t... Indices>
   static auto
-  applyImpl(C* o, M m, mozilla::Tuple<Args...>& args,
-            mozilla::IndexSequence<Indices...>)
-      -> decltype(((*o).*m)(mozilla::Get<Indices>(args).PassAsParameter()...))
+  applyImpl(C* o, M m, Tuple<Args...>& args, IndexSequence<Indices...>)
+      -> decltype(((*o).*m)(Get<Indices>(args).PassAsParameter()...))
   {
-    return ((*o).*m)(mozilla::Get<Indices>(args).PassAsParameter()...);
+    return ((*o).*m)(Get<Indices>(args).PassAsParameter()...);
   }
   template<class C, typename M> auto apply(C* o, M m)
       -> decltype(applyImpl(o, m, mArguments,
-                  typename mozilla::IndexSequenceFor<Ts...>::Type()))
+                  typename IndexSequenceFor<Ts...>::Type()))
   {
     return applyImpl(o, m, mArguments,
-        typename mozilla::IndexSequenceFor<Ts...>::Type());
+        typename IndexSequenceFor<Ts...>::Type());
   }
 };
 
 template<typename Method, bool Owning, bool Cancelable, typename... Storages>
-class nsRunnableMethodImpl
-  : public nsRunnableMethodTraits<Method, Owning, Cancelable>::base_type
+class RunnableMethodImpl
+  : public ::nsRunnableMethodTraits<Method, Owning, Cancelable>::base_type
 {
-  typedef typename nsRunnableMethodTraits<Method, Owning, Cancelable>::class_type
+  typedef typename ::nsRunnableMethodTraits<Method, Owning, Cancelable>::class_type
       ClassType;
-  nsRunnableMethodReceiver<ClassType, Owning> mReceiver;
+  ::nsRunnableMethodReceiver<ClassType, Owning> mReceiver;
   Method mMethod;
-  nsRunnableMethodArguments<Storages...> mArgs;
+  RunnableMethodArguments<Storages...> mArgs;
 public:
-  virtual ~nsRunnableMethodImpl() { Revoke(); };
+  virtual ~RunnableMethodImpl() { Revoke(); };
   template<typename... Args>
-  explicit nsRunnableMethodImpl(ClassType* aObj, Method aMethod,
-                                Args&&... aArgs)
+  explicit RunnableMethodImpl(ClassType* aObj, Method aMethod,
+                              Args&&... aArgs)
     : mReceiver(aObj)
     , mMethod(aMethod)
-    , mArgs(mozilla::Forward<Args>(aArgs)...)
+    , mArgs(Forward<Args>(aArgs)...)
   {
     static_assert(sizeof...(Storages) == sizeof...(Args), "Storages and Args should have equal sizes");
   }
   NS_IMETHOD Run()
   {
     if (MOZ_LIKELY(mReceiver.Get())) {
       mArgs.apply(mReceiver.Get(), mMethod);
     }
@@ -760,99 +763,99 @@ public:
   nsresult Cancel() {
     static_assert(Cancelable, "Don't use me!");
     Revoke();
     return NS_OK;
   }
   void Revoke() { mReceiver.Revoke(); }
 };
 
+} // namespace detail
+
 // Use this template function like so:
 //
 //   nsCOMPtr<nsIRunnable> event =
 //     mozilla::NewRunnableMethod(myObject, &MyClass::HandleEvent);
 //   NS_DispatchToCurrentThread(event);
 //
 // Statically enforced constraints:
 //  - myObject must be of (or implicitly convertible to) type MyClass
-//  - MyClass must defined AddRef and Release methods
+//  - MyClass must define AddRef and Release methods
 //
 
-namespace mozilla {
-
 template<typename PtrType, typename Method>
-already_AddRefed<typename nsRunnableMethodTraits<Method, true, false>::base_type>
+already_AddRefed<typename ::nsRunnableMethodTraits<Method, true, false>::base_type>
 NewRunnableMethod(PtrType aPtr, Method aMethod)
 {
-  return do_AddRef(new nsRunnableMethodImpl<Method, true, false>(aPtr, aMethod));
+  return do_AddRef(new detail::RunnableMethodImpl<Method, true, false>(aPtr, aMethod));
 }
 
 template<typename PtrType, typename Method>
-already_AddRefed<typename nsRunnableMethodTraits<Method, true, true>::base_type>
+already_AddRefed<typename ::nsRunnableMethodTraits<Method, true, true>::base_type>
 NewCancelableRunnableMethod(PtrType aPtr, Method aMethod)
 {
-  return do_AddRef(new nsRunnableMethodImpl<Method, true, true>(aPtr, aMethod));
+  return do_AddRef(new detail::RunnableMethodImpl<Method, true, true>(aPtr, aMethod));
 }
 
 template<typename PtrType, typename Method>
-already_AddRefed<typename nsRunnableMethodTraits<Method, false, false>::base_type>
+already_AddRefed<typename ::nsRunnableMethodTraits<Method, false, false>::base_type>
 NewNonOwningRunnableMethod(PtrType&& aPtr, Method aMethod)
 {
-  return do_AddRef(new nsRunnableMethodImpl<Method, false, false>(aPtr, aMethod));
+  return do_AddRef(new detail::RunnableMethodImpl<Method, false, false>(aPtr, aMethod));
 }
 
 template<typename PtrType, typename Method>
-already_AddRefed<typename nsRunnableMethodTraits<Method, false, true>::base_type>
+already_AddRefed<typename ::nsRunnableMethodTraits<Method, false, true>::base_type>
 NewNonOwningCancelableRunnableMethod(PtrType&& aPtr, Method aMethod)
 {
-  return do_AddRef(new nsRunnableMethodImpl<Method, false, true>(aPtr, aMethod));
+  return do_AddRef(new detail::RunnableMethodImpl<Method, false, true>(aPtr, aMethod));
 }
 
 // Similar to NewRunnableMethod. Call like so:
 // nsCOMPtr<nsIRunnable> event =
 //   NewRunnableMethod<Types,...>(myObject, &MyClass::HandleEvent, myArg1,...);
 // 'Types' are the stored type for each argument, see ParameterStorage for details.
 template<typename... Storages, typename Method, typename PtrType, typename... Args>
-already_AddRefed<typename nsRunnableMethodTraits<Method, true, false>::base_type>
+already_AddRefed<typename ::nsRunnableMethodTraits<Method, true, false>::base_type>
 NewRunnableMethod(PtrType&& aPtr, Method aMethod, Args&&... aArgs)
 {
   static_assert(sizeof...(Storages) == sizeof...(Args),
                 "<Storages...> size should be equal to number of arguments");
-  return do_AddRef(new nsRunnableMethodImpl<Method, true, false, Storages...>(
+  return do_AddRef(new detail::RunnableMethodImpl<Method, true, false, Storages...>(
       aPtr, aMethod, mozilla::Forward<Args>(aArgs)...));
 }
 
 template<typename... Storages, typename Method, typename PtrType, typename... Args>
-already_AddRefed<typename nsRunnableMethodTraits<Method, false, false>::base_type>
+already_AddRefed<typename ::nsRunnableMethodTraits<Method, false, false>::base_type>
 NewNonOwningRunnableMethod(PtrType&& aPtr, Method aMethod, Args&&... aArgs)
 {
   static_assert(sizeof...(Storages) == sizeof...(Args),
                 "<Storages...> size should be equal to number of arguments");
-  return do_AddRef(new nsRunnableMethodImpl<Method, false, false, Storages...>(
+  return do_AddRef(new detail::RunnableMethodImpl<Method, false, false, Storages...>(
       aPtr, aMethod, mozilla::Forward<Args>(aArgs)...));
 }
 
 template<typename... Storages, typename Method, typename PtrType, typename... Args>
-already_AddRefed<typename nsRunnableMethodTraits<Method, true, true>::base_type>
+already_AddRefed<typename ::nsRunnableMethodTraits<Method, true, true>::base_type>
 NewCancelableRunnableMethod(PtrType&& aPtr, Method aMethod, Args&&... aArgs)
 {
   static_assert(sizeof...(Storages) == sizeof...(Args),
                 "<Storages...> size should be equal to number of arguments");
-  return do_AddRef(new nsRunnableMethodImpl<Method, true, true, Storages...>(
+  return do_AddRef(new detail::RunnableMethodImpl<Method, true, true, Storages...>(
       aPtr, aMethod, mozilla::Forward<Args>(aArgs)...));
 }
 
 template<typename... Storages, typename Method, typename PtrType, typename... Args>
-already_AddRefed<typename nsRunnableMethodTraits<Method, false, true>::base_type>
+already_AddRefed<typename ::nsRunnableMethodTraits<Method, false, true>::base_type>
 NewNonOwningCancelableRunnableMethod(PtrType&& aPtr, Method aMethod,
                                                 Args&&... aArgs)
 {
   static_assert(sizeof...(Storages) == sizeof...(Args),
                 "<Storages...> size should be equal to number of arguments");
-  return do_AddRef(new nsRunnableMethodImpl<Method, false, true, Storages...>(
+  return do_AddRef(new detail::RunnableMethodImpl<Method, false, true, Storages...>(
       aPtr, aMethod, mozilla::Forward<Args>(aArgs)...));
 }
 
 } // namespace mozilla
 
 #endif  // XPCOM_GLUE_AVOID_NSPR
 
 // This class is designed to be used when you have an event class E that has a