Bug 1404198: Part 2b - Switch to NS_NewTimer* in xpcom. r=njn

MozReview-Commit-ID: BEtHEpOmT1E

--HG--
extra : rebase_source : dac8a182f1ad76df6715146e1da1279c02c0406f
This commit is contained in:
Kris Maglione 2017-10-15 23:11:22 -07:00
Родитель 3c7ea8250b
Коммит f6ba082a01
11 изменённых файлов: 49 добавлений и 101 удалений

Просмотреть файл

@ -1736,13 +1736,9 @@ nsMemoryReporterManager::StartGettingReports()
}
if (!s->mChildrenPending.IsEmpty()) {
nsCOMPtr<nsITimer> timer = do_CreateInstance(NS_TIMER_CONTRACTID);
// Don't use NS_ENSURE_* here; can't return until the report is finished.
if (NS_WARN_IF(!timer)) {
FinishReporting();
return NS_ERROR_FAILURE;
}
rv = timer->InitWithNamedFuncCallback(
nsCOMPtr<nsITimer> timer;
rv = NS_NewTimerWithFuncCallback(
getter_AddRefs(timer),
TimeoutCallback,
this,
kTimeoutLengthMS,

Просмотреть файл

@ -98,16 +98,11 @@ MessageLoopIdleTask::MessageLoopIdleTask(nsIRunnable* aTask,
nsresult
MessageLoopIdleTask::Init(uint32_t aEnsureRunsAfterMS)
{
mTimer = do_CreateInstance("@mozilla.org/timer;1");
if (NS_WARN_IF(!mTimer)) {
return NS_ERROR_UNEXPECTED;
}
RefPtr<MessageLoopTimerCallback> callback =
new MessageLoopTimerCallback(this);
return mTimer->InitWithCallback(callback, aEnsureRunsAfterMS,
nsITimer::TYPE_ONE_SHOT);
return NS_NewTimerWithCallback(getter_AddRefs(mTimer),
callback, aEnsureRunsAfterMS,
nsITimer::TYPE_ONE_SHOT);
}
NS_IMETHODIMP

Просмотреть файл

@ -445,26 +445,22 @@ private:
if (mTimer || !mTimerPeriod) {
return NS_OK;
}
mTimer = do_CreateInstance("@mozilla.org/timer;1");
if (!mTimer) {
return NS_ERROR_OUT_OF_MEMORY;
}
if (mEventTarget) {
mTimer->SetTarget(mEventTarget);
} else if (!NS_IsMainThread()) {
nsCOMPtr<nsIEventTarget> target = mEventTarget;
if (!target && !NS_IsMainThread()) {
// TimerCallback should always be run on the main thread to prevent races
// to the destruction of the tracker.
nsCOMPtr<nsIEventTarget> target = do_GetMainThread();
target = do_GetMainThread();
NS_ENSURE_STATE(target);
mTimer->SetTarget(target);
}
mTimer->InitWithNamedFuncCallback(
return NS_NewTimerWithFuncCallback(
getter_AddRefs(mTimer),
TimerCallback,
this,
mTimerPeriod,
nsITimer::TYPE_REPEATING_SLACK_LOW_PRIORITY,
mName);
return NS_OK;
mName,
target);
}
};

Просмотреть файл

@ -17,6 +17,7 @@
#ifdef XP_WIN
#include "nsIObserver.h"
#include "nsIObserverService.h"
#include "mozilla/ResultExtensions.h"
#include "mozilla/Services.h"
#include "nsIIdleService.h"
#include "nsISimpleEnumerator.h"
@ -174,16 +175,9 @@ public:
// idle observer too early, it will be registered before the fake idle
// service is installed when running in xpcshell, and this interferes with
// the fake idle service, causing xpcshell-test failures.
mTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
if (NS_WARN_IF(!mTimer)) {
return NS_ERROR_FAILURE;
}
nsresult rv = mTimer->Init(this,
SCHEDULE_TIMEOUT_MS,
nsITimer::TYPE_ONE_SHOT);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
MOZ_TRY_VAR(mTimer, NS_NewTimerWithObserver(this,
SCHEDULE_TIMEOUT_MS,
nsITimer::TYPE_ONE_SHOT));
// Register shutdown observer so we can cancel the timer if we shutdown before
// the timer runs.

Просмотреть файл

@ -591,9 +591,9 @@ public:
{
CheckExecutedMethods("Method3", 3);
mTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
mTimer->InitWithNamedFuncCallback(
Method4, this, 10, nsITimer::TYPE_ONE_SHOT, "IdleObject::Method3");
NS_NewTimerWithFuncCallback(getter_AddRefs(mTimer),
Method4, this, 10, nsITimer::TYPE_ONE_SHOT,
"IdleObject::Method3");
NS_IdleDispatchToCurrentThread(
NewIdleRunnableMethodWithTimer("IdleObject::Method5", this, &IdleObject::Method5), 50);
NS_IdleDispatchToCurrentThread(

Просмотреть файл

@ -112,22 +112,18 @@ TEST(Timers, TargetedTimers)
AutoTestThread testThread;
ASSERT_TRUE(testThread);
nsresult rv;
nsCOMPtr<nsITimer> timer = do_CreateInstance(NS_TIMER_CONTRACTID, &rv);
ASSERT_TRUE(NS_SUCCEEDED(rv));
nsIEventTarget* target = static_cast<nsIEventTarget*>(testThread);
rv = timer->SetTarget(target);
ASSERT_TRUE(NS_SUCCEEDED(rv));
nsIThread* notifiedThread = nullptr;
nsCOMPtr<nsITimerCallback> callback =
new TimerCallback(&notifiedThread, newMon);
ASSERT_TRUE(callback);
rv = timer->InitWithCallback(callback, 2000, nsITimer::TYPE_ONE_SHOT);
nsIEventTarget* target = static_cast<nsIEventTarget*>(testThread);
nsCOMPtr<nsITimer> timer;
nsresult rv = NS_NewTimerWithCallback(getter_AddRefs(timer),
callback, 2000, nsITimer::TYPE_ONE_SHOT,
target);
ASSERT_TRUE(NS_SUCCEEDED(rv));
ReentrantMonitorAutoEnter mon(*newMon);
@ -142,21 +138,17 @@ TEST(Timers, TimerWithStoppedTarget)
AutoTestThread testThread;
ASSERT_TRUE(testThread);
nsresult rv;
nsCOMPtr<nsITimer> timer = do_CreateInstance(NS_TIMER_CONTRACTID, &rv);
ASSERT_TRUE(NS_SUCCEEDED(rv));
nsIEventTarget* target = static_cast<nsIEventTarget*>(testThread);
rv = timer->SetTarget(target);
ASSERT_TRUE(NS_SUCCEEDED(rv));
// If this is called, we'll assert
nsCOMPtr<nsITimerCallback> callback =
new TimerCallback(nullptr, nullptr);
ASSERT_TRUE(callback);
rv = timer->InitWithCallback(callback, 100, nsITimer::TYPE_ONE_SHOT);
nsCOMPtr<nsITimer> timer;
nsresult rv = NS_NewTimerWithCallback(getter_AddRefs(timer),
callback, 100, nsITimer::TYPE_ONE_SHOT,
target);
ASSERT_TRUE(NS_SUCCEEDED(rv));
testThread->Shutdown();
@ -229,13 +221,12 @@ public:
PR_Sleep(PR_MillisecondsToInterval(waitTime));
} while(true);
nsresult rv;
mBefore = TimeStamp::Now();
mMiddle = mBefore + TimeDuration::FromMilliseconds(
kTimerOffset + kTimerInterval * kNumTimers / 2);
for (uint32_t i = 0; i < kNumTimers; ++i) {
nsCOMPtr<nsITimer> timer = do_CreateInstance(NS_TIMER_CONTRACTID, &rv);
ASSERT_TRUE(NS_SUCCEEDED(rv));
nsCOMPtr<nsITimer> timer = NS_NewTimer();
ASSERT_TRUE(timer);
if (i < aNumDifferingTimers) {
if (aTarget) {
@ -564,12 +555,8 @@ class FuzzTestThreadState final : public nsITimerCallback {
void CreateRandomTimer()
{
nsresult rv;
nsCOMPtr<nsITimer> timer = do_CreateInstance(NS_TIMER_CONTRACTID, &rv);
MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv), "Failed to create timer.");
rv = timer->SetTarget(static_cast<nsIEventTarget*>(mThread.get()));
MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv), "Failed to set target.");
nsCOMPtr<nsITimer> timer = NS_NewTimer(static_cast<nsIEventTarget*>(mThread.get()));
MOZ_RELEASE_ASSERT(timer, "Failed to create timer.");
InitRandomTimer(timer.get());
}

Просмотреть файл

@ -145,7 +145,7 @@ IdleTaskRunner::Schedule(bool aAllowIdleDispatch)
NS_IdleDispatchToCurrentThread(runnable.forget());
} else {
if (!mScheduleTimer) {
mScheduleTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
mScheduleTimer = NS_NewTimer();
if (!mScheduleTimer) {
return;
}
@ -190,7 +190,7 @@ IdleTaskRunner::SetTimerInternal(uint32_t aDelay)
}
if (!mTimer) {
mTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
mTimer = NS_NewTimer();
} else {
mTimer->Cancel();
}

Просмотреть файл

@ -153,7 +153,7 @@ LazyIdleThread::EnsureThread()
}
}
mIdleTimer = do_CreateInstance(NS_TIMER_CONTRACTID, &rv);
mIdleTimer = NS_NewTimer();
if (NS_WARN_IF(!mIdleTimer)) {
return NS_ERROR_UNEXPECTED;
}

Просмотреть файл

@ -42,15 +42,9 @@ public:
nsresult Init()
{
nsresult rv;
mTimer = do_CreateInstance(NS_TIMER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
MOZ_ASSERT(mTimer);
rv = mTimer->SetTarget(mTarget);
NS_ENSURE_SUCCESS(rv, rv);
return mTimer->InitWithCallback(this, mDelay, nsITimer::TYPE_ONE_SHOT);
return NS_NewTimerWithCallback(getter_AddRefs(mTimer),
this, mDelay, nsITimer::TYPE_ONE_SHOT,
mTarget);
}
nsresult DoRun()

Просмотреть файл

@ -81,16 +81,6 @@ CancelableRunnable::Cancel()
NS_IMPL_ISUPPORTS_INHERITED(IdleRunnable, CancelableRunnable,
nsIIdleRunnable)
namespace mozilla {
namespace detail {
already_AddRefed<nsITimer> CreateTimer()
{
nsCOMPtr<nsITimer> timer = do_CreateInstance(NS_TIMER_CONTRACTID);
return timer.forget();
}
} // namespace detail
} // namespace mozilla
NS_IMPL_ISUPPORTS_INHERITED(PrioritizableRunnable, Runnable,
nsIRunnablePriority)
@ -360,15 +350,13 @@ public:
{
MOZ_ASSERT(aTarget);
MOZ_ASSERT(!mTimer);
mTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
if (mTimer) {
mTimer->SetTarget(aTarget);
mTimer->InitWithNamedFuncCallback(TimedOut,
this,
aDelay,
nsITimer::TYPE_ONE_SHOT,
"IdleRunnableWrapper::SetTimer");
}
NS_NewTimerWithFuncCallback(getter_AddRefs(mTimer),
TimedOut,
this,
aDelay,
nsITimer::TYPE_ONE_SHOT,
"IdleRunnableWrapper::SetTimer",
aTarget);
}
NS_IMETHOD GetName(nsACString& aName) override

Просмотреть файл

@ -638,8 +638,6 @@ NS_NewRunnableFunction(const char* aName, Function&& aFunction)
namespace mozilla {
namespace detail {
already_AddRefed<nsITimer> CreateTimer();
template <RunnableKind Kind>
class TimerBehaviour
{
@ -658,7 +656,7 @@ public:
nsITimer* GetTimer()
{
if (!mTimer) {
mTimer = CreateTimer();
mTimer = NS_NewTimer();
}
return mTimer;