Bug 1404198: Part 2a - Add non-virtual constructors for nsITimer. r=njn

MozReview-Commit-ID: 3I7MAquvMHj

--HG--
extra : rebase_source : 9fb92a49fb9b89aec738aca5f77ef3a612802df6
This commit is contained in:
Kris Maglione 2017-10-15 23:10:17 -07:00
Родитель 3876d40960
Коммит 3c7ea8250b
2 изменённых файлов: 263 добавлений и 0 удалений

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

@ -262,6 +262,80 @@ interface nsITimer : nsISupports
};
%{C++
#include "nsCOMPtr.h"
already_AddRefed<nsITimer> NS_NewTimer();
already_AddRefed<nsITimer> NS_NewTimer(nsIEventTarget* aTarget);
nsresult
NS_NewTimerWithObserver(nsITimer** aTimer,
nsIObserver* aObserver,
uint32_t aDelay,
uint32_t aType,
nsIEventTarget* aTarget = nullptr);
mozilla::Result<nsCOMPtr<nsITimer>, nsresult>
NS_NewTimerWithObserver(nsIObserver* aObserver,
uint32_t aDelay,
uint32_t aType,
nsIEventTarget* aTarget = nullptr);
nsresult
NS_NewTimerWithCallback(nsITimer** aTimer,
nsITimerCallback* aCallback,
uint32_t aDelay,
uint32_t aType,
nsIEventTarget* aTarget = nullptr);
mozilla::Result<nsCOMPtr<nsITimer>, nsresult>
NS_NewTimerWithCallback(nsITimerCallback* aCallback,
uint32_t aDelay,
uint32_t aType,
nsIEventTarget* aTarget = nullptr);
nsresult
NS_NewTimerWithCallback(nsITimer** aTimer,
nsITimerCallback* aCallback,
const mozilla::TimeDuration& aDelay,
uint32_t aType,
nsIEventTarget* aTarget = nullptr);
mozilla::Result<nsCOMPtr<nsITimer>, nsresult>
NS_NewTimerWithCallback(nsITimerCallback* aCallback,
const mozilla::TimeDuration& aDelay,
uint32_t aType,
nsIEventTarget* aTarget = nullptr);
nsresult
NS_NewTimerWithFuncCallback(nsITimer** aTimer,
nsTimerCallbackFunc aCallback,
void* aClosure,
uint32_t aDelay,
uint32_t aType,
const char* aNameString,
nsIEventTarget* aTarget = nullptr);
mozilla::Result<nsCOMPtr<nsITimer>, nsresult>
NS_NewTimerWithFuncCallback(nsTimerCallbackFunc aCallback,
void* aClosure,
uint32_t aDelay,
uint32_t aType,
const char* aNameString,
nsIEventTarget* aTarget = nullptr);
nsresult
NS_NewTimerWithFuncCallback(nsITimer** aTimer,
nsTimerCallbackFunc aCallback,
void* aClosure,
uint32_t aDelay,
uint32_t aType,
nsTimerNameCallbackFunc aNameCallback,
nsIEventTarget* aTarget = nullptr);
mozilla::Result<nsCOMPtr<nsITimer>, nsresult>
NS_NewTimerWithFuncCallback(nsTimerCallbackFunc aCallback,
void* aClosure,
uint32_t aDelay,
uint32_t aType,
nsTimerNameCallbackFunc aNameCallback,
nsIEventTarget* aTarget = nullptr);
#define NS_TIMER_CONTRACTID "@mozilla.org/timer;1"
#define NS_TIMER_CALLBACK_TOPIC "timer-callback"
%}

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

