Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(161)

Side by Side Diff: base/mac/memory_pressure_monitor_mac.h

Issue 1124163003: Rename OS-specific MemoryPressureMonitor implementations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compile error on ChromeOS. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_MAC_H_
6 #define BASE_MAC_MEMORY_PRESSURE_MONITOR_MAC_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
27 class TestMemoryPressureMonitorMac;
28
29 struct DispatchSourceSDeleter {
30 void operator()(dispatch_source_s* ptr) {
31 dispatch_source_cancel(ptr);
32 dispatch_release(ptr);
33 }
34 };
35
36 // Declares the interface for the Mac MemoryPressureMonitor, which reports
37 // memory pressure events and status.
38 class BASE_EXPORT MemoryPressureMonitorMac : public MemoryPressureMonitor {
39 public:
40 using MemoryPressureLevel = base::MemoryPressureListener::MemoryPressureLevel;
41 MemoryPressureMonitorMac();
42 ~MemoryPressureMonitorMac() override;
43
44 // Returns the currently-observed memory pressure.
45 MemoryPressureLevel GetCurrentPressureLevel() const override;
46
47 private:
48 friend TestMemoryPressureMonitorMac;
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(MemoryPressureMonitorMac);
58 };
59
60 } // namespace base
61
62 #endif // BASE_MAC_MEMORY_PRESSURE_MONITOR_MAC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698