mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-27 07:34:20 +00:00
Bug 714358 System time change implementation, r=mounir
This commit is contained in:
parent
5f194e2f32
commit
ec4bd9ff6f
@ -16,5 +16,5 @@ interface nsIDOMMozTimeManager : nsISupports
|
||||
* - If |time| is a Date object, |set(time)| is equivalent to
|
||||
* |set(time.getTime())|.
|
||||
*/
|
||||
void set(in jsval time);
|
||||
[implicit_jscontext] void set(in jsval time);
|
||||
};
|
||||
|
32
hal/Hal.cpp
32
hal/Hal.cpp
@ -406,7 +406,39 @@ bool GetLight(LightType light, hal::LightConfiguration* aConfig)
|
||||
RETURN_PROXY_IF_SANDBOXED(GetLight(light, aConfig));
|
||||
}
|
||||
|
||||
static StaticAutoPtr<ObserverList<SystemTimeChange>> sSystemTimeObserver;
|
||||
|
||||
static void
|
||||
InitializeSystemTimeChangeObserver()
|
||||
{
|
||||
if (!sSystemTimeObserver) {
|
||||
sSystemTimeObserver = new ObserverList<SystemTimeChange>;
|
||||
ClearOnShutdown(&sSystemTimeObserver);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
RegisterSystemTimeChangeObserver(SystemTimeObserver *aObserver)
|
||||
{
|
||||
AssertMainThread();
|
||||
InitializeSystemTimeChangeObserver();
|
||||
sSystemTimeObserver->AddObserver(aObserver);
|
||||
}
|
||||
|
||||
void
|
||||
UnregisterSystemTimeChangeObserver(SystemTimeObserver *aObserver)
|
||||
{
|
||||
AssertMainThread();
|
||||
sSystemTimeObserver->RemoveObserver(aObserver);
|
||||
}
|
||||
|
||||
void
|
||||
NotifySystemTimeChange(const hal::SystemTimeChange& aReason)
|
||||
{
|
||||
InitializeSystemTimeChangeObserver();
|
||||
sSystemTimeObserver->Broadcast(aReason);
|
||||
}
|
||||
|
||||
void
|
||||
AdjustSystemClock(int32_t aDeltaMilliseconds)
|
||||
{
|
||||
|
20
hal/Hal.h
20
hal/Hal.h
@ -50,6 +50,8 @@ class WindowIdentifier;
|
||||
extern PRLogModuleInfo *sHalLog;
|
||||
#define HAL_LOG(msg) PR_LOG(mozilla::hal::sHalLog, PR_LOG_DEBUG, msg)
|
||||
|
||||
typedef Observer<SystemTimeChange> SystemTimeObserver;
|
||||
|
||||
} // namespace hal
|
||||
|
||||
namespace MOZ_HAL_NAMESPACE {
|
||||
@ -255,6 +257,24 @@ void SetTimezone(const nsCString& aTimezoneSpec);
|
||||
*/
|
||||
nsCString GetTimezone();
|
||||
|
||||
/**
|
||||
* Register observer for system time changed notification.
|
||||
* @param aObserver The observer that should be added.
|
||||
*/
|
||||
void RegisterSystemTimeChangeObserver(hal::SystemTimeObserver* aObserver);
|
||||
|
||||
/**
|
||||
* Unregister the observer for system time changed.
|
||||
* @param aObserver The observer that should be removed.
|
||||
*/
|
||||
void UnregisterSystemTimeChangeObserver(hal::SystemTimeObserver* aObserver);
|
||||
|
||||
/**
|
||||
* Notify of a change in the system cloeck or time zone.
|
||||
* @param aReason
|
||||
*/
|
||||
void NotifySystemTimeChange(const hal::SystemTimeChange& aReason);
|
||||
|
||||
/**
|
||||
* Reboot the device.
|
||||
*/
|
||||
|
@ -74,6 +74,13 @@ enum WakeLockControl {
|
||||
NUM_WAKE_LOCK
|
||||
};
|
||||
|
||||
enum SystemTimeChange {
|
||||
SYS_TIME_CHANGE_UNKNOWN = -1,
|
||||
SYS_TIME_CHANGE_CLOCK,
|
||||
SYS_TIME_CHANGE_TZ,
|
||||
SYS_TIME_CHANGE_GUARD
|
||||
};
|
||||
|
||||
} // namespace hal
|
||||
} // namespace mozilla
|
||||
|
||||
@ -146,7 +153,16 @@ struct ParamTraits<mozilla::hal::ProcessPriority>:
|
||||
mozilla::hal::NUM_PROCESS_PRIORITY> {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* SystemTimeChange serializer.
|
||||
*/
|
||||
template <>
|
||||
struct ParamTraits<mozilla::hal::SystemTimeChange>
|
||||
: public EnumSerializer<mozilla::hal::SystemTimeChange,
|
||||
mozilla::hal::SYS_TIME_CHANGE_UNKNOWN,
|
||||
mozilla::hal::SYS_TIME_CHANGE_GUARD>
|
||||
{};
|
||||
|
||||
} // namespace IPC
|
||||
|
||||
#endif // mozilla_hal_Types_h
|
||||
|
@ -581,6 +581,10 @@ sys_clock_settime(clockid_t clk_id, const struct timespec *tp)
|
||||
void
|
||||
AdjustSystemClock(int32_t aDeltaMilliseconds)
|
||||
{
|
||||
if (aDeltaMilliseconds == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct timespec now;
|
||||
|
||||
// Preventing context switch before setting system clock
|
||||
@ -600,16 +604,26 @@ AdjustSystemClock(int32_t aDeltaMilliseconds)
|
||||
now.tv_sec -= 1;
|
||||
}
|
||||
// we need to have root privilege.
|
||||
sys_clock_settime(CLOCK_REALTIME, &now);
|
||||
if (sys_clock_settime(CLOCK_REALTIME, &now) != 0) {
|
||||
NS_ERROR("sys_clock_settime failed");
|
||||
return;
|
||||
}
|
||||
|
||||
hal::NotifySystemTimeChange(hal::SYS_TIME_CHANGE_CLOCK);
|
||||
}
|
||||
|
||||
void
|
||||
SetTimezone(const nsCString& aTimezoneSpec)
|
||||
{
|
||||
{
|
||||
if (aTimezoneSpec.Equals(GetTimezone())) {
|
||||
return;
|
||||
}
|
||||
|
||||
property_set("persist.sys.timezone", aTimezoneSpec.get());
|
||||
// this function is automatically called by the other time conversion
|
||||
// functions that depend on the timezone. To be safe, we call it manually.
|
||||
tzset();
|
||||
hal::NotifySystemTimeChange(hal::SYS_TIME_CHANGE_TZ);
|
||||
}
|
||||
|
||||
nsCString
|
||||
|
@ -24,6 +24,7 @@ using mozilla::hal::SwitchDevice;
|
||||
using mozilla::hal::ProcessPriority;
|
||||
using nsIntRect;
|
||||
using PRTime;
|
||||
using mozilla::hal::SystemTimeChange;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
@ -86,6 +87,7 @@ child:
|
||||
NotifyWakeLockChange(WakeLockInformation aWakeLockInfo);
|
||||
NotifyScreenConfigurationChange(ScreenConfiguration aScreenOrientation);
|
||||
NotifySwitchChange(SwitchEvent aEvent);
|
||||
NotifySystemTimeChange(SystemTimeChange aReason);
|
||||
|
||||
parent:
|
||||
Vibrate(uint32_t[] pattern, uint64_t[] id, PBrowser browser);
|
||||
|
@ -676,6 +676,11 @@ public:
|
||||
hal::SetProcessPriority(aPid, aPriority);
|
||||
return true;
|
||||
}
|
||||
|
||||
void Notify(const SystemTimeChange& aReason)
|
||||
{
|
||||
unused << SendNotifySystemTimeChange(aReason);
|
||||
}
|
||||
};
|
||||
|
||||
class HalChild : public PHalChild {
|
||||
@ -712,6 +717,12 @@ public:
|
||||
hal::NotifySwitchChange(aEvent);
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool
|
||||
RecvNotifySystemTimeChange(const SystemTimeChange& aReason) {
|
||||
hal::NotifySystemTimeChange(aReason);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
bool
|
||||
|
Loading…
x
Reference in New Issue
Block a user