test_discardable_memory_allocator.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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
  3. // found in the LICENSE file.
  4. #ifndef BASE_TEST_TEST_DISCARDABLE_MEMORY_ALLOCATOR_H_
  5. #define BASE_TEST_TEST_DISCARDABLE_MEMORY_ALLOCATOR_H_
  6. #include <stddef.h>
  7. #include "base/memory/discardable_memory_allocator.h"
  8. namespace base {
  9. // TestDiscardableMemoryAllocator is a simple DiscardableMemoryAllocator
  10. // implementation that can be used for testing. It allocates one-shot
  11. // DiscardableMemory instances backed by heap memory.
  12. class TestDiscardableMemoryAllocator : public DiscardableMemoryAllocator {
  13. public:
  14. TestDiscardableMemoryAllocator() = default;
  15. TestDiscardableMemoryAllocator(const TestDiscardableMemoryAllocator&) =
  16. delete;
  17. TestDiscardableMemoryAllocator& operator=(
  18. const TestDiscardableMemoryAllocator&) = delete;
  19. // Overridden from DiscardableMemoryAllocator:
  20. std::unique_ptr<DiscardableMemory> AllocateLockedDiscardableMemory(
  21. size_t size) override;
  22. size_t GetBytesAllocated() const override;
  23. void ReleaseFreeMemory() override {
  24. // Do nothing since it is backed by heap memory.
  25. }
  26. };
  27. } // namespace base
  28. #endif // BASE_TEST_TEST_DISCARDABLE_MEMORY_ALLOCATOR_H_