From ab3cc3a2372b75bf6269585ffe512486af062767 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20H=C4=83loiu?= Date: Sun, 17 Jul 2022 14:06:05 +0300 Subject: [PATCH] fix: add support for --ozone-platform-hint flag on Linux --- chromium_src/BUILD.gn | 9 ++++++++- filenames.gni | 1 + shell/browser/electron_browser_main_parts.cc | 16 +++++++++------- shell/browser/electron_browser_main_parts.h | 6 ++++++ .../lifetime/application_lifetime_linux.cc | 11 +++++++++++ 5 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 shell/browser/lifetime/application_lifetime_linux.cc diff --git a/chromium_src/BUILD.gn b/chromium_src/BUILD.gn index bfd971e576a85..b70b188786ac2 100644 --- a/chromium_src/BUILD.gn +++ b/chromium_src/BUILD.gn @@ -21,6 +21,7 @@ static_library("chrome") { "//chrome/browser/browser_features.h", "//chrome/browser/browser_process.cc", "//chrome/browser/browser_process.h", + "//chrome/browser/chrome_browser_main_extra_parts.h", "//chrome/browser/devtools/devtools_contents_resizing_strategy.cc", "//chrome/browser/devtools/devtools_contents_resizing_strategy.h", "//chrome/browser/devtools/devtools_embedder_message_dispatcher.cc", @@ -117,7 +118,13 @@ static_library("chrome") { } if (is_linux) { - sources += [ "//chrome/browser/media/webrtc/window_icon_util_ozone.cc" ] + sources += [ + "//chrome/browser/chrome_browser_main_extra_parts_linux.cc", + "//chrome/browser/chrome_browser_main_extra_parts_linux.h", + "//chrome/browser/chrome_browser_main_extra_parts_ozone.cc", + "//chrome/browser/chrome_browser_main_extra_parts_ozone.h", + "//chrome/browser/media/webrtc/window_icon_util_ozone.cc", + ] } if (use_aura) { diff --git a/filenames.gni b/filenames.gni index 5b9d3cc721dbb..3bf9a9a0ed7e9 100644 --- a/filenames.gni +++ b/filenames.gni @@ -25,6 +25,7 @@ filenames = { "shell/browser/browser_linux.cc", "shell/browser/lib/power_observer_linux.cc", "shell/browser/lib/power_observer_linux.h", + "shell/browser/lifetime/application_lifetime_linux.cc", "shell/browser/linux/unity_service.cc", "shell/browser/linux/unity_service.h", "shell/browser/notifications/linux/libnotify_notification.cc", diff --git a/shell/browser/electron_browser_main_parts.cc b/shell/browser/electron_browser_main_parts.cc index 8ffd3e4a3089f..f3524a5251e2f 100644 --- a/shell/browser/electron_browser_main_parts.cc +++ b/shell/browser/electron_browser_main_parts.cc @@ -68,6 +68,7 @@ #if BUILDFLAG(IS_LINUX) #include "base/environment.h" #include "base/threading/thread_task_runner_handle.h" +#include "chrome/browser/chrome_browser_main_extra_parts_linux.h" #include "device/bluetooth/bluetooth_adapter_factory.h" #include "device/bluetooth/dbus/dbus_bluez_manager_wrapper_linux.h" #include "electron/electron_gtk_stubs.h" @@ -180,7 +181,11 @@ class DarkThemeObserver : public ui::NativeThemeObserver { ElectronBrowserMainParts* ElectronBrowserMainParts::self_ = nullptr; ElectronBrowserMainParts::ElectronBrowserMainParts() - : fake_browser_process_(std::make_unique()), + : +#if BUILDFLAG(IS_LINUX) + main_extra_part_(std::make_unique()), +#endif + fake_browser_process_(std::make_unique()), browser_(std::make_unique()), node_bindings_( NodeBindings::Create(NodeBindings::BrowserEnvironment::kBrowser)), @@ -217,7 +222,7 @@ int ElectronBrowserMainParts::PreEarlyInitialization() { HandleSIGCHLD(); #endif #if BUILDFLAG(IS_LINUX) - ui::OzonePlatform::PreEarlyInitialization(); + main_extra_part_->PreEarlyInitialization(); #endif #if BUILDFLAG(IS_MAC) screen_ = std::make_unique(); @@ -476,10 +481,7 @@ void ElectronBrowserMainParts::WillRunMainMessageLoop( void ElectronBrowserMainParts::PostCreateMainMessageLoop() { #if BUILDFLAG(IS_LINUX) - auto shutdown_cb = - base::BindOnce(base::RunLoop::QuitCurrentWhenIdleClosureDeprecated()); - ui::OzonePlatform::GetInstance()->PostCreateMainMessageLoop( - std::move(shutdown_cb)); + main_extra_part_->PostCreateMainMessageLoop(); bluez::DBusBluezManagerWrapperLinux::Initialize(); // Set up crypt config. This needs to be done before anything starts the @@ -541,7 +543,7 @@ void ElectronBrowserMainParts::PostMainMessageLoopRun() { content::DevToolsAgentHost::StopRemoteDebuggingPipeHandler(); #if BUILDFLAG(IS_LINUX) - ui::OzonePlatform::GetInstance()->PostMainMessageLoopRun(); + main_extra_part_->PostMainMessageLoopRun(); #endif } diff --git a/shell/browser/electron_browser_main_parts.h b/shell/browser/electron_browser_main_parts.h index 95ced64ed7c9e..d39e22101065b 100644 --- a/shell/browser/electron_browser_main_parts.h +++ b/shell/browser/electron_browser_main_parts.h @@ -19,6 +19,10 @@ #include "ui/display/screen.h" #include "ui/views/layout/layout_provider.h" +#if BUILDFLAG(IS_LINUX) +#include "chrome/browser/chrome_browser_main_extra_parts.h" +#endif + class BrowserProcessImpl; class IconManager; @@ -142,6 +146,8 @@ class ElectronBrowserMainParts : public content::BrowserMainParts { #if BUILDFLAG(IS_LINUX) // Used to notify the native theme of changes to dark mode. std::unique_ptr dark_theme_observer_; + + std::unique_ptr main_extra_part_; #endif std::unique_ptr layout_provider_; diff --git a/shell/browser/lifetime/application_lifetime_linux.cc b/shell/browser/lifetime/application_lifetime_linux.cc new file mode 100644 index 0000000000000..7de13b62ba928 --- /dev/null +++ b/shell/browser/lifetime/application_lifetime_linux.cc @@ -0,0 +1,11 @@ +// Copyright (c) 2022 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#include "base/run_loop.h" + +namespace chrome { +void SessionEnding() { + base::RunLoop::QuitCurrentWhenIdleDeprecated(); +} +} // namespace chrome