1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
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"
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
28 enum class MemoryPressureReason
{
34 class MemoryPressureListener
{
36 virtual void OnMemoryPressure(MemoryPressureReason aWhy
) = 0;
39 class MemoryPressureObserver final
: public nsIObserver
{
44 // Returns null if anything goes wrong.
45 static already_AddRefed
<MemoryPressureObserver
> Create(
46 MemoryPressureListener
* aListener
);
51 explicit MemoryPressureObserver(MemoryPressureListener
* aListener
);
52 virtual ~MemoryPressureObserver();
53 MemoryPressureListener
* mListener
;
57 } // namespace mozilla