Bug 1320753 - Adding nsINamed naming to nsITimer (r=ehsan)

MozReview-Commit-ID: AbyLcMhRvbx
This commit is contained in:
Bill McCloskey 2016-11-22 20:40:13 -08:00
parent 972fbd3fdf
commit 6df682a091
3 changed files with 50 additions and 0 deletions

View File

@ -149,6 +149,8 @@ public:
return NS_OK;
}
NS_IMETHOD GetName(nsACString& aName) override;
nsTimerEvent()
: mTimer()
, mGeneration(0)
@ -267,6 +269,16 @@ nsTimerEvent::DeleteAllocatorIfNeeded()
}
}
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()
{

View File

@ -651,6 +651,42 @@ nsTimerImpl::SetDelayInternal(uint32_t aDelay, TimeStamp 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()
{
}

View File

@ -111,6 +111,8 @@ public:
return mType >= nsITimer::TYPE_REPEATING_PRECISE;
}
void GetName(nsACString& aName);
nsCOMPtr<nsIEventTarget> mEventTarget;
void* mClosure;