| Index: third_party/WebKit/Source/platform/MemoryCoordinator.cpp
|
| diff --git a/third_party/WebKit/Source/platform/MemoryCoordinator.cpp b/third_party/WebKit/Source/platform/MemoryCoordinator.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3a8f022b4023e78082f0f02fa82ea26b51cd5471
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/platform/MemoryCoordinator.cpp
|
| @@ -0,0 +1,66 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "platform/MemoryCoordinator.h"
|
| +
|
| +#include "platform/TraceEvent.h"
|
| +#include "platform/fonts/FontCache.h"
|
| +#include "platform/graphics/ImageDecodingStore.h"
|
| +#include "wtf/allocator/Partitions.h"
|
| +
|
| +namespace blink {
|
| +
|
| +MemoryCoordinator& MemoryCoordinator::instance()
|
| +{
|
| + DEFINE_STATIC_LOCAL(Persistent<MemoryCoordinator>, external, (new MemoryCoordinator));
|
| + DCHECK(isMainThread());
|
| + return *external.get();
|
| +}
|
| +
|
| +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);
|
| + 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();
|
| + }
|
| + WTF::Partitions::decommitFreeableMemory();
|
| +}
|
| +
|
| +DEFINE_TRACE(MemoryCoordinator)
|
| +{
|
| + visitor->trace(m_clients);
|
| +}
|
| +
|
| +} // namespace blink
|
|
|