| 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_manager.h" | 8 #include "base/memory/discardable_memory_manager.h" |
| 9 | 9 |
| 10 namespace base { | 10 namespace base { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 void DiscardableMemoryEmulated::UnregisterMemoryPressureListeners() { | 49 void DiscardableMemoryEmulated::UnregisterMemoryPressureListeners() { |
| 50 g_shared_state.Pointer()->manager.UnregisterMemoryPressureListener(); | 50 g_shared_state.Pointer()->manager.UnregisterMemoryPressureListener(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 // static | 53 // static |
| 54 void DiscardableMemoryEmulated::PurgeForTesting() { | 54 void DiscardableMemoryEmulated::PurgeForTesting() { |
| 55 g_shared_state.Pointer()->manager.PurgeAll(); | 55 g_shared_state.Pointer()->manager.PurgeAll(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 bool DiscardableMemoryEmulated::Initialize() { | 58 bool DiscardableMemoryEmulated::Initialize() { |
| 59 return Lock() == DISCARDABLE_MEMORY_LOCK_STATUS_PURGED; | 59 return Lock() != DISCARDABLE_MEMORY_LOCK_STATUS_FAILED; |
| 60 } | 60 } |
| 61 | 61 |
| 62 DiscardableMemoryLockStatus DiscardableMemoryEmulated::Lock() { | 62 DiscardableMemoryLockStatus DiscardableMemoryEmulated::Lock() { |
| 63 DCHECK(!is_locked_); | 63 DCHECK(!is_locked_); |
| 64 | 64 |
| 65 bool purged = false; | 65 bool purged = false; |
| 66 if (!g_shared_state.Pointer()->manager.AcquireLock(this, &purged)) | 66 if (!g_shared_state.Pointer()->manager.AcquireLock(this, &purged)) |
| 67 return DISCARDABLE_MEMORY_LOCK_STATUS_FAILED; | 67 return DISCARDABLE_MEMORY_LOCK_STATUS_FAILED; |
| 68 | 68 |
| 69 is_locked_ = true; | 69 is_locked_ = true; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 90 memory_.reset(new uint8[bytes_]); | 90 memory_.reset(new uint8[bytes_]); |
| 91 return false; | 91 return false; |
| 92 } | 92 } |
| 93 | 93 |
| 94 void DiscardableMemoryEmulated::Purge() { | 94 void DiscardableMemoryEmulated::Purge() { |
| 95 memory_.reset(); | 95 memory_.reset(); |
| 96 } | 96 } |
| 97 | 97 |
| 98 } // namespace internal | 98 } // namespace internal |
| 99 } // namespace base | 99 } // namespace base |
| OLD | NEW |