diff --git a/widget/gtk/WakeLockListener.cpp b/widget/gtk/WakeLockListener.cpp index e256aade97d91..7a30c6830f4c4 100644 --- a/widget/gtk/WakeLockListener.cpp +++ b/widget/gtk/WakeLockListener.cpp @@ -647,11 +647,6 @@ SendUninhibit ( ) ; -nsresult -ProcessNextRequest -( -) -; # if defined @@ -878,13 +873,11 @@ char * GetInhibitStateName ( -WakeLockState -aState ) { switch ( -aState +mState ) { case @@ -937,6 +930,32 @@ ifdef MOZ_ENABLE_DBUS / / +We +' +re +waiting +for +DBus +reply +( +inhibit +/ +uninhibit +calls +) +. +bool +mWaitingForDBusInhibit += +false +; +bool +mWaitingForDBusUninhibit += +false +; +/ +/ mInhibitRequestID is received @@ -964,6 +983,18 @@ uint32_t > mInhibitRequestID ; +RefPtr +< +GCancellable +> +mInhibitCancellable +; +RefPtr +< +GCancellable +> +mUnInhibitCancellable +; / / Used @@ -980,57 +1011,8 @@ request nsCString mRequestObjectPath ; -/ -/ -It -' -s -used -to -quit -DBus -operation -on -shutdown -. -RefPtr -< -GCancellable -> -mCancellable -; -/ -/ -If -we -fail -to -uninhibit -DBus -screensaver -just -disable -/ -/ -it -completelly -. -int -mUninhibitAttempts -= -5 -; # endif -std -: -: -queue -< -WakeLockState -> -mStateQueue -; static int sWakeLockType @@ -1058,13 +1040,9 @@ uint32_t aInhibitRequestID ) { -mState -= -Inhibited -; -mCancellable +mWaitingForDBusInhibit = -nullptr +false ; mInhibitRequestID = @@ -1086,15 +1064,58 @@ mInhibitRequestID % u " +" +state +% +s +" * mInhibitRequestID +GetInhibitStateName +( +) ) ; -ProcessNextRequest +/ +/ +Uninhibit +was +requested +before +inhibit +request +was +finished +. +/ +/ +So +ask +for +it +now +. +if +( +mState += += +WaitingToUninhibit +) +{ +UninhibitScreensaver ( ) ; } +else +{ +mState += +Inhibited +; +} +} void WakeLockTopic : @@ -1120,9 +1141,9 @@ d aFatal ) ; -mCancellable +mWaitingForDBusInhibit = -nullptr +false ; ClearDBusInhibitToken ( @@ -1157,24 +1178,7 @@ SendInhibit ( ) ; -return -; } -/ -/ -Flip -back -to -uninhibited -state -as -we -failed -. -mState -= -Uninhibited -; } void WakeLockTopic @@ -1193,26 +1197,63 @@ WakeLockTopic DBusUninhibitSucceeded ( ) +state +% +s " +GetInhibitStateName +( +) ) ; -mState -= -Uninhibited -; -mCancellable +mWaitingForDBusUninhibit = -nullptr +false ; ClearDBusInhibitToken ( ) ; -ProcessNextRequest +/ +/ +Inhibit +was +requested +before +uninhibit +request +was +finished +. +/ +/ +So +ask +for +it +now +. +if +( +mState += += +WaitingToInhibit +) +{ +InhibitScreensaver ( ) ; } +else +{ +mState += +Uninhibited +; +} +} void WakeLockTopic : @@ -1233,62 +1274,17 @@ DBusUninhibitFailed " ) ; -mState +mWaitingForDBusUninhibit = -Inhibited +false ; -mCancellable +mInhibitRequestID = -nullptr -; -/ -/ -We -' -re -in -inhibited -state -and -we -can -' -t -switch -back -. -/ -/ -Let -' -s -try -again -but -there -isn -' -t -much -to -do -. -if +Nothing ( -- -- -mUninhibitAttempts -= -= -0 ) -{ -sWakeLockType -= -Unsupported ; } -} void WakeLockTopic : @@ -1348,32 +1344,88 @@ WakeLockTopic DBusInhibitScreensaver ( ) +mWaitingForDBusInhibit +% +d +" +" +mWaitingForDBusUninhibit +% +d " +mWaitingForDBusInhibit +mWaitingForDBusUninhibit ) ; -MOZ_DIAGNOSTIC_ASSERT +if ( -! -mCancellable +mWaitingForDBusInhibit ) -; -MOZ_DIAGNOSTIC_ASSERT +{ +WAKE_LOCK_LOG ( -mState -= -= -WaitingToInhibit +" +already +waiting +to +inihibit +return +" ) ; -mCancellable -= -dont_AddRef +return +; +} +if ( -g_cancellable_new +mWaitingForDBusUninhibit +) +{ +WAKE_LOCK_LOG +( +" +cancel +un +- +inihibit +request +" +) +; +g_cancellable_cancel +( +mUnInhibitCancellable +) +; +mUnInhibitCancellable += +nullptr +; +mWaitingForDBusUninhibit += +false +; +} +mWaitingForDBusInhibit += +true +; +if +( +! +mInhibitCancellable +) +{ +mInhibitCancellable += +dont_AddRef +( +g_cancellable_new ( ) ) ; +} widget : : @@ -1396,7 +1448,7 @@ nullptr aName aPath aCall -mCancellable +mInhibitCancellable ) - > @@ -1461,7 +1513,7 @@ get ) G_DBUS_CALL_FLAGS_NONE DBUS_TIMEOUT -mCancellable +mInhibitCancellable ) - > @@ -1846,11 +1898,21 @@ WakeLockTopic DBusUninhibitScreensaver ( ) +mWaitingForDBusInhibit +% +d +" +" +mWaitingForDBusUninhibit +% +d request id % d " +mWaitingForDBusInhibit +mWaitingForDBusUninhibit mInhibitRequestID ? * @@ -1862,6 +1924,53 @@ mInhibitRequestID ; if ( +mWaitingForDBusUninhibit +) +{ +WAKE_LOCK_LOG +( +" +already +waiting +to +uninihibit +return +" +) +; +return +; +} +if +( +mWaitingForDBusInhibit +) +{ +WAKE_LOCK_LOG +( +" +cancel +inihibit +request +" +) +; +g_cancellable_cancel +( +mInhibitCancellable +) +; +mInhibitCancellable += +nullptr +; +mWaitingForDBusInhibit += +false +; +} +if +( ! mInhibitRequestID . @@ -1881,28 +1990,28 @@ quit " ) ; -DBusUninhibitFailed -( -) -; +/ +/ +missing +uninhibit +token +just +quit +. return ; } -MOZ_DIAGNOSTIC_ASSERT -( -! -mCancellable -) +mWaitingForDBusUninhibit += +true ; -MOZ_DIAGNOSTIC_ASSERT +if ( -mState -= -= -WaitingToUninhibit +! +mUnInhibitCancellable ) -; -mCancellable +{ +mUnInhibitCancellable = dont_AddRef ( @@ -1911,6 +2020,7 @@ g_cancellable_new ) ) ; +} RefPtr < GVariant @@ -1966,7 +2076,7 @@ nullptr aName aPath aCall -mCancellable +mUnInhibitCancellable ) - > @@ -2033,7 +2143,7 @@ get ) G_DBUS_CALL_FLAGS_NONE DBUS_TIMEOUT -mCancellable +mUnInhibitCancellable ) - > @@ -2191,24 +2301,79 @@ WakeLockTopic InhibitFreeDesktopPortal ( ) +mWaitingForDBusInhibit +% +d +" +" +mWaitingForDBusUninhibit +% +d " +mWaitingForDBusInhibit +mWaitingForDBusUninhibit ) ; -MOZ_DIAGNOSTIC_ASSERT +if ( -! -mCancellable +mWaitingForDBusInhibit +) +{ +WAKE_LOCK_LOG +( +" +already +waiting +to +inihibit +return +" ) ; -MOZ_DIAGNOSTIC_ASSERT +return +; +} +if ( -mState +mWaitingForDBusUninhibit +) +{ +WAKE_LOCK_LOG +( +" +cancel +un +- +inihibit +request +" +) +; +g_cancellable_cancel +( +mUnInhibitCancellable +) +; +mUnInhibitCancellable = +nullptr +; +mWaitingForDBusUninhibit = -WaitingToInhibit -) +false +; +} +mWaitingForDBusInhibit += +true ; -mCancellable +if +( +! +mInhibitCancellable +) +{ +mInhibitCancellable = dont_AddRef ( @@ -2217,6 +2382,7 @@ g_cancellable_new ) ) ; +} CreateDBusProxyForBus ( G_BUS_TYPE_SESSION @@ -2230,7 +2396,7 @@ nullptr FREEDESKTOP_PORTAL_DESKTOP_TARGET FREEDESKTOP_PORTAL_DESKTOP_OBJECT FREEDESKTOP_PORTAL_DESKTOP_INTERFACE -mCancellable +mInhibitCancellable ) - > @@ -2356,7 +2522,7 @@ b ) G_DBUS_CALL_FLAGS_NONE DBUS_TIMEOUT -mCancellable +mInhibitCancellable ) - > @@ -2815,12 +2981,22 @@ WakeLockTopic UninhibitFreeDesktopPortal ( ) +mWaitingForDBusInhibit +% +d +" +" +mWaitingForDBusUninhibit +% +d object path : % s " +mWaitingForDBusInhibit +mWaitingForDBusUninhibit mRequestObjectPath . get @@ -2830,6 +3006,53 @@ get ; if ( +mWaitingForDBusUninhibit +) +{ +WAKE_LOCK_LOG +( +" +already +waiting +to +uninihibit +return +" +) +; +return +; +} +if +( +mWaitingForDBusInhibit +) +{ +WAKE_LOCK_LOG +( +" +cancel +inihibit +request +" +) +; +g_cancellable_cancel +( +mInhibitCancellable +) +; +mInhibitCancellable += +nullptr +; +mWaitingForDBusInhibit += +false +; +} +if +( mRequestObjectPath . IsEmpty @@ -2853,28 +3076,20 @@ n " ) ; -DBusUninhibitFailed -( -) -; return ; } -MOZ_DIAGNOSTIC_ASSERT -( -! -mCancellable -) +mWaitingForDBusUninhibit += +true ; -MOZ_DIAGNOSTIC_ASSERT +if ( -mState -= -= -WaitingToUninhibit +! +mUnInhibitCancellable ) -; -mCancellable +{ +mUnInhibitCancellable = dont_AddRef ( @@ -2883,6 +3098,7 @@ g_cancellable_new ) ) ; +} nsCOMPtr < nsISerialEventTarget @@ -2918,7 +3134,7 @@ portal . Request " -mCancellable +mUnInhibitCancellable ) - > @@ -2959,7 +3175,7 @@ Close nullptr G_DBUS_CALL_FLAGS_NONE DBUS_TIMEOUT -mCancellable +mUnInhibitCancellable ) - > @@ -3528,25 +3744,6 @@ inhibit ; / / -Set -failed -state -now -to -remove -WaitingTo -* -one -mState -= -inhibit -? -Uninhibited -: -Inhibited -; -/ -/ Should only be @@ -3699,21 +3896,6 @@ InhibitWaylandIdle " ) ; -/ -/ -Set -failed -state -now -to -remove -WaitingTo -* -one -mState -= -Uninhibited -; nsWaylandDisplay * waylandDisplay @@ -4157,150 +4339,110 @@ s " GetInhibitStateName ( -mState ) ) ; -/ -/ -We -' -re -broken -don -' -t -even -try if ( -sWakeLockType +mState = = -Unsupported -) -{ -return -NS_ERROR_FAILURE -; -} -mStateQueue -. -push -( Inhibited -) -; -if -( -mState -= -= -WaitingToInhibit | | mState = = -WaitingToUninhibit +WaitingToInhibit ) { return NS_OK ; } -return -ProcessNextRequest -( -) +mState += +WaitingToInhibit ; -} -nsresult -WakeLockTopic -: -: -UninhibitScreensaver -( -) -{ -WAKE_LOCK_LOG -( -" -WakeLockTopic -: -: -UnInhibitScreensaver +/ +/ +Iterate +through +wake +lock +types +in +case +of +failure +. +while ( -) -state -% -s -" -GetInhibitStateName +! +SendInhibit ( -mState ) ) -; +{ / / We -' -re -broken don ' t -even +switch +away +from +native +locks +. +Just try +again +. if ( +IsNativeWakeLock +( sWakeLockType -= -= -Unsupported +) ) { return NS_ERROR_FAILURE ; } -mStateQueue -. -push -( -Uninhibited -) -; if ( -mState -= -= -WaitingToInhibit -| -| -mState -= -= -WaitingToUninhibit +! +SwitchToNextWakeLockType +( +) ) { return -NS_OK +NS_ERROR_FAILURE ; } +} return -ProcessNextRequest ( +sWakeLockType +! += +Unsupported ) +? +NS_OK +: +NS_ERROR_FAILURE ; } nsresult WakeLockTopic : : -ProcessNextRequest +UninhibitScreensaver ( ) { @@ -4310,122 +4452,67 @@ WAKE_LOCK_LOG WakeLockTopic : : -ProcessNextRequest +UnInhibitScreensaver ( ) -: -recent state % s " GetInhibitStateName ( -mState ) ) ; -MOZ_DIAGNOSTIC_ASSERT +if ( mState = = -Inhibited +Uninhibited | | mState = = -Uninhibited -) -; -while -( -! -mStateQueue -. -empty -( -) -) -{ -WakeLockState -nextState -= -mStateQueue -. -front -( -) -; -mStateQueue -. -pop -( -) -; -WAKE_LOCK_LOG -( -" -WakeLockTopic -: -: -ProcessNextRequest -( -) -: -next -state -% -s -" -GetInhibitStateName -( -nextState -) -) -; -if -( -nextState -= -= -mState -) -{ -continue -; -} -switch -( -nextState +WaitingToUninhibit ) { -case -Inhibited -: -mState -= -WaitingToInhibit -; return -SendInhibit -( -) -? NS_OK -: -NS_ERROR_FAILURE ; -break -; -case -Uninhibited -: +} mState = WaitingToUninhibit ; +/ +/ +Don +' +t +switch +wake +lock +type +in +case +of +failure +. +/ +/ +We +need +to +use +the +same +lock +/ +unlock +type +. return SendUninhibit ( @@ -4435,41 +4522,6 @@ NS_OK : NS_ERROR_FAILURE ; -default -: -MOZ_DIAGNOSTIC_ASSERT -( -false -" -Wrong -state -! -" -) -; -return -NS_ERROR_FAILURE -; -} -} -WAKE_LOCK_LOG -( -" -WakeLockTopic -: -: -ProcessNextRequest -( -) -: -empty -queue -" -) -; -return -NS_OK -; } void WakeLockTopic @@ -4494,25 +4546,13 @@ s " GetInhibitStateName ( -mState ) ) ; -if -( -mCancellable -) -{ -g_cancellable_cancel +UninhibitScreensaver ( -mCancellable ) ; -mCancellable -= -nullptr -; -} } bool WakeLockTopic @@ -4790,13 +4830,34 @@ sWakeLockType ) ) { -mState +/ +/ +We +' +re +switching +out +of +DBus +wakelock +- +clear +our +recent +DBus +states +. +mWaitingForDBusInhibit = -Uninhibited +false ; -mCancellable +mWaitingForDBusUninhibit = -nullptr +false +; +mState += +Uninhibited ; ClearDBusInhibitToken (