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 #include "base/memory/discardable_memory_shmem_allocator.h" | 5 #include "base/memory/discardable_memory_shmem_allocator.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/discardable_shared_memory.h" | 9 #include "base/memory/discardable_shared_memory.h" |
10 | 10 |
11 namespace base { | 11 namespace base { |
12 namespace { | 12 namespace { |
13 | 13 |
14 // Default allocator implementation that allocates in-process | 14 // Default allocator implementation that allocates in-process |
15 // DiscardableSharedMemory instances. | 15 // DiscardableSharedMemory instances. |
16 class DiscardableMemoryShmemAllocatorImpl | 16 class DiscardableMemoryShmemAllocatorImpl |
17 : public DiscardableMemoryShmemAllocator { | 17 : public DiscardableMemoryShmemAllocator { |
18 public: | 18 public: |
19 // Overridden from DiscardableMemoryShmemAllocator: | 19 // Overridden from DiscardableMemoryShmemAllocator: |
20 virtual scoped_ptr<DiscardableSharedMemory> | 20 scoped_ptr<DiscardableSharedMemory> AllocateLockedDiscardableSharedMemory( |
21 AllocateLockedDiscardableSharedMemory(size_t size) override { | 21 size_t size) override { |
22 scoped_ptr<DiscardableSharedMemory> memory(new DiscardableSharedMemory); | 22 scoped_ptr<DiscardableSharedMemory> memory(new DiscardableSharedMemory); |
23 if (!memory->CreateAndMap(size)) | 23 if (!memory->CreateAndMap(size)) |
24 return scoped_ptr<DiscardableSharedMemory>(); | 24 return scoped_ptr<DiscardableSharedMemory>(); |
25 | 25 |
26 return memory.Pass(); | 26 return memory.Pass(); |
27 } | 27 } |
28 }; | 28 }; |
29 | 29 |
30 LazyInstance<DiscardableMemoryShmemAllocatorImpl>::Leaky g_default_allocator = | 30 LazyInstance<DiscardableMemoryShmemAllocatorImpl>::Leaky g_default_allocator = |
31 LAZY_INSTANCE_INITIALIZER; | 31 LAZY_INSTANCE_INITIALIZER; |
(...skipping 17 matching lines...) Expand all Loading... |
49 // static | 49 // static |
50 DiscardableMemoryShmemAllocator* | 50 DiscardableMemoryShmemAllocator* |
51 DiscardableMemoryShmemAllocator::GetInstance() { | 51 DiscardableMemoryShmemAllocator::GetInstance() { |
52 if (!g_allocator) | 52 if (!g_allocator) |
53 g_allocator = g_default_allocator.Pointer(); | 53 g_allocator = g_default_allocator.Pointer(); |
54 | 54 |
55 return g_allocator; | 55 return g_allocator; |
56 } | 56 } |
57 | 57 |
58 } // namespace base | 58 } // namespace base |
OLD | NEW |