Bug 1891710: part 2) Enable <Element-outerHTML.html> WPT for Trusted Types. r=smaug
[gecko.git] / gfx / layers / MemoryPressureObserver.h
blob27048c99ed8703ee75034e444f28d915cdb8acab
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: sw=2 ts=8 et :
3 */
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #ifndef MOZILLA_LAYERS_MEMORYPRESSUREOBSERVER_H
9 #define MOZILLA_LAYERS_MEMORYPRESSUREOBSERVER_H
11 #include "nsIObserver.h"
13 namespace mozilla {
14 namespace layers {
16 // A simple memory pressure observer implementation born out of the realization
17 // that almost all of our memory pressure observers do exactly the same thing.
19 // The intended way to use it is to have the class that nees to react on memory
20 // pressure inherit the MemoryPressureListener interface and own a strong
21 // reference to a MemoryPressureListener object.
22 // Call Unregister on the listener in the destructor of your class or whenever
23 // you do not which to receive the notification anymore, otherwise the listener
24 // will be held alive by the observer service (leak) and keep a dangling pointer
25 // to your class.
27 /// See nsIMemory.idl
28 enum class MemoryPressureReason {
29 LOW_MEMORY,
30 LOW_MEMORY_ONGOING,
31 HEAP_MINIMIZE,
34 class MemoryPressureListener {
35 public:
36 virtual void OnMemoryPressure(MemoryPressureReason aWhy) = 0;
39 class MemoryPressureObserver final : public nsIObserver {
40 public:
41 NS_DECL_ISUPPORTS
42 NS_DECL_NSIOBSERVER
44 // Returns null if anything goes wrong.
45 static already_AddRefed<MemoryPressureObserver> Create(
46 MemoryPressureListener* aListener);
48 void Unregister();
50 private:
51 explicit MemoryPressureObserver(MemoryPressureListener* aListener);
52 virtual ~MemoryPressureObserver();
53 MemoryPressureListener* mListener;
56 } // namespace layers
57 } // namespace mozilla
59 #endif