Skip to content

Commit

Permalink
Bug 1404198: Part 2j - Switch to NS_NewTimer* everywhere else. r=njn
Browse files Browse the repository at this point in the history
MozReview-Commit-ID: LmGIgfmNSmk

--HG--
extra : rebase_source : bf34e852beb0c8f6eafd09184c2e0cda95f95f83
  • Loading branch information
kmaglione committed Sep 25, 2017
1 parent 60d080b commit 4a767c7
Show file tree
Hide file tree
Showing 19 changed files with 117 additions and 148 deletions.
5 changes: 3 additions & 2 deletions accessible/base/nsAccessibilityService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,10 @@ nsAccessibilityService::CreatePluginAccessible(nsPluginFrame* aFrame,
if (!sPendingPlugins->Contains(aContent) &&
(Preferences::GetBool("accessibility.delay_plugins") ||
Compatibility::IsJAWS() || Compatibility::IsWE())) {
nsCOMPtr<nsITimer> timer = do_CreateInstance(NS_TIMER_CONTRACTID);
RefPtr<PluginTimerCallBack> cb = new PluginTimerCallBack(aContent);
timer->InitWithCallback(cb, Preferences::GetUint("accessibility.delay_plugin_time"),
nsCOMPtr<nsITimer> timer;
NS_NewTimerWithCallback(getter_AddRefs(timer),
cb, Preferences::GetUint("accessibility.delay_plugin_time"),
nsITimer::TYPE_ONE_SHOT);
sPluginTimers->AppendElement(timer);
sPendingPlugins->AppendElement(aContent);
Expand Down
13 changes: 6 additions & 7 deletions accessible/generic/DocAccessible.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -650,15 +650,14 @@ DocAccessible::ScrollPositionDidChange(nscoord aX, nscoord aY)
mScrollWatchTimer->SetDelay(kScrollPosCheckWait); // Create new timer, to avoid leaks
}
else {
mScrollWatchTimer = do_CreateInstance("@mozilla.org/timer;1");
NS_NewTimerWithFuncCallback(getter_AddRefs(mScrollWatchTimer),
ScrollTimerCallback,
this,
kScrollPosCheckWait,
nsITimer::TYPE_REPEATING_SLACK,
"a11y::DocAccessible::ScrollPositionDidChange");
if (mScrollWatchTimer) {
NS_ADDREF_THIS(); // Kung fu death grip
mScrollWatchTimer->InitWithNamedFuncCallback(
ScrollTimerCallback,
this,
kScrollPosCheckWait,
nsITimer::TYPE_REPEATING_SLACK,
"a11y::DocAccessible::ScrollPositionDidChange");
}
}
mScrollPositionChangedTicks = 1;
Expand Down
15 changes: 6 additions & 9 deletions accessible/xpcom/xpcAccessibilityService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,12 @@ xpcAccessibilityService::Release(void)
// xpcAccessibilityService and we can attempt to shut down acceessiblity
// service.
if (count == 1 && !mShutdownTimer) {
mShutdownTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
if (mShutdownTimer) {
mShutdownTimer->InitWithNamedFuncCallback(
ShutdownCallback,
this,
100,
nsITimer::TYPE_ONE_SHOT,
"xpcAccessibilityService::Release");
}
NS_NewTimerWithFuncCallback(getter_AddRefs(mShutdownTimer),
ShutdownCallback,
this,
100,
nsITimer::TYPE_ONE_SHOT,
"xpcAccessibilityService::Release");
}

return count;
Expand Down
56 changes: 26 additions & 30 deletions docshell/base/nsDocShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "mozilla/LoadInfo.h"
#include "mozilla/HTMLEditor.h"
#include "mozilla/Preferences.h"
#include "mozilla/ResultExtensions.h"
#include "mozilla/Services.h"
#include "mozilla/StartupTimeline.h"
#include "mozilla/Telemetry.h"
Expand Down Expand Up @@ -456,23 +457,13 @@ nsPingListener::StartTimeout(DocGroup* aDocGroup)
{
NS_ENSURE_ARG(aDocGroup);

nsCOMPtr<nsITimer> timer = do_CreateInstance(NS_TIMER_CONTRACTID);
timer->SetTarget(aDocGroup->EventTargetFor(TaskCategory::Network));

if (timer) {
nsresult rv =
timer->InitWithNamedFuncCallback(OnPingTimeout,
mLoadGroup,
PING_TIMEOUT,
nsITimer::TYPE_ONE_SHOT,
"nsPingListener::StartTimeout");
if (NS_SUCCEEDED(rv)) {
mTimer = timer;
return NS_OK;
}
}

return NS_ERROR_OUT_OF_MEMORY;
return NS_NewTimerWithFuncCallback(getter_AddRefs(mTimer),
OnPingTimeout,
mLoadGroup,
PING_TIMEOUT,
nsITimer::TYPE_ONE_SHOT,
"nsPingListener::StartTimeout",
aDocGroup->EventTargetFor(TaskCategory::Network));
}

NS_IMETHODIMP
Expand Down Expand Up @@ -6858,14 +6849,15 @@ nsDocShell::RefreshURI(nsIURI* aURI, int32_t aDelay, bool aRepeat,
} else {
// There is no page loading going on right now. Create the
// timer and fire it right away.
nsCOMPtr<nsITimer> timer = do_CreateInstance("@mozilla.org/timer;1");
NS_ENSURE_TRUE(timer, NS_ERROR_FAILURE);
nsCOMPtr<nsPIDOMWindowOuter> win = GetWindow();
NS_ENSURE_TRUE(win, NS_ERROR_FAILURE);

nsCOMPtr<nsITimer> timer;
MOZ_TRY_VAR(timer,
NS_NewTimerWithCallback(refreshTimer, aDelay, nsITimer::TYPE_ONE_SHOT,
win->TabGroup()->EventTargetFor(TaskCategory::Network)));

mRefreshURIList->AppendElement(timer, /*weak =*/ false); // owning timer ref
timer->SetTarget(win->TabGroup()->EventTargetFor(TaskCategory::Network));
timer->InitWithCallback(refreshTimer, aDelay, nsITimer::TYPE_ONE_SHOT);
}
return NS_OK;
}
Expand Down Expand Up @@ -7345,16 +7337,20 @@ nsDocShell::RefreshURIFromQueue()
uint32_t delay =
static_cast<nsRefreshTimer*>(
static_cast<nsITimerCallback*>(refreshInfo))->GetDelay();
nsCOMPtr<nsITimer> timer = do_CreateInstance("@mozilla.org/timer;1");
nsCOMPtr<nsPIDOMWindowOuter> win = GetWindow();
if (timer && win) {
// Replace the nsRefreshTimer element in the queue with
// its corresponding timer object, so that in case another
// load comes through before the timer can go off, the timer will
// get cancelled in CancelRefreshURITimer()
mRefreshURIList->ReplaceElementAt(timer, n, /*weak =*/ false);
timer->SetTarget(win->TabGroup()->EventTargetFor(TaskCategory::Network));
timer->InitWithCallback(refreshInfo, delay, nsITimer::TYPE_ONE_SHOT);
if (win) {
nsCOMPtr<nsITimer> timer;
NS_NewTimerWithCallback(getter_AddRefs(timer),
refreshInfo, delay, nsITimer::TYPE_ONE_SHOT,
win->TabGroup()->EventTargetFor(TaskCategory::Network));

if (timer) {
// Replace the nsRefreshTimer element in the queue with
// its corresponding timer object, so that in case another
// load comes through before the timer can go off, the timer will
// get cancelled in CancelRefreshURITimer()
mRefreshURIList->ReplaceElementAt(timer, n, /*weak =*/ false);
}
}
}
}
Expand Down
45 changes: 23 additions & 22 deletions docshell/base/nsDocShellTreeOwner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1244,30 +1244,31 @@ ChromeTooltipListener::MouseMove(nsIDOMEvent* aMouseEvent)
}

