OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_emulated.h" | 5 #include "base/memory/discardable_memory_emulated.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/memory/discardable_memory_provider.h" | 8 #include "base/memory/discardable_memory_provider.h" |
9 | 9 |
10 namespace base { | 10 namespace base { |
(...skipping 12 matching lines...) Expand all Loading... |
23 g_provider.Pointer()->Register(this, size); | 23 g_provider.Pointer()->Register(this, size); |
24 } | 24 } |
25 | 25 |
26 DiscardableMemoryEmulated::~DiscardableMemoryEmulated() { | 26 DiscardableMemoryEmulated::~DiscardableMemoryEmulated() { |
27 if (is_locked_) | 27 if (is_locked_) |
28 Unlock(); | 28 Unlock(); |
29 g_provider.Pointer()->Unregister(this); | 29 g_provider.Pointer()->Unregister(this); |
30 } | 30 } |
31 | 31 |
32 bool DiscardableMemoryEmulated::Initialize() { | 32 bool DiscardableMemoryEmulated::Initialize() { |
33 return Lock() == DISCARDABLE_MEMORY_PURGED; | 33 return Lock() == DISCARDABLE_MEMORY_LOCK_STATUS_PURGED; |
34 } | 34 } |
35 | 35 |
36 LockDiscardableMemoryStatus DiscardableMemoryEmulated::Lock() { | 36 DiscardableMemoryLockStatus DiscardableMemoryEmulated::Lock() { |
37 DCHECK(!is_locked_); | 37 DCHECK(!is_locked_); |
38 | 38 |
39 bool purged = false; | 39 bool purged = false; |
40 memory_ = g_provider.Pointer()->Acquire(this, &purged); | 40 memory_ = g_provider.Pointer()->Acquire(this, &purged); |
41 if (!memory_) | 41 if (!memory_) |
42 return DISCARDABLE_MEMORY_FAILED; | 42 return DISCARDABLE_MEMORY_LOCK_STATUS_FAILED; |
43 | 43 |
44 is_locked_ = true; | 44 is_locked_ = true; |
45 return purged ? DISCARDABLE_MEMORY_PURGED : DISCARDABLE_MEMORY_SUCCESS; | 45 return purged ? DISCARDABLE_MEMORY_LOCK_STATUS_PURGED |
| 46 : DISCARDABLE_MEMORY_LOCK_STATUS_SUCCESS; |
46 } | 47 } |
47 | 48 |
48 void DiscardableMemoryEmulated::Unlock() { | 49 void DiscardableMemoryEmulated::Unlock() { |
49 DCHECK(is_locked_); | 50 DCHECK(is_locked_); |
50 g_provider.Pointer()->Release(this, memory_.Pass()); | 51 g_provider.Pointer()->Release(this, memory_.Pass()); |
51 is_locked_ = false; | 52 is_locked_ = false; |
52 } | 53 } |
53 | 54 |
54 void* DiscardableMemoryEmulated::Memory() const { | 55 void* DiscardableMemoryEmulated::Memory() const { |
55 DCHECK(memory_); | 56 DCHECK(memory_); |
56 return memory_.get(); | 57 return memory_.get(); |
57 } | 58 } |
58 | 59 |
59 // static | 60 // static |
60 void DiscardableMemoryEmulated::PurgeForTesting() { | 61 void DiscardableMemoryEmulated::PurgeForTesting() { |
61 g_provider.Pointer()->PurgeAll(); | 62 g_provider.Pointer()->PurgeAll(); |
62 } | 63 } |
63 | 64 |
64 } // namespace internal | 65 } // namespace internal |
65 } // namespace base | 66 } // namespace base |
OLD | NEW |