Bug 790497 - Alarm API - Adjust firing time for "ignoreTimezone" alarms when timezone is reset. r=cjones

This commit is contained in:
Gene Lian 2012-09-12 18:15:15 +08:00
parent b2e8059680
commit 2c968cb59a
2 changed files with 25 additions and 11 deletions

View File

@ -16,12 +16,17 @@ void
AlarmHalService::Init()
{
mAlarmEnabled = RegisterTheOneAlarmObserver(this);
if (!mAlarmEnabled) {
return;
}
RegisterSystemTimeChangeObserver(this);
}
/* virtual */ AlarmHalService::~AlarmHalService()
{
if (mAlarmEnabled) {
UnregisterTheOneAlarmObserver();
UnregisterSystemTimeChangeObserver(this);
}
}
@ -48,7 +53,6 @@ AlarmHalService::SetAlarm(int32_t aSeconds, int32_t aNanoseconds, bool* aStatus)
}
bool status = hal::SetAlarm(aSeconds, aNanoseconds);
if (status) {
*aStatus = status;
return NS_OK;
@ -74,9 +78,19 @@ AlarmHalService::SetTimezoneChangedCb(nsITimezoneChangedCb* aTimeZoneChangedCb)
void
AlarmHalService::Notify(const mozilla::void_t& aVoid)
{
if (mAlarmFiredCb) {
mAlarmFiredCb->OnAlarmFired();
if (!mAlarmFiredCb) {
return;
}
mAlarmFiredCb->OnAlarmFired();
}
void
AlarmHalService::Notify(const SystemTimeChange& aReason)
{
if (aReason != SYS_TIME_CHANGE_TZ || !mTimezoneChangedCb) {
return;
}
mTimezoneChangedCb->OnTimezoneChanged(GetTimezoneOffset(false));
}
int32_t

View File

@ -19,8 +19,11 @@ namespace mozilla {
namespace dom {
namespace alarm {
using namespace hal;
class AlarmHalService : public nsIAlarmHalService,
mozilla::hal::AlarmObserver
public AlarmObserver,
public SystemTimeObserver
{
public:
NS_DECL_ISUPPORTS
@ -34,17 +37,14 @@ public:
// Implementing hal::AlarmObserver
void Notify(const mozilla::void_t& aVoid);
// Implementing hal::SystemTimeObserver
void Notify(const SystemTimeChange& aReason);
private:
bool mAlarmEnabled;
nsCOMPtr<nsIAlarmFiredCb> mAlarmFiredCb;
static StaticRefPtr<AlarmHalService> sSingleton;
// TODO The mTimezoneChangedCb would be called
// when a timezone-changed event is detected
// at run-time. To do so, we can register a
// timezone-changed observer, see bug 714358.
// We need to adjust the alarm time respect to
// the correct timezone where user is located.
nsCOMPtr<nsIAlarmFiredCb> mAlarmFiredCb;
nsCOMPtr<nsITimezoneChangedCb> mTimezoneChangedCb;
int32_t GetTimezoneOffset(bool aIgnoreDST);