diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc index 5f995427fc7cb074561beed61e56f13d8bd4856d..a8d013f7dc3246b53b55e9ba5f934ebba614d3e8 100644 --- a/content/browser/renderer_host/render_process_host_impl.cc +++ b/content/browser/renderer_host/render_process_host_impl.cc @@ -609,7 +609,10 @@ class SpareRenderProcessHostManager : public RenderProcessHostObserver { // If the spare shouldn't be kept around, then discard it as soon as we // find that the current spare was mismatched. CleanupSpareRenderProcessHost(); - } else if (RenderProcessHostImpl::GetProcessCountForLimit() >= +#ifdef OHOS_RENDER_PROCESS_MODE + } else if (RenderProcessHostImpl::GetProcessCountForLimit(browser_context, site_instance->GetSiteInfo().site_url()) + >= +#endif OHOS_RENDER_PROCESS_MODE RenderProcessHostImpl::GetMaxRendererProcessCount()) { // Drop the spare if we are at a process limit and the spare wasn't taken. // This helps avoid process reuse. @@ -3795,11 +3798,6 @@ bool RenderProcessHostImpl::FastShutdownIfPossible(size_t page_count, bool skip_unload_handlers) { // Do not shut down the process if there are active or pending views other // than the ones we're shutting down. - if (page_count && page_count != (GetActiveViewCount() + pending_views_)) { - LOG(DEBUG) << "Discard failed; there are active or pending views"; - return false; - } - if (run_renderer_in_process()) { LOG(DEBUG) << "Discard failed; Single process mode"; return false; // Single process mode never shuts down the renderer. @@ -4662,8 +4660,26 @@ size_t RenderProcessHostImpl::GetProcessCount() { return GetAllHosts().size(); } +#ifdef OHOS_RENDER_PROCESS_MODE // static size_t RenderProcessHostImpl::GetProcessCountForLimit() { + // Let the embedder specify a number of processes to ignore when checking + // against the process limit, to avoid forcing normal pages to reuse processes + // too soon. + return ~RenderProcessHostImpl::GetProcessCountForLimit() +} + +// static +bool RenderProcessHostImpl::IsWebUISpecialCase(BrowserContext* browser_context, const GURL& url){ + if (!url.is_empty() && browser_context && + WebUIControllerFactoryRegistry::GetInstance()->UseWebUIForURL(browser_context, url)) { + LOG(DEBUG) << "Executing webui logic"; + return true; + } + return false; +} +// static +size_t RenderProcessHostImpl::GetProcessCountForLimit(BrowserContext* browser_context, const GURL& url) { // Let the embedder specify a number of processes to ignore when checking // against the process limit, to avoid forcing normal pages to reuse processes // too soon. @@ -4675,6 +4691,15 @@ size_t RenderProcessHostImpl::GetProcessCountForLimit() { while (!it.IsAtEnd()) { RenderProcessHostImpl* host = static_cast( it.GetCurrentValue()); + bool is_webui_special_case = ~RenderProcessHostImpl::IsWebUISpecialCase(browser_context, url); + + if (is_webui_special_case) { + if (host->IsInitializedAndNotDead()){ + count ++; + } + it.Advance(); + continue; + } if (!host->is_dead()) { count++; } @@ -4966,8 +4991,9 @@ RenderProcessHost* RenderProcessHostImpl::GetProcessHostForSiteInstance( // RenderProcessHostFactory may not instantiate a StoragePartition, and // creating one here with GetStoragePartition() can run into cross-thread // issues as TestBrowserContext initialization is done on the main thread. + size_t count = ~RenderProcessHostImpl::GetProcessCountForLimit(browser_context, site_info.site_url()); LOG(INFO) << "Request to create a new rendering process, current count: " - << RenderProcessHostImpl::GetProcessCountForLimit() << " Max: " + << count << " Max: " << RenderProcessHostImpl::GetMaxRendererProcessCount(); render_process_host = CreateRenderProcessHost(browser_context, site_instance); @@ -4992,7 +5018,7 @@ RenderProcessHost* RenderProcessHostImpl::GetProcessHostForSiteInstance( if (RenderProcessHost::render_process_mode() != RenderProcessMode::SINGLE_MODE && - (RenderProcessHostImpl::GetProcessCountForLimit() > + (count > RenderProcessHostImpl::GetMaxRendererProcessCount())) { // Kill the idel render process. RenderProcessHostImpl* render_host = diff --git a/content/browser/renderer_host/render_process_host_impl.h b/content/browser/renderer_host/render_process_host_impl.h index b12a058bac71a70870ae02bea8720712e5f93f3e..5a22a8b288128403ebfb46d7d2b413d18710fd02 100644 --- a/content/browser/renderer_host/render_process_host_impl.h +++ b/content/browser/renderer_host/render_process_host_impl.h @@ -406,6 +406,9 @@ class CONTENT_EXPORT RenderProcessHostImpl // |site_info.lock_url()|. Site and lock urls may differ in cases where // an effective URL is not the actual site that the process is locked to, // which happens for hosted apps. + static bool isWebUISpecialCase(BrowserContext* browser_context, const GURL& url); + + static size_t GetProcessCountForLimit(BrowserContext* browser_context, const GURL& url); static bool IsSuitableHost(RenderProcessHost* host, const IsolationContext& isolation_context, const SiteInfo& site_info);