| Index: base/memory/memory_pressure_notifier.cc
|
| diff --git a/base/memory/memory_pressure_notifier.cc b/base/memory/memory_pressure_notifier.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..96c6cb7aeec0a041909cc9c886c6ba5dbdc5596f
|
| --- /dev/null
|
| +++ b/base/memory/memory_pressure_notifier.cc
|
| @@ -0,0 +1,52 @@
|
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "base/memory/memory_pressure_notifier.h"
|
| +
|
| +#include "base/memory/singleton.h"
|
| +
|
| +namespace base {
|
| +
|
| +MemoryPressureNotifier::Listener::Listener(
|
| + const MemoryPressureNotifier::MemoryPressureCallback& callback)
|
| + : callback_(callback) {
|
| + MemoryPressureNotifier::GetInstance()->RegisterListener(this);
|
| +}
|
| +
|
| +MemoryPressureNotifier::Listener::~Listener() {
|
| + MemoryPressureNotifier::GetInstance()->UnregisterListener(this);
|
| +}
|
| +
|
| +void MemoryPressureNotifier::Listener::Notify(
|
| + MemoryPressureType memory_pressure_type) {
|
| + callback_.Run(memory_pressure_type);
|
| +}
|
| +
|
| +// static
|
| +MemoryPressureNotifier* MemoryPressureNotifier::GetInstance() {
|
| + return Singleton<MemoryPressureNotifier,
|
| + LeakySingletonTraits<MemoryPressureNotifier> >::get();
|
| +}
|
| +
|
| +MemoryPressureNotifier::MemoryPressureNotifier()
|
| + : observers_(new ObserverListThreadSafe<Listener>()) {
|
| +}
|
| +
|
| +MemoryPressureNotifier::~MemoryPressureNotifier() {}
|
| +
|
| +void MemoryPressureNotifier::RegisterListener(Listener* listener) {
|
| + observers_->AddObserver(listener);
|
| +}
|
| +
|
| +void MemoryPressureNotifier::UnregisterListener(Listener* listener) {
|
| + observers_->RemoveObserver(listener);
|
| +}
|
| +
|
| +void MemoryPressureNotifier::HandleMemoryPressure(
|
| + MemoryPressureType memory_pressure_type) {
|
| + observers_->Notify(
|
| + &MemoryPressureNotifier::Listener::Notify, memory_pressure_type);
|
| +}
|
| +
|
| +} // namespace base
|
|
|