[M130 Migration] Added switch for single renderer process 06/324606/3
authorutkarshlal <utkarsh.lal@samsung.com>
Wed, 21 May 2025 10:55:56 +0000 (16:25 +0530)
committerBot Blink <blinkbot@samsung.com>
Wed, 21 May 2025 13:14:53 +0000 (13:14 +0000)
Added kSingleRendererProcess switch to limit renderer processes to 1.
Append --single-renderer-process flag at runtime to enable.

References:
https://review.tizen.org/gerrit/c/316129
https://review.tizen.org/gerrit/c/320425

Change-Id: I49d11771aa112b0d9e450f060d5a5f97c9dc1280
Signed-off-by: utkarshlal <utkarsh.lal@samsung.com>
content/browser/renderer_host/render_frame_host_impl.cc
content/browser/renderer_host/render_process_host_impl.cc
content/browser/renderer_host/spare_render_process_host_manager.cc
content/browser/site_info.cc
content/public/common/content_switches.cc
content/public/common/content_switches.h

index 65a16529fa4e2a87702feca9942339d7cb66086f..9fcc3896be487f14e4be8a4514e9023bd3e59ee2 100644 (file)
@@ -7030,6 +7030,10 @@ void RenderFrameHostImpl::AllowBindings(BindingsPolicySet bindings) {
   // code in-process, the security invariant cannot be enforced, therefore it
   // should be skipped in that case.
   if (!webui_bindings.empty() &&
+#if BUILDFLAG(IS_TIZEN)
+      !base::CommandLine::ForCurrentProcess()->HasSwitch(
+          switches::kSingleRendererProcess) &&
+#endif  // BUILDFLAG(IS_TIZEN)
       !RenderProcessHost::run_renderer_in_process()) {
     ProcessLock process_lock = GetProcess()->GetProcessLock();
     if (!process_lock.is_locked_to_site() ||
@@ -7067,6 +7071,10 @@ void RenderFrameHostImpl::AllowBindings(BindingsPolicySet bindings) {
           }
         });
     if (non_empty_frame_count > 0 &&
+#if BUILDFLAG(IS_TIZEN)
+        !base::CommandLine::ForCurrentProcess()->HasSwitch(
+            switches::kSingleRendererProcess) &&
+#endif  // BUILDFLAG(IS_TIZEN)
         !base::CommandLine::ForCurrentProcess()->HasSwitch(
             switches::kSingleProcess)) {
       return;
index 9190e37813f5826d337f290ff118ae5f41584c10..705e74bad9d6841001f12ad5f96e0141e63443b4 100644 (file)
@@ -4357,7 +4357,12 @@ bool RenderProcessHostImpl::IsSuitableHost(
   BrowserContext* browser_context =
       isolation_context.browser_or_resource_context().ToBrowserContext();
   DCHECK(browser_context);
-  if (run_renderer_in_process()) {
+  if (run_renderer_in_process()
+#if BUILDFLAG(IS_TIZEN)
+      || base::CommandLine::ForCurrentProcess()->HasSwitch(
+             switches::kSingleRendererProcess)
+#endif
+  ) {
     DCHECK_EQ(host->GetBrowserContext(), browser_context)
         << " Single-process mode does not support multiple browser contexts.";
     return true;
@@ -4595,8 +4600,14 @@ size_t RenderProcessHostImpl::GetProcessCountForLimit() {
 bool RenderProcessHost::ShouldTryToUseExistingProcessHost(
     BrowserContext* browser_context,
     const GURL& url) {
-  if (run_renderer_in_process())
+  if (run_renderer_in_process()
+#if BUILDFLAG(IS_TIZEN)
+      || base::CommandLine::ForCurrentProcess()->HasSwitch(
+             switches::kSingleRendererProcess)
+#endif
+  ) {
     return true;
+  }
 
   // NOTE: Sometimes it's necessary to create more render processes than
   //       GetMaxRendererProcessCount(), for instance when we want to create
@@ -4804,6 +4815,23 @@ RenderProcessHost* RenderProcessHostImpl::GetProcessHostForSiteInstance(
     }
   }
 
+#if BUILDFLAG(IS_TIZEN)
+  // As long as the browser context is same, we can re-use existing renderers.
+  // But for cases like profile change or incognito mode, a new browser context
+  // is created. In such cases, the new browser context and existing render
+  // process host have different storage partitions. For such scenarios, we
+  // allow the creation of new RenderProcessHost to adhere to the current
+  // Chromium design.
+  if (base::CommandLine::ForCurrentProcess()->HasSwitch(
+          switches::kSingleRendererProcess)) {
+    if (render_process_host &&
+        !render_process_host->InSameStoragePartition(
+            browser_context->GetStoragePartition(site_instance, false))) {
+      render_process_host = nullptr;
+    }
+  }
+#endif
+
   // If we found a process to reuse, double-check that it is suitable for
   // |site_instance|. For example, if the SiteInfo for |site_instance| requires
   // a dedicated process, we should never pick a process used by, or locked to,
index e220c68d639c4fc723e70062ef1c5cf1fe641aa4..1ae2705ba74a35db40e2051fbc0a8ac4086bd7f0 100644 (file)
@@ -18,6 +18,9 @@
 #include "content/public/browser/render_process_host.h"
 #include "content/public/common/content_client.h"
 #include "content/public/common/content_features.h"
+#if BUILDFLAG(IS_TIZEN)
+#include "content/public/common/content_switches.h"
+#endif  // BUILDFLAG(IS_TIZEN)
 
 namespace content {
 
@@ -106,6 +109,10 @@ void SpareRenderProcessHostManager::WarmupSpareRenderProcessHost(
   // got too many processes. See also ShouldTryToUseExistingProcessHost in
   // this file.
   if (RenderProcessHost::run_renderer_in_process() ||
+#if BUILDFLAG(IS_TIZEN)
+      base::CommandLine::ForCurrentProcess()->HasSwitch(
+          switches::kSingleRendererProcess) ||
+#endif
       RenderProcessHostImpl::GetProcessCountForLimit() >=
           RenderProcessHostImpl::GetMaxRendererProcessCount()) {
     return;
index a5e0ceb37eb79f5117067d20129b14f48aedba94..d2858879c2584daa2e0002ea727e07e427db7ca7 100644 (file)
@@ -760,8 +760,14 @@ bool SiteInfo::ShouldLockProcessToSite(
   // Don't lock to origin in --single-process mode, since this mode puts
   // cross-site pages into the same process.  Note that this also covers the
   // single-process mode in Android Webview.
-  if (RenderProcessHost::run_renderer_in_process())
+  if (RenderProcessHost::run_renderer_in_process()
+#if BUILDFLAG(IS_TIZEN)
+      || base::CommandLine::ForCurrentProcess()->HasSwitch(
+             switches::kSingleRendererProcess)
+#endif
+  ) {
     return false;
+  }
 
   if (!RequiresDedicatedProcess(isolation_context))
     return false;
index 7bb0f551e218c722dbb0cfa7dde52dfc2d59764a..0b3e0aa3778a60bcee21c0b721457905fb49a18f 100644 (file)
@@ -1033,6 +1033,7 @@ const char kRemoteDebuggingIoPipes[] = "remote-debugging-io-pipes";
 
 #if BUILDFLAG(IS_TIZEN)
 const char kMaxRefreshRate[] = "max-refresh-rate";
+const char kSingleRendererProcess[] = "single-renderer-process";
 #endif
 
 #if BUILDFLAG(IS_TIZEN_TV)
index 131aeab662425aff858fb898116fe390aacde7ab..21313a3cdba592d271f8930e11a91ba9a7b8c355 100644 (file)
@@ -298,6 +298,7 @@ CONTENT_EXPORT extern const char kRemoteDebuggingIoPipes[];
 
 #if BUILDFLAG(IS_TIZEN)
 CONTENT_EXPORT extern const char kMaxRefreshRate[];
+CONTENT_EXPORT extern const char kSingleRendererProcess[];
 #endif
 
 #if BUILDFLAG(IS_TIZEN_TV)