Repository: electron/electron
File: shell/browser/ui/file_dialog_linux_portal.cc (C++)

Code before:
  scoped_refptr<dbus::Bus> bus = base::MakeRefCounted<dbus::Bus>(options);
  dbus_utils::CheckForServiceAndStart(
      bus, kXdgPortalService,
      base::BindOnce(
          [](scoped_refptr<dbus::Bus> bus, base::AtomicFlag* flag,
             std::optional<bool> name_has_owner) {
            if (name_has_owner.value_or(false)) {
              //
              dbus::ObjectPath portal_path(kXdgPortalObject);
              dbus::ObjectProxy* portal =
                  bus->GetObjectProxy(kXdgPortalService, portal_path);
              FileChooserProperties properties(portal);
              if (!properties.GetAndBlock(&properties.version)) {
                LOG(ERROR) << "Failed to read portal version property";
              } else if (properties.version.value() >=
                         g_required_portal_version) {
                g_portal_available = true;
                g_available_portal_version = properties.version.value();
              }
            }
            VLOG(1) << "File chooser portal available: "
                    << (g_portal_available ? "yes" : "no");
            flag->Set();
            bus->ShutdownAndBlock();
          },
          bus, flag));
}

}  // namespace

void StartPortalAvailabilityTestInBackground() {
  if (GetAvailabilityTestCompletionFlag()->IsSet())
    return;

  const auto* cmd = base::CommandLine::ForCurrentProcess();
  if (!base::StringToUint(
          cmd->GetSwitchValueASCII(kXdgPortalRequiredVersionFlag),
          &g_required_portal_version)) {
    VLOG(1) << "Unable to parse --xdg-portal-required-version";
  }

  dbus_thread_linux::GetTaskRunner()->PostTask(
      FROM_HERE, base::BindOnce(&CheckPortalAvailabilityOnBusThread));
}

bool IsPortalAvailable() {
  if (!GetAvailabilityTestCompletionFlag()->IsSet())
    LOG(WARNING) << "Portal availability checked before test was complete";

  return g_portal_available;
}

Review comment (suggestion):
```suggestion
          std::move(bus), flag));
```

Code after:
  scoped_refptr<dbus::Bus> bus = base::MakeRefCounted<dbus::Bus>(options);
  dbus_utils::CheckForServiceAndStart(
      bus, kXdgPortalService,
      base::BindOnce(
          [](scoped_refptr<dbus::Bus> bus, base::AtomicFlag* flag,
             std::optional<bool> name_has_owner) {
            if (name_has_owner.value_or(false)) {
              //
              dbus::ObjectPath portal_path(kXdgPortalObject);
              dbus::ObjectProxy* portal =
                  bus->GetObjectProxy(kXdgPortalService, portal_path);
              FileChooserProperties properties(portal);
              if (!properties.GetAndBlock(&properties.version)) {
                LOG(ERROR) << "Failed to read portal version property";
              } else if (properties.version.value() >=
                         g_required_portal_version) {
                g_portal_available = true;
                g_available_portal_version = properties.version.value();
              }
            }
            VLOG(1) << "File chooser portal available: "
                    << (g_portal_available ? "yes" : "no");
            flag->Set();
            bus->ShutdownAndBlock();
          },
          std::move(bus), flag));
}

}  // namespace

void StartPortalAvailabilityTestInBackground() {
  if (GetAvailabilityTestCompletionFlag()->IsSet())
    return;

  const auto* cmd = base::CommandLine::ForCurrentProcess();
  if (!base::StringToUint(
          cmd->GetSwitchValueASCII(kXdgPortalRequiredVersionFlag),
          &g_required_portal_version)) {
    VLOG(1) << "Unable to parse --xdg-portal-required-version";
  }

  dbus_thread_linux::GetTaskRunner()->PostTask(
      FROM_HERE, base::BindOnce(&CheckPortalAvailabilityOnBusThread));
}

bool IsPortalAvailable() {
  if (!GetAvailabilityTestCompletionFlag()->IsSet())
    LOG(WARNING) << "Portal availability checked before test was complete";

  return g_portal_available;
}