Bug 1320753 - Adding nsINamed naming to nsITimer (r=ehsan)
authorBill McCloskey <billm@mozilla.com>
Tue, 22 Nov 2016 20:40:13 -0800
changeset 324956 704915079f6b12990201dc378ee05c8861e98a7c
parent 324955 97c6218a8654c2a97698ebb13300180ae925fe7f
child 324957 ac84d68036e44439bb1589dd3f1f8174a2c342be
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersehsan
bugs1320753
milestone53.0a1
Bug 1320753 - Adding nsINamed naming to nsITimer (r=ehsan) MozReview-Commit-ID: AbyLcMhRvbx
xpcom/threads/TimerThread.cpp
xpcom/threads/nsTimerImpl.cpp
xpcom/threads/nsTimerImpl.h
--- a/xpcom/threads/TimerThread.cpp
+++ b/xpcom/threads/TimerThread.cpp
@@ -144,16 +144,18 @@ public:
     // Since nsTimerImpl is not thread-safe, we should release |mTimer|
     // here in the target thread to avoid race condition. Otherwise,
     // ~nsTimerEvent() which calls nsTimerImpl::Release() could run in the
     // timer thread and result in race condition.
     mTimer = nullptr;
     return NS_OK;
   }
 
+  NS_IMETHOD GetName(nsACString& aName) override;
+
   nsTimerEvent()
     : mTimer()
     , mGeneration(0)
   {
     // Note: We override operator new for this class, and the override is
     // fallible!
     sAllocatorUsers++;
   }
@@ -263,16 +265,26 @@ nsTimerEvent::DeleteAllocatorIfNeeded()
 {
   if (sCanDeleteAllocator && sAllocatorUsers == 0) {
     delete sAllocator;
     sAllocator = nullptr;
   }
 }
 
 NS_IMETHODIMP
+nsTimerEvent::GetName(nsACString& aName)
+{
+  bool current;
+  MOZ_RELEASE_ASSERT(NS_SUCCEEDED(mTimer->mEventTarget->IsOnCurrentThread(&current)) && current);
+
+  mTimer->GetName(aName);
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 nsTimerEvent::Run()
 {
   if (!mTimer) {
     MOZ_ASSERT(false);
     return NS_OK;
   }
 
   if (mGeneration != mTimer->GetGeneration()) {
--- a/xpcom/threads/nsTimerImpl.cpp
+++ b/xpcom/threads/nsTimerImpl.cpp
@@ -646,16 +646,52 @@ nsTimerImpl::SetDelayInternal(uint32_t a
     if (mStart.IsNull()) {
       mStart = aBase;
     } else {
       mStart2 = aBase;
     }
   }
 }
 
+void
+nsTimerImpl::GetName(nsACString& aName)
+{
+  switch (mCallbackType) {
+    case CallbackType::Function:
+      if (mName.is<NameString>()) {
+        aName.Assign(mName.as<NameString>());
+      } else if (mName.is<NameFunc>()) {
+        static const size_t buflen = 1024;
+        char buf[buflen];
+        mName.as<NameFunc>()(mITimer, mClosure, buf, buflen);
+        aName.Assign(buf);
+      } else {
+        MOZ_ASSERT(mName.is<NameNothing>());
+        aName.Truncate();
+      }
+      break;
+
+    case CallbackType::Interface:
+      if (nsCOMPtr<nsINamed> named = do_QueryInterface(mCallback.i)) {
+        named->GetName(aName);
+      }
+      break;
+
+    case CallbackType::Observer:
+      if (nsCOMPtr<nsINamed> named = do_QueryInterface(mCallback.o)) {
+        named->GetName(aName);
+      }
+      break;
+
+    case CallbackType::Unknown:
+      aName.Truncate();
+      break;
+  }
+}
+
 nsTimer::~nsTimer()
 {
 }
 
 size_t
 nsTimer::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
 {
   return aMallocSizeOf(this);
--- a/xpcom/threads/nsTimerImpl.h
+++ b/xpcom/threads/nsTimerImpl.h
@@ -106,16 +106,18 @@ public:
     return mType >= nsITimer::TYPE_REPEATING_SLACK;
   }
 
   bool IsRepeatingPrecisely() const
   {
     return mType >= nsITimer::TYPE_REPEATING_PRECISE;
   }
 
+  void GetName(nsACString& aName);
+
   nsCOMPtr<nsIEventTarget> mEventTarget;
 
   void*                 mClosure;
 
   union CallbackUnion
   {
     nsTimerCallbackFunc c;
     // These refcounted references are managed manually, as they are in a union