| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_MEMORY_PRESSURE_MONITOR_MAC_H_ | 5 #ifndef BASE_MAC_MEMORY_MEMORY_PRESSURE_MONITOR_H_ |
| 6 #define BASE_MEMORY_MEMORY_PRESSURE_MONITOR_MAC_H_ | 6 #define BASE_MAC_MEMORY_MEMORY_PRESSURE_MONITOR_H_ |
| 7 | 7 |
| 8 #include <dispatch/dispatch.h> | 8 #include <dispatch/dispatch.h> |
| 9 | 9 |
| 10 #include "base/base_export.h" | 10 #include "base/base_export.h" |
| 11 #include "base/memory/memory_pressure_listener.h" | 11 #include "base/memory/memory_pressure_listener.h" |
| 12 #include "base/memory/memory_pressure_monitor.h" | 12 #include "base/memory/memory_pressure_monitor.h" |
| 13 | 13 |
| 14 // The following was added to <dispatch/source.h> after 10.8. | 14 // The following was added to <dispatch/source.h> after 10.8. |
| 15 // TODO(shrike): Remove the DISPATCH_MEMORYPRESSURE_NORMAL ifndef once builders | 15 // TODO(shrike): Remove the DISPATCH_MEMORYPRESSURE_NORMAL ifndef once builders |
| 16 // reach 10.9 or higher. | 16 // reach 10.9 or higher. |
| 17 #ifndef DISPATCH_MEMORYPRESSURE_NORMAL | 17 #ifndef DISPATCH_MEMORYPRESSURE_NORMAL |
| 18 | 18 |
| 19 #define DISPATCH_MEMORYPRESSURE_NORMAL 0x01 | 19 #define DISPATCH_MEMORYPRESSURE_NORMAL 0x01 |
| 20 #define DISPATCH_MEMORYPRESSURE_WARN 0x02 | 20 #define DISPATCH_MEMORYPRESSURE_WARN 0x02 |
| 21 #define DISPATCH_MEMORYPRESSURE_CRITICAL 0x04 | 21 #define DISPATCH_MEMORYPRESSURE_CRITICAL 0x04 |
| 22 | 22 |
| 23 #endif // DISPATCH_MEMORYPRESSURE_NORMAL | 23 #endif // DISPATCH_MEMORYPRESSURE_NORMAL |
| 24 | 24 |
| 25 namespace base { | 25 namespace base { |
| 26 namespace mac { |
| 26 | 27 |
| 27 class TestMemoryPressureMonitorMac; | 28 class TestMemoryPressureMonitor; |
| 28 | 29 |
| 29 struct DispatchSourceSDeleter { | 30 struct DispatchSourceSDeleter { |
| 30 void operator()(dispatch_source_s* ptr) { | 31 void operator()(dispatch_source_s* ptr) { |
| 31 dispatch_source_cancel(ptr); | 32 dispatch_source_cancel(ptr); |
| 32 dispatch_release(ptr); | 33 dispatch_release(ptr); |
| 33 } | 34 } |
| 34 }; | 35 }; |
| 35 | 36 |
| 36 // Declares the interface for the Mac MemoryPressureMonitor, which reports | 37 // Declares the interface for the Mac MemoryPressureMonitor, which reports |
| 37 // memory pressure events and status. | 38 // memory pressure events and status. |
| 38 class BASE_EXPORT MemoryPressureMonitorMac : public MemoryPressureMonitor { | 39 class BASE_EXPORT MemoryPressureMonitor : public MemoryPressureMonitor { |
| 39 public: | 40 public: |
| 40 using MemoryPressureLevel = base::MemoryPressureListener::MemoryPressureLevel; | 41 MemoryPressureMonitor(); |
| 41 MemoryPressureMonitorMac(); | 42 ~MemoryPressureMonitor() override; |
| 42 ~MemoryPressureMonitorMac() override; | |
| 43 | 43 |
| 44 // Returns the currently-observed memory pressure. | 44 // Returns the currently-observed memory pressure. |
| 45 MemoryPressureLevel GetCurrentPressureLevel() const override; | 45 MemoryPressureLevel GetCurrentPressureLevel() const override; |
| 46 | 46 |
| 47 private: | 47 private: |
| 48 friend TestMemoryPressureMonitorMac; | 48 friend TestMemoryPressureMonitor; |
| 49 | 49 |
| 50 static MemoryPressureLevel | 50 static MemoryPressureLevel |
| 51 MemoryPressureLevelForMacMemoryPressure(int mac_memory_pressure); | 51 MemoryPressureLevelForMacMemoryPressure(int mac_memory_pressure); |
| 52 static void NotifyMemoryPressureChanged(dispatch_source_s* event_source); | 52 static void NotifyMemoryPressureChanged(dispatch_source_s* event_source); |
| 53 | 53 |
| 54 scoped_ptr<dispatch_source_s, DispatchSourceSDeleter> | 54 scoped_ptr<dispatch_source_s, DispatchSourceSDeleter> |
| 55 memory_level_event_source_; | 55 memory_level_event_source_; |
| 56 | 56 |
| 57 DISALLOW_COPY_AND_ASSIGN(MemoryPressureMonitorMac); | 57 DISALLOW_COPY_AND_ASSIGN(MemoryPressureMonitor); |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 } // namespace mac |
| 60 } // namespace base | 61 } // namespace base |
| 61 | 62 |
| 62 #endif // BASE_MEMORY_MEMORY_PRESSURE_MONITOR_MAC_H_ | 63 #endif // BASE_MAC_MEMORY_MEMORY_PRESSURE_MONITOR_H_ |
| OLD | NEW |