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

Unified Diff: base/memory/memory_pressure_listener.cc

Issue 17242002: MemoryPressureListener: fixes ref-counting. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: AddRef 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/memory_pressure_listener.cc
diff --git a/base/memory/memory_pressure_listener.cc b/base/memory/memory_pressure_listener.cc
index 911dbb38c89b86349f05aa392f4b4dfee56c3d88..e2ea106eaa60cf9ca5c43272400b23cae710ec02 100644
--- a/base/memory/memory_pressure_listener.cc
+++ b/base/memory/memory_pressure_listener.cc
@@ -9,9 +9,26 @@
namespace {
-base::LazyInstance<ObserverListThreadSafe<base::MemoryPressureListener> >::Leaky
- g_observers = LAZY_INSTANCE_INITIALIZER;
-
+// ObserverListThreadSafe is RefCountedThreadSafe, this traits is needed
+// to ensure the LazyInstance will hold a reference to it.
+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);
+ // Leaky.
+ ret->AddRef();
+ return ret;
+ }
+};
+
+base::LazyInstance<
+ ObserverListThreadSafe<base::MemoryPressureListener>,
+ LeakyLazyObserverListTraits> g_observers = LAZY_INSTANCE_INITIALIZER;
} // namespace
namespace base {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698