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

Side by Side Diff: content/common/host_discardable_shared_memory_manager.cc

Issue 944823007: content: Improve HostDiscardableSharedMemoryManager's memory pressure handling. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 unified diff | Download patch
« no previous file with comments | « no previous file | 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/common/host_discardable_shared_memory_manager.h" 5 #include "content/common/host_discardable_shared_memory_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/debug/crash_logging.h" 10 #include "base/debug/crash_logging.h"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 enforce_memory_policy_pending_ = false; 152 enforce_memory_policy_pending_ = false;
153 ReduceMemoryUsageUntilWithinMemoryLimit(); 153 ReduceMemoryUsageUntilWithinMemoryLimit();
154 } 154 }
155 155
156 void HostDiscardableSharedMemoryManager::OnMemoryPressure( 156 void HostDiscardableSharedMemoryManager::OnMemoryPressure(
157 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { 157 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) {
158 base::AutoLock lock(lock_); 158 base::AutoLock lock(lock_);
159 159
160 switch (memory_pressure_level) { 160 switch (memory_pressure_level) {
161 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE: 161 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE:
162 break;
162 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE: 163 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE:
164 // Purge memory until usage is within half of |memory_limit_|.
165 ReduceMemoryUsageUntilWithinLimit(memory_limit_ / 2);
163 break; 166 break;
164 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL: 167 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL:
165 // Purge everything possible when pressure is critical. 168 // Purge everything possible when pressure is critical.
166 ReduceMemoryUsageUntilWithinLimit(0); 169 ReduceMemoryUsageUntilWithinLimit(0);
167 break; 170 break;
168 } 171 }
169 } 172 }
170 173
171 void 174 void
172 HostDiscardableSharedMemoryManager::ReduceMemoryUsageUntilWithinMemoryLimit() { 175 HostDiscardableSharedMemoryManager::ReduceMemoryUsageUntilWithinMemoryLimit() {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 250
248 enforce_memory_policy_pending_ = true; 251 enforce_memory_policy_pending_ = true;
249 base::MessageLoop::current()->PostDelayedTask( 252 base::MessageLoop::current()->PostDelayedTask(
250 FROM_HERE, 253 FROM_HERE,
251 base::Bind(&HostDiscardableSharedMemoryManager::EnforceMemoryPolicy, 254 base::Bind(&HostDiscardableSharedMemoryManager::EnforceMemoryPolicy,
252 weak_ptr_factory_.GetWeakPtr()), 255 weak_ptr_factory_.GetWeakPtr()),
253 base::TimeDelta::FromMilliseconds(kEnforceMemoryPolicyDelayMs)); 256 base::TimeDelta::FromMilliseconds(kEnforceMemoryPolicyDelayMs));
254 } 257 }
255 258
256 } // namespace content 259 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698