diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-05-09 17:04:10 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-07-10 10:26:29 +0200 |
commit | 0a01998411de6a46af8d0b0ae13b8f401cd14a4b (patch) | |
tree | 7c27c908723628b70b21bfb52428c72acf050a71 /src/core/browser_main_parts_qt.cpp | |
parent | 3c34f95ad4a96737f66ab4933edb9e00abecdc24 (diff) |
Adaptations for Chromium 74
Change-Id: Icdefa05eec39c632328dfc40862e5b734170bf3f
Reviewed-by: Peter Varga <pvarga@inf.u-szeged.hu>
Diffstat (limited to 'src/core/browser_main_parts_qt.cpp')
-rw-r--r-- | src/core/browser_main_parts_qt.cpp | 65 |
1 files changed, 29 insertions, 36 deletions
diff --git a/src/core/browser_main_parts_qt.cpp b/src/core/browser_main_parts_qt.cpp index dacaf177f..421a44890 100644 --- a/src/core/browser_main_parts_qt.cpp +++ b/src/core/browser_main_parts_qt.cpp @@ -42,9 +42,11 @@ #include "api/qwebenginemessagepumpscheduler_p.h" #include "base/message_loop/message_loop.h" -#include "base/message_loop/message_loop_impl.h" #include "base/message_loop/message_loop_current.h" +#include "base/message_loop/message_pump_for_ui.h" #include "base/process/process.h" +#include "base/task/sequence_manager/sequence_manager_impl.h" +#include "base/task/sequence_manager/thread_controller_with_message_pump_impl.h" #include "base/threading/thread_restrictions.h" #include "content/public/browser/browser_main_parts.h" #include "content/public/browser/browser_thread.h" @@ -58,7 +60,6 @@ #include "extensions/extension_system_factory_qt.h" #include "common/extensions/extensions_client_qt.h" #endif //BUILDFLAG(ENABLE_EXTENSIONS) -#include "services/resource_coordinator/public/cpp/process_resource_coordinator.h" #include "services/resource_coordinator/public/cpp/resource_coordinator_features.h" #include "services/service_manager/public/cpp/connector.h" #include "services/service_manager/public/cpp/service.h" @@ -75,6 +76,7 @@ #endif #if defined(OS_MACOSX) +#include "base/message_loop/message_pump_mac.h" #include "ui/base/idle/idle.h" #endif @@ -114,12 +116,7 @@ public: : m_scheduler([this]() { handleScheduledWork(); }) {} - void setDelegate(Delegate *delegate) - { - m_delegate = delegate; - } - - void Run(Delegate *delegate) override + void Run(Delegate *) override { // This is used only when MessagePumpForUIQt is used outside of the GUI thread. NOTIMPLEMENTED(); @@ -134,15 +131,27 @@ public: void ScheduleWork() override { // NOTE: This method may called from any thread at any time. + ensureDelegate(); m_scheduler.scheduleWork(); } void ScheduleDelayedWork(const base::TimeTicks &delayed_work_time) override { + // NOTE: This method may called from any thread at any time. + ensureDelegate(); m_scheduler.scheduleDelayedWork(GetTimeIntervalMilliseconds(delayed_work_time)); } private: + void ensureDelegate() + { + if (!m_delegate) { + auto messageLoop = base::MessageLoopCurrentForUI::Get().ToMessageLoopBaseDeprecated(); + auto seqMan = static_cast<base::sequence_manager::internal::SequenceManagerImpl *>(messageLoop); + m_delegate = static_cast<base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl *>( + seqMan->controller_.get()); + } + } // Both Qt and Chromium keep track of the current GL context by using // thread-local variables, and naturally they are completely unaware of each // other. As a result, when a QOpenGLContext is made current, the previous @@ -190,8 +199,6 @@ private: void handleScheduledWork() { - Q_ASSERT(m_delegate); - ScopedGLContextChecker glContextChecker; bool more_work_is_plausible = m_delegate->DoWork(); @@ -213,29 +220,19 @@ private: QWebEngineMessagePumpScheduler m_scheduler; }; -// Needed to access protected constructor from MessageLoop. -class MessageLoopForUIQt : public base::MessageLoop { -public: - MessageLoopForUIQt() : MessageLoop(TYPE_UI, base::BindOnce(&messagePumpFactory)) - { - BindToCurrentThread(); - - auto pump = static_cast<MessagePumpForUIQt *>(pump_); - auto backend = static_cast<base::MessageLoopImpl *>(backend_.get()); - pump->setDelegate(backend); - } -private: - static std::unique_ptr<base::MessagePump> messagePumpFactory() - { - return base::WrapUnique(new MessagePumpForUIQt); +std::unique_ptr<base::MessagePump> messagePumpFactory() +{ + static bool madePrimaryPump = false; + if (!madePrimaryPump) { + madePrimaryPump = true; + return std::make_unique<MessagePumpForUIQt>(); } -}; - -BrowserMainPartsQt::BrowserMainPartsQt() : content::BrowserMainParts() -{ } - -BrowserMainPartsQt::~BrowserMainPartsQt() = default; - +#if defined(OS_MACOSX) + return base::MessagePumpMac::Create(); +#else + return std::make_unique<base::MessagePumpForUI>(); +#endif +} int BrowserMainPartsQt::PreEarlyInitialization() { @@ -247,8 +244,6 @@ int BrowserMainPartsQt::PreEarlyInitialization() void BrowserMainPartsQt::PreMainMessageLoopStart() { - // Overrides message loop creation in BrowserMainLoop::MainMessageLoopStart(). - m_mainMessageLoop.reset(new MessageLoopForUIQt); } void BrowserMainPartsQt::PreMainMessageLoopRun() @@ -288,8 +283,6 @@ void BrowserMainPartsQt::ServiceManagerConnectionStarted(content::ServiceManager { ServiceQt::GetInstance()->InitConnector(); connection->GetConnector()->WarmService(service_manager::ServiceFilter::ByName("qtwebengine")); - m_processResourceCoordinator = std::make_unique<resource_coordinator::ProcessResourceCoordinator>(connection->GetConnector()); - m_processResourceCoordinator->OnProcessLaunched(base::Process::Current()); } } // namespace QtWebEngineCore |