Chromium Code Reviews| Index: third_party/WebKit/Source/platform/MemoryCoordinator.cpp |
| diff --git a/third_party/WebKit/Source/core/dom/MemoryCoordinator.cpp b/third_party/WebKit/Source/platform/MemoryCoordinator.cpp |
| similarity index 53% |
| rename from third_party/WebKit/Source/core/dom/MemoryCoordinator.cpp |
| rename to third_party/WebKit/Source/platform/MemoryCoordinator.cpp |
| index 745d979f619014d132f3afd30088efb834717643..96fa073243f44e8c6af25ce2f388a258c1fd6eae 100644 |
| --- a/third_party/WebKit/Source/core/dom/MemoryCoordinator.cpp |
| +++ b/third_party/WebKit/Source/platform/MemoryCoordinator.cpp |
| @@ -2,9 +2,8 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "core/dom/MemoryCoordinator.h" |
| +#include "platform/MemoryCoordinator.h" |
| -#include "core/fetch/MemoryCache.h" |
| #include "platform/TraceEvent.h" |
| #include "platform/fonts/FontCache.h" |
| #include "platform/graphics/ImageDecodingStore.h" |
| @@ -13,6 +12,10 @@ |
| namespace blink { |
| +DEFINE_TRACE(MemoryCoordinatorClient) |
| +{ |
| +} |
| + |
| MemoryCoordinator& MemoryCoordinator::instance() |
| { |
| DEFINE_STATIC_LOCAL(MemoryCoordinator, instance, ()); |
| @@ -27,17 +30,45 @@ MemoryCoordinator::~MemoryCoordinator() |
| { |
| } |
| +void MemoryCoordinator::registerClient(MemoryCoordinatorClient* client) |
| +{ |
| + DCHECK(isMainThread()); |
| + DCHECK(client); |
| + DCHECK(!m_clients.contains(client)); |
| + m_clients.add(client); |
| +} |
| + |
| +void MemoryCoordinator::unregisterClient(MemoryCoordinatorClient* client) |
| +{ |
| + DCHECK(isMainThread()); |
| + m_clients.remove(client); |
| +} |
| + |
| +void MemoryCoordinator::purgeMemory() |
| +{ |
| + for (auto& client : m_clients) |
| + client->purgeMemory(); |
| + WTF::Partitions::decommitFreeableMemory(); |
| +} |
| + |
| void MemoryCoordinator::onMemoryPressure(WebMemoryPressureLevel level) |
| { |
| TRACE_EVENT0("blink", "MemoryCoordinator::onMemoryPressure"); |
| + for (auto& client : m_clients) |
| + client->onMemoryPressure(level); |
|
boliu
2016/08/16 17:26:28
Getting a null pointer crash here.
https://uberchr
|
| if (level == WebMemoryPressureLevelCritical) { |
| // Clear the image cache. |
| + // TODO(tasak|bashi): Make ImageDecodingStore and FontCache be |
| + // MemoryCoordinatorClients rather than clearing caches here. |
| ImageDecodingStore::instance().clear(); |
| FontCache::fontCache()->invalidate(); |
| } |
| - if (ProcessHeap::isLowEndDevice()) |
| - memoryCache()->pruneAll(); |
| WTF::Partitions::decommitFreeableMemory(); |
| } |
| +DEFINE_TRACE(MemoryCoordinator) |
| +{ |
| + visitor->trace(m_clients); |
| +} |
| + |
| } // namespace blink |