| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "base/thread.h" | 7 #include "base/thread.h" |
| 8 #include "chrome/browser/browser_list.h" | 8 #include "chrome/browser/browser_list.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/history/history.h" | 10 #include "chrome/browser/history/history.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 } | 121 } |
| 122 | 122 |
| 123 ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, | 123 ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, |
| 124 NewRunnableMethod(purge_memory_io_helper.get(), | 124 NewRunnableMethod(purge_memory_io_helper.get(), |
| 125 &PurgeMemoryIOHelper::PurgeMemoryOnIOThread)); | 125 &PurgeMemoryIOHelper::PurgeMemoryOnIOThread)); |
| 126 | 126 |
| 127 // TODO(pkasting): | 127 // TODO(pkasting): |
| 128 // * Purge AppCache memory. Not yet implemented sufficiently. | 128 // * Purge AppCache memory. Not yet implemented sufficiently. |
| 129 // * Browser-side DatabaseTracker. Not implemented sufficiently. | 129 // * Browser-side DatabaseTracker. Not implemented sufficiently. |
| 130 | 130 |
| 131 #if defined(OS_WIN) | 131 #if defined(OS_WIN) && defined(USE_TCMALLOC) |
| 132 // Tell tcmalloc to release any free pages it's still holding. | 132 // Tell tcmalloc to release any free pages it's still holding. |
| 133 // | 133 // |
| 134 // TODO(pkasting): A lot of the above calls kick off actions on other threads. | 134 // TODO(pkasting): A lot of the above calls kick off actions on other threads. |
| 135 // Maybe we should find a way to avoid calling this until those actions | 135 // Maybe we should find a way to avoid calling this until those actions |
| 136 // complete? | 136 // complete? |
| 137 MallocExtension::instance()->ReleaseFreeMemory(); | 137 MallocExtension::instance()->ReleaseFreeMemory(); |
| 138 #endif | 138 #endif |
| 139 } | 139 } |
| 140 | 140 |
| 141 // static | 141 // static |
| 142 void MemoryPurger::PurgeRenderers() { | 142 void MemoryPurger::PurgeRenderers() { |
| 143 // Direct all renderers to free everything they can. | 143 // Direct all renderers to free everything they can. |
| 144 // | 144 // |
| 145 // Concern: Telling a bunch of renderer processes to destroy their data may | 145 // Concern: Telling a bunch of renderer processes to destroy their data may |
| 146 // cause them to page everything in to do it, which could take a lot of time/ | 146 // cause them to page everything in to do it, which could take a lot of time/ |
| 147 // cause jank. | 147 // cause jank. |
| 148 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); | 148 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); |
| 149 !i.IsAtEnd(); i.Advance()) | 149 !i.IsAtEnd(); i.Advance()) |
| 150 PurgeRendererForHost(i.GetCurrentValue()); | 150 PurgeRendererForHost(i.GetCurrentValue()); |
| 151 } | 151 } |
| 152 | 152 |
| 153 // static | 153 // static |
| 154 void MemoryPurger::PurgeRendererForHost(RenderProcessHost* host) { | 154 void MemoryPurger::PurgeRendererForHost(RenderProcessHost* host) { |
| 155 // Direct the renderer to free everything it can. | 155 // Direct the renderer to free everything it can. |
| 156 host->Send(new ViewMsg_PurgeMemory()); | 156 host->Send(new ViewMsg_PurgeMemory()); |
| 157 } | 157 } |
| OLD | NEW |