chrome/browser/chrome_content_browser_client.cc
// This function is trying to limit the amount of processes used by extensions
// with background pages. It uses a globally set percentage of processes to
// run such extensions and if the limit is exceeded, it returns true, to
// indicate to the content module to group extensions together.
This function is trying to limit the amount of processes used by extensions
with background pages. It uses a globally set percentage of processes to
run such extensions and if the limit is exceeded, it returns true, to
indicate to the content module to group extensions together.
This function is trying to limit the amount of processes used by extensions with background pages . It uses a globally set percentage of processes to run such extensions and if the limit is exceeded it returns true to indicate to the content module to group extensions together .
bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
    content::BrowserContext* browser_context, const GURL& url) {
  if (!url.is_valid())
    return false;
  Profile* profile = Profile::FromBrowserContext(browser_context);
  ExtensionService* service = !profile ? NULL :
      extensions::ExtensionSystem::Get(profile)->extension_service();
  if (!service)
    return false;
  const Extension* extension =
      service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
  if (!extension)
    return false;
  if (!extension->has_background_page())
    return false;
  std::set<int> process_ids;
  size_t max_process_count =
      content::RenderProcessHost::GetMaxRendererProcessCount();
  std::vector<Profile*> profiles = g_browser_process->profile_manager()->
      GetLoadedProfiles();
  for (size_t i = 0; i < profiles.size(); ++i) {
    ExtensionProcessManager* epm =
        extensions::ExtensionSystem::Get(profiles[i])->process_manager();
    for (ExtensionProcessManager::const_iterator iter =
             epm->background_hosts().begin();
         iter != epm->background_hosts().end(); ++iter) {
      const extensions::ExtensionHost* host = *iter;
      process_ids.insert(host->render_process_host()->GetID());
    }
  }
  if (process_ids.size() >
      (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
    return true;
  }
  return false;
}
bool ChromeContentBrowserClient :: ShouldTryToUseExistingProcessHost ( content :: BrowserContext * browser_context , const GURL & url ) { if ( ! url . is_valid ( ) ) return false ; Profile * profile = Profile :: FromBrowserContext ( browser_context ) ; ExtensionService * service = ! profile ? NULL : extensions :: ExtensionSystem :: Get ( profile ) -> extension_service ( ) ; if ( ! service ) return false ; const Extension * extension = service -> extensions ( ) -> GetExtensionOrAppByURL ( ExtensionURLInfo ( url ) ) ; if ( ! extension ) return false ; if ( ! extension -> has_background_page ( ) ) return false ; std :: set < int > process_ids ; size_t max_process_count = content :: RenderProcessHost :: GetMaxRendererProcessCount ( ) ; std :: vector < Profile * > profiles = g_browser_process -> profile_manager ( ) -> GetLoadedProfiles ( ) ; for ( size_t i = 0 ; i < profiles . size ( ) ; ++ i ) { ExtensionProcessManager * epm = extensions :: ExtensionSystem :: Get ( profiles [ i ] ) -> process_manager ( ) ; for ( ExtensionProcessManager :: const_iterator iter = epm -> background_hosts ( ) . begin ( ) ; iter != epm -> background_hosts ( ) . end ( ) ; ++ iter ) { const extensions :: ExtensionHost * host = * iter ; process_ids . insert ( host -> render_process_host ( ) -> GetID ( ) ) ; } } if ( process_ids . size ( ) > ( max_process_count * chrome :: kMaxShareOfExtensionProcesses ) ) { return true ; } return false ; }
This function is trying to limit the amount of processes used by extensions
with background pages.
This function is trying to limit the amount of processes used by extensions with background pages .
// It has to be a valid URL for us to check for an extension. // We have to have a valid extension with background page to proceed. // Go through all profiles to ensure we have total count of extension // processes containing background pages, otherwise one profile can // starve the other.