This source file includes following definitions.
- RegisterMemoryPressureListeners
- UnregisterMemoryPressureListeners
- GetSupportedTypes
- CreateLockedMemoryWithType
- PurgeForTestingSupported
- PurgeForTesting
#include "base/memory/discardable_memory.h"
#include "base/logging.h"
#include "base/memory/discardable_memory_emulated.h"
#include "base/memory/discardable_memory_malloc.h"
namespace base {
void DiscardableMemory::RegisterMemoryPressureListeners() {
internal::DiscardableMemoryEmulated::RegisterMemoryPressureListeners();
}
void DiscardableMemory::UnregisterMemoryPressureListeners() {
internal::DiscardableMemoryEmulated::UnregisterMemoryPressureListeners();
}
void DiscardableMemory::GetSupportedTypes(
std::vector<DiscardableMemoryType>* types) {
const DiscardableMemoryType supported_types[] = {
DISCARDABLE_MEMORY_TYPE_EMULATED,
DISCARDABLE_MEMORY_TYPE_MALLOC
};
types->assign(supported_types, supported_types + arraysize(supported_types));
}
scoped_ptr<DiscardableMemory> DiscardableMemory::CreateLockedMemoryWithType(
DiscardableMemoryType type, size_t size) {
switch (type) {
case DISCARDABLE_MEMORY_TYPE_NONE:
case DISCARDABLE_MEMORY_TYPE_ANDROID:
case DISCARDABLE_MEMORY_TYPE_MAC:
return scoped_ptr<DiscardableMemory>();
case DISCARDABLE_MEMORY_TYPE_EMULATED: {
scoped_ptr<internal::DiscardableMemoryEmulated> memory(
new internal::DiscardableMemoryEmulated(size));
if (!memory->Initialize())
return scoped_ptr<DiscardableMemory>();
return memory.PassAs<DiscardableMemory>();
}
case DISCARDABLE_MEMORY_TYPE_MALLOC: {
scoped_ptr<internal::DiscardableMemoryMalloc> memory(
new internal::DiscardableMemoryMalloc(size));
if (!memory->Initialize())
return scoped_ptr<DiscardableMemory>();
return memory.PassAs<DiscardableMemory>();
}
}
NOTREACHED();
return scoped_ptr<DiscardableMemory>();
}
bool DiscardableMemory::PurgeForTestingSupported() {
return true;
}
void DiscardableMemory::PurgeForTesting() {
internal::DiscardableMemoryEmulated::PurgeForTesting();
}
}