summaryrefslogtreecommitdiffstats
path: root/base/memory
diff options
context:
space:
mode:
authorbulach@chromium.org <bulach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-18 13:31:56 +0000
committerbulach@chromium.org <bulach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-18 13:31:56 +0000
commit343807548029eda502378f5696194c1ba4eff619 (patch)
treeb3053fd5f9f4776a6878c9ea8579fddc76d4a016 /base/memory
parent1483f9d99443d2d70105885c265fed874cdba12d (diff)
downloadchromium_src-343807548029eda502378f5696194c1ba4eff619.zip
chromium_src-343807548029eda502378f5696194c1ba4eff619.tar.gz
chromium_src-343807548029eda502378f5696194c1ba4eff619.tar.bz2
MemoryPressureListener: fixes ref-counting.
Following crrev.com/205796, the internal observer list is ref-counted, the lazy instance must keep a ref to it. BUG=246125 Review URL: https://chromiumcodereview.appspot.com/17242002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@206968 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/memory')
-rw-r--r--base/memory/memory_pressure_listener.cc23
1 files changed, 20 insertions, 3 deletions
diff --git a/base/memory/memory_pressure_listener.cc b/base/memory/memory_pressure_listener.cc
index 911dbb3..e2ea106 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 {