if (!mShowingTooltip && !mTooltipShownOnce) {
mTooltipTimer = do_CreateInstance("@mozilla.org/timer;1");
if (mTooltipTimer) {
nsCOMPtr<EventTarget> eventTarget =
aMouseEvent->InternalDOMEvent()->GetTarget();
if (eventTarget) {
mPossibleTooltipNode = do_QueryInterface(eventTarget);
nsCOMPtr<nsIGlobalObject> global(eventTarget->GetOwnerGlobal());
if (global) {
mTooltipTimer->SetTarget(global->EventTargetFor(TaskCategory::UI));
}
nsIEventTarget* target = nullptr;

nsCOMPtr<EventTarget> eventTarget =
aMouseEvent->InternalDOMEvent()->GetTarget();
if (eventTarget) {
mPossibleTooltipNode = do_QueryInterface(eventTarget);
nsCOMPtr<nsIGlobalObject> global(eventTarget->GetOwnerGlobal());
if (global) {
target = global->EventTargetFor(TaskCategory::UI);
}
if (mPossibleTooltipNode) {
nsresult rv = mTooltipTimer->InitWithNamedFuncCallback(
sTooltipCallback,
this,
LookAndFeel::GetInt(LookAndFeel::eIntID_TooltipDelay, 500),
nsITimer::TYPE_ONE_SHOT,
"ChromeTooltipListener::MouseMove");
if (NS_FAILED(rv)) {
mPossibleTooltipNode = nullptr;
}
}

if (mPossibleTooltipNode) {
nsresult rv = NS_NewTimerWithFuncCallback(
getter_AddRefs(mTooltipTimer),
sTooltipCallback,
this,
LookAndFeel::GetInt(LookAndFeel::eIntID_TooltipDelay, 500),
nsITimer::TYPE_ONE_SHOT,
"ChromeTooltipListener::MouseMove",
target);
if (NS_FAILED(rv)) {
mPossibleTooltipNode = nullptr;
NS_WARNING("Could not create a timer for tooltip tracking");
}
} else {
NS_WARNING("Could not create a timer for tooltip tracking");
}
} else {
mTooltipShownOnce = true;
Expand Down
5 changes: 2 additions & 3 deletions editor/composer/nsComposerCommandsUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,8 @@ nsresult
nsComposerCommandsUpdater::PrimeUpdateTimer()
{
if (!mUpdateTimer) {
nsresult rv = NS_OK;
mUpdateTimer = do_CreateInstance("@mozilla.org/timer;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
mUpdateTimer = NS_NewTimer();;
NS_ENSURE_TRUE(mUpdateTimer, NS_ERROR_OUT_OF_MEMORY);
}

const uint32_t kUpdateTimerDelay = 150;
Expand Down
10 changes: 5 additions & 5 deletions editor/composer/nsEditingSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -967,16 +967,16 @@ nsEditingSession::EndDocumentLoad(nsIWebProgress *aWebProgress,
mLoadBlankDocTimer = nullptr;
}

mLoadBlankDocTimer = do_CreateInstance("@mozilla.org/timer;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);

mEditorStatus = eEditorCreationInProgress;
mLoadBlankDocTimer->InitWithNamedFuncCallback(
rv = NS_NewTimerWithFuncCallback(
getter_AddRefs(mLoadBlankDocTimer),
nsEditingSession::TimerCallback,
static_cast<void*>(mDocShell.get()),
10,
nsITimer::TYPE_ONE_SHOT,
"nsEditingSession::EndDocumentLoad");
NS_ENSURE_SUCCESS(rv, rv);

mEditorStatus = eEditorCreationInProgress;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions editor/libeditor/TextEditRules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -713,8 +713,8 @@ TextEditRules::WillInsertText(EditAction aAction,
if (mTimer) {
mTimer->Cancel();
} else {
mTimer = do_CreateInstance("@mozilla.org/timer;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
mTimer = NS_NewTimer();
NS_ENSURE_TRUE(mTimer, NS_ERROR_OUT_OF_MEMORY);
}
mTimer->InitWithCallback(this, LookAndFeel::GetPasswordMaskDelay(),
nsITimer::TYPE_ONE_SHOT);
Expand Down
10 changes: 3 additions & 7 deletions extensions/pref/autoconfig/src/nsAutoConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "mozilla/ResultExtensions.h"
#include "nsAutoConfig.h"
#include "nsIURI.h"
#include "nsIHttpChannel.h"
Expand Down Expand Up @@ -335,13 +336,8 @@ nsresult nsAutoConfig::downloadAutoConfig()
if (NS_SUCCEEDED(rv) && minutes > 0) {
// Create a new timer and pass this nsAutoConfig
// object as a timer callback.
mTimer = do_CreateInstance("@mozilla.org/timer;1",&rv);
if (NS_FAILED(rv))
return rv;
rv = mTimer->InitWithCallback(this, minutes * 60 * 1000,
nsITimer::TYPE_REPEATING_SLACK);
if (NS_FAILED(rv))
return rv;
MOZ_TRY_VAR(mTimer, NS_NewTimerWithCallback(this, minutes * 60 * 1000,
nsITimer::TYPE_REPEATING_SLACK));
}
} //first_time

Expand Down
5 changes: 2 additions & 3 deletions ipc/glue/BackgroundImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1030,9 +1030,8 @@ ParentImpl::CreateBackgroundThread()
nsCOMPtr<nsITimer> newShutdownTimer;

if (!sShutdownTimer) {
nsresult rv;
newShutdownTimer = do_CreateInstance(NS_TIMER_CONTRACTID, &rv);
if (NS_WARN_IF(NS_FAILED(rv))) {
newShutdownTimer = NS_NewTimer();
if (!newShutdownTimer) {
return false;
}
}
Expand Down
10 changes: 3 additions & 7 deletions ipc/glue/MessagePump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ MessagePump::Run(MessagePump::Delegate* aDelegate)
nsIThread* thisThread = NS_GetCurrentThread();
MOZ_ASSERT(thisThread);

mDelayedWorkTimer = do_CreateInstance(kNS_TIMER_CID);
mDelayedWorkTimer = NS_NewTimer();
MOZ_ASSERT(mDelayedWorkTimer);

base::ScopedNSAutoreleasePool autoReleasePool;
Expand Down Expand Up @@ -162,7 +162,7 @@ MessagePump::ScheduleDelayedWork(const base::TimeTicks& aDelayedTime)
|| mEventTarget->IsOnCurrentThread());

if (!mDelayedWorkTimer) {
mDelayedWorkTimer = do_CreateInstance(kNS_TIMER_CID);
mDelayedWorkTimer = NS_NewTimer();
if (!mDelayedWorkTimer) {
// Called before XPCOM has started up? We can't do this correctly.
NS_WARNING("Delayed task might not run!");
Expand Down Expand Up @@ -310,13 +310,9 @@ MessagePumpForNonMainThreads::Run(base::MessagePump::Delegate* aDelegate)
nsIThread* thread = NS_GetCurrentThread();
MOZ_RELEASE_ASSERT(mEventTarget->IsOnCurrentThread());

mDelayedWorkTimer = do_CreateInstance(kNS_TIMER_CID);
mDelayedWorkTimer = NS_NewTimer(mEventTarget);
MOZ_ASSERT(mDelayedWorkTimer);

if (NS_FAILED(mDelayedWorkTimer->SetTarget(mEventTarget))) {
MOZ_CRASH("Failed to set timer target!");
}

// Chromium event notifications to be processed will be received by this
// event loop as a DoWorkRunnables via ScheduleWork. Chromium events that
// were received before our thread is valid, however, will not generate
Expand Down
2 changes: 1 addition & 1 deletion mobile/android/components/build/nsAndroidHistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ nsAndroidHistory::nsAndroidHistory()
{
LoadPrefs();

mTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
mTimer = NS_NewTimer();
}

NS_IMETHODIMP
Expand Down
2 changes: 1 addition & 1 deletion parser/html/nsHtml5StreamParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ nsHtml5StreamParser::nsHtml5StreamParser(nsHtml5TreeOpExecutor* aExecutor,
, mLoadFlusher(new nsHtml5LoadFlusher(aExecutor))
, mFeedChardet(false)
, mInitialEncodingWasFromParentFrame(false)
, mFlushTimer(do_CreateInstance("@mozilla.org/timer;1"))
, mFlushTimer(NS_NewTimer())
, mFlushTimerMutex("nsHtml5StreamParser mFlushTimerMutex")
, mFlushTimerArmed(false)
, mFlushTimerEverFired(false)
Expand Down
4 changes: 2 additions & 2 deletions security/manager/ssl/DataStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -963,8 +963,8 @@ DataStorage::SetTimer()

nsresult rv;
if (!mTimer) {
mTimer = do_CreateInstance("@mozilla.org/timer;1", &rv);
if (NS_WARN_IF(NS_FAILED(rv))) {
mTimer = NS_NewTimer();
if (NS_WARN_IF(!mTimer)) {
return;
}
}
Expand Down
4 changes: 2 additions & 2 deletions startupcache/StartupCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,9 +581,9 @@ nsresult
StartupCache::ResetStartupWriteTimer()
{
mStartupWriteInitiated = false;
nsresult rv;
nsresult rv = NS_OK;
if (!mTimer)
mTimer = do_CreateInstance("@mozilla.org/timer;1", &rv);
mTimer = NS_NewTimer();
else
rv = mTimer->Cancel();
NS_ENSURE_SUCCESS(rv, rv);
Expand Down
4 changes: 2 additions & 2 deletions tools/profiler/gecko/ThreadResponsiveness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ class CheckResponsivenessTask : public Runnable,

if (!mStop) {
if (!mTimer) {
mTimer = do_CreateInstance("@mozilla.org/timer;1");
mTimer->SetTarget(SystemGroup::EventTargetFor(TaskCategory::Other));
mTimer = NS_NewTimer(
SystemGroup::EventTargetFor(TaskCategory::Other));
}
mTimer->InitWithCallback(this, 16, nsITimer::TYPE_ONE_SHOT);
}
Expand Down
8 changes: 2 additions & 6 deletions uriloader/exthandler/nsExternalHelperAppService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* This must occur *after* base/basictypes.h to avoid typedefs conflicts. */
#include "mozilla/ArrayUtils.h"
#include "mozilla/Base64.h"
#include "mozilla/ResultExtensions.h"

#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/TabChild.h"
Expand Down Expand Up @@ -2531,12 +2532,7 @@ nsresult nsExternalAppHandler::MaybeCloseWindow()
// Now close the old window. Do it on a timer so that we don't run
// into issues trying to close the window before it has fully opened.
NS_ASSERTION(!mTimer, "mTimer was already initialized once!");
mTimer = do_CreateInstance("@mozilla.org/timer;1");
if (!mTimer) {
return NS_ERROR_FAILURE;
}

mTimer->InitWithCallback(this, 0, nsITimer::TYPE_ONE_SHOT);
MOZ_TRY_VAR(mTimer, NS_NewTimerWithCallback(this, 0, nsITimer::TYPE_ONE_SHOT));
mWindowToClose = window;
}
}
Expand Down
2 changes: 1 addition & 1 deletion xpfe/appshell/nsWebShellWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ nsWebShellWindow::SetPersistenceTimer(uint32_t aDirtyFlags)
{
MutexAutoLock lock(mSPTimerLock);
if (!mSPTimer) {
mSPTimer = do_CreateInstance("@mozilla.org/timer;1");
mSPTimer = NS_NewTimer();
if (!mSPTimer) {
NS_WARNING("Couldn't create @mozilla.org/timer;1 instance?");
return;
Expand Down
Loading

0 comments on commit 4a767c7

Please sign in to comment.