| 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 #ifndef BASE_MEMORY_DISCARDABLE_MEMORY_EMULATED_H_ | 5 #ifndef BASE_MEMORY_DISCARDABLE_MEMORY_EMULATED_H_ |
| 6 #define BASE_MEMORY_DISCARDABLE_MEMORY_EMULATED_H_ | 6 #define BASE_MEMORY_DISCARDABLE_MEMORY_EMULATED_H_ |
| 7 | 7 |
| 8 #include "base/memory/discardable_memory.h" | 8 #include "base/memory/discardable_memory.h" |
| 9 | 9 |
| 10 #include "base/memory/discardable_memory_manager.h" | 10 #include "base/memory/discardable_memory_manager.h" |
| 11 | 11 |
| 12 namespace base { | 12 namespace base { |
| 13 namespace internal { | 13 namespace internal { |
| 14 | 14 |
| 15 class DiscardableMemoryEmulated | 15 class DiscardableMemoryEmulated |
| 16 : public DiscardableMemory, | 16 : public DiscardableMemory, |
| 17 public internal::DiscardableMemoryManagerAllocation { | 17 public internal::DiscardableMemoryManagerAllocation { |
| 18 public: | 18 public: |
| 19 explicit DiscardableMemoryEmulated(size_t bytes); | 19 explicit DiscardableMemoryEmulated(size_t bytes); |
| 20 virtual ~DiscardableMemoryEmulated(); | 20 virtual ~DiscardableMemoryEmulated(); |
| 21 | 21 |
| 22 static void RegisterMemoryPressureListeners(); | |
| 23 static void UnregisterMemoryPressureListeners(); | |
| 24 static bool ReduceMemoryUsage(); | 22 static bool ReduceMemoryUsage(); |
| 25 | 23 |
| 24 // TODO(reveman): Remove this as it is breaking the discardable memory design |
| 25 // principle that implementations should not rely on information this is |
| 26 // unavailable in kernel space. crbug.com/400423 |
| 27 BASE_EXPORT static void ReduceMemoryUsageUntilWithinLimit(size_t bytes); |
| 28 |
| 26 static void PurgeForTesting(); | 29 static void PurgeForTesting(); |
| 27 | 30 |
| 28 bool Initialize(); | 31 bool Initialize(); |
| 29 | 32 |
| 30 // Overridden from DiscardableMemory: | 33 // Overridden from DiscardableMemory: |
| 31 virtual DiscardableMemoryLockStatus Lock() OVERRIDE; | 34 virtual DiscardableMemoryLockStatus Lock() OVERRIDE; |
| 32 virtual void Unlock() OVERRIDE; | 35 virtual void Unlock() OVERRIDE; |
| 33 virtual void* Memory() const OVERRIDE; | 36 virtual void* Memory() const OVERRIDE; |
| 34 | 37 |
| 35 // Overridden from internal::DiscardableMemoryManagerAllocation: | 38 // Overridden from internal::DiscardableMemoryManagerAllocation: |
| 36 virtual bool AllocateAndAcquireLock() OVERRIDE; | 39 virtual bool AllocateAndAcquireLock() OVERRIDE; |
| 37 virtual void ReleaseLock() OVERRIDE {} | 40 virtual void ReleaseLock() OVERRIDE {} |
| 38 virtual void Purge() OVERRIDE; | 41 virtual void Purge() OVERRIDE; |
| 39 | 42 |
| 40 private: | 43 private: |
| 41 const size_t bytes_; | 44 const size_t bytes_; |
| 42 scoped_ptr<uint8[]> memory_; | 45 scoped_ptr<uint8[]> memory_; |
| 43 bool is_locked_; | 46 bool is_locked_; |
| 44 | 47 |
| 45 DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryEmulated); | 48 DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryEmulated); |
| 46 }; | 49 }; |
| 47 | 50 |
| 48 } // namespace internal | 51 } // namespace internal |
| 49 } // namespace base | 52 } // namespace base |
| 50 | 53 |
| 51 #endif // BASE_MEMORY_DISCARDABLE_MEMORY_EMULATED_H_ | 54 #endif // BASE_MEMORY_DISCARDABLE_MEMORY_EMULATED_H_ |
| OLD | NEW |