| 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_MACH_H_ | 5 #ifndef BASE_MEMORY_DISCARDABLE_MEMORY_MACH_H_ |
| 6 #define BASE_MEMORY_DISCARDABLE_MEMORY_MACH_H_ | 6 #define BASE_MEMORY_DISCARDABLE_MEMORY_MACH_H_ |
| 7 | 7 |
| 8 #include "base/memory/discardable_memory.h" | 8 #include "base/memory/discardable_memory.h" |
| 9 | 9 |
| 10 #include "base/mac/scoped_mach_vm.h" | 10 #include "base/mac/scoped_mach_vm.h" |
| 11 #include "base/memory/discardable_memory_manager.h" | 11 #include "base/memory/discardable_memory_manager.h" |
| 12 | 12 |
| 13 namespace base { | 13 namespace base { |
| 14 namespace internal { | 14 namespace internal { |
| 15 | 15 |
| 16 class DiscardableMemoryMach | 16 class DiscardableMemoryMach |
| 17 : public DiscardableMemory, | 17 : public DiscardableMemory, |
| 18 public internal::DiscardableMemoryManagerAllocation { | 18 public internal::DiscardableMemoryManagerAllocation { |
| 19 public: | 19 public: |
| 20 explicit DiscardableMemoryMach(size_t bytes); | 20 explicit DiscardableMemoryMach(size_t bytes); |
| 21 ~DiscardableMemoryMach() override; | 21 ~DiscardableMemoryMach() override; |
| 22 | 22 |
| 23 static void PurgeForTesting(); | |
| 24 | |
| 25 bool Initialize(); | 23 bool Initialize(); |
| 26 | 24 |
| 27 // Overridden from DiscardableMemory: | 25 // Overridden from DiscardableMemory: |
| 28 DiscardableMemoryLockStatus Lock() override; | 26 DiscardableMemoryLockStatus Lock() override; |
| 29 void Unlock() override; | 27 void Unlock() override; |
| 30 void* Memory() const override; | 28 void* Memory() const override; |
| 31 | 29 |
| 32 // Overridden from internal::DiscardableMemoryManagerAllocation: | 30 // Overridden from internal::DiscardableMemoryManagerAllocation: |
| 33 bool AllocateAndAcquireLock() override; | 31 bool AllocateAndAcquireLock() override; |
| 34 void ReleaseLock() override; | 32 void ReleaseLock() override; |
| 35 void Purge() override; | 33 void Purge() override; |
| 36 bool IsMemoryResident() const override; | |
| 37 | 34 |
| 38 private: | 35 private: |
| 39 mac::ScopedMachVM memory_; | 36 mac::ScopedMachVM memory_; |
| 40 const size_t bytes_; | 37 const size_t bytes_; |
| 41 bool is_locked_; | 38 bool is_locked_; |
| 42 | 39 |
| 43 DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryMach); | 40 DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryMach); |
| 44 }; | 41 }; |
| 45 | 42 |
| 46 } // namespace internal | 43 } // namespace internal |
| 47 } // namespace base | 44 } // namespace base |
| 48 | 45 |
| 49 #endif // BASE_MEMORY_DISCARDABLE_MEMORY_MACH_H_ | 46 #endif // BASE_MEMORY_DISCARDABLE_MEMORY_MACH_H_ |
| OLD | NEW |