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 5 #ifndef BASE_MEMORY_DISCARDABLE_MEMORY_ALLOCATOR_H_ 6 #define BASE_MEMORY_DISCARDABLE_MEMORY_ALLOCATOR_H_ 7 8 #include <stddef.h> 9 10 #include <memory> 11 12 #include "base/base_export.h" 13 14 namespace base { 15 class DiscardableMemory; 16 17 class BASE_EXPORT DiscardableMemoryAllocator { 18 public: 19 // Returns the allocator instance. 20 static DiscardableMemoryAllocator* GetInstance(); 21 22 // Sets the allocator instance. Can only be called once, e.g. on startup. 23 // Ownership of |instance| remains with the caller. 24 static void SetInstance(DiscardableMemoryAllocator* allocator); 25 26 // Giant WARNING: Discardable[Shared]Memory is only implemented on Android. On 27 // non-Android platforms, it behaves exactly the same as SharedMemory. 28 // See LockPages() in discardable_shared_memory.cc. 29 virtual std::unique_ptr<DiscardableMemory> AllocateLockedDiscardableMemory( 30 size_t size) = 0; 31 32 protected: 33 virtual ~DiscardableMemoryAllocator() = default; 34 }; 35 36 } // namespace base 37 38 #endif // BASE_MEMORY_DISCARDABLE_MEMORY_ALLOCATOR_H_ 39