Bug 1350436 - Collapse Dispatcher into ValidatingDispatcher (r=froydnj)
authorBill McCloskey <billm@mozilla.com>
Wed, 08 Mar 2017 21:46:01 -0800
changeset 560283 1ff47d6ae913a460e61906e1bd7c1beef17c310c
parent 560282 2e1cf27870806c50856d4b49f1d40e45ce8a49ac
child 560284 68dcc900c5bd9daefc73f48d3ba375482ce14ef5
push id53365
push userjichen@mozilla.com
push dateTue, 11 Apr 2017 08:35:12 +0000
reviewersfroydnj
bugs1350436
milestone55.0a1
Bug 1350436 - Collapse Dispatcher into ValidatingDispatcher (r=froydnj) MozReview-Commit-ID: DrcElmf4iyn
dom/base/DispatcherTrait.cpp
xpcom/threads/Dispatcher.cpp
xpcom/threads/Dispatcher.h
--- a/dom/base/DispatcherTrait.cpp
+++ b/dom/base/DispatcherTrait.cpp
@@ -13,17 +13,17 @@
 using namespace mozilla;
 using namespace mozilla::dom;
 
 nsresult
 DispatcherTrait::Dispatch(const char* aName,
                           TaskCategory aCategory,
                           already_AddRefed<nsIRunnable>&& aRunnable)
 {
-  return Dispatcher::UnlabeledDispatch(aName, aCategory, Move(aRunnable));
+  return ValidatingDispatcher::UnlabeledDispatch(aName, aCategory, Move(aRunnable));
 }
 
 nsIEventTarget*
 DispatcherTrait::EventTargetFor(TaskCategory aCategory) const
 {
   nsCOMPtr<nsIEventTarget> main = do_GetMainThread();
   return main;
 }