@ -16,6 +16,7 @@
#include "mozilla/Logging.h"
#include "mozilla/Move.h"
#include "mozilla/Mutex.h"
#include "mozilla/ResultExtensions.h"
#ifdef MOZ_TASK_TRACER
#include "GeckoTaskTracerImpl.h"
using namespace mozilla::tasktracer;
@ -32,6 +33,7 @@ using namespace mozilla::tasktracer;
using mozilla::Atomic;
using mozilla::LogLevel;
using mozilla::MakeRefPtr;
using mozilla::Move;
using mozilla::MutexAutoLock;
using mozilla::TimeDuration;
@ -56,6 +58,193 @@ NS_GetTimerDeadlineHintOnCurrentThread(TimeStamp aDefault, uint32_t aSearchBound
: TimeStamp();
}
already_AddRefed<nsITimer>
NS_NewTimer()
{
return do_AddRef(new nsTimer());
}
already_AddRefed<nsITimer>
NS_NewTimer(nsIEventTarget* aTarget)
{
auto timer = MakeRefPtr<nsTimer>();
if (aTarget && MOZ_LIKELY(timer)) {
MOZ_ALWAYS_SUCCEEDS(timer->SetTarget(aTarget));
}
return timer.forget();
}
mozilla::Result<nsCOMPtr<nsITimer>, nsresult>
NS_NewTimerWithObserver(nsIObserver* aObserver,
uint32_t aDelay,
uint32_t aType,
nsIEventTarget* aTarget)
{
nsCOMPtr<nsITimer> timer;
MOZ_TRY(NS_NewTimerWithObserver(getter_AddRefs(timer),
aObserver,
aDelay,
aType,
aTarget));
return Move(timer);
}
nsresult
NS_NewTimerWithObserver(nsITimer** aTimer,
nsIObserver* aObserver,
uint32_t aDelay,
uint32_t aType,
nsIEventTarget* aTarget)
{
auto timer = MakeRefPtr<nsTimer>();
if (aTarget) {
MOZ_ALWAYS_SUCCEEDS(timer->SetTarget(aTarget));
}
MOZ_TRY(timer->Init(aObserver, aDelay, aType));
timer.forget(aTimer);
return NS_OK;
}
mozilla::Result<nsCOMPtr<nsITimer>, nsresult>
NS_NewTimerWithCallback(nsITimerCallback* aCallback,
uint32_t aDelay,
uint32_t aType,
nsIEventTarget* aTarget)
{
nsCOMPtr<nsITimer> timer;
MOZ_TRY(NS_NewTimerWithCallback(getter_AddRefs(timer),
aCallback,
aDelay,
aType,
aTarget));
return Move(timer);
}
nsresult
NS_NewTimerWithCallback(nsITimer** aTimer,
nsITimerCallback* aCallback,
uint32_t aDelay,
uint32_t aType,
nsIEventTarget* aTarget)
{
auto timer = MakeRefPtr<nsTimer>();
if (aTarget) {
MOZ_ALWAYS_SUCCEEDS(timer->SetTarget(aTarget));
}
MOZ_TRY(timer->InitWithCallback(aCallback, aDelay, aType));
timer.forget(aTimer);
return NS_OK;
}
mozilla::Result<nsCOMPtr<nsITimer>, nsresult>
NS_NewTimerWithCallback(nsITimerCallback* aCallback,
const TimeDuration& aDelay,
uint32_t aType,
nsIEventTarget* aTarget)
{
nsCOMPtr<nsITimer> timer;
MOZ_TRY(NS_NewTimerWithCallback(getter_AddRefs(timer),
aCallback,
aDelay,
aType,
aTarget));
return Move(timer);
}
nsresult
NS_NewTimerWithCallback(nsITimer** aTimer,
nsITimerCallback* aCallback,
const TimeDuration& aDelay,
uint32_t aType,
nsIEventTarget* aTarget)
{
auto timer = MakeRefPtr<nsTimer>();
if (aTarget) {
MOZ_ALWAYS_SUCCEEDS(timer->SetTarget(aTarget));
}
MOZ_TRY(timer->InitHighResolutionWithCallback(aCallback, aDelay, aType));
timer.forget(aTimer);
return NS_OK;
}
mozilla::Result<nsCOMPtr<nsITimer>, nsresult>
NS_NewTimerWithFuncCallback(nsTimerCallbackFunc aCallback,
void* aClosure,
uint32_t aDelay,
uint32_t aType,
const char* aNameString,
nsIEventTarget* aTarget)
{
nsCOMPtr<nsITimer> timer;
MOZ_TRY(NS_NewTimerWithFuncCallback(getter_AddRefs(timer),
aCallback,
aClosure,
aDelay,
aType,
aNameString,
aTarget));
return Move(timer);
}
nsresult
NS_NewTimerWithFuncCallback(nsITimer** aTimer,
nsTimerCallbackFunc aCallback,
void* aClosure,
uint32_t aDelay,
uint32_t aType,
const char* aNameString,
nsIEventTarget* aTarget)
{
auto timer = MakeRefPtr<nsTimer>();
if (aTarget) {
MOZ_ALWAYS_SUCCEEDS(timer->SetTarget(aTarget));
}
MOZ_TRY(timer->InitWithNamedFuncCallback(aCallback, aClosure,
aDelay, aType,
aNameString));
timer.forget(aTimer);
return NS_OK;
}
mozilla::Result<nsCOMPtr<nsITimer>, nsresult>
NS_NewTimerWithFuncCallback(nsTimerCallbackFunc aCallback,
void* aClosure,
uint32_t aDelay,
uint32_t aType,
nsTimerNameCallbackFunc aNameCallback,
nsIEventTarget* aTarget)
{
nsCOMPtr<nsITimer> timer;
MOZ_TRY(NS_NewTimerWithFuncCallback(getter_AddRefs(timer),
aCallback,
aClosure,
aDelay,
aType,
aNameCallback,
aTarget));
return Move(timer);
}
nsresult
NS_NewTimerWithFuncCallback(nsITimer** aTimer,
nsTimerCallbackFunc aCallback,
void* aClosure,
uint32_t aDelay,
uint32_t aType,
nsTimerNameCallbackFunc aNameCallback,
nsIEventTarget* aTarget)
{
auto timer = MakeRefPtr<nsTimer>();
if (aTarget) {
MOZ_ALWAYS_SUCCEEDS(timer->SetTarget(aTarget));
}
MOZ_TRY(timer->InitWithNameableFuncCallback(aCallback, aClosure,
aDelay, aType,
aNameCallback));
timer.forget(aTimer);
return NS_OK;
}
// This module prints info about which timers are firing, which is useful for
// wakeups for the purposes of power profiling. Set the following environment
// variable before starting the browser.