Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(619)

Side by Side Diff: base/memory/memory_pressure_notifier.cc

Issue 15995014: Adds MemoryPressureListener. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Joth's comments Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 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.
4
5 #include "base/memory/memory_pressure_notifier.h"
6
7 #include "base/memory/singleton.h"
8
9 namespace base {
10
11 MemoryPressureNotifier::Listener::Listener(
12 const MemoryPressureNotifier::MemoryPressureCallback& callback)
13 : callback_(callback) {
14 MemoryPressureNotifier::GetInstance()->RegisterListener(this);
15 }
16
17 MemoryPressureNotifier::Listener::~Listener() {
18 MemoryPressureNotifier::GetInstance()->UnregisterListener(this);
19 }
20
21 void MemoryPressureNotifier::Listener::Notify(
22 MemoryPressureType memory_pressure_type) {
23 callback_.Run(memory_pressure_type);
24 }
25
26 // static
27 MemoryPressureNotifier* MemoryPressureNotifier::GetInstance() {
28 return Singleton<MemoryPressureNotifier,
29 LeakySingletonTraits<MemoryPressureNotifier> >::get();
30 }
31
32 MemoryPressureNotifier::MemoryPressureNotifier()
33 : observers_(new ObserverListThreadSafe<Listener>()) {
34 }
35
36 MemoryPressureNotifier::~MemoryPressureNotifier() {}
37
38 void MemoryPressureNotifier::RegisterListener(Listener* listener) {
39 observers_->AddObserver(listener);
40 }
41
42 void MemoryPressureNotifier::UnregisterListener(Listener* listener) {
43 observers_->RemoveObserver(listener);
44 }
45
46 void MemoryPressureNotifier::HandleMemoryPressure(
47 MemoryPressureType memory_pressure_type) {
48 observers_->Notify(
49 &MemoryPressureNotifier::Listener::Notify, memory_pressure_type);
50 }
51
52 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698