From f9706f260aa9fd78c799c1456f0ac75d13f5e7ba Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Mon, 18 Nov 2019 15:02:39 -0500 Subject: [PATCH] Windows: cefclient: Fix assertions with --use-views --multi-threaded-message-loop --- .../cefclient/browser/root_window_manager.cc | 12 ++++++--- tests/cefclient/browser/root_window_views.cc | 26 ++++++++++--------- tests/cefclient/browser/root_window_views.h | 5 ++-- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/tests/cefclient/browser/root_window_manager.cc b/tests/cefclient/browser/root_window_manager.cc index cf03ab44e..abe7b1338 100644 --- a/tests/cefclient/browser/root_window_manager.cc +++ b/tests/cefclient/browser/root_window_manager.cc @@ -107,8 +107,7 @@ class ClientRequestContextHandler : public CefRequestContextHandler, } // namespace RootWindowManager::RootWindowManager(bool terminate_when_all_windows_closed) - : terminate_when_all_windows_closed_(terminate_when_all_windows_closed), - image_cache_(new ImageCache) { + : terminate_when_all_windows_closed_(terminate_when_all_windows_closed) { CefRefPtr command_line = CefCommandLine::GetGlobalCommandLine(); DCHECK(command_line.get()); @@ -354,8 +353,11 @@ CefRefPtr RootWindowManager::GetRequestContext( } scoped_refptr RootWindowManager::GetImageCache() { - REQUIRE_MAIN_THREAD(); + CEF_REQUIRE_UI_THREAD(); + if (!image_cache_) { + image_cache_ = new ImageCache; + } return image_cache_; } @@ -446,6 +448,10 @@ void RootWindowManager::CleanupOnUIThread() { temp_window_.reset(nullptr); } + if (image_cache_) { + image_cache_ = nullptr; + } + // Quit the main message loop. MainMessageLoop::Get()->Quit(); } diff --git a/tests/cefclient/browser/root_window_views.cc b/tests/cefclient/browser/root_window_views.cc index f0800ff88..7023a37a8 100644 --- a/tests/cefclient/browser/root_window_views.cc +++ b/tests/cefclient/browser/root_window_views.cc @@ -59,8 +59,8 @@ void RootWindowViews::Init(RootWindow::Delegate* delegate, CreateClientHandler(config.url); initialized_ = true; - // Continue initialization on the main thread. - InitOnMainThread(settings, config.url); + // Continue initialization on the UI thread. + InitOnUIThread(settings, config.url, delegate_->GetRequestContext(this)); } void RootWindowViews::InitAsPopup(RootWindow::Delegate* delegate, @@ -187,17 +187,17 @@ ClientWindowHandle RootWindowViews::GetWindowHandle() const { } bool RootWindowViews::WithExtension() const { - REQUIRE_MAIN_THREAD(); + DCHECK(initialized_); return with_extension_; } bool RootWindowViews::WithControls() { - CEF_REQUIRE_UI_THREAD(); + DCHECK(initialized_); return with_controls_; } bool RootWindowViews::WithExtension() { - REQUIRE_MAIN_THREAD(); + DCHECK(initialized_); return with_extension_; } @@ -475,12 +475,14 @@ void RootWindowViews::CreateClientHandler(const std::string& url) { client_handler_->set_download_favicon_images(true); } -void RootWindowViews::InitOnMainThread(const CefBrowserSettings& settings, - const std::string& startup_url) { - if (!CURRENTLY_ON_MAIN_THREAD()) { - // Execute this method on the main thread. - MAIN_POST_CLOSURE(base::Bind(&RootWindowViews::InitOnMainThread, this, - settings, startup_url)); +void RootWindowViews::InitOnUIThread( + const CefBrowserSettings& settings, + const std::string& startup_url, + CefRefPtr request_context) { + if (!CefCurrentlyOn(TID_UI)) { + // Execute this method on the UI thread. + CefPostTask(TID_UI, base::Bind(&RootWindowViews::InitOnUIThread, this, + settings, startup_url, request_context)); return; } @@ -493,7 +495,7 @@ void RootWindowViews::InitOnMainThread(const CefBrowserSettings& settings, image_cache_->LoadImages( image_set, base::Bind(&RootWindowViews::CreateViewsWindow, this, settings, - startup_url, delegate_->GetRequestContext(this))); + startup_url, request_context)); } void RootWindowViews::CreateViewsWindow( diff --git a/tests/cefclient/browser/root_window_views.h b/tests/cefclient/browser/root_window_views.h index 5cce3ca10..1c719c426 100644 --- a/tests/cefclient/browser/root_window_views.h +++ b/tests/cefclient/browser/root_window_views.h @@ -89,8 +89,9 @@ class RootWindowViews : public RootWindow, private: void CreateClientHandler(const std::string& url); - void InitOnMainThread(const CefBrowserSettings& settings, - const std::string& startup_url); + void InitOnUIThread(const CefBrowserSettings& settings, + const std::string& startup_url, + CefRefPtr request_context); void CreateViewsWindow(const CefBrowserSettings& settings, const std::string& startup_url, CefRefPtr request_context,