[Webkit-unassigned] [Bug 231670] [GLIB] Simplify SleepDisabler by checking if we are under sandbox

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Mon Oct 18 05:51:06 PDT 2021


https://bugs.webkit.org/show_bug.cgi?id=231670

Adrian Perez <aperez at igalia.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |aperez at igalia.com
 Attachment #441571|review?                     |review+
              Flags|                            |

--- Comment #12 from Adrian Perez <aperez at igalia.com> ---
Comment on attachment 441571
  --> https://bugs.webkit.org/attachment.cgi?id=441571
Patch

I left some comments about the helper functions, but as the code was just
moved around it's fine—but if you feel like changing them before landing,
that would be neat :)


View in context: https://bugs.webkit.org/attachment.cgi?id=441571&action=review

> Source/WTF/wtf/glib/Sandbox.cpp:39
> +    return *ret;

It should not be needed to use std::optional here, you can just:

   bool isInsideFlatpak()
   {
       static bool ret = g_file_test("/.flatpak-info", G_FILE_TEST_EXISTS);
       return ret;
   }

The C++11 specification guarantees that a static local is initialized only
once when program control flow goes through it, and that it is thread-safe
(amusingly, manually checking the optional is not thread-safe :D)

The same applies to the other checks below.

> Source/WTF/wtf/glib/Sandbox.cpp:70
> +    return usePortal[0] != '0';

This one is a bit trickier, but one can use a lambda that gets invoked
immediately to initialize the static value:

    bool shouldUsePortal() {
        static bool ret = ([]() -> bool {
            // do checks, return true/false
        })();
        return ret;
    }

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20211018/6a323181/attachment.htm>


More information about the webkit-unassigned mailing list