This source file includes following definitions.
- Notify
- NotifyMemoryPressure
#include "base/memory/memory_pressure_listener.h"
#include "base/lazy_instance.h"
#include "base/observer_list_threadsafe.h"
namespace {
struct LeakyLazyObserverListTraits :
base::internal::LeakyLazyInstanceTraits<
ObserverListThreadSafe<base::MemoryPressureListener> > {
static ObserverListThreadSafe<base::MemoryPressureListener>*
New(void* instance) {
ObserverListThreadSafe<base::MemoryPressureListener>* ret =
base::internal::LeakyLazyInstanceTraits<
ObserverListThreadSafe<base::MemoryPressureListener> >::New(
instance);
ret->AddRef();
return ret;
}
};
base::LazyInstance<
ObserverListThreadSafe<base::MemoryPressureListener>,
LeakyLazyObserverListTraits> g_observers = LAZY_INSTANCE_INITIALIZER;
}
namespace base {
MemoryPressureListener::MemoryPressureListener(
const MemoryPressureListener::MemoryPressureCallback& callback)
: callback_(callback) {
g_observers.Get().AddObserver(this);
}
MemoryPressureListener::~MemoryPressureListener() {
g_observers.Get().RemoveObserver(this);
}
void MemoryPressureListener::Notify(MemoryPressureLevel memory_pressure_level) {
callback_.Run(memory_pressure_level);
}
void MemoryPressureListener::NotifyMemoryPressure(
MemoryPressureLevel memory_pressure_level) {
g_observers.Get().Notify(&MemoryPressureListener::Notify,
memory_pressure_level);
}
}