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 { |