From 13bdfa9ad70c2c1fd979c863f80755aab55d074e Mon Sep 17 00:00:00 2001 From: slim Date: Sat, 26 Oct 2024 10:11:58 +0800 Subject: [PATCH 1/2] webui limit Signed-off-by: slim --- .../renderer_host/render_process_host_impl.cc | 37 +++++++++++++++++-- .../renderer_host/render_process_host_impl.h | 3 ++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc index 5f995427fc..2a9fe83844 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. @@ -4662,8 +4665,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 +4696,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 +4996,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 +5023,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 b12a058bac..5a22a8b288 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); -- Gitee From 16b404163f54966509f5001c1dd2055eb30ecac9 Mon Sep 17 00:00:00 2001 From: slim Date: Wed, 11 Dec 2024 17:47:32 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=B6=85=E5=87=BA?= =?UTF-8?q?=E4=B8=8A=E9=99=90=E6=A6=82=E7=8E=87kill=E4=B8=8D=E4=BA=86?= =?UTF-8?q?=E7=A9=BA=E9=97=B2=E8=BF=9B=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: slim --- content/browser/renderer_host/render_process_host_impl.cc | 5 ----- 1 file changed, 5 deletions(-) diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc index 2a9fe83844..a8d013f7dc 100644 --- a/content/browser/renderer_host/render_process_host_impl.cc +++ b/content/browser/renderer_host/render_process_host_impl.cc @@ -3798,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. -- Gitee