Add flag to control usage of GaiaAuthFetcherIOS.
[chromium-blink-merge.git] / base / memory / memory_pressure_monitor_mac.h
blob8d4c26a55f0c0ded0a8260afea68d49549ea940f
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.
5 #ifndef BASE_MEMORY_MEMORY_PRESSURE_MONITOR_MAC_H_
6 #define BASE_MEMORY_MEMORY_PRESSURE_MONITOR_MAC_H_
8 #include <dispatch/dispatch.h>
10 #include "base/base_export.h"
11 #include "base/memory/memory_pressure_listener.h"
12 #include "base/memory/memory_pressure_monitor.h"
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
19 #define DISPATCH_MEMORYPRESSURE_NORMAL 0x01
20 #define DISPATCH_MEMORYPRESSURE_WARN 0x02
21 #define DISPATCH_MEMORYPRESSURE_CRITICAL 0x04
23 #endif // DISPATCH_MEMORYPRESSURE_NORMAL
25 namespace base {
26 namespace mac {
28 class TestMemoryPressureMonitor;
30 struct DispatchSourceSDeleter {
31 void operator()(dispatch_source_s* ptr) {
32 dispatch_source_cancel(ptr);
33 dispatch_release(ptr);
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;
44 // Returns the currently-observed memory pressure.
45 MemoryPressureLevel GetCurrentPressureLevel() const override;
47 private:
48 friend TestMemoryPressureMonitor;
50 static MemoryPressureLevel
51 MemoryPressureLevelForMacMemoryPressure(int mac_memory_pressure);
52 static void NotifyMemoryPressureChanged(dispatch_source_s* event_source);
54 scoped_ptr<dispatch_source_s, DispatchSourceSDeleter>
55 memory_level_event_source_;
57 DISALLOW_COPY_AND_ASSIGN(MemoryPressureMonitor);
60 } // namespace mac
61 } // namespace base
63 #endif // BASE_MEMORY_MEMORY_PRESSURE_MONITOR_MAC_H_