Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1346)

Unified Diff: content/browser/renderer_host/render_process_host_impl.cc

Issue 1383123003: Revert of Fixed the audio backgrounding bug (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 c6f6a5a2d00b0d5f8fb97938a322317df39a4d03..ff87202bcccaf9b7b6daa3be1592569b477f4287 100644
--- a/content/browser/renderer_host/render_process_host_impl.cc
+++ b/content/browser/renderer_host/render_process_host_impl.cc
@@ -259,8 +259,9 @@
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)
@@ -277,8 +278,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);
@@ -291,8 +292,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.
@@ -316,12 +317,14 @@
// 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()) {
@@ -355,8 +358,7 @@
#if defined(OS_POSIX)
: ipc_fd_(channel->TakeClientFileDescriptor())
#endif // OS_POSIX
- {
- }
+ {}
~RendererSandboxedProcessLauncherDelegate() override {}
@@ -384,7 +386,9 @@
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)
@@ -408,7 +412,7 @@
}
private:
- std::map<int, SessionStorageNamespaceMap>
+ std::map<int, SessionStorageNamespaceMap >
session_storage_namespaces_awaiting_close_;
DISALLOW_COPY_AND_ASSIGN(SessionStorageHolder);
};
@@ -430,7 +434,7 @@
base::MessageLoop* g_in_process_thread;
base::MessageLoop*
-RenderProcessHostImpl::GetInProcessRendererThreadForTesting() {
+ RenderProcessHostImpl::GetInProcessRendererThreadForTesting() {
return g_in_process_thread;
}
@@ -504,7 +508,7 @@
pending_views_(0),
mojo_application_host_(new MojoApplicationHost),
visible_widgets_(0),
- is_process_backgrounded_(false),
+ backgrounded_(true),
is_initialized_(false),
id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()),
browser_context_(browser_context),
@@ -549,6 +553,11 @@
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
@@ -561,7 +570,8 @@
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;
@@ -607,7 +617,7 @@
UnregisterHost(GetID());
if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kDisableGpuShaderDiskCache)) {
+ switches::kDisableGpuShaderDiskCache)) {
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
base::Bind(&RemoveShaderInfo, GetID()));
}
@@ -632,8 +642,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
@@ -671,9 +681,8 @@
// 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)
@@ -708,8 +717,10 @@
// 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;
}
@@ -732,7 +743,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";
@@ -761,9 +772,12 @@
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(
@@ -803,25 +817,33 @@
// 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)));
@@ -829,12 +851,14 @@
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
@@ -844,14 +868,15 @@
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)
@@ -870,8 +895,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));
@@ -894,7 +919,8 @@
AddFilter(service_worker_filter.get());
AddFilter(new SharedWorkerMessageFilter(
- GetID(), resource_context,
+ GetID(),
+ resource_context,
WorkerStoragePartition(
storage_partition_impl_->GetURLRequestContext(),
storage_partition_impl_->GetMediaURLRequestContext(),
@@ -917,12 +943,15 @@
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());
@@ -1025,9 +1054,10 @@
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);
@@ -1045,10 +1075,11 @@
}
#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);
}
@@ -1086,29 +1117,28 @@
}
void RenderProcessHostImpl::WidgetRestored() {
+ // Verify we were properly backgrounded.
+ DCHECK_EQ(backgrounded_, (visible_widgets_ == 0));
visible_widgets_++;
- UpdateProcessPriority();
- DCHECK(!is_process_backgrounded_);
+ SetBackgrounded(false);
}
void RenderProcessHostImpl::WidgetHidden() {
- // On startup, the browser will call Hide. We ignore this call.
- if (visible_widgets_ == 0)
+ // On startup, the browser will call Hide
+ if (backgrounded_)
return;
- --visible_widgets_;
+ DCHECK_EQ(backgrounded_, (visible_widgets_ == 0));
+ visible_widgets_--;
+ DCHECK_GE(visible_widgets_, 0);
if (visible_widgets_ == 0) {
- DCHECK(!is_process_backgrounded_);
- UpdateProcessPriority();
+ DCHECK(!backgrounded_);
+ SetBackgrounded(true);
}
}
int RenderProcessHostImpl::VisibleWidgetCount() const {
return visible_widgets_;
-}
-
-void RenderProcessHostImpl::AudioStateChanged() {
- UpdateProcessPriority();
}
bool RenderProcessHostImpl::IsForGuestsOnly() const {
@@ -1132,8 +1162,9 @@
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())
@@ -1195,8 +1226,8 @@
field_trial_states);
}
- GetContentClient()->browser()->AppendExtraCommandLineSwitches(command_line,
- GetID());
+ GetContentClient()->browser()->AppendExtraCommandLineSwitches(
+ command_line, GetID());
if (IsPinchToZoomEnabled())
command_line->AppendSwitch(switches::kEnablePinch);
@@ -1485,7 +1516,8 @@
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.
@@ -1556,9 +1588,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;
@@ -1615,9 +1647,11 @@
// 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() {
@@ -1704,11 +1738,13 @@
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;
@@ -1777,7 +1813,8 @@
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);
@@ -1788,7 +1825,8 @@
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&AudioInputRendererHost::EnableDebugRecording,
- audio_input_renderer_host_, file));
+ audio_input_renderer_host_,
+ file));
}
void RenderProcessHostImpl::DisableAudioDebugRecordings() {
@@ -1798,7 +1836,8 @@
// 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()));
@@ -1806,8 +1845,9 @@
// 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(
@@ -1823,10 +1863,13 @@
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_ =
@@ -1908,8 +1951,7 @@
// 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)) {
@@ -1922,9 +1964,10 @@
}
// 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;
@@ -1996,8 +2039,7 @@
// 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
@@ -2018,8 +2060,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
@@ -2033,8 +2075,9 @@
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();
@@ -2051,8 +2094,9 @@
}
// 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).
@@ -2081,12 +2125,13 @@
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))) {
@@ -2106,13 +2151,14 @@
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);
}
@@ -2162,14 +2208,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;
@@ -2183,8 +2229,10 @@
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();
}
@@ -2224,11 +2272,13 @@
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);
}
@@ -2254,29 +2304,24 @@
SetSuddenTerminationAllowed(enabled);
}
-void RenderProcessHostImpl::UpdateProcessPriority() {
- if (!child_process_launcher_.get() || child_process_launcher_->IsStarting()) {
- is_process_backgrounded_ = false;
+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())
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);
-
-// TODO(sebsg): Remove this ifdef when https://crbug.com/537671 is fixed.
-#if !defined(OS_ANDROID)
- if (is_process_backgrounded_ == should_background)
+
+ // Don't background processes which have active audio streams.
+ if (backgrounded_ && audio_renderer_host_->HasActiveAudio())
return;
-#endif
-
- TRACE_EVENT1("renderer_host", "RenderProcessHostImpl::UpdateProcessPriority",
- "should_background", should_background);
- is_process_backgrounded_ = should_background;
+
+ const base::CommandLine* command_line =
+ base::CommandLine::ForCurrentProcess();
+ if (command_line->HasSwitch(switches::kDisableRendererBackgrounding))
+ return;
#if defined(OS_WIN)
// The cbstext.dll loads as a global GetMessage hook in the browser process
@@ -2294,10 +2339,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(should_background);
+ child_process_launcher_->SetProcessBackgrounded(backgrounded);
// Notify the child process of background state.
- Send(new ChildProcessMsg_SetProcessBackgrounded(should_background));
+ Send(new ChildProcessMsg_SetProcessBackgrounded(backgrounded));
}
void RenderProcessHostImpl::OnProcessLaunched() {
@@ -2320,15 +2365,7 @@
FROM_HERE_WITH_EXPLICIT_FUNCTION(
"465841 RenderProcessHostImpl::OnProcessLaunched::Backgrounded"));
DCHECK(child_process_launcher_->GetProcess().IsValid());
- 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();
+ SetBackgrounded(backgrounded_);
}
// TODO(erikchen): Remove ScopedTracker below once http://crbug.com/465841
@@ -2343,9 +2380,10 @@
// 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.
@@ -2404,12 +2442,13 @@
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_;
}
@@ -2419,8 +2458,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);
@@ -2450,16 +2489,22 @@
#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) {
@@ -2490,9 +2535,11 @@
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(
@@ -2510,7 +2557,7 @@
base::FilePath RenderProcessHostImpl::GetAecDumpFilePathWithExtensions(
const base::FilePath& file) {
return file.AddExtension(IntToStringType(base::GetProcId(GetHandle())))
- .AddExtension(kAecDumpFileNameAddition);
+ .AddExtension(kAecDumpFileNameAddition);
}
#endif // defined(ENABLE_WEBRTC)
« no previous file with comments | « content/browser/renderer_host/render_process_host_impl.h ('k') | content/public/browser/render_process_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698