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

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

Issue 2718963002: Drop the global memory state from memory coordinator (Closed)
Patch Set: tweak Created 3 years, 10 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/memory/memory_state_updater.cc
diff --git a/content/browser/memory/memory_state_updater.cc b/content/browser/memory/memory_state_updater.cc
index fb75dbd2016aecfef0b80fb4da54a4826a0c76f2..e714ef386e44ddeace89c66bd41b581800444e2e 100644
--- a/content/browser/memory/memory_state_updater.cc
+++ b/content/browser/memory/memory_state_updater.cc
@@ -71,9 +71,14 @@ MemoryStateUpdater::MemoryStateUpdater(
MemoryStateUpdater::~MemoryStateUpdater() {}
-base::MemoryState MemoryStateUpdater::CalculateNextState() {
- using MemoryState = base::MemoryState;
+void MemoryStateUpdater::ScheduleUpdateCondition(base::TimeDelta delta) {
+ update_condition_closure_.Reset(
+ base::Bind(&MemoryStateUpdater::UpdateCondition, base::Unretained(this)));
+ task_runner_->PostDelayedTask(FROM_HERE, update_condition_closure_.callback(),
+ delta);
+}
+MemoryCondition MemoryStateUpdater::CalculateNextCondition() {
int available =
coordinator_->memory_monitor()->GetFreeMemoryUntilCriticalMB();
@@ -83,53 +88,37 @@ base::MemoryState MemoryStateUpdater::CalculateNextState() {
available);
if (available <= 0)
- return MemoryState::SUSPENDED;
+ return MemoryCondition::CRITICAL;
- auto current_state = coordinator_->GetGlobalMemoryState();
+ auto current = coordinator_->GetMemoryCondtion();
int expected_renderer_count = available / expected_renderer_size_;
- switch (current_state) {
- case MemoryState::NORMAL:
+ switch (current) {
+ case MemoryCondition::NORMAL:
if (expected_renderer_count <= new_renderers_until_suspended_)
- return MemoryState::SUSPENDED;
+ return MemoryCondition::CRITICAL;
if (expected_renderer_count <= new_renderers_until_throttled_)
- return MemoryState::THROTTLED;
- return MemoryState::NORMAL;
- case MemoryState::THROTTLED:
+ return MemoryCondition::WARNING;
+ return MemoryCondition::NORMAL;
+ case MemoryCondition::WARNING:
if (expected_renderer_count <= new_renderers_until_suspended_)
- return MemoryState::SUSPENDED;
+ return MemoryCondition::CRITICAL;
if (expected_renderer_count >= new_renderers_back_to_normal_)
- return MemoryState::NORMAL;
- return MemoryState::THROTTLED;
- case MemoryState::SUSPENDED:
+ return MemoryCondition::NORMAL;
+ return MemoryCondition::WARNING;
+ case MemoryCondition::CRITICAL:
if (expected_renderer_count >= new_renderers_back_to_normal_)
- return MemoryState::NORMAL;
+ return MemoryCondition::NORMAL;
if (expected_renderer_count >= new_renderers_back_to_throttled_)
- return MemoryState::THROTTLED;
- return MemoryState::SUSPENDED;
- case MemoryState::UNKNOWN:
- // Fall through
- default:
- NOTREACHED();
- return MemoryState::UNKNOWN;
- }
-}
-
-void MemoryStateUpdater::UpdateState() {
- auto current_state = coordinator_->GetGlobalMemoryState();
- auto next_state = CalculateNextState();
- if (coordinator_->ChangeStateIfNeeded(current_state, next_state)) {
- ScheduleUpdateState(minimum_transition_period_);
- } else {
- ScheduleUpdateState(monitoring_interval_);
+ return MemoryCondition::WARNING;
+ return MemoryCondition::CRITICAL;
}
}
-void MemoryStateUpdater::ScheduleUpdateState(base::TimeDelta delta) {
- update_state_closure_.Reset(base::Bind(&MemoryStateUpdater::UpdateState,
- base::Unretained(this)));
- task_runner_->PostDelayedTask(FROM_HERE, update_state_closure_.callback(),
- delta);
+void MemoryStateUpdater::UpdateCondition() {
+ auto next_condition = CalculateNextCondition();
+ coordinator_->UpdateConditionIfNeeded(next_condition);
+ ScheduleUpdateCondition(monitoring_interval_);
}
void MemoryStateUpdater::InitializeParameters() {

Powered by Google App Engine
This is Rietveld 408576698