Chromium Code Reviews| Index: content/browser/renderer_host/render_process_host_impl.cc |
| diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc |
| index ff87202bcccaf9b7b6daa3be1592569b477f4287..531f4c17f9805e07bd2e2124f42f4c6bb607cb6a 100644 |
| --- a/content/browser/renderer_host/render_process_host_impl.cc |
| +++ b/content/browser/renderer_host/render_process_host_impl.cc |
| @@ -259,9 +259,8 @@ void GetContexts( |
| ResourceContext** resource_context_out, |
| net::URLRequestContext** request_context_out) { |
| *resource_context_out = resource_context; |
| - *request_context_out = |
| - GetRequestContext(request_context, media_request_context, |
| - request.resource_type); |
| + *request_context_out = GetRequestContext( |
| + request_context, media_request_context, request.resource_type); |
| } |
| #if defined(ENABLE_WEBRTC) |
| @@ -278,8 +277,8 @@ IPC::PlatformFileForTransit CreateAecDumpFileForProcess( |
| base::File dump_file(file_path, |
| base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_APPEND); |
| if (!dump_file.IsValid()) { |
| - VLOG(1) << "Could not open AEC dump file, error=" << |
| - dump_file.error_details(); |
| + VLOG(1) << "Could not open AEC dump file, error=" |
| + << dump_file.error_details(); |
| return IPC::InvalidPlatformFileForTransit(); |
| } |
| return IPC::TakeFileHandleForProcess(dump_file.Pass(), process); |
| @@ -292,8 +291,8 @@ void DisableAecDumpOnFileThread() { |
| #endif |
| // the global list of all renderer processes |
| -base::LazyInstance<IDMap<RenderProcessHost> >::Leaky |
| - g_all_hosts = LAZY_INSTANCE_INITIALIZER; |
| +base::LazyInstance<IDMap<RenderProcessHost>>::Leaky g_all_hosts = |
| + LAZY_INSTANCE_INITIALIZER; |
| // Map of site to process, to ensure we only have one RenderProcessHost per |
| // site in process-per-site mode. Each map is specific to a BrowserContext. |
| @@ -317,14 +316,12 @@ class SiteProcessMap : public base::SupportsUserData::Data { |
| // Find all instances of this process in the map, then separately remove |
| // them. |
| std::set<std::string> sites; |
| - for (SiteToProcessMap::const_iterator i = map_.begin(); |
| - i != map_.end(); |
| + for (SiteToProcessMap::const_iterator i = map_.begin(); i != map_.end(); |
| i++) { |
| if (i->second == host) |
| sites.insert(i->first); |
| } |
| - for (std::set<std::string>::iterator i = sites.begin(); |
| - i != sites.end(); |
| + for (std::set<std::string>::iterator i = sites.begin(); i != sites.end(); |
| i++) { |
| SiteToProcessMap::iterator iter = map_.find(*i); |
| if (iter != map_.end()) { |
| @@ -358,7 +355,8 @@ class RendererSandboxedProcessLauncherDelegate |
| #if defined(OS_POSIX) |
| : ipc_fd_(channel->TakeClientFileDescriptor()) |
| #endif // OS_POSIX |
| - {} |
| + { |
| + } |
| ~RendererSandboxedProcessLauncherDelegate() override {} |
| @@ -386,9 +384,7 @@ class RendererSandboxedProcessLauncherDelegate |
| base::ScopedFD TakeIpcFd() override { return ipc_fd_.Pass(); } |
| #endif // OS_WIN |
| - SandboxType GetSandboxType() override { |
| - return SANDBOX_TYPE_RENDERER; |
| - } |
| + SandboxType GetSandboxType() override { return SANDBOX_TYPE_RENDERER; } |
| private: |
| #if defined(OS_POSIX) |
| @@ -412,7 +408,7 @@ class SessionStorageHolder : public base::SupportsUserData::Data { |
| } |
| private: |
| - std::map<int, SessionStorageNamespaceMap > |
| + std::map<int, SessionStorageNamespaceMap> |
| session_storage_namespaces_awaiting_close_; |
| DISALLOW_COPY_AND_ASSIGN(SessionStorageHolder); |
| }; |
| @@ -434,7 +430,7 @@ RendererMainThreadFactoryFunction g_renderer_main_thread_factory = NULL; |
| base::MessageLoop* g_in_process_thread; |
| base::MessageLoop* |
| - RenderProcessHostImpl::GetInProcessRendererThreadForTesting() { |
| +RenderProcessHostImpl::GetInProcessRendererThreadForTesting() { |
| return g_in_process_thread; |
| } |
| @@ -508,7 +504,7 @@ RenderProcessHostImpl::RenderProcessHostImpl( |
| pending_views_(0), |
| mojo_application_host_(new MojoApplicationHost), |
| visible_widgets_(0), |
| - backgrounded_(true), |
| + is_process_backgrounded_(false), |
| is_initialized_(false), |
| id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), |
| browser_context_(browser_context), |
| @@ -553,11 +549,6 @@ RenderProcessHostImpl::RenderProcessHostImpl( |
| if (BootstrapSandboxManager::ShouldEnable()) |
| AddObserver(BootstrapSandboxManager::GetInstance()); |
| #endif |
| - |
| - // Note: When we create the RenderProcessHostImpl, it's technically |
| - // backgrounded, because it has no visible listeners. But the process |
| - // doesn't actually exist yet, so we'll Background it later, after |
| - // creation. |
| } |
| // static |
| @@ -570,8 +561,7 @@ void RenderProcessHostImpl::ShutDownInProcessRenderer() { |
| case 1: { |
| RenderProcessHostImpl* host = static_cast<RenderProcessHostImpl*>( |
| AllHostsIterator().GetCurrentValue()); |
| - FOR_EACH_OBSERVER(RenderProcessHostObserver, |
| - host->observers_, |
| + FOR_EACH_OBSERVER(RenderProcessHostObserver, host->observers_, |
| RenderProcessHostDestroyed(host)); |
| #ifndef NDEBUG |
| host->is_self_deleted_ = true; |
| @@ -617,7 +607,7 @@ RenderProcessHostImpl::~RenderProcessHostImpl() { |
| UnregisterHost(GetID()); |
| if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| - switches::kDisableGpuShaderDiskCache)) { |
| + switches::kDisableGpuShaderDiskCache)) { |
| BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| base::Bind(&RemoveShaderInfo, GetID())); |
| } |
| @@ -642,8 +632,8 @@ bool RenderProcessHostImpl::Init() { |
| browser_command_line.GetSwitchValueNative(switches::kRendererCmdPrefix); |
| #if defined(OS_LINUX) |
| - int flags = renderer_prefix.empty() ? ChildProcessHost::CHILD_ALLOW_SELF : |
| - ChildProcessHost::CHILD_NORMAL; |
| + int flags = renderer_prefix.empty() ? ChildProcessHost::CHILD_ALLOW_SELF |
| + : ChildProcessHost::CHILD_NORMAL; |
| #else |
| int flags = ChildProcessHost::CHILD_NORMAL; |
| #endif |
| @@ -681,8 +671,9 @@ bool RenderProcessHostImpl::Init() { |
| // on separate threads. |
| in_process_renderer_.reset( |
| g_renderer_main_thread_factory(InProcessChildThreadParams( |
| - channel_id, BrowserThread::UnsafeGetMessageLoopForThread( |
| - BrowserThread::IO)->task_runner()))); |
| + channel_id, |
| + BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO) |
| + ->task_runner()))); |
| base::Thread::Options options; |
| #if defined(OS_WIN) && !defined(OS_MACOSX) |
| @@ -717,10 +708,8 @@ bool RenderProcessHostImpl::Init() { |
| // As long as there's no renderer prefix, we can use the zygote process |
| // at this stage. |
| child_process_launcher_.reset(new ChildProcessLauncher( |
| - new RendererSandboxedProcessLauncherDelegate(channel_.get()), |
| - cmd_line, |
| - GetID(), |
| - this)); |
| + new RendererSandboxedProcessLauncherDelegate(channel_.get()), cmd_line, |
| + GetID(), this)); |
| fast_shutdown_started_ = false; |
| } |
| @@ -743,7 +732,7 @@ scoped_ptr<IPC::ChannelProxy> RenderProcessHostImpl::CreateChannelProxy( |
| BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
| scoped_refptr<base::SequencedTaskRunner> mojo_task_runner = |
| BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO) |
| - ->task_runner(); |
| + ->task_runner(); |
| if (ShouldUseMojoChannel()) { |
| VLOG(1) << "Mojo Channel is enabled on host"; |
| @@ -772,12 +761,9 @@ void RenderProcessHostImpl::CreateMessageFilters() { |
| scoped_refptr<RenderMessageFilter> render_message_filter( |
| new RenderMessageFilter( |
| - GetID(), |
| - GetBrowserContext(), |
| + GetID(), GetBrowserContext(), |
| GetBrowserContext()->GetRequestContextForRenderProcess(GetID()), |
| - widget_helper_.get(), |
| - audio_manager, |
| - media_internals, |
| + widget_helper_.get(), audio_manager, media_internals, |
| storage_partition_impl_->GetDOMStorageContext())); |
| AddFilter(render_message_filter.get()); |
| AddFilter(new RenderFrameMessageFilter( |
| @@ -817,33 +803,25 @@ void RenderProcessHostImpl::CreateMessageFilters() { |
| // The AudioInputRendererHost and AudioRendererHost needs to be available for |
| // lookup, so it's stashed in a member variable. |
| audio_input_renderer_host_ = new AudioInputRendererHost( |
| - GetID(), |
| - base::GetProcId(GetHandle()), |
| - audio_manager, |
| - media_stream_manager, |
| - AudioMirroringManager::GetInstance(), |
| + GetID(), base::GetProcId(GetHandle()), audio_manager, |
| + media_stream_manager, AudioMirroringManager::GetInstance(), |
| BrowserMainLoop::GetInstance()->user_input_monitor()); |
| AddFilter(audio_input_renderer_host_.get()); |
| audio_renderer_host_ = new AudioRendererHost( |
| - GetID(), |
| - audio_manager, |
| - AudioMirroringManager::GetInstance(), |
| - media_internals, |
| - media_stream_manager, |
| + GetID(), audio_manager, AudioMirroringManager::GetInstance(), |
| + media_internals, media_stream_manager, |
| browser_context->GetResourceContext()->GetMediaDeviceIDSalt()); |
| AddFilter(audio_renderer_host_.get()); |
| AddFilter( |
| new MidiHost(GetID(), BrowserMainLoop::GetInstance()->midi_manager())); |
| AddFilter(new VideoCaptureHost(media_stream_manager)); |
| AddFilter(new AppCacheDispatcherHost( |
| - storage_partition_impl_->GetAppCacheService(), |
| - GetID())); |
| + storage_partition_impl_->GetAppCacheService(), GetID())); |
| AddFilter(new ClipboardMessageFilter); |
| AddFilter(new DOMStorageMessageFilter( |
| storage_partition_impl_->GetDOMStorageContext())); |
| AddFilter(new IndexedDBDispatcherHost( |
| - GetID(), |
| - storage_partition_impl_->GetURLRequestContext(), |
| + GetID(), storage_partition_impl_->GetURLRequestContext(), |
| storage_partition_impl_->GetIndexedDBContext(), |
| ChromeBlobStorageContext::GetFor(browser_context))); |
| @@ -851,14 +829,12 @@ void RenderProcessHostImpl::CreateMessageFilters() { |
| AddFilter(gpu_message_filter_); |
| #if defined(ENABLE_WEBRTC) |
| AddFilter(new WebRTCIdentityServiceHost( |
| - GetID(), |
| - storage_partition_impl_->GetWebRTCIdentityStore(), |
| + GetID(), storage_partition_impl_->GetWebRTCIdentityStore(), |
| resource_context)); |
| peer_connection_tracker_host_ = new PeerConnectionTrackerHost(GetID()); |
| AddFilter(peer_connection_tracker_host_.get()); |
| AddFilter(new MediaStreamDispatcherHost( |
| - GetID(), |
| - browser_context->GetResourceContext()->GetMediaDeviceIDSalt(), |
| + GetID(), browser_context->GetResourceContext()->GetMediaDeviceIDSalt(), |
| media_stream_manager)); |
| AddFilter(new MediaStreamTrackMetricsHost()); |
| #endif |
| @@ -868,15 +844,14 @@ void RenderProcessHostImpl::CreateMessageFilters() { |
| AddFilter(new SpeechRecognitionDispatcherHost( |
| GetID(), storage_partition_impl_->GetURLRequestContext())); |
| AddFilter(new FileAPIMessageFilter( |
| - GetID(), |
| - storage_partition_impl_->GetURLRequestContext(), |
| + GetID(), storage_partition_impl_->GetURLRequestContext(), |
| storage_partition_impl_->GetFileSystemContext(), |
| ChromeBlobStorageContext::GetFor(browser_context), |
| StreamContext::GetFor(browser_context))); |
| AddFilter(new FileUtilitiesMessageFilter(GetID())); |
| AddFilter(new MimeRegistryMessageFilter()); |
| - AddFilter(new DatabaseMessageFilter( |
| - storage_partition_impl_->GetDatabaseTracker())); |
| + AddFilter( |
| + new DatabaseMessageFilter(storage_partition_impl_->GetDatabaseTracker())); |
| #if defined(OS_MACOSX) |
| AddFilter(new TextInputClientMessageFilter(GetID())); |
| #elif defined(OS_WIN) |
| @@ -895,8 +870,8 @@ void RenderProcessHostImpl::CreateMessageFilters() { |
| WebSocketDispatcherHost::GetRequestContextCallback |
| websocket_request_context_callback( |
| - base::Bind(&GetRequestContext, request_context, |
| - media_request_context, RESOURCE_TYPE_SUB_RESOURCE)); |
| + base::Bind(&GetRequestContext, request_context, media_request_context, |
| + RESOURCE_TYPE_SUB_RESOURCE)); |
| AddFilter( |
| new WebSocketDispatcherHost(GetID(), websocket_request_context_callback)); |
| @@ -919,8 +894,7 @@ void RenderProcessHostImpl::CreateMessageFilters() { |
| AddFilter(service_worker_filter.get()); |
| AddFilter(new SharedWorkerMessageFilter( |
| - GetID(), |
| - resource_context, |
| + GetID(), resource_context, |
| WorkerStoragePartition( |
| storage_partition_impl_->GetURLRequestContext(), |
| storage_partition_impl_->GetMediaURLRequestContext(), |
| @@ -943,15 +917,12 @@ void RenderProcessHostImpl::CreateMessageFilters() { |
| AddFilter(new ResolveProxyMsgHelper( |
| browser_context->GetRequestContextForRenderProcess(GetID()))); |
| AddFilter(new QuotaDispatcherHost( |
| - GetID(), |
| - storage_partition_impl_->GetQuotaManager(), |
| + GetID(), storage_partition_impl_->GetQuotaManager(), |
| GetContentClient()->browser()->CreateQuotaPermissionContext())); |
| notification_message_filter_ = new NotificationMessageFilter( |
| - GetID(), |
| - storage_partition_impl_->GetPlatformNotificationContext(), |
| - resource_context, |
| - browser_context); |
| + GetID(), storage_partition_impl_->GetPlatformNotificationContext(), |
| + resource_context, browser_context); |
| AddFilter(notification_message_filter_.get()); |
| AddFilter(new GamepadBrowserMessageFilter()); |
| @@ -1054,10 +1025,9 @@ void RenderProcessHostImpl::SendUpdateValueState(unsigned int target, |
| const gpu::ValueState& state) { |
| DCHECK(subscribe_uniform_enabled_); |
| if (subscription_set_.find(target) != subscription_set_.end()) { |
| - GpuProcessHost::SendOnIO( |
| - GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, |
| - CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH, |
| - new GpuMsg_UpdateValueState(id_, target, state)); |
| + GpuProcessHost::SendOnIO(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, |
| + CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH, |
| + new GpuMsg_UpdateValueState(id_, target, state)); |
| } else { |
| // Store the ValueState locally in case a Valuebuffer subscribes to it later |
| pending_valuebuffer_state_->UpdateState(target, state); |
| @@ -1075,11 +1045,10 @@ media::BrowserCdm* RenderProcessHostImpl::GetBrowserCdm(int render_frame_id, |
| } |
| #endif |
| -void RenderProcessHostImpl::AddRoute( |
| - int32 routing_id, |
| - IPC::Listener* listener) { |
| - CHECK(!listeners_.Lookup(routing_id)) |
| - << "Found Routing ID Conflict: " << routing_id; |
| +void RenderProcessHostImpl::AddRoute(int32 routing_id, |
| + IPC::Listener* listener) { |
| + CHECK(!listeners_.Lookup(routing_id)) << "Found Routing ID Conflict: " |
| + << routing_id; |
| listeners_.AddWithID(listener, routing_id); |
| } |
| @@ -1117,23 +1086,20 @@ void RenderProcessHostImpl::ShutdownForBadMessage() { |
| } |
| void RenderProcessHostImpl::WidgetRestored() { |
| - // Verify we were properly backgrounded. |
| - DCHECK_EQ(backgrounded_, (visible_widgets_ == 0)); |
| visible_widgets_++; |
| - SetBackgrounded(false); |
| + UpdateProcessPriority(); |
| + DCHECK(!is_process_backgrounded_); |
| } |
| void RenderProcessHostImpl::WidgetHidden() { |
| - // On startup, the browser will call Hide |
| - if (backgrounded_) |
| + // On startup, the browser will call Hide. We ignore this call. |
| + if (visible_widgets_ == 0) |
| return; |
| - DCHECK_EQ(backgrounded_, (visible_widgets_ == 0)); |
| - visible_widgets_--; |
| - DCHECK_GE(visible_widgets_, 0); |
| + --visible_widgets_; |
| if (visible_widgets_ == 0) { |
| - DCHECK(!backgrounded_); |
| - SetBackgrounded(true); |
| + DCHECK(!is_process_backgrounded_); |
| + UpdateProcessPriority(); |
| } |
| } |
| @@ -1141,6 +1107,10 @@ int RenderProcessHostImpl::VisibleWidgetCount() const { |
| return visible_widgets_; |
| } |
| +void RenderProcessHostImpl::AudioStateChanged() { |
| + UpdateProcessPriority(); |
| +} |
| + |
| bool RenderProcessHostImpl::IsForGuestsOnly() const { |
| return is_for_guests_only_; |
| } |
| @@ -1162,9 +1132,8 @@ static void AppendCompositorCommandLineFlags(base::CommandLine* command_line) { |
| int msaa_sample_count = GpuRasterizationMSAASampleCount(); |
| if (msaa_sample_count >= 0) { |
| - command_line->AppendSwitchASCII( |
| - switches::kGpuRasterizationMSAASampleCount, |
| - base::IntToString(msaa_sample_count)); |
| + command_line->AppendSwitchASCII(switches::kGpuRasterizationMSAASampleCount, |
| + base::IntToString(msaa_sample_count)); |
| } |
| if (IsZeroCopyUploadEnabled()) |
| @@ -1226,8 +1195,8 @@ void RenderProcessHostImpl::AppendRendererCommandLine( |
| field_trial_states); |
| } |
| - GetContentClient()->browser()->AppendExtraCommandLineSwitches( |
| - command_line, GetID()); |
| + GetContentClient()->browser()->AppendExtraCommandLineSwitches(command_line, |
| + GetID()); |
| if (IsPinchToZoomEnabled()) |
| command_line->AppendSwitch(switches::kEnablePinch); |
| @@ -1516,8 +1485,7 @@ bool RenderProcessHostImpl::FastShutdownIfPossible() { |
| if (!GetContentClient()->browser()->IsFastShutdownPossible()) |
| return false; |
| - if (!child_process_launcher_.get() || |
| - child_process_launcher_->IsStarting() || |
| + if (!child_process_launcher_.get() || child_process_launcher_->IsStarting() || |
| !GetHandle()) |
| return false; // Render process hasn't started or is probably crashed. |
| @@ -1588,9 +1556,9 @@ bool RenderProcessHostImpl::OnMessageReceived(const IPC::Message& msg) { |
| IPC_MESSAGE_HANDLER(AecDumpMsg_UnregisterAecDumpConsumer, |
| OnUnregisterAecDumpConsumer) |
| #endif |
| - // Adding single handlers for your service here is fine, but once your |
| - // service needs more than one handler, please extract them into a new |
| - // message filter and add that filter to CreateMessageFilters(). |
| + // Adding single handlers for your service here is fine, but once your |
| + // service needs more than one handler, please extract them into a new |
| + // message filter and add that filter to CreateMessageFilters(). |
| IPC_END_MESSAGE_MAP() |
| return true; |
| @@ -1647,11 +1615,9 @@ void RenderProcessHostImpl::OnChannelConnected(int32 peer_pid) { |
| // Inform AudioInputRendererHost about the new render process PID. |
| // AudioInputRendererHost is reference counted, so it's lifetime is |
| // guarantueed during the lifetime of the closure. |
| - BrowserThread::PostTask( |
| - BrowserThread::IO, FROM_HERE, |
| - base::Bind(&AudioInputRendererHost::set_renderer_pid, |
| - audio_input_renderer_host_, |
| - peer_pid)); |
| + BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| + base::Bind(&AudioInputRendererHost::set_renderer_pid, |
| + audio_input_renderer_host_, peer_pid)); |
| } |
| void RenderProcessHostImpl::OnChannelError() { |
| @@ -1738,13 +1704,11 @@ void RenderProcessHostImpl::Cleanup() { |
| DCHECK(!deleting_soon_); |
| DCHECK_EQ(0, pending_views_); |
| - FOR_EACH_OBSERVER(RenderProcessHostObserver, |
| - observers_, |
| + FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_, |
| RenderProcessHostDestroyed(this)); |
| NotificationService::current()->Notify( |
| NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
| - Source<RenderProcessHost>(this), |
| - NotificationService::NoDetails()); |
| + Source<RenderProcessHost>(this), NotificationService::NoDetails()); |
| #ifndef NDEBUG |
| is_self_deleted_ = true; |
| @@ -1813,8 +1777,7 @@ void RenderProcessHostImpl::EnableAudioDebugRecordings( |
| DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| // Enable AEC dump for each registered consumer. |
| - base::FilePath file_with_extensions = |
| - GetAecDumpFilePathWithExtensions(file); |
| + base::FilePath file_with_extensions = GetAecDumpFilePathWithExtensions(file); |
| for (std::vector<int>::iterator it = aec_dump_consumers_.begin(); |
| it != aec_dump_consumers_.end(); ++it) { |
| EnableAecDumpForId(file_with_extensions, *it); |
| @@ -1825,8 +1788,7 @@ void RenderProcessHostImpl::EnableAudioDebugRecordings( |
| BrowserThread::PostTask( |
| BrowserThread::IO, FROM_HERE, |
| base::Bind(&AudioInputRendererHost::EnableDebugRecording, |
| - audio_input_renderer_host_, |
| - file)); |
| + audio_input_renderer_host_, file)); |
| } |
| void RenderProcessHostImpl::DisableAudioDebugRecordings() { |
| @@ -1836,8 +1798,7 @@ void RenderProcessHostImpl::DisableAudioDebugRecordings() { |
| // for avoiding races between enable and disable. Nothing is done on the FILE |
| // thread. |
| BrowserThread::PostTaskAndReply( |
| - BrowserThread::FILE, FROM_HERE, |
| - base::Bind(&DisableAecDumpOnFileThread), |
| + BrowserThread::FILE, FROM_HERE, base::Bind(&DisableAecDumpOnFileThread), |
| base::Bind(&RenderProcessHostImpl::SendDisableAecDumpToRenderer, |
| weak_factory_.GetWeakPtr())); |
| @@ -1845,9 +1806,8 @@ void RenderProcessHostImpl::DisableAudioDebugRecordings() { |
| // guaranteed during the lifetime of the closure. |
| BrowserThread::PostTask( |
| BrowserThread::IO, FROM_HERE, |
| - base::Bind( |
| - &AudioInputRendererHost::DisableDebugRecording, |
| - audio_input_renderer_host_)); |
| + base::Bind(&AudioInputRendererHost::DisableDebugRecording, |
| + audio_input_renderer_host_)); |
| } |
| void RenderProcessHostImpl::SetWebRtcLogMessageCallback( |
| @@ -1863,13 +1823,10 @@ RenderProcessHostImpl::StartRtpDump( |
| if (!p2p_socket_dispatcher_host_.get()) |
| return WebRtcStopRtpDumpCallback(); |
| - BrowserThread::PostTask(BrowserThread::IO, |
| - FROM_HERE, |
| + BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| base::Bind(&P2PSocketDispatcherHost::StartRtpDump, |
| - p2p_socket_dispatcher_host_, |
| - incoming, |
| - outgoing, |
| - packet_callback)); |
| + p2p_socket_dispatcher_host_, incoming, |
| + outgoing, packet_callback)); |
| if (stop_rtp_dump_callback_.is_null()) { |
| stop_rtp_dump_callback_ = |
| @@ -1951,7 +1908,8 @@ void RenderProcessHostImpl::FilterURL(RenderProcessHost* rph, |
| // Do not allow browser plugin guests to navigate to non-web URLs, since they |
| // cannot swap processes or grant bindings. |
| - bool non_web_url_in_guest = rph->IsForGuestsOnly() && |
| + bool non_web_url_in_guest = |
| + rph->IsForGuestsOnly() && |
| !(url->is_valid() && policy->IsWebSafeScheme(url->scheme())); |
| if (non_web_url_in_guest || !policy->CanRequestURL(rph->GetID(), *url)) { |
| @@ -1964,10 +1922,9 @@ void RenderProcessHostImpl::FilterURL(RenderProcessHost* rph, |
| } |
| // static |
| -bool RenderProcessHostImpl::IsSuitableHost( |
| - RenderProcessHost* host, |
| - BrowserContext* browser_context, |
| - const GURL& site_url) { |
| +bool RenderProcessHostImpl::IsSuitableHost(RenderProcessHost* host, |
| + BrowserContext* browser_context, |
| + const GURL& site_url) { |
| if (run_renderer_in_process()) |
| return true; |
| @@ -2039,7 +1996,8 @@ RenderProcessHost* RenderProcessHost::FromID(int render_process_id) { |
| // static |
| bool RenderProcessHost::ShouldTryToUseExistingProcessHost( |
| - BrowserContext* browser_context, const GURL& url) { |
| + BrowserContext* browser_context, |
| + const GURL& url) { |
| // If --site-per-process is enabled, do not try to reuse renderer processes |
| // when over the limit. |
| // TODO(nick): This is overly conservative and isn't launchable. Move this |
| @@ -2060,8 +2018,8 @@ bool RenderProcessHost::ShouldTryToUseExistingProcessHost( |
| if (g_all_hosts.Get().size() >= GetMaxRendererProcessCount()) |
| return true; |
| - return GetContentClient()->browser()-> |
| - ShouldTryToUseExistingProcessHost(browser_context, url); |
| + return GetContentClient()->browser()->ShouldTryToUseExistingProcessHost( |
| + browser_context, url); |
| } |
| // static |
| @@ -2075,9 +2033,8 @@ RenderProcessHost* RenderProcessHost::GetExistingProcessHost( |
| iterator iter(AllHostsIterator()); |
| while (!iter.IsAtEnd()) { |
| if (GetContentClient()->browser()->MayReuseHost(iter.GetCurrentValue()) && |
| - RenderProcessHostImpl::IsSuitableHost( |
| - iter.GetCurrentValue(), |
| - browser_context, site_url)) { |
| + RenderProcessHostImpl::IsSuitableHost(iter.GetCurrentValue(), |
| + browser_context, site_url)) { |
| suitable_renderers.push_back(iter.GetCurrentValue()); |
| } |
| iter.Advance(); |
| @@ -2094,9 +2051,8 @@ RenderProcessHost* RenderProcessHost::GetExistingProcessHost( |
| } |
| // static |
| -bool RenderProcessHost::ShouldUseProcessPerSite( |
| - BrowserContext* browser_context, |
| - const GURL& url) { |
| +bool RenderProcessHost::ShouldUseProcessPerSite(BrowserContext* browser_context, |
| + const GURL& url) { |
| // Returns true if we should use the process-per-site model. This will be |
| // the case if the --process-per-site switch is specified, or in |
| // process-per-site-instance for particular sites (e.g., WebUI). |
| @@ -2125,13 +2081,12 @@ RenderProcessHost* RenderProcessHostImpl::GetProcessHostForSite( |
| BrowserContext* browser_context, |
| const GURL& url) { |
| // Look up the map of site to process for the given browser_context. |
| - SiteProcessMap* map = |
| - GetSiteProcessMapForBrowserContext(browser_context); |
| + SiteProcessMap* map = GetSiteProcessMapForBrowserContext(browser_context); |
| // See if we have an existing process with appropriate bindings for this site. |
| // If not, the caller should create a new process and register it. |
| - std::string site = SiteInstance::GetSiteForURL(browser_context, url) |
| - .possibly_invalid_spec(); |
| + std::string site = |
| + SiteInstance::GetSiteForURL(browser_context, url).possibly_invalid_spec(); |
| RenderProcessHost* host = map->FindProcess(site); |
| if (host && (!GetContentClient()->browser()->MayReuseHost(host) || |
| !IsSuitableHost(host, browser_context, url))) { |
| @@ -2151,14 +2106,13 @@ void RenderProcessHostImpl::RegisterProcessHostForSite( |
| RenderProcessHost* process, |
| const GURL& url) { |
| // Look up the map of site to process for the given browser_context. |
| - SiteProcessMap* map = |
| - GetSiteProcessMapForBrowserContext(browser_context); |
| + SiteProcessMap* map = GetSiteProcessMapForBrowserContext(browser_context); |
| // Only register valid, non-empty sites. Empty or invalid sites will not |
| // use process-per-site mode. We cannot check whether the process has |
| // appropriate bindings here, because the bindings have not yet been granted. |
| - std::string site = SiteInstance::GetSiteForURL(browser_context, url) |
| - .possibly_invalid_spec(); |
| + std::string site = |
| + SiteInstance::GetSiteForURL(browser_context, url).possibly_invalid_spec(); |
| if (!site.empty()) |
| map->RegisterProcess(site, process); |
| } |
| @@ -2208,14 +2162,14 @@ void RenderProcessHostImpl::ProcessDied(bool already_dead, |
| delete queued_messages_.front(); |
| queued_messages_.pop(); |
| } |
| + UpdateProcessPriority(); |
| + DCHECK(!is_process_backgrounded_); |
| within_process_died_observer_ = true; |
| NotificationService::current()->Notify( |
| - NOTIFICATION_RENDERER_PROCESS_CLOSED, |
| - Source<RenderProcessHost>(this), |
| + NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), |
| Details<RendererClosedDetails>(&details)); |
| - FOR_EACH_OBSERVER(RenderProcessHostObserver, |
| - observers_, |
| + FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_, |
| RenderProcessExited(this, status, exit_code)); |
| within_process_died_observer_ = false; |
| @@ -2229,10 +2183,8 @@ void RenderProcessHostImpl::ProcessDied(bool already_dead, |
| IDMap<IPC::Listener>::iterator iter(&listeners_); |
| while (!iter.IsAtEnd()) { |
| - iter.GetCurrentValue()->OnMessageReceived( |
| - FrameHostMsg_RenderProcessGone(iter.GetCurrentKey(), |
| - static_cast<int>(status), |
| - exit_code)); |
| + iter.GetCurrentValue()->OnMessageReceived(FrameHostMsg_RenderProcessGone( |
| + iter.GetCurrentKey(), static_cast<int>(status), exit_code)); |
| iter.Advance(); |
| } |
| @@ -2272,13 +2224,11 @@ void RenderProcessHostImpl::ReleaseOnCloseACK( |
| DCHECK(host); |
| if (sessions.empty()) |
| return; |
| - SessionStorageHolder* holder = static_cast<SessionStorageHolder*> |
| - (host->GetUserData(kSessionStorageHolderKey)); |
| + SessionStorageHolder* holder = static_cast<SessionStorageHolder*>( |
| + host->GetUserData(kSessionStorageHolderKey)); |
| if (!holder) { |
| holder = new SessionStorageHolder(); |
| - host->SetUserData( |
| - kSessionStorageHolderKey, |
| - holder); |
| + host->SetUserData(kSessionStorageHolderKey, holder); |
| } |
| holder->Hold(sessions, view_route_id); |
| } |
| @@ -2304,24 +2254,29 @@ void RenderProcessHostImpl::SuddenTerminationChanged(bool enabled) { |
| SetSuddenTerminationAllowed(enabled); |
| } |
| -void RenderProcessHostImpl::SetBackgrounded(bool backgrounded) { |
| - TRACE_EVENT1("renderer_host", "RenderProcessHostImpl::SetBackgrounded", |
| - "backgrounded", backgrounded); |
| - // Note: we always set the backgrounded_ value. If the process is NULL |
| - // (and hence hasn't been created yet), we will set the process priority |
| - // later when we create the process. |
| - backgrounded_ = backgrounded; |
| - if (!child_process_launcher_.get() || child_process_launcher_->IsStarting()) |
| +void RenderProcessHostImpl::UpdateProcessPriority() { |
| + if (!child_process_launcher_.get() || child_process_launcher_->IsStarting()) { |
| + is_process_backgrounded_ = false; |
| return; |
| + } |
| - // Don't background processes which have active audio streams. |
| - if (backgrounded_ && audio_renderer_host_->HasActiveAudio()) |
| - return; |
| + // We background a process as soon as it hosts no active audio streams and no |
| + // visible widgets -- the callers must call this function whenever we |
| + // transition in/out of those states. |
| + const bool should_background = |
| + visible_widgets_ == 0 && !audio_renderer_host_->HasActiveAudio() && |
| + !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| + switches::kDisableRendererBackgrounding); |
| - const base::CommandLine* command_line = |
| - base::CommandLine::ForCurrentProcess(); |
| - if (command_line->HasSwitch(switches::kDisableRendererBackgrounding)) |
| +// TODO(sebsg): Remove this ifdef when https://crbug.com/537671 is fixed. |
| +#if !defined(OS_ANDROID) |
| + if (is_process_backgrounded_ == should_background) |
| return; |
| +#endif |
| + |
| + TRACE_EVENT1("renderer_host", "RenderProcessHostImpl::UpdateProcessPriority", |
| + "should_background", should_background); |
| + is_process_backgrounded_ = should_background; |
| #if defined(OS_WIN) |
| // The cbstext.dll loads as a global GetMessage hook in the browser process |
| @@ -2334,15 +2289,28 @@ void RenderProcessHostImpl::SetBackgrounded(bool backgrounded) { |
| return; |
| #endif // OS_WIN |
| +#if defined(OS_WIN) |
| + // Same as below, but bound to an experiment (http://crbug.com/458594 ). |
| + // Enabled by default in the absence of field trials to get coverage on the |
| + // perf waterfall. |
| + base::FieldTrial* trial = |
| + base::FieldTrialList::Find("BackgroundRendererProcesses"); |
| + if (!trial || |
| + !base::StartsWith(trial->group_name(), "Disallow", |
| + base::CompareCase::SENSITIVE)) { |
| + child_process_launcher_->SetProcessBackgrounded(should_background); |
| + } |
| +#else |
|
ncarter (slow)
2015/10/05 17:10:39
Gab removed this code a couple days ago, but it lo
sebsg
2015/10/05 18:42:40
Done.
|
| // Control the background state from the browser process, otherwise the task |
| // telling the renderer to "unbackground" itself may be preempted by other |
| // tasks executing at lowered priority ahead of it or simply by not being |
| // swiftly scheduled by the OS per the low process priority |
| // (http://crbug.com/398103). |
| - child_process_launcher_->SetProcessBackgrounded(backgrounded); |
| + child_process_launcher_->SetProcessBackgrounded(should_background); |
| +#endif // OS_WIN |
| // Notify the child process of background state. |
| - Send(new ChildProcessMsg_SetProcessBackgrounded(backgrounded)); |
| + Send(new ChildProcessMsg_SetProcessBackgrounded(should_background)); |
| } |
| void RenderProcessHostImpl::OnProcessLaunched() { |
| @@ -2365,7 +2333,15 @@ void RenderProcessHostImpl::OnProcessLaunched() { |
| FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| "465841 RenderProcessHostImpl::OnProcessLaunched::Backgrounded")); |
| DCHECK(child_process_launcher_->GetProcess().IsValid()); |
| - SetBackgrounded(backgrounded_); |
| + DCHECK(!is_process_backgrounded_); |
| + |
| + // Not all platforms launch processes in the same backgrounded state. Make |
| + // sure |is_process_backgrounded_| reflects this platform's initial process |
| + // state. |
| + is_process_backgrounded_ = |
| + child_process_launcher_->GetProcess().IsProcessBackgrounded(); |
| + |
| + UpdateProcessPriority(); |
| } |
| // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/465841 |
| @@ -2380,10 +2356,9 @@ void RenderProcessHostImpl::OnProcessLaunched() { |
| // The queued messages contain such things as "navigate". If this notification |
| // was after, we can end up executing JavaScript before the initialization |
| // happens. |
| - NotificationService::current()->Notify( |
| - NOTIFICATION_RENDERER_PROCESS_CREATED, |
| - Source<RenderProcessHost>(this), |
| - NotificationService::NoDetails()); |
| + NotificationService::current()->Notify(NOTIFICATION_RENDERER_PROCESS_CREATED, |
| + Source<RenderProcessHost>(this), |
| + NotificationService::NoDetails()); |
| // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/465841 |
| // is fixed. |
| @@ -2442,13 +2417,12 @@ void RenderProcessHostImpl::OnProcessLaunchFailed() { |
| return; |
| // TODO(wfh): Fill in the real error code here see crbug.com/526198. |
| - RendererClosedDetails details { base::TERMINATION_STATUS_LAUNCH_FAILED, |
| - -1 }; |
| + RendererClosedDetails details{base::TERMINATION_STATUS_LAUNCH_FAILED, -1}; |
| ProcessDied(true, &details); |
| } |
| -scoped_refptr<AudioRendererHost> |
| -RenderProcessHostImpl::audio_renderer_host() const { |
| +scoped_refptr<AudioRendererHost> RenderProcessHostImpl::audio_renderer_host() |
| + const { |
| return audio_renderer_host_; |
| } |
| @@ -2458,8 +2432,8 @@ void RenderProcessHostImpl::OnUserMetricsRecordAction( |
| } |
| void RenderProcessHostImpl::OnCloseACK(int old_route_id) { |
| - SessionStorageHolder* holder = static_cast<SessionStorageHolder*> |
| - (GetUserData(kSessionStorageHolderKey)); |
| + SessionStorageHolder* holder = |
| + static_cast<SessionStorageHolder*>(GetUserData(kSessionStorageHolderKey)); |
| if (!holder) |
| return; |
| holder->Release(old_route_id); |
| @@ -2489,22 +2463,16 @@ void RenderProcessHostImpl::OnGpuSwitched() { |
| #if defined(ENABLE_WEBRTC) |
| void RenderProcessHostImpl::OnRegisterAecDumpConsumer(int id) { |
| BrowserThread::PostTask( |
| - BrowserThread::UI, |
| - FROM_HERE, |
| - base::Bind( |
| - &RenderProcessHostImpl::RegisterAecDumpConsumerOnUIThread, |
| - weak_factory_.GetWeakPtr(), |
| - id)); |
| + BrowserThread::UI, FROM_HERE, |
| + base::Bind(&RenderProcessHostImpl::RegisterAecDumpConsumerOnUIThread, |
| + weak_factory_.GetWeakPtr(), id)); |
| } |
| void RenderProcessHostImpl::OnUnregisterAecDumpConsumer(int id) { |
| BrowserThread::PostTask( |
| - BrowserThread::UI, |
| - FROM_HERE, |
| - base::Bind( |
| - &RenderProcessHostImpl::UnregisterAecDumpConsumerOnUIThread, |
| - weak_factory_.GetWeakPtr(), |
| - id)); |
| + BrowserThread::UI, FROM_HERE, |
| + base::Bind(&RenderProcessHostImpl::UnregisterAecDumpConsumerOnUIThread, |
| + weak_factory_.GetWeakPtr(), id)); |
| } |
| void RenderProcessHostImpl::RegisterAecDumpConsumerOnUIThread(int id) { |
| @@ -2535,11 +2503,9 @@ void RenderProcessHostImpl::EnableAecDumpForId(const base::FilePath& file, |
| BrowserThread::PostTaskAndReplyWithResult( |
| BrowserThread::FILE, FROM_HERE, |
| base::Bind(&CreateAecDumpFileForProcess, |
| - file.AddExtension(IntToStringType(id)), |
| - GetHandle()), |
| + file.AddExtension(IntToStringType(id)), GetHandle()), |
| base::Bind(&RenderProcessHostImpl::SendAecDumpFileToRenderer, |
| - weak_factory_.GetWeakPtr(), |
| - id)); |
| + weak_factory_.GetWeakPtr(), id)); |
| } |
| void RenderProcessHostImpl::SendAecDumpFileToRenderer( |
| @@ -2557,7 +2523,7 @@ void RenderProcessHostImpl::SendDisableAecDumpToRenderer() { |
| base::FilePath RenderProcessHostImpl::GetAecDumpFilePathWithExtensions( |
| const base::FilePath& file) { |
| return file.AddExtension(IntToStringType(base::GetProcId(GetHandle()))) |
| - .AddExtension(kAecDumpFileNameAddition); |
| + .AddExtension(kAecDumpFileNameAddition); |
| } |
| #endif // defined(ENABLE_WEBRTC) |