Bug 793759 - Implement HalChild::ActorDestroy and prevent HalChild calls to HalParent after ActorDestroy is called. r=cjones

This commit is contained in:
Steven Lee 2012-10-06 21:53:22 -04:00
Родитель da48899757
Коммит baec46c4f8
3 изменённых файлов: 36 добавлений и 15 удалений

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

@ -32,15 +32,20 @@ using namespace mozilla::services;
#define PROXY_IF_SANDBOXED(_call) \
do { \
if (InSandbox()) { \
hal_sandbox::_call; \
if (!hal_sandbox::IsHalChildLive()) { \
hal_sandbox::_call; \
} \
} else { \
hal_impl::_call; \
} \
} while (0)
#define RETURN_PROXY_IF_SANDBOXED(_call) \
#define RETURN_PROXY_IF_SANDBOXED(_call, defValue)\
do { \
if (InSandbox()) { \
if (hal_sandbox::IsHalChildLive()) { \
return defValue; \
} \
return hal_sandbox::_call; \
} else { \
return hal_impl::_call; \
@ -363,7 +368,7 @@ NotifyBatteryChange(const BatteryInformation& aInfo)
bool GetScreenEnabled()
{
AssertMainThread();
RETURN_PROXY_IF_SANDBOXED(GetScreenEnabled());
RETURN_PROXY_IF_SANDBOXED(GetScreenEnabled(), false);
}
void SetScreenEnabled(bool enabled)
@ -379,7 +384,7 @@ bool GetCpuSleepAllowed()
// what the battery API does. But since this is only used by
// privileged interface, the synchronous getter is OK here.
AssertMainThread();
RETURN_PROXY_IF_SANDBOXED(GetCpuSleepAllowed());
RETURN_PROXY_IF_SANDBOXED(GetCpuSleepAllowed(), true);
}
void SetCpuSleepAllowed(bool allowed)
@ -391,7 +396,7 @@ void SetCpuSleepAllowed(bool allowed)
double GetScreenBrightness()
{
AssertMainThread();
RETURN_PROXY_IF_SANDBOXED(GetScreenBrightness());
RETURN_PROXY_IF_SANDBOXED(GetScreenBrightness(), 0);
}
void SetScreenBrightness(double brightness)
@ -403,13 +408,13 @@ void SetScreenBrightness(double brightness)
bool SetLight(LightType light, const hal::LightConfiguration& aConfig)
{
AssertMainThread();
RETURN_PROXY_IF_SANDBOXED(SetLight(light, aConfig));
RETURN_PROXY_IF_SANDBOXED(SetLight(light, aConfig), false);
}
bool GetLight(LightType light, hal::LightConfiguration* aConfig)
{
AssertMainThread();
RETURN_PROXY_IF_SANDBOXED(GetLight(light, aConfig));
RETURN_PROXY_IF_SANDBOXED(GetLight(light, aConfig), false);
}
class SystemTimeObserversManager : public ObserversManager<SystemTimeChange>
@ -464,7 +469,7 @@ nsCString
GetTimezone()
{
AssertMainThread();
RETURN_PROXY_IF_SANDBOXED(GetTimezone());
RETURN_PROXY_IF_SANDBOXED(GetTimezone(), nsCString(""));
}
void
@ -655,7 +660,7 @@ bool
LockScreenOrientation(const dom::ScreenOrientation& aOrientation)
{
AssertMainThread();
RETURN_PROXY_IF_SANDBOXED(LockScreenOrientation(aOrientation));
RETURN_PROXY_IF_SANDBOXED(LockScreenOrientation(aOrientation), false);
}
void
@ -680,7 +685,7 @@ DisableSwitchNotifications(hal::SwitchDevice aDevice) {
hal::SwitchState GetCurrentSwitchState(hal::SwitchDevice aDevice)
{
AssertMainThread();
RETURN_PROXY_IF_SANDBOXED(GetCurrentSwitchState(aDevice));
RETURN_PROXY_IF_SANDBOXED(GetCurrentSwitchState(aDevice), SWITCH_STATE_UNKNOWN);
}
typedef mozilla::ObserverList<SwitchEvent> SwitchObserverList;
@ -758,7 +763,7 @@ RegisterTheOneAlarmObserver(AlarmObserver* aObserver)
MOZ_ASSERT(!sAlarmObserver);
sAlarmObserver = aObserver;
RETURN_PROXY_IF_SANDBOXED(EnableAlarm());
RETURN_PROXY_IF_SANDBOXED(EnableAlarm(), false);
}
void
@ -783,7 +788,7 @@ SetAlarm(int32_t aSeconds, int32_t aNanoseconds)
{
// It's pointless to program an alarm nothing is going to observe ...
MOZ_ASSERT(sAlarmObserver);
RETURN_PROXY_IF_SANDBOXED(SetAlarm(aSeconds, aNanoseconds));
RETURN_PROXY_IF_SANDBOXED(SetAlarm(aSeconds, aNanoseconds), false);
}
void
@ -856,19 +861,19 @@ SetFMRadioFrequency(const uint32_t aFrequency) {
uint32_t
GetFMRadioFrequency() {
AssertMainThread();
RETURN_PROXY_IF_SANDBOXED(GetFMRadioFrequency());
RETURN_PROXY_IF_SANDBOXED(GetFMRadioFrequency(), 0);
}
bool
IsFMRadioOn() {
AssertMainThread();
RETURN_PROXY_IF_SANDBOXED(IsFMRadioOn());
RETURN_PROXY_IF_SANDBOXED(IsFMRadioOn(), false);
}
uint32_t
GetFMRadioSignalStrength() {
AssertMainThread();
RETURN_PROXY_IF_SANDBOXED(GetFMRadioSignalStrength());
RETURN_PROXY_IF_SANDBOXED(GetFMRadioSignalStrength(), 0);
}
void

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

@ -84,6 +84,7 @@ void EnableSystemTimeChangeNotifications();
*/
void DisableSystemTimeChangeNotifications();
bool IsHalChildLive();
} // namespace MOZ_HAL_NAMESPACE
} // namespace mozilla

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

@ -25,6 +25,14 @@ using namespace mozilla::hal;
namespace mozilla {
namespace hal_sandbox {
static bool sHalChildIsLive = false;
bool
IsHalChildLive()
{
return sHalChildIsLive;
}
static PHalChild* sHal;
static PHalChild*
Hal()
@ -396,6 +404,7 @@ public:
hal::UnregisterSensorObserver(SensorType(sensor), this);
}
hal::UnregisterWakeLockObserver(this);
hal::UnregisterSystemTimeChangeObserver(this);
}
virtual bool
@ -837,6 +846,12 @@ public:
class HalChild : public PHalChild {
public:
virtual void
ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE
{
sHalChildIsLive = true;
}
virtual bool
RecvNotifyBatteryChange(const BatteryInformation& aBatteryInfo) MOZ_OVERRIDE {
hal::NotifyBatteryChange(aBatteryInfo);