diff --git a/atom/browser/atom_browser_context.cc b/atom/browser/atom_browser_context.cc index fff0e85f2a83..9c0fb997713f 100644 --- a/atom/browser/atom_browser_context.cc +++ b/atom/browser/atom_browser_context.cc @@ -72,7 +72,7 @@ AtomBrowserContext::AtomBrowserContext(const std::string& partition, bool in_memory, const base::DictionaryValue& options) : base::RefCountedDeleteOnSequence( - base::SequencedTaskRunnerHandle::Get()), + base::ThreadTaskRunnerHandle::Get()), in_memory_pref_store_(nullptr), storage_policy_(new SpecialStoragePolicy), in_memory_(in_memory), diff --git a/atom/browser/common_web_contents_delegate.cc b/atom/browser/common_web_contents_delegate.cc index 00a179698226..cb15a17e1d04 100644 --- a/atom/browser/common_web_contents_delegate.cc +++ b/atom/browser/common_web_contents_delegate.cc @@ -205,8 +205,19 @@ void CommonWebContentsDelegate::SetOwnerWindow( void CommonWebContentsDelegate::ResetManagedWebContents(bool async) { if (async) { - base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, - web_contents_.release()); + // Browser context should be destroyed only after the WebContents, + // this is guaranteed in the sync mode by the order of declaration, + // in the async version we maintain a reference until the WebContents + // is destroyed. + // //electron/patches/common/chromium/content_browser_main_loop.patch + // is required to get the right quit closure for the main message loop. + base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask( + FROM_HERE, + base::BindOnce([](scoped_refptr browser_context, + std::unique_ptr + web_contents) { web_contents.reset(); }, + base::RetainedRef(browser_context_), + std::move(web_contents_))); } else { web_contents_.reset(); } diff --git a/patches/common/chromium/.patches.yaml b/patches/common/chromium/.patches.yaml index cc4f1e8fa8af..c5d30c893685 100644 --- a/patches/common/chromium/.patches.yaml +++ b/patches/common/chromium/.patches.yaml @@ -477,3 +477,10 @@ patches: Pass RenderProcessHost through to PlatformNotificationService. This is so Electron can identify which renderer a notification came from. +- + author: deepak1556 + file: content_browser_main_loop.patch + description: | + Pass idle quit closure for main message loop, so that pending tasks are + run before shutdown. This is required to cleanup WebContents asynchronously + in atom::CommonWebContentsDelegate::ResetManageWebContents. diff --git a/patches/common/chromium/content_browser_main_loop.patch b/patches/common/chromium/content_browser_main_loop.patch new file mode 100644 index 000000000000..0c53f391db41 --- /dev/null +++ b/patches/common/chromium/content_browser_main_loop.patch @@ -0,0 +1,13 @@ +diff --git a/content/browser/browser_main_loop.cc b/content/browser/browser_main_loop.cc +index eb942391306e..9111cf18b7fc 100644 +--- a/content/browser/browser_main_loop.cc ++++ b/content/browser/browser_main_loop.cc +@@ -1571,7 +1571,7 @@ void BrowserMainLoop::MainMessageLoopRun() { + } + + base::RunLoop run_loop; +- parts_->PreDefaultMainMessageLoopRun(run_loop.QuitClosure()); ++ parts_->PreDefaultMainMessageLoopRun(run_loop.QuitWhenIdleClosure()); + run_loop.Run(); + #endif + }