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:
Martin Stransky 2018-10-01 13:22:48 +00:00
parent d78f4217af
commit a9fb723907
2 changed files with 20 additions and 7 deletions

View File

@ -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;
}

View File

@ -41,6 +41,8 @@ private:
WakeLockListener();
~WakeLockListener() = default;
bool EnsureDBusConnection();
static mozilla::StaticRefPtr<WakeLockListener> sSingleton;
#ifdef MOZ_ENABLE_DBUS