summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-08 18:24:26 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-08 18:24:26 +0000
commitfede6ca1035f1275847b861eaf6a07f8b35a65ab (patch)
treeceeee6c5b61d094b21cbdef50990019b74b59b5c /chrome
parent01f42660659e45edd7c0a4ad8ecd7a6bb00e370e (diff)
downloadchromium_src-fede6ca1035f1275847b861eaf6a07f8b35a65ab.zip
chromium_src-fede6ca1035f1275847b861eaf6a07f8b35a65ab.tar.gz
chromium_src-fede6ca1035f1275847b861eaf6a07f8b35a65ab.tar.bz2
Add functionality to the renderer thread to purge memory. Not yet called.
BUG=23400 TEST=none Review URL: http://codereview.chromium.org/267021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28415 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/common/render_messages_internal.h6
-rw-r--r--chrome/renderer/render_thread.cc32
-rw-r--r--chrome/renderer/render_thread.h1
3 files changed, 39 insertions, 0 deletions
diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h
index 3925798..e5993a6 100644
--- a/chrome/common/render_messages_internal.h
+++ b/chrome/common/render_messages_internal.h
@@ -139,6 +139,12 @@ IPC_BEGIN_MESSAGES(View)
int /* document_cookie */,
bool /* success */)
+ // Tells the renderer to dump as much memory as it can, perhaps because we
+ // have memory pressure or the renderer is (or will be) paged out. This
+ // should only result in purging objects we can recalculate, e.g. caches or
+ // JS garbage, not in purging irreplaceable objects.
+ IPC_MESSAGE_CONTROL0(ViewMsg_PurgeMemory)
+
// Tells the render view that a ViewHostMsg_ScrollRect message was processed.
// This signals the render view that it can send another ScrollRect message.
IPC_MESSAGE_ROUTED0(ViewMsg_ScrollRect_ACK)
diff --git a/chrome/renderer/render_thread.cc b/chrome/renderer/render_thread.cc
index 241ce45..268d0b4 100644
--- a/chrome/renderer/render_thread.cc
+++ b/chrome/renderer/render_thread.cc
@@ -47,6 +47,9 @@
#include "ipc/ipc_message.h"
#include "webkit/api/public/WebCache.h"
#include "webkit/api/public/WebColor.h"
+#include "webkit/api/public/WebCrossOriginPreflightResultCache.h"
+#include "webkit/api/public/WebFontCache.h"
+#include "webkit/api/public/WebColor.h"
#include "webkit/api/public/WebKit.h"
#include "webkit/api/public/WebStorageEventDispatcher.h"
#include "webkit/api/public/WebString.h"
@@ -62,6 +65,8 @@
#endif
using WebKit::WebCache;
+using WebKit::WebCrossOriginPreflightResultCache;
+using WebKit::WebFontCache;
using WebKit::WebString;
using WebKit::WebStorageEventDispatcher;
@@ -292,6 +297,7 @@ void RenderThread::OnControlMessageReceived(const IPC::Message& msg) {
OnExtensionMessageInvoke)
IPC_MESSAGE_HANDLER(ViewMsg_Extension_SetFunctionNames,
OnSetExtensionFunctionNames)
+ IPC_MESSAGE_HANDLER(ViewMsg_PurgeMemory, OnPurgeMemory)
IPC_MESSAGE_HANDLER(ViewMsg_PurgePluginListCache,
OnPurgePluginListCache)
IPC_MESSAGE_HANDLER(ViewMsg_Extension_UpdatePageActions,
@@ -525,6 +531,32 @@ void RenderThread::OnExtensionMessageInvoke(const std::string& function_name,
RendererExtensionBindings::Invoke(function_name, args, NULL);
}
+void RenderThread::OnPurgeMemory() {
+ EnsureWebKitInitialized();
+
+ // Clear the object cache (as much as possible; some live objects cannot be
+ // freed).
+ WebCache::clear();
+
+ // Clear the font/glyph cache.
+ WebFontCache::clear();
+
+ // Clear the Cross-Origin Preflight cache.
+ WebCrossOriginPreflightResultCache::clear();
+
+ // 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.
+ while (!v8::V8::IdleNotification())
+ ;
+
+#if defined(OS_WIN)
+ // Tell tcmalloc to release any free pages it's still holding.
+ MallocExtension::instance()->ReleaseFreeMemory();
+#endif
+}
+
void RenderThread::OnPurgePluginListCache(bool reload_pages) {
EnsureWebKitInitialized();
// The call below will cause a GetPlugins call with refresh=true, but at this
diff --git a/chrome/renderer/render_thread.h b/chrome/renderer/render_thread.h
index 5f14260..e60c91b 100644
--- a/chrome/renderer/render_thread.h
+++ b/chrome/renderer/render_thread.h
@@ -177,6 +177,7 @@ class RenderThread : public RenderThreadBase,
void OnExtensionMessageInvoke(const std::string& function_name,
const ListValue& args);
+ void OnPurgeMemory();
void OnPurgePluginListCache(bool reload_pages);
// Gather usage statistics from the in-memory cache and inform our host.