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

Side by Side Diff: content/browser/memory/memory_condition_observer.cc

Issue 2783613002: WIP: memory coordinator: Check /dev/chromeos-low-mem to determine memory condition
Patch Set: Created 3 years, 8 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 unified diff | Download patch
« no previous file with comments | « content/browser/memory/memory_condition_observer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/memory/memory_condition_observer.h" 5 #include "content/browser/memory/memory_condition_observer.h"
6 6
7 #include "base/metrics/histogram_macros.h" 7 #include "base/metrics/histogram_macros.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "components/variations/variations_associated_data.h" 9 #include "components/variations/variations_associated_data.h"
10 #include "content/browser/memory/memory_monitor.h" 10 #include "content/browser/memory/memory_monitor.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 *target = base::TimeDelta::FromSeconds(value); 57 *target = base::TimeDelta::FromSeconds(value);
58 } 58 }
59 } 59 }
60 60
61 } // namespace 61 } // namespace
62 62
63 MemoryConditionObserver::MemoryConditionObserver( 63 MemoryConditionObserver::MemoryConditionObserver(
64 MemoryCoordinatorImpl* coordinator, 64 MemoryCoordinatorImpl* coordinator,
65 scoped_refptr<base::SingleThreadTaskRunner> task_runner) 65 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
66 : coordinator_(coordinator), task_runner_(task_runner) { 66 : coordinator_(coordinator), task_runner_(task_runner) {
67 #if defined(OS_CHROMEOS)
68 low_memory_observer_ = base::MakeUnique<base::chromeos::LowMemoryObserver>();
69 #endif
67 DCHECK(coordinator_); 70 DCHECK(coordinator_);
68 InitializeParameters(); 71 InitializeParameters();
69 DCHECK(ValidateParameters()); 72 DCHECK(ValidateParameters());
70 } 73 }
71 74
72 MemoryConditionObserver::~MemoryConditionObserver() {} 75 MemoryConditionObserver::~MemoryConditionObserver() {}
73 76
74 void MemoryConditionObserver::ScheduleUpdateCondition(base::TimeDelta delay) { 77 void MemoryConditionObserver::ScheduleUpdateCondition(base::TimeDelta delay) {
75 update_condition_closure_.Reset(base::Bind( 78 update_condition_closure_.Reset(base::Bind(
76 &MemoryConditionObserver::UpdateCondition, base::Unretained(this))); 79 &MemoryConditionObserver::UpdateCondition, base::Unretained(this)));
(...skipping 11 matching lines...) Expand all
88 91
89 void MemoryConditionObserver::SetMonitoringInterval(base::TimeDelta interval) { 92 void MemoryConditionObserver::SetMonitoringInterval(base::TimeDelta interval) {
90 DCHECK(!interval.is_zero()); 93 DCHECK(!interval.is_zero());
91 if (interval == monitoring_interval_) 94 if (interval == monitoring_interval_)
92 return; 95 return;
93 monitoring_interval_ = interval; 96 monitoring_interval_ = interval;
94 ScheduleUpdateCondition(interval); 97 ScheduleUpdateCondition(interval);
95 } 98 }
96 99
97 MemoryCondition MemoryConditionObserver::CalculateNextCondition() { 100 MemoryCondition MemoryConditionObserver::CalculateNextCondition() {
101 #if defined(OS_CHROMEOS)
102 if (low_memory_observer_->IsLowMemoryCondition())
103 return MemoryCondition::CRITICAL;
104 #endif
105
98 int available = 106 int available =
99 coordinator_->memory_monitor()->GetFreeMemoryUntilCriticalMB(); 107 coordinator_->memory_monitor()->GetFreeMemoryUntilCriticalMB();
100 108
101 // TODO(chrisha): Move this histogram recording to a better place when 109 // TODO(chrisha): Move this histogram recording to a better place when
102 // https://codereview.chromium.org/2479673002/ is landed. 110 // https://codereview.chromium.org/2479673002/ is landed.
103 UMA_HISTOGRAM_MEMORY_LARGE_MB("Memory.Coordinator.FreeMemoryUntilCritical", 111 UMA_HISTOGRAM_MEMORY_LARGE_MB("Memory.Coordinator.FreeMemoryUntilCritical",
104 available); 112 available);
105 113
106 if (available <= 0) 114 if (available <= 0)
107 return MemoryCondition::CRITICAL; 115 return MemoryCondition::CRITICAL;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 } 183 }
176 184
177 bool MemoryConditionObserver::ValidateParameters() { 185 bool MemoryConditionObserver::ValidateParameters() {
178 return (new_renderers_until_warning_ > new_renderers_until_critical_) && 186 return (new_renderers_until_warning_ > new_renderers_until_critical_) &&
179 (new_renderers_back_to_normal_ > new_renderers_back_to_warning_) && 187 (new_renderers_back_to_normal_ > new_renderers_back_to_warning_) &&
180 (new_renderers_back_to_normal_ > new_renderers_until_warning_) && 188 (new_renderers_back_to_normal_ > new_renderers_until_warning_) &&
181 (new_renderers_back_to_warning_ > new_renderers_until_critical_); 189 (new_renderers_back_to_warning_ > new_renderers_until_critical_);
182 } 190 }
183 191
184 } // namespace content 192 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/memory/memory_condition_observer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698