Backed out changeset 63c54b25b36f (bug 1862159) for causing bp-nu bustages in WakeLockListener.h. CLOSED TREE

This commit is contained in:
Stanca Serban 2023-11-08 17:04:46 +02:00
Родитель c49907e14f
Коммит 388b8f06a2
2 изменённых файлов: 56 добавлений и 112 удалений

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

@ -50,9 +50,8 @@ NS_IMPL_ISUPPORTS(WakeLockListener, nsIDOMMozWakeLockListener)
StaticRefPtr<WakeLockListener> WakeLockListener::sSingleton;
#define WAKE_LOCK_LOG(str, ...) \
MOZ_LOG(gLinuxWakeLockLog, mozilla::LogLevel::Debug, \
("[%p] " str, this, ##__VA_ARGS__))
#define WAKE_LOCK_LOG(...) \
MOZ_LOG(gLinuxWakeLockLog, mozilla::LogLevel::Debug, (__VA_ARGS__))
static mozilla::LazyLogModule gLinuxWakeLockLog("LinuxWakeLock");
enum WakeLockType {
@ -71,20 +70,6 @@ enum WakeLockType {
Unsupported = 6,
};
bool IsDBusWakeLock(int aWakeLockType) {
#if defined(MOZ_ENABLE_DBUS)
switch (aWakeLockType) {
case FreeDesktopScreensaver:
case FreeDesktopPower:
case GNOME:
return true;
default:
return false;
}
#endif
return false;
}
#ifdef MOZ_LOGGING
const char* WakeLockTypeNames[7] = {
"Initial", "FreeDesktopScreensaver", "FreeDesktopPower", "GNOME",
@ -98,13 +83,9 @@ class WakeLockTopic {
explicit WakeLockTopic(const nsAString& aTopic) {
CopyUTF16toUTF8(aTopic, mTopic);
WAKE_LOCK_LOG("WakeLockTopic::WakeLockTopic() created %s", mTopic.get());
if (sWakeLockType == Initial) {
SwitchToNextWakeLockType();
}
#ifdef MOZ_ENABLE_DBUS
mCancellable = dont_AddRef(g_cancellable_new());
#endif
}
nsresult InhibitScreensaver(void);
@ -115,7 +96,7 @@ class WakeLockTopic {
bool SendUninhibit();
#if defined(MOZ_X11)
bool CheckXScreenSaverSupport();
static bool CheckXScreenSaverSupport();
bool InhibitXScreenSaver(bool inhibit);
#endif
@ -130,6 +111,7 @@ class WakeLockTopic {
bool SwitchToNextWakeLockType();
#ifdef MOZ_ENABLE_DBUS
void DBusPrepareCancellable();
void DBusInhibitScreensaver(const char* aName, const char* aPath,
const char* aCall, const char* aMethod,
RefPtr<GVariant> aArgs);
@ -149,11 +131,9 @@ class WakeLockTopic {
void DBusUninhibitSucceeded();
void DBusUninhibitFailed();
#endif
~WakeLockTopic() {
WAKE_LOCK_LOG("WakeLockTopic::~WakeLockTopic() state %d", mInhibited);
#ifdef MOZ_ENABLE_DBUS
g_cancellable_cancel(mCancellable);
#endif
if (mInhibited) {
UninhibitScreensaver();
}
@ -169,15 +149,12 @@ class WakeLockTopic {
bool mInhibited = false;
#ifdef MOZ_ENABLE_DBUS
// We're waiting for DBus reply (inhibit/uninhibit calls).
bool mWaitingForDBusInhibit = false;
bool mWaitingForDBusUninhibit = false;
// We're waiting for DBus reply (inhibit/uninhibit call).
bool mWaitingForDBusReply = false;
// mInhibitRequestID is received from success screen saver inhibit call
// and it's needed for screen saver enablement.
uint32_t mInhibitRequestID = 0;
RefPtr<GCancellable> mCancellable;
#endif
static int sWakeLockType;
@ -187,14 +164,12 @@ int WakeLockTopic::sWakeLockType = Initial;
#ifdef MOZ_ENABLE_DBUS
void WakeLockTopic::DBusInhibitSucceeded(uint32_t aInhibitRequestID) {
mWaitingForDBusInhibit = false;
mWaitingForDBusReply = false;
mInhibitRequestID = aInhibitRequestID;
mInhibited = true;
WAKE_LOCK_LOG(
"WakeLockTopic::DBusInhibitSucceeded(), mInhibitRequestID %u "
"mShouldInhibit %d",
mInhibitRequestID, mShouldInhibit);
WAKE_LOCK_LOG("WakeLockTopic::DBusInhibitSucceeded(), mInhibitRequestID %u",
mInhibitRequestID);
// Uninhibit was requested before inhibit request was finished.
// So ask for it now.
@ -206,7 +181,7 @@ void WakeLockTopic::DBusInhibitSucceeded(uint32_t aInhibitRequestID) {
void WakeLockTopic::DBusInhibitFailed(bool aFatal) {
WAKE_LOCK_LOG("WakeLockTopic::DBusInhibitFailed(%d)", aFatal);
mWaitingForDBusInhibit = false;
mWaitingForDBusReply = false;
mInhibitRequestID = 0;
// Non-recoverable DBus error. Switch to another wake lock type.
@ -216,10 +191,9 @@ void WakeLockTopic::DBusInhibitFailed(bool aFatal) {
}
void WakeLockTopic::DBusUninhibitSucceeded() {
WAKE_LOCK_LOG("WakeLockTopic::DBusUninhibitSucceeded() mShouldInhibit %d",
mShouldInhibit);
WAKE_LOCK_LOG("WakeLockTopic::DBusInhibitSucceeded()");
mWaitingForDBusUninhibit = false;
mWaitingForDBusReply = false;
mInhibitRequestID = 0;
mInhibited = false;
@ -232,45 +206,36 @@ void WakeLockTopic::DBusUninhibitSucceeded() {
void WakeLockTopic::DBusUninhibitFailed() {
WAKE_LOCK_LOG("WakeLockTopic::DBusUninhibitFailed()");
mWaitingForDBusUninhibit = false;
mInhibitRequestID = 0;
mWaitingForDBusReply = false;
}
void WakeLockTopic::DBusInhibitScreensaver(const char* aName, const char* aPath,
const char* aCall,
const char* aMethod,
RefPtr<GVariant> aArgs) {
WAKE_LOCK_LOG(
"WakeLockTopic::DBusInhibitScreensaver() mWaitingForDBusInhibit %d "
"mWaitingForDBusUninhibit %d",
mWaitingForDBusInhibit, mWaitingForDBusUninhibit);
if (mWaitingForDBusInhibit) {
WAKE_LOCK_LOG(" already waiting to inihibit, return");
return;
WAKE_LOCK_LOG("WakeLockTopic::DBusInhibitScreensaver() waiting %d",
mWaitingForDBusReply);
if (mWaitingForDBusReply) {
// g_cancellable_cancel(mCancellable);
}
if (mWaitingForDBusUninhibit) {
WAKE_LOCK_LOG(" cancel un-inihibit request");
g_cancellable_cancel(mCancellable);
mWaitingForDBusUninhibit = false;
}
mWaitingForDBusInhibit = true;
mWaitingForDBusReply = true;
widget::CreateDBusProxyForBus(
G_BUS_TYPE_SESSION,
GDBusProxyFlags(G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS |
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES),
/* aInterfaceInfo = */ nullptr, aName, aPath, aCall, mCancellable)
/* aInterfaceInfo = */ nullptr, aName, aPath, aCall)
->Then(
GetCurrentSerialEventTarget(), __func__,
[self = RefPtr{this}, this, args = RefPtr{aArgs},
[self = RefPtr{this}, args = RefPtr{aArgs},
aMethod](RefPtr<GDBusProxy>&& aProxy) {
WAKE_LOCK_LOG(
"WakeLockTopic::DBusInhibitScreensaver() proxy created");
DBusProxyCall(aProxy.get(), aMethod, args.get(),
G_DBUS_CALL_FLAGS_NONE, DBUS_TIMEOUT, mCancellable)
G_DBUS_CALL_FLAGS_NONE, DBUS_TIMEOUT)
->Then(
GetCurrentSerialEventTarget(), __func__,
[s = RefPtr{this}, this](RefPtr<GVariant>&& aResult) {
[s = RefPtr{self}](RefPtr<GVariant>&& aResult) {
if (!g_variant_is_of_type(aResult.get(),
G_VARIANT_TYPE_TUPLE) ||
g_variant_n_children(aResult.get()) != 1) {
@ -278,7 +243,7 @@ void WakeLockTopic::DBusInhibitScreensaver(const char* aName, const char* aPath,
"WakeLockTopic::DBusInhibitScreensaver() wrong "
"reply type %s\n",
g_variant_get_type_string(aResult.get()));
DBusInhibitFailed(/* aFatal */ true);
s->DBusInhibitFailed(/* aFatal */ true);
return;
}
RefPtr<GVariant> variant = dont_AddRef(
@ -289,31 +254,29 @@ void WakeLockTopic::DBusInhibitScreensaver(const char* aName, const char* aPath,
"WakeLockTopic::DBusInhibitScreensaver() wrong "
"reply type %s\n",
g_variant_get_type_string(aResult.get()));
DBusInhibitFailed(/* aFatal */ true);
s->DBusInhibitFailed(/* aFatal */ true);
return;
}
DBusInhibitSucceeded(g_variant_get_uint32(variant));
s->DBusInhibitSucceeded(g_variant_get_uint32(variant));
},
[s = RefPtr{this}, this,
aMethod](GUniquePtr<GError>&& aError) {
[s = RefPtr{self}, aMethod](GUniquePtr<GError>&& aError) {
// Failed to send inhibit request over proxy.
// Switch to another wake lock type.
WAKE_LOCK_LOG(
"WakeLockTopic::DBusInhibitFailed() %s call failed : "
"%s\n",
aMethod, aError->message);
DBusInhibitFailed(
/* aFatal */ !IsCancelledGError(aError.get()));
s->DBusInhibitFailed(/* aFatal */ true);
});
},
[self = RefPtr{this}, this](GUniquePtr<GError>&& aError) {
[self = RefPtr{this}](GUniquePtr<GError>&& aError) {
// We failed to create DBus proxy. Switch to another
// wake lock type.
WAKE_LOCK_LOG(
"WakeLockTopic::DBusInhibitScreensaver() Proxy creation "
"failed: %s\n",
aError->message);
DBusInhibitFailed(/* aFatal */ !IsCancelledGError(aError.get()));
self->DBusInhibitFailed(/* aFatal */ true);
});
}
@ -322,27 +285,17 @@ void WakeLockTopic::DBusUninhibitScreensaver(const char* aName,
const char* aCall,
const char* aMethod) {
WAKE_LOCK_LOG(
"WakeLockTopic::DBusUninhibitScreensaver() mWaitingForDBusInhibit %d "
"mWaitingForDBusUninhibit %d request id %u",
mWaitingForDBusInhibit, mWaitingForDBusUninhibit, mInhibitRequestID);
"WakeLockTopic::DBusUninhibitScreensaver() waiting %d request id %u",
mWaitingForDBusReply, mInhibitRequestID);
if (mWaitingForDBusUninhibit) {
WAKE_LOCK_LOG(" already waiting to uninihibit, return");
if (mWaitingForDBusReply) {
return;
}
if (mWaitingForDBusInhibit) {
WAKE_LOCK_LOG(" cancel inihibit request");
g_cancellable_cancel(mCancellable);
mWaitingForDBusInhibit = false;
}
if (!mInhibitRequestID) {
WAKE_LOCK_LOG(" missing inihibit token, quit.");
// missing uninhibit token, just quit.
return;
}
mWaitingForDBusUninhibit = true;
mWaitingForDBusReply = true;
RefPtr<GVariant> variant =
dont_AddRef(g_variant_ref_sink(g_variant_new("(u)", mInhibitRequestID)));
@ -350,35 +303,34 @@ void WakeLockTopic::DBusUninhibitScreensaver(const char* aName,
G_BUS_TYPE_SESSION,
GDBusProxyFlags(G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS |
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES),
/* aInterfaceInfo = */ nullptr, aName, aPath, aCall, mCancellable)
/* aInterfaceInfo = */ nullptr, aName, aPath, aCall)
->Then(
GetCurrentSerialEventTarget(), __func__,
[self = RefPtr{this}, this, args = RefPtr{variant},
[self = RefPtr{this}, args = RefPtr{variant},
aMethod](RefPtr<GDBusProxy>&& aProxy) {
WAKE_LOCK_LOG(
"WakeLockTopic::DBusUninhibitScreensaver() proxy created");
DBusProxyCall(aProxy.get(), aMethod, args.get(),
G_DBUS_CALL_FLAGS_NONE, DBUS_TIMEOUT, mCancellable)
G_DBUS_CALL_FLAGS_NONE, DBUS_TIMEOUT)
->Then(
GetCurrentSerialEventTarget(), __func__,
[s = RefPtr{this}, this](RefPtr<GVariant>&& aResult) {
DBusUninhibitSucceeded();
[s = RefPtr{self}](RefPtr<GVariant>&& aResult) {
s->DBusUninhibitSucceeded();
},
[s = RefPtr{this}, this,
aMethod](GUniquePtr<GError>&& aError) {
[s = RefPtr{self}, aMethod](GUniquePtr<GError>&& aError) {
WAKE_LOCK_LOG(
"WakeLockTopic::DBusUninhibitFailed() %s call failed "
": %s\n",
aMethod, aError->message);
DBusUninhibitFailed();
s->DBusUninhibitFailed();
});
},
[self = RefPtr{this}, this](GUniquePtr<GError>&& aError) {
[self = RefPtr{this}](GUniquePtr<GError>&& aError) {
WAKE_LOCK_LOG(
"WakeLockTopic::DBusUninhibitFailed() Proxy creation failed: "
"%s\n",
aError->message);
DBusUninhibitFailed();
self->DBusUninhibitFailed();
});
}
@ -614,7 +566,7 @@ bool WakeLockTopic::SendUninhibit() {
}
nsresult WakeLockTopic::InhibitScreensaver() {
WAKE_LOCK_LOG("WakeLockTopic::InhibitScreensaver() Inhibited %d", mInhibited);
WAKE_LOCK_LOG("WakeLockTopic::InhibitScreensaver() state %d", mInhibited);
if (mInhibited) {
// Screensaver is inhibited. Nothing to do here.
@ -631,8 +583,7 @@ nsresult WakeLockTopic::InhibitScreensaver() {
}
nsresult WakeLockTopic::UninhibitScreensaver() {
WAKE_LOCK_LOG("WakeLockTopic::UninhibitScreensaver() Inhibited %d",
mInhibited);
WAKE_LOCK_LOG("WakeLockTopic::UninhibitScreensaver() state %d", mInhibited);
if (!mInhibited) {
// Screensaver isn't inhibited. Nothing to do here.
@ -695,14 +646,6 @@ bool WakeLockTopic::SwitchToNextWakeLockType() {
});
#endif
if (IsDBusWakeLock(sWakeLockType)) {
// We're switching out of DBus wakelock - clear our recent DBus states.
mWaitingForDBusInhibit = false;
mWaitingForDBusUninhibit = false;
mInhibitRequestID = 0;
mInhibited = false;
}
while (sWakeLockType != Unsupported) {
sWakeLockType++;
if (IsWakeLockTypeAvailable(sWakeLockType)) {
@ -722,8 +665,7 @@ WakeLockListener* WakeLockListener::GetSingleton(bool aCreate) {
/* static */
void WakeLockListener::Shutdown() {
MOZ_LOG(gLinuxWakeLockLog, mozilla::LogLevel::Debug,
("WakeLockListener::Shutdown()"));
WAKE_LOCK_LOG("WakeLockListener::Shutdown()");
sSingleton = nullptr;
}
@ -734,15 +676,17 @@ nsresult WakeLockListener::Callback(const nsAString& topic,
return NS_OK;
}
RefPtr<WakeLockTopic> topicLock = mTopics.LookupOrInsertWith(
topic, [&] { return MakeRefPtr<WakeLockTopic>(topic); });
WAKE_LOCK_LOG("WakeLockListener %s state %s",
NS_ConvertUTF16toUTF8(topic).get(),
NS_ConvertUTF16toUTF8(state).get());
RefPtr<WakeLockTopic>* topicLock =
mTopics.GetOrInsertNew(topic, MakeRefPtr<WakeLockTopic>(topic));
// Treat "locked-background" the same as "unlocked" on desktop linux.
bool shouldLock = state.EqualsLiteral("locked-foreground");
WAKE_LOCK_LOG("WakeLockListener topic %s state %s request lock %d",
NS_ConvertUTF16toUTF8(topic).get(),
NS_ConvertUTF16toUTF8(state).get(), shouldLock);
WAKE_LOCK_LOG("shouldLock %d", shouldLock);
return shouldLock ? topicLock->InhibitScreensaver()
: topicLock->UninhibitScreensaver();
return shouldLock ? topicLock->get()->InhibitScreensaver()
: topicLock->get()->UninhibitScreensaver();
}

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

@ -43,7 +43,7 @@ class WakeLockListener final : public nsIDOMMozWakeLockListener {
// Map of topic names to |WakeLockTopic|s.
// We assume a small, finite-sized set of topics.
nsRefPtrHashtable<nsStringHashKey, WakeLockTopic> mTopics;
nsClassHashtable<nsStringHashKey, RefPtr<WakeLockTopic>> mTopics;
};
#endif // __WakeLockListener_h__