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

Unified Diff: content/browser/memory/memory_coordinator_impl.cc

Issue 2443093002: memory coordinator: Observe renderer visibility to update state (Closed)
Patch Set: Created 4 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
« no previous file with comments | « content/browser/memory/memory_coordinator_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/memory/memory_coordinator_impl.cc
diff --git a/content/browser/memory/memory_coordinator_impl.cc b/content/browser/memory/memory_coordinator_impl.cc
index 53d215ae838ba5ad2ebb25905cb5574ff202c142..647c00f1aaef7ca6d4bec3f1af00406254f42654 100644
--- a/content/browser/memory/memory_coordinator_impl.cc
+++ b/content/browser/memory/memory_coordinator_impl.cc
@@ -6,6 +6,10 @@
#include "base/threading/thread_task_runner_handle.h"
#include "content/browser/memory/memory_monitor.h"
+#include "content/public/browser/notification_service.h"
+#include "content/public/browser/notification_types.h"
+#include "content/public/browser/render_process_host.h"
+#include "content/public/browser/render_widget_host.h"
#include "content/public/common/content_features.h"
namespace content {
@@ -94,6 +98,10 @@ void MemoryCoordinatorImpl::Start() {
DCHECK(CalledOnValidThread());
DCHECK(last_state_change_.is_null());
DCHECK(ValidateParameters());
+
+ notification_registrar_.Add(
+ this, NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED,
+ NotificationService::AllBrowserContextsAndSources());
ScheduleUpdateState(base::TimeDelta());
}
@@ -106,6 +114,24 @@ base::MemoryState MemoryCoordinatorImpl::GetCurrentMemoryState() const {
return current_state_;
}
+void MemoryCoordinatorImpl::Observe(int type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ DCHECK(type == NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED);
+ RenderWidgetHost* render_widget_host = Source<RenderWidgetHost>(source).ptr();
+ RenderProcessHost* process = render_widget_host->GetProcess();
+ if (!process)
+ return;
+ auto iter = children().find(process->GetID());
+ if (iter == children().end())
+ return;
+ bool is_visible = *Details<bool>(details).ptr();
+ // We don't throttle/suspend a visible renderer for now.
+ auto new_state = is_visible ? mojom::MemoryState::NORMAL
+ : ToMojomMemoryState(current_state_);
+ SetMemoryState(iter->first, new_state);
+}
+
base::MemoryState MemoryCoordinatorImpl::CalculateNextState() {
using MemoryState = base::MemoryState;
@@ -174,9 +200,6 @@ void MemoryCoordinatorImpl::NotifyStateToChildren() {
auto mojo_state = ToMojomMemoryState(current_state_);
// It's OK to call SetMemoryState() unconditionally because it checks whether
// this state transition is valid.
- // TODO(bashi): In SUSPENDED state, we should update children's state
- // accordingly when the foreground tab is changed (e.g. resume a renderer
- // which becomes foreground and suspend a renderer which goes to background).
for (auto& iter : children())
SetMemoryState(iter.first, mojo_state);
}
« no previous file with comments | « content/browser/memory/memory_coordinator_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698