mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-27 12:50:09 +00:00
Bug 1495404 - Postpone dbus_bus_get() call until we need it at WakeLockListener::Callback(), r=jhorak
Differential Revision: https://phabricator.services.mozilla.com/D7281 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
d78f4217af
commit
a9fb723907
@ -397,13 +397,8 @@ WakeLockTopic::ReceiveInhibitReply(DBusPendingCall* pending, void* user_data)
|
||||
|
||||
|
||||
WakeLockListener::WakeLockListener()
|
||||
: mConnection(already_AddRefed<DBusConnection>(
|
||||
dbus_bus_get(DBUS_BUS_SESSION, nullptr)))
|
||||
: mConnection(nullptr)
|
||||
{
|
||||
if (mConnection) {
|
||||
dbus_connection_set_exit_on_disconnect(mConnection, false);
|
||||
dbus_connection_setup_with_g_main(mConnection, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
/* static */ WakeLockListener*
|
||||
@ -422,10 +417,26 @@ WakeLockListener::Shutdown()
|
||||
sSingleton = nullptr;
|
||||
}
|
||||
|
||||
bool
|
||||
WakeLockListener::EnsureDBusConnection()
|
||||
{
|
||||
if (!mConnection) {
|
||||
mConnection =
|
||||
already_AddRefed<DBusConnection>(dbus_bus_get(DBUS_BUS_SESSION, nullptr));
|
||||
|
||||
if (mConnection) {
|
||||
dbus_connection_set_exit_on_disconnect(mConnection, false);
|
||||
dbus_connection_setup_with_g_main(mConnection, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
return mConnection != nullptr;
|
||||
}
|
||||
|
||||
nsresult
|
||||
WakeLockListener::Callback(const nsAString& topic, const nsAString& state)
|
||||
{
|
||||
if (!mConnection) {
|
||||
if (!EnsureDBusConnection()) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,8 @@ private:
|
||||
WakeLockListener();
|
||||
~WakeLockListener() = default;
|
||||
|
||||
bool EnsureDBusConnection();
|
||||
|
||||
static mozilla::StaticRefPtr<WakeLockListener> sSingleton;
|
||||
|
||||
#ifdef MOZ_ENABLE_DBUS
|
||||
|
Loading…
x
Reference in New Issue
Block a user