--- a/xpcom/threads/Dispatcher.cpp
+++ b/xpcom/threads/Dispatcher.cpp
@@ -103,27 +103,20 @@ DispatcherEventTarget::DelayedDispatch(a
 
 NS_IMETHODIMP
 DispatcherEventTarget::IsOnCurrentThread(bool* aIsOnCurrentThread)
 {
   *aIsOnCurrentThread = NS_IsMainThread();
   return NS_OK;
 }
 
-AbstractThread*
-Dispatcher::AbstractMainThreadFor(TaskCategory aCategory)
-{
-  MOZ_RELEASE_ASSERT(NS_IsMainThread());
-  return AbstractMainThreadForImpl(aCategory);
-}
-
 /* static */ nsresult
-Dispatcher::UnlabeledDispatch(const char* aName,
-                              TaskCategory aCategory,
-                              already_AddRefed<nsIRunnable>&& aRunnable)
+ValidatingDispatcher::UnlabeledDispatch(const char* aName,
+                                        TaskCategory aCategory,
+                                        already_AddRefed<nsIRunnable>&& aRunnable)
 {
   nsCOMPtr<nsIRunnable> runnable(aRunnable);
   if (aName) {
     if (nsCOMPtr<nsINamed> named = do_QueryInterface(runnable)) {
       named->SetName(aName);
     }
   }
   if (NS_IsMainThread()) {
@@ -152,16 +145,23 @@ nsIEventTarget*
 ValidatingDispatcher::EventTargetFor(TaskCategory aCategory) const
 {
   MOZ_ASSERT(aCategory != TaskCategory::Count);
   MOZ_ASSERT(mEventTargets[size_t(aCategory)]);
   return mEventTargets[size_t(aCategory)];
 }
 
 AbstractThread*
+ValidatingDispatcher::AbstractMainThreadFor(TaskCategory aCategory)
+{
+  MOZ_RELEASE_ASSERT(NS_IsMainThread());
+  return AbstractMainThreadForImpl(aCategory);
+}
+
+AbstractThread*
 ValidatingDispatcher::AbstractMainThreadForImpl(TaskCategory aCategory)
 {
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aCategory != TaskCategory::Count);
   MOZ_ASSERT(mEventTargets[size_t(aCategory)]);
 
   if (!mAbstractThreads[size_t(aCategory)]) {
     mAbstractThreads[size_t(aCategory)] =
--- a/xpcom/threads/Dispatcher.h
+++ b/xpcom/threads/Dispatcher.h
@@ -26,53 +26,23 @@ class TabGroup;
 // (with roughly one group per tab). Runnables will be annotated with the set of
 // groups that they touch. Two runnables may run concurrently on different
 // fibers as long as they touch different groups.
 //
 // A Dispatcher is an abstract class to represent a "group". Essentially the
 // only functionality offered by a Dispatcher is the ability to dispatch
 // runnables to the group. TabGroup, DocGroup, and SystemGroup are the concrete
 // implementations of Dispatcher.
-class Dispatcher
-{
-public:
-  NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
-
-  // Implementations of this method must be safe to call off the main thread.
-  virtual nsresult Dispatch(const char* aName,
-                            TaskCategory aCategory,
-                            already_AddRefed<nsIRunnable>&& aRunnable) = 0;
-
-  // Implementations of this method must be safe to call off the main thread.
-  // The returned nsIEventTarget must also be usable from any thread.
-  virtual nsIEventTarget* EventTargetFor(TaskCategory aCategory) const = 0;
-
-  // Must always be called on the main thread. The returned AbstractThread can
-  // always be used off the main thread.
-  AbstractThread* AbstractMainThreadFor(TaskCategory aCategory);
-
-  // This method performs a safe cast. It returns null if |this| is not of the
-  // requested type.
-  virtual dom::TabGroup* AsTabGroup() { return nullptr; }
-
-  static nsresult UnlabeledDispatch(const char* aName,
-                                    TaskCategory aCategory,
-                                    already_AddRefed<nsIRunnable>&& aRunnable);
-
-protected:
-  // Implementations are guaranteed that this method is called on the main
-  // thread.
-  virtual AbstractThread* AbstractMainThreadForImpl(TaskCategory aCategory) = 0;
-};
-
-class ValidatingDispatcher : public Dispatcher
+class ValidatingDispatcher
 {
 public:
   ValidatingDispatcher();
 
+  NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
+
   class MOZ_STACK_CLASS AutoProcessEvent final {
   public:
     AutoProcessEvent();
     ~AutoProcessEvent();
 
   private:
     ValidatingDispatcher* mPrevRunningDispatcher;
   };
@@ -83,26 +53,38 @@ public:
     MOZ_ASSERT(!sRunningDispatcher || mAccessValid);
   }
 
   class Runnable;
   friend class Runnable;
 
   bool* GetValidAccessPtr() { return &mAccessValid; }
 
-  nsresult Dispatch(const char* aName,
-                    TaskCategory aCategory,
-                    already_AddRefed<nsIRunnable>&& aRunnable) override;
+  virtual nsresult Dispatch(const char* aName,
+                            TaskCategory aCategory,
+                            already_AddRefed<nsIRunnable>&& aRunnable);
+
+  virtual nsIEventTarget* EventTargetFor(TaskCategory aCategory) const;
 
-  nsIEventTarget* EventTargetFor(TaskCategory aCategory) const override;
+  // Must always be called on the main thread. The returned AbstractThread can
+  // always be used off the main thread.
+  AbstractThread* AbstractMainThreadFor(TaskCategory aCategory);
+
+  // This method performs a safe cast. It returns null if |this| is not of the
+  // requested type.
+  virtual dom::TabGroup* AsTabGroup() { return nullptr; }
+
+  static nsresult UnlabeledDispatch(const char* aName,
+                                    TaskCategory aCategory,
+                                    already_AddRefed<nsIRunnable>&& aRunnable);
 
 protected:
   // Implementations are guaranteed that this method is called on the main
   // thread.
-  AbstractThread* AbstractMainThreadForImpl(TaskCategory aCategory) override;
+  virtual AbstractThread* AbstractMainThreadForImpl(TaskCategory aCategory);
 
   // Helper method to create an event target specific to a particular TaskCategory.
   virtual already_AddRefed<nsIEventTarget>
   CreateEventTargetFor(TaskCategory aCategory);
 
   // Given an event target returned by |dispatcher->CreateEventTargetFor|, this
   // function returns |dispatcher|.
   static ValidatingDispatcher* FromEventTarget(nsIEventTarget* aEventTarget);