Windows: cefclient: Fix assertions with --use-views --multi-threaded-message-loop

This commit is contained in:
Marshall Greenblatt 2019-11-18 15:02:39 -05:00
parent 319de22d89
commit f9706f260a
3 changed files with 26 additions and 17 deletions

View File

@ -107,8 +107,7 @@ class ClientRequestContextHandler : public CefRequestContextHandler,
} // namespace } // namespace
RootWindowManager::RootWindowManager(bool terminate_when_all_windows_closed) RootWindowManager::RootWindowManager(bool terminate_when_all_windows_closed)
: terminate_when_all_windows_closed_(terminate_when_all_windows_closed), : terminate_when_all_windows_closed_(terminate_when_all_windows_closed) {
image_cache_(new ImageCache) {
CefRefPtr<CefCommandLine> command_line = CefRefPtr<CefCommandLine> command_line =
CefCommandLine::GetGlobalCommandLine(); CefCommandLine::GetGlobalCommandLine();
DCHECK(command_line.get()); DCHECK(command_line.get());
@ -354,8 +353,11 @@ CefRefPtr<CefRequestContext> RootWindowManager::GetRequestContext(
} }
scoped_refptr<ImageCache> RootWindowManager::GetImageCache() { scoped_refptr<ImageCache> RootWindowManager::GetImageCache() {
REQUIRE_MAIN_THREAD(); CEF_REQUIRE_UI_THREAD();
if (!image_cache_) {
image_cache_ = new ImageCache;
}
return image_cache_; return image_cache_;
} }
@ -446,6 +448,10 @@ void RootWindowManager::CleanupOnUIThread() {
temp_window_.reset(nullptr); temp_window_.reset(nullptr);
} }
if (image_cache_) {
image_cache_ = nullptr;
}
// Quit the main message loop. // Quit the main message loop.
MainMessageLoop::Get()->Quit(); MainMessageLoop::Get()->Quit();
} }

View File

@ -59,8 +59,8 @@ void RootWindowViews::Init(RootWindow::Delegate* delegate,
CreateClientHandler(config.url); CreateClientHandler(config.url);
initialized_ = true; initialized_ = true;
// Continue initialization on the main thread. // Continue initialization on the UI thread.
InitOnMainThread(settings, config.url); InitOnUIThread(settings, config.url, delegate_->GetRequestContext(this));
} }
void RootWindowViews::InitAsPopup(RootWindow::Delegate* delegate, void RootWindowViews::InitAsPopup(RootWindow::Delegate* delegate,
@ -187,17 +187,17 @@ ClientWindowHandle RootWindowViews::GetWindowHandle() const {
} }
bool RootWindowViews::WithExtension() const { bool RootWindowViews::WithExtension() const {
REQUIRE_MAIN_THREAD(); DCHECK(initialized_);
return with_extension_; return with_extension_;
} }
bool RootWindowViews::WithControls() { bool RootWindowViews::WithControls() {
CEF_REQUIRE_UI_THREAD(); DCHECK(initialized_);
return with_controls_; return with_controls_;
} }
bool RootWindowViews::WithExtension() { bool RootWindowViews::WithExtension() {
REQUIRE_MAIN_THREAD(); DCHECK(initialized_);
return with_extension_; return with_extension_;
} }
@ -475,12 +475,14 @@ void RootWindowViews::CreateClientHandler(const std::string& url) {
client_handler_->set_download_favicon_images(true); client_handler_->set_download_favicon_images(true);
} }
void RootWindowViews::InitOnMainThread(const CefBrowserSettings& settings, void RootWindowViews::InitOnUIThread(
const std::string& startup_url) { const CefBrowserSettings& settings,
if (!CURRENTLY_ON_MAIN_THREAD()) { const std::string& startup_url,
// Execute this method on the main thread. CefRefPtr<CefRequestContext> request_context) {
MAIN_POST_CLOSURE(base::Bind(&RootWindowViews::InitOnMainThread, this, if (!CefCurrentlyOn(TID_UI)) {
settings, startup_url)); // Execute this method on the UI thread.
CefPostTask(TID_UI, base::Bind(&RootWindowViews::InitOnUIThread, this,
settings, startup_url, request_context));
return; return;
} }
@ -493,7 +495,7 @@ void RootWindowViews::InitOnMainThread(const CefBrowserSettings& settings,
image_cache_->LoadImages( image_cache_->LoadImages(
image_set, base::Bind(&RootWindowViews::CreateViewsWindow, this, settings, image_set, base::Bind(&RootWindowViews::CreateViewsWindow, this, settings,
startup_url, delegate_->GetRequestContext(this))); startup_url, request_context));
} }
void RootWindowViews::CreateViewsWindow( void RootWindowViews::CreateViewsWindow(

View File

@ -89,8 +89,9 @@ class RootWindowViews : public RootWindow,
private: private:
void CreateClientHandler(const std::string& url); void CreateClientHandler(const std::string& url);
void InitOnMainThread(const CefBrowserSettings& settings, void InitOnUIThread(const CefBrowserSettings& settings,
const std::string& startup_url); const std::string& startup_url,
CefRefPtr<CefRequestContext> request_context);
void CreateViewsWindow(const CefBrowserSettings& settings, void CreateViewsWindow(const CefBrowserSettings& settings,
const std::string& startup_url, const std::string& startup_url,
CefRefPtr<CefRequestContext> request_context, CefRefPtr<CefRequestContext> request_context,