| 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..c6f6a5a2d00b0d5f8fb97938a322317df39a4d03 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 @@
|
| 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 @@
|
| 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 @@
|
| #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 @@
|
| // 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 @@
|
| #if defined(OS_POSIX)
|
| : ipc_fd_(channel->TakeClientFileDescriptor())
|
| #endif // OS_POSIX
|
| - {}
|
| + {
|
| + }
|
|
|
| ~RendererSandboxedProcessLauncherDelegate() override {}
|
|
|
| @@ -386,9 +384,7 @@
|
| 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 @@
|
| }
|
|
|
| private:
|
| - std::map<int, SessionStorageNamespaceMap >
|
| + std::map<int, SessionStorageNamespaceMap>
|
| session_storage_namespaces_awaiting_close_;
|
| DISALLOW_COPY_AND_ASSIGN(SessionStorageHolder);
|
| };
|
| @@ -434,7 +430,7 @@
|
| base::MessageLoop* g_in_process_thread;
|
|
|
| base::MessageLoop*
|
| - RenderProcessHostImpl::GetInProcessRendererThreadForTesting() {
|
| +RenderProcessHostImpl::GetInProcessRendererThreadForTesting() {
|
| return g_in_process_thread;
|
| }
|
|
|
| @@ -508,7 +504,7 @@
|
| 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 @@
|
| 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 @@
|
| 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 @@
|
| 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 @@
|
| 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 @@
|
| // 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 @@
|
| // 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 @@
|
| 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 @@
|
|
|
| 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 @@
|
| // 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 @@
|
| 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 @@
|
| 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 @@
|
|
|
| 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 @@
|
| 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 @@
|
| 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 @@
|
| 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 @@
|
| }
|
| #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,28 +1086,29 @@
|
| }
|
|
|
| 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();
|
| }
|
| }
|
|
|
| int RenderProcessHostImpl::VisibleWidgetCount() const {
|
| return visible_widgets_;
|
| +}
|
| +
|
| +void RenderProcessHostImpl::AudioStateChanged() {
|
| + UpdateProcessPriority();
|
| }
|
|
|
| bool RenderProcessHostImpl::IsForGuestsOnly() const {
|
| @@ -1162,9 +1132,8 @@
|
|
|
| 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 @@
|
| 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 @@
|
| 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 @@
|
| 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 @@
|
| // 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 @@
|
| 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 @@
|
| 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 @@
|
| 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 @@
|
| // 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 @@
|
| // 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 @@
|
| 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 @@
|
|
|
| // 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 @@
|
| }
|
|
|
| // 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 @@
|
|
|
| // 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 @@
|
| 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 @@
|
| 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 @@
|
| }
|
|
|
| // 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 @@
|
| 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 @@
|
| 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 @@
|
| 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 @@
|
|
|
| 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 @@
|
| 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 @@
|
| 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())
|
| + }
|
| +
|
| + // 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);
|
| +
|
| +// TODO(sebsg): Remove this ifdef when https://crbug.com/537671 is fixed.
|
| +#if !defined(OS_ANDROID)
|
| + if (is_process_backgrounded_ == should_background)
|
| return;
|
| -
|
| - const base::CommandLine* command_line =
|
| - base::CommandLine::ForCurrentProcess();
|
| - if (command_line->HasSwitch(switches::kDisableRendererBackgrounding))
|
| - 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
|
| @@ -2339,10 +2294,10 @@
|
| // 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);
|
|
|
| // Notify the child process of background state.
|
| - Send(new ChildProcessMsg_SetProcessBackgrounded(backgrounded));
|
| + Send(new ChildProcessMsg_SetProcessBackgrounded(should_background));
|
| }
|
|
|
| void RenderProcessHostImpl::OnProcessLaunched() {
|
| @@ -2365,7 +2320,15 @@
|
| 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 +2343,9 @@
|
| // 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 +2404,12 @@
|
| 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 +2419,8 @@
|
| }
|
|
|
| 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 +2450,16 @@
|
| #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 +2490,9 @@
|
| 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 +2510,7 @@
|
| base::FilePath RenderProcessHostImpl::GetAecDumpFilePathWithExtensions(
|
| const base::FilePath& file) {
|
| return file.AddExtension(IntToStringType(base::GetProcId(GetHandle())))
|
| - .AddExtension(kAecDumpFileNameAddition);
|
| + .AddExtension(kAecDumpFileNameAddition);
|
| }
|
| #endif // defined(ENABLE_WEBRTC)
|
|
|
|
|