OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_MEMORY_DISCARDABLE_MEMORY_SHMEM_ALLOCATOR_H_ | 5 #ifndef BASE_MEMORY_DISCARDABLE_MEMORY_SHMEM_ALLOCATOR_H_ |
6 #define BASE_MEMORY_DISCARDABLE_MEMORY_SHMEM_ALLOCATOR_H_ | 6 #define BASE_MEMORY_DISCARDABLE_MEMORY_SHMEM_ALLOCATOR_H_ |
7 | 7 |
8 #include "base/base_export.h" | 8 #include "base/base_export.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 | 10 |
11 namespace base { | 11 namespace base { |
12 | 12 |
13 // TODO(reveman): Remove this by having allocator interface return | 13 // TODO(reveman): Remove this by having allocator interface return |
14 // real DiscardableMemory instances. crbug.com/442945 | 14 // real DiscardableMemory instances. crbug.com/442945 |
15 class BASE_EXPORT DiscardableMemoryShmemChunk { | 15 class BASE_EXPORT DiscardableMemoryShmemChunk { |
16 public: | 16 public: |
17 virtual ~DiscardableMemoryShmemChunk() {} | 17 virtual ~DiscardableMemoryShmemChunk() {} |
18 | 18 |
19 virtual bool Lock() = 0; | 19 virtual bool Lock() = 0; |
20 virtual void Unlock() = 0; | 20 virtual void Unlock() = 0; |
21 virtual void* Memory() const = 0; | 21 virtual void* Memory() const = 0; |
22 virtual bool IsMemoryResident() const = 0; | |
23 }; | 22 }; |
24 | 23 |
25 class BASE_EXPORT DiscardableMemoryShmemAllocator { | 24 class BASE_EXPORT DiscardableMemoryShmemAllocator { |
26 public: | 25 public: |
27 // Returns the allocator instance. | 26 // Returns the allocator instance. |
28 static DiscardableMemoryShmemAllocator* GetInstance(); | 27 static DiscardableMemoryShmemAllocator* GetInstance(); |
29 | 28 |
30 // Sets the allocator instance. Can only be called once, e.g. on startup. | 29 // Sets the allocator instance. Can only be called once, e.g. on startup. |
31 // Ownership of |instance| remains with the caller. | 30 // Ownership of |instance| remains with the caller. |
32 static void SetInstance(DiscardableMemoryShmemAllocator* allocator); | 31 static void SetInstance(DiscardableMemoryShmemAllocator* allocator); |
33 | 32 |
34 virtual scoped_ptr<DiscardableMemoryShmemChunk> | 33 virtual scoped_ptr<DiscardableMemoryShmemChunk> |
35 AllocateLockedDiscardableMemory(size_t size) = 0; | 34 AllocateLockedDiscardableMemory(size_t size) = 0; |
36 | 35 |
37 protected: | 36 protected: |
38 virtual ~DiscardableMemoryShmemAllocator() {} | 37 virtual ~DiscardableMemoryShmemAllocator() {} |
39 }; | 38 }; |
40 | 39 |
41 } // namespace base | 40 } // namespace base |
42 | 41 |
43 #endif // BASE_MEMORY_DISCARDABLE_MEMORY_SHMEM_ALLOCATOR_H_ | 42 #endif // BASE_MEMORY_DISCARDABLE_MEMORY_SHMEM_ALLOCATOR_H_ |
OLD | NEW |