Index: content/browser/browser_context.cc |
diff --git a/content/browser/browser_context.cc b/content/browser/browser_context.cc |
index 6ca86e7466eabfaebe409351bac63468cce016a8..4dd3de040224e738f7516953bed8d43e422ca0df 100644 |
--- a/content/browser/browser_context.cc |
+++ b/content/browser/browser_context.cc |
@@ -30,6 +30,7 @@ |
#include "content/public/browser/blob_handle.h" |
#include "content/public/browser/browser_thread.h" |
#include "content/public/browser/content_browser_client.h" |
+#include "content/public/browser/render_process_host.h" |
#include "content/public/browser/site_instance.h" |
#include "content/public/common/content_switches.h" |
#include "content/public/common/mojo_shell_connection.h" |
@@ -332,6 +333,21 @@ void BrowserContext::NotifyWillBeDestroyed(BrowserContext* browser_context) { |
// render process hosts die before their profile (browser context) dies. |
ForEachStoragePartition(browser_context, |
base::Bind(ShutdownServiceWorkerContext)); |
+ |
+ // Some tests don't setup RenderProcessHost correctly and don't necessary run |
+ // on the UI thread anyway, so we can't use the AllHostIterator. |
+ if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) |
+ return; |
+ |
+ // Force release the worker ref count to release the render process which have |
+ // been kept alive for shared workers. |
+ for (content::RenderProcessHost::iterator host_iterator = |
+ content::RenderProcessHost::AllHostsIterator(); |
+ !host_iterator.IsAtEnd(); host_iterator.Advance()) { |
+ content::RenderProcessHost* host = host_iterator.GetCurrentValue(); |
+ if (host->GetBrowserContext() == browser_context) |
+ host->ForceReleaseWorkerRefCount(); |
+ } |
} |
void BrowserContext::EnsureResourceContextInitialized(BrowserContext* context) { |