| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/memory_purger.h" | 5 #include "chrome/browser/memory_purger.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/threading/thread.h" | 9 #include "base/threading/thread.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/history/history.h" | 11 #include "chrome/browser/history/history.h" |
| 12 #include "chrome/browser/profiles/profile_manager.h" | 12 #include "chrome/browser/profiles/profile_manager.h" |
| 13 #include "chrome/browser/ui/browser_list.h" | 13 #include "chrome/browser/ui/browser_list.h" |
| 14 #include "chrome/browser/webdata/web_data_service.h" | 14 #include "chrome/browser/webdata/web_data_service.h" |
| 15 #include "chrome/common/render_messages.h" | 15 #include "chrome/common/render_messages.h" |
| 16 #include "content/browser/in_process_webkit/webkit_context.h" | 16 #include "content/browser/in_process_webkit/webkit_context.h" |
| 17 #include "content/browser/renderer_host/backing_store_manager.h" | 17 #include "content/browser/renderer_host/backing_store_manager.h" |
| 18 #include "content/browser/renderer_host/render_process_host.h" | 18 #include "content/browser/renderer_host/render_process_host.h" |
| 19 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 19 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
| 20 #include "content/common/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
| 21 #include "net/proxy/proxy_resolver.h" | 21 #include "net/proxy/proxy_resolver.h" |
| 22 #include "net/proxy/proxy_service.h" | 22 #include "net/proxy/proxy_service.h" |
| 23 #include "net/url_request/url_request_context.h" | 23 #include "net/url_request/url_request_context.h" |
| 24 #include "net/url_request/url_request_context_getter.h" | 24 #include "net/url_request/url_request_context_getter.h" |
| 25 #include "third_party/tcmalloc/chromium/src/google/malloc_extension.h" | 25 #include "third_party/tcmalloc/chromium/src/google/malloc_extension.h" |
| 26 | 26 |
| 27 // PurgeMemoryHelper ----------------------------------------------------------- | 27 // PurgeMemoryHelper ----------------------------------------------------------- |
| 28 | 28 |
| 29 // This is a small helper class used to ensure that the objects we want to use | 29 // This is a small helper class used to ensure that the objects we want to use |
| 30 // on multiple threads are properly refed, so they don't get deleted out from | 30 // on multiple threads are properly refed, so they don't get deleted out from |
| (...skipping 25 matching lines...) Expand all Loading... |
| 56 | 56 |
| 57 void PurgeMemoryIOHelper::PurgeMemoryOnIOThread() { | 57 void PurgeMemoryIOHelper::PurgeMemoryOnIOThread() { |
| 58 // Ask ProxyServices to purge any memory they can (generally garbage in the | 58 // Ask ProxyServices to purge any memory they can (generally garbage in the |
| 59 // wrapped ProxyResolver's JS engine). | 59 // wrapped ProxyResolver's JS engine). |
| 60 for (RequestContextGetters::const_iterator i( | 60 for (RequestContextGetters::const_iterator i( |
| 61 request_context_getters_.begin()); | 61 request_context_getters_.begin()); |
| 62 i != request_context_getters_.end(); ++i) | 62 i != request_context_getters_.end(); ++i) |
| 63 (*i)->GetURLRequestContext()->proxy_service()->PurgeMemory(); | 63 (*i)->GetURLRequestContext()->proxy_service()->PurgeMemory(); |
| 64 | 64 |
| 65 // The appcache and safe browsing services listen for this notification. | 65 // The appcache and safe browsing services listen for this notification. |
| 66 NotificationService::current()->Notify( | 66 content::NotificationService::current()->Notify( |
| 67 content::NOTIFICATION_PURGE_MEMORY, | 67 content::NOTIFICATION_PURGE_MEMORY, |
| 68 content::Source<void>(NULL), | 68 content::Source<void>(NULL), |
| 69 NotificationService::NoDetails()); | 69 content::NotificationService::NoDetails()); |
| 70 } | 70 } |
| 71 | 71 |
| 72 // ----------------------------------------------------------------------------- | 72 // ----------------------------------------------------------------------------- |
| 73 | 73 |
| 74 // static | 74 // static |
| 75 void MemoryPurger::PurgeAll() { | 75 void MemoryPurger::PurgeAll() { |
| 76 PurgeBrowser(); | 76 PurgeBrowser(); |
| 77 PurgeRenderers(); | 77 PurgeRenderers(); |
| 78 | 78 |
| 79 // TODO(pkasting): | 79 // TODO(pkasting): |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); | 146 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); |
| 147 !i.IsAtEnd(); i.Advance()) | 147 !i.IsAtEnd(); i.Advance()) |
| 148 PurgeRendererForHost(i.GetCurrentValue()); | 148 PurgeRendererForHost(i.GetCurrentValue()); |
| 149 } | 149 } |
| 150 | 150 |
| 151 // static | 151 // static |
| 152 void MemoryPurger::PurgeRendererForHost(RenderProcessHost* host) { | 152 void MemoryPurger::PurgeRendererForHost(RenderProcessHost* host) { |
| 153 // Direct the renderer to free everything it can. | 153 // Direct the renderer to free everything it can. |
| 154 host->Send(new ChromeViewMsg_PurgeMemory()); | 154 host->Send(new ChromeViewMsg_PurgeMemory()); |
| 155 } | 155 } |
| OLD | NEW |