| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/allocator/allocator_extension.h" |
| 9 #include "base/bind.h" | 10 #include "base/bind.h" |
| 10 #include "base/threading/thread.h" | 11 #include "base/threading/thread.h" |
| 11 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/history/history.h" | 13 #include "chrome/browser/history/history.h" |
| 13 #include "chrome/browser/profiles/profile_manager.h" | 14 #include "chrome/browser/profiles/profile_manager.h" |
| 14 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 15 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 15 #include "chrome/browser/ui/browser_list.h" | 16 #include "chrome/browser/ui/browser_list.h" |
| 16 #include "chrome/browser/webdata/web_data_service.h" | 17 #include "chrome/browser/webdata/web_data_service.h" |
| 17 #include "chrome/common/render_messages.h" | 18 #include "chrome/common/render_messages.h" |
| 18 #include "content/public/browser/render_process_host.h" | 19 #include "content/public/browser/render_process_host.h" |
| 19 #include "content/public/browser/render_widget_host.h" | 20 #include "content/public/browser/render_widget_host.h" |
| 20 #include "content/public/browser/resource_context.h" | 21 #include "content/public/browser/resource_context.h" |
| 21 #include "net/proxy/proxy_resolver.h" | 22 #include "net/proxy/proxy_resolver.h" |
| 22 #include "net/proxy/proxy_service.h" | 23 #include "net/proxy/proxy_service.h" |
| 23 #include "net/url_request/url_request_context.h" | 24 #include "net/url_request/url_request_context.h" |
| 24 #include "net/url_request/url_request_context_getter.h" | 25 #include "net/url_request/url_request_context_getter.h" |
| 25 #include "third_party/tcmalloc/chromium/src/gperftools/malloc_extension.h" | |
| 26 | 26 |
| 27 using content::BrowserContext; | 27 using content::BrowserContext; |
| 28 using content::BrowserThread; | 28 using content::BrowserThread; |
| 29 using content::ResourceContext; | 29 using content::ResourceContext; |
| 30 | 30 |
| 31 // PurgeMemoryHelper ----------------------------------------------------------- | 31 // PurgeMemoryHelper ----------------------------------------------------------- |
| 32 | 32 |
| 33 // This is a small helper class used to ensure that the objects we want to use | 33 // This is a small helper class used to ensure that the objects we want to use |
| 34 // on multiple threads are properly refed, so they don't get deleted out from | 34 // on multiple threads are properly refed, so they don't get deleted out from |
| 35 // under us. | 35 // under us. |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 | 120 |
| 121 BrowserThread::PostTask( | 121 BrowserThread::PostTask( |
| 122 BrowserThread::IO, FROM_HERE, | 122 BrowserThread::IO, FROM_HERE, |
| 123 base::Bind(&PurgeMemoryIOHelper::PurgeMemoryOnIOThread, | 123 base::Bind(&PurgeMemoryIOHelper::PurgeMemoryOnIOThread, |
| 124 purge_memory_io_helper.get())); | 124 purge_memory_io_helper.get())); |
| 125 | 125 |
| 126 // TODO(pkasting): | 126 // TODO(pkasting): |
| 127 // * Purge AppCache memory. Not yet implemented sufficiently. | 127 // * Purge AppCache memory. Not yet implemented sufficiently. |
| 128 // * Browser-side DatabaseTracker. Not implemented sufficiently. | 128 // * Browser-side DatabaseTracker. Not implemented sufficiently. |
| 129 | 129 |
| 130 #if !defined(OS_MACOSX) && defined(USE_TCMALLOC) | 130 // Tell our allocator to release any free pages it's still holding. |
| 131 // Tell tcmalloc to release any free pages it's still holding. | |
| 132 // | 131 // |
| 133 // TODO(pkasting): A lot of the above calls kick off actions on other threads. | 132 // TODO(pkasting): A lot of the above calls kick off actions on other threads. |
| 134 // Maybe we should find a way to avoid calling this until those actions | 133 // Maybe we should find a way to avoid calling this until those actions |
| 135 // complete? | 134 // complete? |
| 136 MallocExtension::instance()->ReleaseFreeMemory(); | 135 base::allocator::ReleaseFreeMemory(); |
| 137 #endif | |
| 138 } | 136 } |
| 139 | 137 |
| 140 // static | 138 // static |
| 141 void MemoryPurger::PurgeRenderers() { | 139 void MemoryPurger::PurgeRenderers() { |
| 142 // Direct all renderers to free everything they can. | 140 // Direct all renderers to free everything they can. |
| 143 // | 141 // |
| 144 // Concern: Telling a bunch of renderer processes to destroy their data may | 142 // Concern: Telling a bunch of renderer processes to destroy their data may |
| 145 // cause them to page everything in to do it, which could take a lot of time/ | 143 // cause them to page everything in to do it, which could take a lot of time/ |
| 146 // cause jank. | 144 // cause jank. |
| 147 for (content::RenderProcessHost::iterator i( | 145 for (content::RenderProcessHost::iterator i( |
| 148 content::RenderProcessHost::AllHostsIterator()); | 146 content::RenderProcessHost::AllHostsIterator()); |
| 149 !i.IsAtEnd(); i.Advance()) | 147 !i.IsAtEnd(); i.Advance()) |
| 150 PurgeRendererForHost(i.GetCurrentValue()); | 148 PurgeRendererForHost(i.GetCurrentValue()); |
| 151 } | 149 } |
| 152 | 150 |
| 153 // static | 151 // static |
| 154 void MemoryPurger::PurgeRendererForHost(content::RenderProcessHost* host) { | 152 void MemoryPurger::PurgeRendererForHost(content::RenderProcessHost* host) { |
| 155 // Direct the renderer to free everything it can. | 153 // Direct the renderer to free everything it can. |
| 156 host->Send(new ChromeViewMsg_PurgeMemory()); | 154 host->Send(new ChromeViewMsg_PurgeMemory()); |
| 157 } | 155 } |
| OLD | NEW |