| 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/bind.h" | 9 #include "base/bind.h" | 
| 10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" | 
| 11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" | 
| 12 #include "chrome/browser/history/history.h" | 12 #include "chrome/browser/history/history.h" | 
| 13 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" | 
| 14 #include "chrome/browser/ui/browser_list.h" | 14 #include "chrome/browser/ui/browser_list.h" | 
| 15 #include "chrome/browser/webdata/web_data_service.h" | 15 #include "chrome/browser/webdata/web_data_service.h" | 
| 16 #include "chrome/common/render_messages.h" | 16 #include "chrome/common/render_messages.h" | 
| 17 #include "content/browser/in_process_webkit/webkit_context.h" | 17 #include "content/browser/in_process_webkit/webkit_context.h" | 
| 18 #include "content/browser/renderer_host/backing_store_manager.h" | 18 #include "content/browser/renderer_host/backing_store_manager.h" | 
| 19 #include "content/public/browser/notification_service.h" | 19 #include "content/public/browser/notification_service.h" | 
| 20 #include "content/public/browser/notification_types.h" | 20 #include "content/public/browser/notification_types.h" | 
| 21 #include "content/public/browser/render_process_host.h" | 21 #include "content/public/browser/render_process_host.h" | 
| 22 #include "net/proxy/proxy_resolver.h" | 22 #include "net/proxy/proxy_resolver.h" | 
| 23 #include "net/proxy/proxy_service.h" | 23 #include "net/proxy/proxy_service.h" | 
| 24 #include "net/url_request/url_request_context.h" | 24 #include "net/url_request/url_request_context.h" | 
| 25 #include "net/url_request/url_request_context_getter.h" | 25 #include "net/url_request/url_request_context_getter.h" | 
| 26 #include "third_party/tcmalloc/chromium/src/google/malloc_extension.h" | 26 #include "third_party/tcmalloc/chromium/src/google/malloc_extension.h" | 
| 27 | 27 | 
|  | 28 using content::BrowserContext; | 
| 28 using content::BrowserThread; | 29 using content::BrowserThread; | 
| 29 | 30 | 
| 30 // PurgeMemoryHelper ----------------------------------------------------------- | 31 // PurgeMemoryHelper ----------------------------------------------------------- | 
| 31 | 32 | 
| 32 // 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 | 
| 33 // 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 | 
| 34 // under us. | 35 // under us. | 
| 35 class PurgeMemoryIOHelper | 36 class PurgeMemoryIOHelper | 
| 36     : public base::RefCountedThreadSafe<PurgeMemoryIOHelper> { | 37     : public base::RefCountedThreadSafe<PurgeMemoryIOHelper> { | 
| 37  public: | 38  public: | 
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 111 | 112 | 
| 112     // Unload all web databases (freeing memory used to cache sqlite). | 113     // Unload all web databases (freeing memory used to cache sqlite). | 
| 113     WebDataService* web_data_service = | 114     WebDataService* web_data_service = | 
| 114         profiles[i]->GetWebDataServiceWithoutCreating(); | 115         profiles[i]->GetWebDataServiceWithoutCreating(); | 
| 115     if (web_data_service) | 116     if (web_data_service) | 
| 116       web_data_service->UnloadDatabase(); | 117       web_data_service->UnloadDatabase(); | 
| 117 | 118 | 
| 118     // Ask all WebKitContexts to purge memory (freeing memory used to cache | 119     // Ask all WebKitContexts to purge memory (freeing memory used to cache | 
| 119     // the LocalStorage sqlite DB).  WebKitContext creation is basically free so | 120     // the LocalStorage sqlite DB).  WebKitContext creation is basically free so | 
| 120     // we don't bother with a "...WithoutCreating()" function. | 121     // we don't bother with a "...WithoutCreating()" function. | 
| 121     profiles[i]->GetWebKitContext()->PurgeMemory(); | 122     BrowserContext::GetWebKitContext(profiles[i])->PurgeMemory(); | 
| 122   } | 123   } | 
| 123 | 124 | 
| 124   BrowserThread::PostTask( | 125   BrowserThread::PostTask( | 
| 125       BrowserThread::IO, FROM_HERE, | 126       BrowserThread::IO, FROM_HERE, | 
| 126       base::Bind(&PurgeMemoryIOHelper::PurgeMemoryOnIOThread, | 127       base::Bind(&PurgeMemoryIOHelper::PurgeMemoryOnIOThread, | 
| 127                  purge_memory_io_helper.get())); | 128                  purge_memory_io_helper.get())); | 
| 128 | 129 | 
| 129   // TODO(pkasting): | 130   // TODO(pkasting): | 
| 130   // * Purge AppCache memory.  Not yet implemented sufficiently. | 131   // * Purge AppCache memory.  Not yet implemented sufficiently. | 
| 131   // * Browser-side DatabaseTracker.  Not implemented sufficiently. | 132   // * Browser-side DatabaseTracker.  Not implemented sufficiently. | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
| 151           content::RenderProcessHost::AllHostsIterator()); | 152           content::RenderProcessHost::AllHostsIterator()); | 
| 152        !i.IsAtEnd(); i.Advance()) | 153        !i.IsAtEnd(); i.Advance()) | 
| 153     PurgeRendererForHost(i.GetCurrentValue()); | 154     PurgeRendererForHost(i.GetCurrentValue()); | 
| 154 } | 155 } | 
| 155 | 156 | 
| 156 // static | 157 // static | 
| 157 void MemoryPurger::PurgeRendererForHost(content::RenderProcessHost* host) { | 158 void MemoryPurger::PurgeRendererForHost(content::RenderProcessHost* host) { | 
| 158   // Direct the renderer to free everything it can. | 159   // Direct the renderer to free everything it can. | 
| 159   host->Send(new ChromeViewMsg_PurgeMemory()); | 160   host->Send(new ChromeViewMsg_PurgeMemory()); | 
| 160 } | 161 } | 
| OLD | NEW | 
|---|