| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_BROWSER_MEMORY_MEMORY_MONITOR_MAC_H_ |
| 6 #define CONTENT_BROWSER_MEMORY_MEMORY_MONITOR_MAC_H_ |
| 7 |
| 8 #include "content/browser/memory/memory_monitor.h" |
| 9 #include "content/common/content_export.h" |
| 10 |
| 11 namespace content { |
| 12 |
| 13 // A memory monitor for the Mac platform. |
| 14 class CONTENT_EXPORT MemoryMonitorMac : public MemoryMonitor { |
| 15 public: |
| 16 MemoryMonitorMac(MemoryMonitorDelegate* delegate, |
| 17 base::TimeDelta poll_interval); |
| 18 ~MemoryMonitorMac() override; |
| 19 |
| 20 // MemoryMonitor: |
| 21 int GetFreeMemoryUntilCriticalMB() override; |
| 22 |
| 23 // Factory function to create an instance of this class. |
| 24 static std::unique_ptr<MemoryMonitorMac> Create( |
| 25 MemoryMonitorDelegate* delegate, |
| 26 base::TimeDelta poll_interval); |
| 27 |
| 28 private: |
| 29 // The delegate to be used for retrieving system memory information. Used as a |
| 30 // testing seam. |
| 31 MemoryMonitorDelegate* delegate_; |
| 32 |
| 33 // The poll-interval amount by which |critical_free_mb_| increase. |
| 34 const int64_t poll_interval_adjustment_mb_; |
| 35 |
| 36 // The threshold of free memory that is considered "critical". This value is |
| 37 // determined dynamically via system "memory pressure" events. |
| 38 int critical_free_mb_; |
| 39 }; |
| 40 |
| 41 // A delegate with extra methods required to support Mac. |
| 42 class CONTENT_EXPORT MemoryMonitorMacDelegate : public MemoryMonitorDelegate { |
| 43 public: |
| 44 static MemoryMonitorMacDelegate* GetInstance(); |
| 45 |
| 46 // Returns system memory-pressure information. According to dispatch/source.h |
| 47 // the returned integer values are: |
| 48 // DISPATCH_MEMORYPRESSURE_NORMAL: System has sufficient memory available. |
| 49 // DISPATCH_MEMORYPRESSURE_WARN: System memory is getting low. |
| 50 // DISPATCH_MEMORYPRESSURE_CRITICAL: System has to swap or kill processes. |
| 51 bool GetSystemMemoryPressure(int* mem_pressure) override; |
| 52 }; |
| 53 |
| 54 } // namespace content |
| 55 |
| 56 #endif // CONTENT_BROWSER_MEMORY_MEMORY_MONITOR_MAC_H_ |
| OLD | NEW |