Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "platform/MemoryCoordinator.h" | 5 #include "platform/MemoryCoordinator.h" |
| 6 | 6 |
| 7 #include "platform/fonts/FontCache.h" | 7 #include "platform/fonts/FontCache.h" |
| 8 #include "platform/graphics/ImageDecodingStore.h" | 8 #include "platform/graphics/ImageDecodingStore.h" |
| 9 #include "platform/tracing/TraceEvent.h" | 9 #include "platform/tracing/TraceEvent.h" |
| 10 #include "wtf/allocator/Partitions.h" | 10 #include "wtf/allocator/Partitions.h" |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 void MemoryCoordinator::prepareToSuspend() { | 35 void MemoryCoordinator::prepareToSuspend() { |
| 36 for (auto& client : m_clients) | 36 for (auto& client : m_clients) |
| 37 client->prepareToSuspend(); | 37 client->prepareToSuspend(); |
| 38 WTF::Partitions::decommitFreeableMemory(); | 38 WTF::Partitions::decommitFreeableMemory(); |
| 39 } | 39 } |
| 40 | 40 |
| 41 void MemoryCoordinator::onMemoryPressure(WebMemoryPressureLevel level) { | 41 void MemoryCoordinator::onMemoryPressure(WebMemoryPressureLevel level) { |
| 42 TRACE_EVENT0("blink", "MemoryCoordinator::onMemoryPressure"); | 42 TRACE_EVENT0("blink", "MemoryCoordinator::onMemoryPressure"); |
| 43 for (auto& client : m_clients) | 43 for (auto& client : m_clients) |
| 44 client->onMemoryPressure(level); | 44 client->onMemoryPressure(level); |
| 45 if (level == WebMemoryPressureLevelCritical) { | 45 clearMemory(level == WebMemoryPressureLevelCritical); |
| 46 } | |
| 47 | |
| 48 void MemoryCoordinator::onMemoryStateChange(MemoryState state) { | |
| 49 for (auto& client : m_clients) | |
| 50 client->onMemoryStateChange(state); | |
| 51 clearMemory(state == MemoryState::SUSPENDED); | |
| 52 } | |
| 53 | |
| 54 void MemoryCoordinator::clearMemory(bool critical) { | |
|
haraken
2016/10/07 11:45:30
I'd avoid introducing a boolean flag. See my below
hajimehoshi
2016/10/11 07:05:32
Done.
| |
| 55 if (critical) { | |
| 46 // Clear the image cache. | 56 // Clear the image cache. |
| 47 // TODO(tasak|bashi): Make ImageDecodingStore and FontCache be | 57 // TODO(tasak|bashi): Make ImageDecodingStore and FontCache be |
| 48 // MemoryCoordinatorClients rather than clearing caches here. | 58 // MemoryCoordinatorClients rather than clearing caches here. |
| 49 ImageDecodingStore::instance().clear(); | 59 ImageDecodingStore::instance().clear(); |
| 50 FontCache::fontCache()->invalidate(); | 60 FontCache::fontCache()->invalidate(); |
| 51 } | 61 } |
| 52 WTF::Partitions::decommitFreeableMemory(); | 62 WTF::Partitions::decommitFreeableMemory(); |
| 53 } | 63 } |
| 54 | 64 |
| 55 DEFINE_TRACE(MemoryCoordinator) { | 65 DEFINE_TRACE(MemoryCoordinator) { |
| 56 visitor->trace(m_clients); | 66 visitor->trace(m_clients); |
| 57 } | 67 } |
| 58 | 68 |
| 59 } // namespace blink | 69 } // namespace blink |
| OLD | NEW |