[webkit-reviews] review granted: [Bug 231670] [GLIB] Simplify SleepDisabler by checking if we are under sandbox : [Attachment 441571] Patch

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

Adrian Perez <aperez at igalia.com> has granted Carlos Garcia Campos
<cgarcia at igalia.com>'s request for review:
Bug 231670: [GLIB] Simplify SleepDisabler by checking if we are under sandbox

Attachment 441571: Patch


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

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;

More information about the webkit-reviews mailing list