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