1 // Copyright 2015 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef BASE_TEST_TEST_DISCARDABLE_MEMORY_ALLOCATOR_H_ 6 #define BASE_TEST_TEST_DISCARDABLE_MEMORY_ALLOCATOR_H_ 7 8 #include <stddef.h> 9 10 #include "base/memory/discardable_memory_allocator.h" 11 12 namespace base { 13 14 // TestDiscardableMemoryAllocator is a simple DiscardableMemoryAllocator 15 // implementation that can be used for testing. It allocates one-shot 16 // DiscardableMemory instances backed by heap memory. 17 class TestDiscardableMemoryAllocator : public DiscardableMemoryAllocator { 18 public: 19 TestDiscardableMemoryAllocator() = default; 20 21 TestDiscardableMemoryAllocator(const TestDiscardableMemoryAllocator&) = 22 delete; 23 TestDiscardableMemoryAllocator& operator=( 24 const TestDiscardableMemoryAllocator&) = delete; 25 26 // Overridden from DiscardableMemoryAllocator: 27 std::unique_ptr<DiscardableMemory> AllocateLockedDiscardableMemory( 28 size_t size) override; 29 30 size_t GetBytesAllocated() const override; 31 ReleaseFreeMemory()32 void ReleaseFreeMemory() override { 33 // Do nothing since it is backed by heap memory. 34 } 35 }; 36 37 } // namespace base 38 39 #endif // BASE_TEST_TEST_DISCARDABLE_MEMORY_ALLOCATOR_H_ 40