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/allocator/allocator_extension.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/threading/thread.h" | 11 #include "base/threading/thread.h" |
12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/history/history.h" | 13 #include "chrome/browser/history/history.h" |
14 #include "chrome/browser/profiles/profile_manager.h" | 14 #include "chrome/browser/profiles/profile_manager.h" |
15 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 15 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
16 #include "chrome/browser/ui/browser_list.h" | 16 #include "chrome/browser/ui/browser_list.h" |
17 #include "chrome/browser/webdata/web_data_service.h" | 17 #include "chrome/browser/webdata/web_data_service.h" |
| 18 #include "chrome/browser/webdata/web_data_service_factory.h" |
18 #include "chrome/common/render_messages.h" | 19 #include "chrome/common/render_messages.h" |
19 #include "content/public/browser/render_process_host.h" | 20 #include "content/public/browser/render_process_host.h" |
20 #include "content/public/browser/render_widget_host.h" | 21 #include "content/public/browser/render_widget_host.h" |
21 #include "content/public/browser/resource_context.h" | 22 #include "content/public/browser/resource_context.h" |
22 #include "net/proxy/proxy_resolver.h" | 23 #include "net/proxy/proxy_resolver.h" |
23 #include "net/proxy/proxy_service.h" | 24 #include "net/proxy/proxy_service.h" |
24 #include "net/url_request/url_request_context.h" | 25 #include "net/url_request/url_request_context.h" |
25 #include "net/url_request/url_request_context_getter.h" | 26 #include "net/url_request/url_request_context_getter.h" |
26 | 27 |
27 using content::BrowserContext; | 28 using content::BrowserContext; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 | 108 |
108 // Unload all history backends (freeing memory used to cache sqlite). | 109 // Unload all history backends (freeing memory used to cache sqlite). |
109 // Spinning up the history service is expensive, so we avoid doing it if it | 110 // Spinning up the history service is expensive, so we avoid doing it if it |
110 // hasn't been done already. | 111 // hasn't been done already. |
111 HistoryService* history_service = | 112 HistoryService* history_service = |
112 profiles[i]->GetHistoryServiceWithoutCreating(); | 113 profiles[i]->GetHistoryServiceWithoutCreating(); |
113 if (history_service) | 114 if (history_service) |
114 history_service->UnloadBackend(); | 115 history_service->UnloadBackend(); |
115 | 116 |
116 // Unload all web databases (freeing memory used to cache sqlite). | 117 // Unload all web databases (freeing memory used to cache sqlite). |
117 WebDataService* web_data_service = | 118 scoped_refptr<WebDataService> web_data_service = |
118 profiles[i]->GetWebDataServiceWithoutCreating(); | 119 WebDataServiceFactory::GetForProfileIfExists( |
119 if (web_data_service) | 120 profiles[i], Profile::EXPLICIT_ACCESS); |
| 121 if (web_data_service.get()) |
120 web_data_service->UnloadDatabase(); | 122 web_data_service->UnloadDatabase(); |
121 | 123 |
122 BrowserContext::PurgeMemory(profiles[i]); | 124 BrowserContext::PurgeMemory(profiles[i]); |
123 } | 125 } |
124 | 126 |
125 BrowserThread::PostTask( | 127 BrowserThread::PostTask( |
126 BrowserThread::IO, FROM_HERE, | 128 BrowserThread::IO, FROM_HERE, |
127 base::Bind(&PurgeMemoryIOHelper::PurgeMemoryOnIOThread, | 129 base::Bind(&PurgeMemoryIOHelper::PurgeMemoryOnIOThread, |
128 purge_memory_io_helper.get())); | 130 purge_memory_io_helper.get())); |
129 | 131 |
(...skipping 20 matching lines...) Expand all Loading... |
150 content::RenderProcessHost::AllHostsIterator()); | 152 content::RenderProcessHost::AllHostsIterator()); |
151 !i.IsAtEnd(); i.Advance()) | 153 !i.IsAtEnd(); i.Advance()) |
152 PurgeRendererForHost(i.GetCurrentValue()); | 154 PurgeRendererForHost(i.GetCurrentValue()); |
153 } | 155 } |
154 | 156 |
155 // static | 157 // static |
156 void MemoryPurger::PurgeRendererForHost(content::RenderProcessHost* host) { | 158 void MemoryPurger::PurgeRendererForHost(content::RenderProcessHost* host) { |
157 // Direct the renderer to free everything it can. | 159 // Direct the renderer to free everything it can. |
158 host->Send(new ChromeViewMsg_PurgeMemory()); | 160 host->Send(new ChromeViewMsg_PurgeMemory()); |
159 } | 161 } |
OLD | NEW |