Chromium Code Reviews| Index: cc/tiles/software_image_decode_cache.cc |
| diff --git a/cc/tiles/software_image_decode_cache.cc b/cc/tiles/software_image_decode_cache.cc |
| index aa2066592517f744eaaaa1020d2ce9bf5d26c61d..1248a2545c5199d161469e3682ac6eaf256a3e44 100644 |
| --- a/cc/tiles/software_image_decode_cache.cc |
| +++ b/cc/tiles/software_image_decode_cache.cc |
| @@ -783,12 +783,10 @@ void SoftwareImageDecodeCache::UnrefAtRasterImage(const ImageKey& key) { |
| } |
| } |
| -void SoftwareImageDecodeCache::ReduceCacheUsage() { |
| +void SoftwareImageDecodeCache::ReduceCacheUsageUntilWithinLimit(size_t limit) { |
| TRACE_EVENT0("cc", "SoftwareImageDecodeCache::ReduceCacheUsage"); |
| - base::AutoLock lock(lock_); |
| - size_t num_to_remove = (decoded_images_.size() > max_items_in_cache_) |
| - ? (decoded_images_.size() - max_items_in_cache_) |
| - : 0; |
| + size_t num_to_remove = |
| + (decoded_images_.size() > limit) ? (decoded_images_.size() - limit) : 0; |
| for (auto it = decoded_images_.rbegin(); |
| num_to_remove != 0 && it != decoded_images_.rend();) { |
| if (it->second->is_locked()) { |
| @@ -801,6 +799,11 @@ void SoftwareImageDecodeCache::ReduceCacheUsage() { |
| } |
| } |
| +void SoftwareImageDecodeCache::ReduceCacheUsage() { |
| + base::AutoLock lock(lock_); |
| + ReduceCacheUsageUntilWithinLimit(max_items_in_cache_); |
| +} |
| + |
| void SoftwareImageDecodeCache::RemovePendingTask(const ImageKey& key, |
| DecodeTaskType task_type) { |
| base::AutoLock lock(lock_); |
| @@ -1160,7 +1163,17 @@ void SoftwareImageDecodeCache::OnMemoryStateChange(base::MemoryState state) { |
| return; |
| } |
| } |
| - ReduceCacheUsage(); |
| + // TODO(bashi): We are going to separate purging from state changes and we |
| + // shouldn't purge memory here (crbug.com/684287). Tentatively call |
| + // OnPurgeMemory() so that we don't break existing experiments. |
| + // (i.e. purge+suspend experiment) |
| + if (state == base::MemoryState::SUSPENDED) |
| + OnPurgeMemory(); |
|
ericrk
2017/01/30 15:58:56
This also removes the ability to handle THROTTLED
bashi
2017/01/31 19:30:56
Yes, it's intentional. I'm going to move ReduceCac
|
| +} |
| + |
| +void SoftwareImageDecodeCache::OnPurgeMemory() { |
| + base::AutoLock lock(lock_); |
| + ReduceCacheUsageUntilWithinLimit(0); |
| } |
| } // namespace cc |