Bug 850607 - Properly react to changes to the 'memory.free_dirty_pages' preference. r=jlebar

This commit is contained in:
Gabriele Svelto 2013-03-13 12:24:04 +01:00
Родитель 82cb55c4f1
Коммит 786c6c9f50
1 изменённых файлов: 15 добавлений и 8 удалений

Просмотреть файл

@ -517,10 +517,15 @@ public:
NS_DECL_NSIOBSERVER
void Init();
private:
static bool sFreeDirtyPages;
};
NS_IMPL_ISUPPORTS1(nsMemoryPressureWatcher, nsIObserver)
bool nsMemoryPressureWatcher::sFreeDirtyPages = false;
/**
* Initialize and subscribe to the memory-pressure events. We subscribe to the
* observer service in this method and not in the constructor because we need
@ -534,12 +539,14 @@ nsMemoryPressureWatcher::Init()
if (os) {
os->AddObserver(this, "memory-pressure", /* ownsWeak */ false);
}
Preferences::AddBoolVarCache(&sFreeDirtyPages, "memory.free_dirty_pages",
false);
}
/**
* Reacts to all types of memory-pressure events, launches a runnable to
* free dirty pages held by jemalloc.
* @see nsMemoryPressureWatcher::FreeDirtyPages
*/
NS_IMETHODIMP
nsMemoryPressureWatcher::Observe(nsISupports *subject, const char *topic,
@ -547,9 +554,11 @@ nsMemoryPressureWatcher::Observe(nsISupports *subject, const char *topic,
{
MOZ_ASSERT(!strcmp(topic, "memory-pressure"), "Unknown topic");
nsRefPtr<nsIRunnable> runnable = new nsJemallocFreeDirtyPagesRunnable();
if (sFreeDirtyPages) {
nsRefPtr<nsIRunnable> runnable = new nsJemallocFreeDirtyPagesRunnable();
NS_DispatchToMainThread(runnable);
NS_DispatchToMainThread(runnable);
}
return NS_OK;
}
@ -590,11 +599,9 @@ void Activate()
sHooksActive = true;
#endif
if (Preferences::GetBool("memory.free_dirty_pages", false)) {
// This object is held alive by the observer service.
nsRefPtr<nsMemoryPressureWatcher> watcher = new nsMemoryPressureWatcher();
watcher->Init();
}
// This object is held alive by the observer service.
nsRefPtr<nsMemoryPressureWatcher> watcher = new nsMemoryPressureWatcher();
watcher->Init();
}
void Init()