| 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/safe_browsing/safe_browsing_service.h" | 14 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 15 #include "chrome/browser/ui/browser_list.h" | 15 #include "chrome/browser/ui/browser_list.h" |
| 16 #include "chrome/browser/webdata/web_data_service.h" | 16 #include "chrome/browser/webdata/web_data_service.h" |
| 17 #include "chrome/browser/webdata/web_data_service_factory.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 #include "third_party/tcmalloc/chromium/src/gperftools/malloc_extension.h" |
| 26 | 27 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 | 102 |
| 102 // Unload all history backends (freeing memory used to cache sqlite). | 103 // Unload all history backends (freeing memory used to cache sqlite). |
| 103 // Spinning up the history service is expensive, so we avoid doing it if it | 104 // Spinning up the history service is expensive, so we avoid doing it if it |
| 104 // hasn't been done already. | 105 // hasn't been done already. |
| 105 HistoryService* history_service = | 106 HistoryService* history_service = |
| 106 profiles[i]->GetHistoryServiceWithoutCreating(); | 107 profiles[i]->GetHistoryServiceWithoutCreating(); |
| 107 if (history_service) | 108 if (history_service) |
| 108 history_service->UnloadBackend(); | 109 history_service->UnloadBackend(); |
| 109 | 110 |
| 110 // Unload all web databases (freeing memory used to cache sqlite). | 111 // Unload all web databases (freeing memory used to cache sqlite). |
| 111 WebDataService* web_data_service = | 112 scoped_refptr<WebDataService> web_data_service = |
| 112 profiles[i]->GetWebDataServiceWithoutCreating(); | 113 WebDataServiceFactory::GetForProfileIfExists( |
| 113 if (web_data_service) | 114 profiles[i], Profile::EXPLICIT_ACCESS); |
| 115 if (web_data_service.get()) |
| 114 web_data_service->UnloadDatabase(); | 116 web_data_service->UnloadDatabase(); |
| 115 | 117 |
| 116 BrowserContext::PurgeMemory(profiles[i]); | 118 BrowserContext::PurgeMemory(profiles[i]); |
| 117 } | 119 } |
| 118 | 120 |
| 119 BrowserThread::PostTask( | 121 BrowserThread::PostTask( |
| 120 BrowserThread::IO, FROM_HERE, | 122 BrowserThread::IO, FROM_HERE, |
| 121 base::Bind(&PurgeMemoryIOHelper::PurgeMemoryOnIOThread, | 123 base::Bind(&PurgeMemoryIOHelper::PurgeMemoryOnIOThread, |
| 122 purge_memory_io_helper.get())); | 124 purge_memory_io_helper.get())); |
| 123 | 125 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 146 content::RenderProcessHost::AllHostsIterator()); | 148 content::RenderProcessHost::AllHostsIterator()); |
| 147 !i.IsAtEnd(); i.Advance()) | 149 !i.IsAtEnd(); i.Advance()) |
| 148 PurgeRendererForHost(i.GetCurrentValue()); | 150 PurgeRendererForHost(i.GetCurrentValue()); |
| 149 } | 151 } |
| 150 | 152 |
| 151 // static | 153 // static |
| 152 void MemoryPurger::PurgeRendererForHost(content::RenderProcessHost* host) { | 154 void MemoryPurger::PurgeRendererForHost(content::RenderProcessHost* host) { |
| 153 // Direct the renderer to free everything it can. | 155 // Direct the renderer to free everything it can. |
| 154 host->Send(new ChromeViewMsg_PurgeMemory()); | 156 host->Send(new ChromeViewMsg_PurgeMemory()); |
| 155 } | 157 } |
| OLD | NEW |