summaryrefslogtreecommitdiffstats
path: root/chrome/browser/memory_purger.cc
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-01 18:50:19 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-01 18:50:19 +0000
commit0dd5dda0318cfbe06bc73f4a24a5e6b6b8e3fc30 (patch)
tree8bff32973fdd833232139ad6ac4bec54137b12a8 /chrome/browser/memory_purger.cc
parent83e214c531938502ad094e440f2dfd9a48fb007a (diff)
downloadchromium_src-0dd5dda0318cfbe06bc73f4a24a5e6b6b8e3fc30.zip
chromium_src-0dd5dda0318cfbe06bc73f4a24a5e6b6b8e3fc30.tar.gz
chromium_src-0dd5dda0318cfbe06bc73f4a24a5e6b6b8e3fc30.tar.bz2
Add framework of MemoryPurger, a class to dump memory from everywhere possible. Currently does nothing.
This also adds a "Purge memory" button to the task manager when run with --purge-memory-button, which can be used to test the functionality. BUG=23400 TEST=Run with --purge-memory-button, open the task manager and see a new button. Click it to toggle it to "Reset purge", and click again to toggle back. Review URL: http://codereview.chromium.org/259003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27751 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/memory_purger.cc')
-rw-r--r--chrome/browser/memory_purger.cc61
1 files changed, 61 insertions, 0 deletions
diff --git a/chrome/browser/memory_purger.cc b/chrome/browser/memory_purger.cc
new file mode 100644
index 0000000..2fc5b9e
--- /dev/null
+++ b/chrome/browser/memory_purger.cc
@@ -0,0 +1,61 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/memory_purger.h"
+
+#include "base/singleton.h"
+
+// static
+MemoryPurger* MemoryPurger::GetSingleton() {
+ return Singleton<MemoryPurger>::get();
+}
+
+void MemoryPurger::OnSuspend() {
+ // TODO:
+ //
+ // * For the browser process:
+ // * Commit all the sqlite databases and unload them from memory; at the
+ // very least, do this with the history system, then use the prefetch trick to
+ // reload it on wake.
+ // * Repeatedly call the V8 idle notification until it returns true
+ // ("nothing more to free"). Note that it makes more sense to do this than to
+ // implement a new "delete everything" pass because object references make it
+ // difficult to free everything possible in just one pass.
+ // * Dump the backing stores.
+ // * Destroy the spellcheck object.
+ // * Tell tcmalloc to free everything it can. (This is vague since it's not
+ // clear to me what this means; Jim, Mike, and Anton will know more here.
+ // Also, do we need to do this in each renderer process too?)
+ //
+ // * For each renderer process:
+ // * Repeatedly call the V8 idle notification until it returns true.
+ // * Tell the WebCore cache manager to set its global limit to 0, which
+ // should flush the image/script/css/etc. caches.
+ // * Destroy the WebCore glyph caches.
+ // * Tell tcmalloc to free everything it can.
+ //
+ // Concern: If we tell a bunch of renderer processes to destroy their data,
+ // they may have to page everything in to do it, which could end up
+ // overflowing the amount of time we have to work with.
+}
+
+void MemoryPurger::OnResume() {
+ // TODO:
+ //
+ // * For the browser process:
+ // * Reload the history system and any other needed sqlite databases.
+ //
+ // * For each renderer process:
+ // * Reset the WebCore cache manager global limit to the default.
+}
+
+MemoryPurger::MemoryPurger() {
+ base::SystemMonitor::Get()->AddObserver(this);
+}
+
+MemoryPurger::~MemoryPurger() {
+ base::SystemMonitor* system_monitor = base::SystemMonitor::Get();
+ if (system_monitor)
+ system_monitor->RemoveObserver(this);
+}