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

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

Issue 2358433003: Make RendererFrameManager a client of memory coordinator (Closed)
Patch Set: Created 4 years, 3 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/renderer_host/renderer_frame_manager.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/renderer_host/renderer_frame_manager.cc
diff --git a/content/browser/renderer_host/renderer_frame_manager.cc b/content/browser/renderer_host/renderer_frame_manager.cc
index 3f2281f6960ca78abbec6d917ffbc77fba98bcc7..55a9571cf1173c68b3781345feb725484ef7a29f 100644
--- a/content/browser/renderer_host/renderer_frame_manager.cc
+++ b/content/browser/renderer_host/renderer_frame_manager.cc
@@ -8,12 +8,14 @@
#include "base/bind.h"
#include "base/logging.h"
+#include "base/memory/memory_coordinator_client_registry.h"
#include "base/memory/memory_pressure_listener.h"
#include "base/memory/memory_pressure_monitor.h"
#include "base/memory/shared_memory.h"
#include "base/sys_info.h"
#include "build/build_config.h"
#include "content/common/host_shared_bitmap_manager.h"
+#include "content/public/common/content_features.h"
namespace content {
namespace {
@@ -72,35 +74,56 @@ void RendererFrameManager::UnlockFrame(RendererFrameManagerClient* frame) {
}
size_t RendererFrameManager::GetMaxNumberOfSavedFrames() const {
- base::MemoryPressureMonitor* monitor = base::MemoryPressureMonitor::Get();
-
- if (!monitor)
- return max_number_of_saved_frames_;
-
- // Until we have a global OnMemoryPressureChanged event we need to query the
- // value from our specific pressure monitor.
int percentage = 100;
- switch (monitor->GetCurrentPressureLevel()) {
- case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE:
- percentage = 100;
- break;
- case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE:
- percentage = kModeratePressurePercentage;
- break;
- case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL:
- percentage = kCriticalPressurePercentage;
- break;
+ if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) {
+ switch (memory_state_) {
+ case base::MemoryState::NORMAL:
+ percentage = 100;
+ break;
+ case base::MemoryState::THROTTLED:
+ percentage = kCriticalPressurePercentage;
+ break;
+ case base::MemoryState::SUSPENDED:
+ case base::MemoryState::UNKNOWN:
+ NOTREACHED();
+ break;
+ }
+ } else {
+ base::MemoryPressureMonitor* monitor = base::MemoryPressureMonitor::Get();
+
+ if (!monitor)
+ return max_number_of_saved_frames_;
+
+ // Until we have a global OnMemoryPressureChanged event we need to query the
+ // value from our specific pressure monitor.
+ int percentage = 100;
bashi 2016/09/20 07:56:51 Remove?
hajimehoshi 2016/09/20 08:09:43 Done.
+ switch (monitor->GetCurrentPressureLevel()) {
+ case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE:
+ percentage = 100;
+ break;
+ case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE:
+ percentage = kModeratePressurePercentage;
+ break;
+ case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL:
+ percentage = kCriticalPressurePercentage;
+ break;
+ }
}
size_t frames = (max_number_of_saved_frames_ * percentage) / 100;
return std::max(static_cast<size_t>(1), frames);
}
RendererFrameManager::RendererFrameManager()
- : memory_pressure_listener_(
+ : memory_state_(base::MemoryState::NORMAL) {
+ if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) {
+ base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this);
+ } else {
+ memory_pressure_listener_.reset(new base::MemoryPressureListener(
base::Bind(&RendererFrameManager::OnMemoryPressure,
- base::Unretained(this))) {
- // Note: With the destruction of this class the |memory_pressure_listener_|
- // gets destroyed and the observer will remove itself.
+ base::Unretained(this))));
+ // Note: With the destruction of this class the |memory_pressure_listener_|
+ // gets destroyed and the observer will remove itself.
+ }
max_number_of_saved_frames_ =
#if defined(OS_ANDROID)
1;
@@ -134,21 +157,43 @@ void RendererFrameManager::CullUnlockedFrames(size_t saved_frame_limit) {
void RendererFrameManager::OnMemoryPressure(
base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) {
- int saved_frame_limit = max_number_of_saved_frames_;
- if (saved_frame_limit <= 1)
- return;
- int percentage = 100;
switch (memory_pressure_level) {
case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE:
- percentage = kModeratePressurePercentage;
+ PurgeMemory(kModeratePressurePercentage);
break;
case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL:
- percentage = kCriticalPressurePercentage;
+ PurgeMemory(kCriticalPressurePercentage);
break;
case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE:
// No need to change anything when there is no pressure.
return;
}
+}
+
+void RendererFrameManager::OnMemoryStateChange(base::MemoryState state) {
+ memory_state_ = state;
+ switch (state) {
+ case base::MemoryState::NORMAL:
+ // Don't have to purge here.
+ break;
+ case base::MemoryState::THROTTLED:
+ // TOOD(hajimehoshi): We don't have throttling 'level' so far. When we
+ // have such value, let's change the argument accroding to the value.
+ PurgeMemory(kCriticalPressurePercentage);
+ break;
+ case base::MemoryState::SUSPENDED:
+ // Note that SUSPENDED never occurs in the main browser process so far.
+ // Fall through.
+ case base::MemoryState::UNKNOWN:
+ NOTREACHED();
+ break;
+ }
+}
+
+void RendererFrameManager::PurgeMemory(int percentage) {
+ int saved_frame_limit = max_number_of_saved_frames_;
+ if (saved_frame_limit <= 1)
+ return;
CullUnlockedFrames(std::max(1, (saved_frame_limit * percentage) / 100));
}
« no previous file with comments | « content/browser/renderer_host/renderer_frame_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698