OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/chromeos/status/memory_menu_button.h" | 5 #include "chrome/browser/chromeos/status/memory_menu_button.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/process_util.h" // GetSystemMemoryInfo | 8 #include "base/process_util.h" // GetSystemMemoryInfo |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
11 #include "chrome/browser/chromeos/status/status_area_host.h" | 11 #include "chrome/browser/chromeos/status/status_area_host.h" |
12 #include "chrome/browser/memory_purger.h" | 12 #include "chrome/browser/memory_purger.h" |
13 #include "chrome/common/render_messages.h" | 13 #include "chrome/common/render_messages.h" |
14 #include "content/browser/renderer_host/render_process_host.h" | 14 #include "content/browser/renderer_host/render_process_host.h" |
15 #include "content/common/notification_service.h" | 15 #include "content/common/notification_service.h" |
16 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
17 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
| 18 #include "views/controls/menu/menu_runner.h" |
18 #include "views/widget/widget.h" | 19 #include "views/widget/widget.h" |
19 | 20 |
20 #if defined(USE_TCMALLOC) | 21 #if defined(USE_TCMALLOC) |
21 #include "third_party/tcmalloc/chromium/src/google/heap-profiler.h" | 22 #include "third_party/tcmalloc/chromium/src/google/heap-profiler.h" |
22 #endif | 23 #endif |
23 | 24 |
24 #if defined(USE_TCMALLOC) | 25 #if defined(USE_TCMALLOC) |
25 const char kProfileDumpFilePrefix[] = "/tmp/chrome_tcmalloc"; | 26 const char kProfileDumpFilePrefix[] = "/tmp/chrome_tcmalloc"; |
26 #endif | 27 #endif |
27 | 28 |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 int MemoryMenuButton::horizontal_padding() { | 205 int MemoryMenuButton::horizontal_padding() { |
205 return 3; | 206 return 3; |
206 } | 207 } |
207 | 208 |
208 // MemoryMenuButton, views::ViewMenuDelegate implementation: | 209 // MemoryMenuButton, views::ViewMenuDelegate implementation: |
209 | 210 |
210 void MemoryMenuButton::RunMenu(views::View* source, const gfx::Point& pt) { | 211 void MemoryMenuButton::RunMenu(views::View* source, const gfx::Point& pt) { |
211 // View passed in must be a views::MenuButton, i.e. the MemoryMenuButton. | 212 // View passed in must be a views::MenuButton, i.e. the MemoryMenuButton. |
212 DCHECK_EQ(source, this); | 213 DCHECK_EQ(source, this); |
213 | 214 |
214 EnsureMenu(); | 215 views::MenuRunner menu_runner(CreateMenu()); |
215 | |
216 gfx::Point screen_location; | 216 gfx::Point screen_location; |
217 views::View::ConvertPointToScreen(source, &screen_location); | 217 views::View::ConvertPointToScreen(source, &screen_location); |
218 gfx::Rect bounds(screen_location, source->size()); | 218 gfx::Rect bounds(screen_location, source->size()); |
219 menu_->RunMenuAt( | 219 if (menu_runner.RunMenuAt( |
220 source->GetWidget()->GetTopLevelWidget(), | 220 source->GetWidget()->GetTopLevelWidget(), this, bounds, |
221 this, | 221 views::MenuItemView::TOPRIGHT, views::MenuRunner::HAS_MNEMONICS) == |
222 bounds, | 222 views::MenuRunner::MENU_DELETED) |
223 views::MenuItemView::TOPRIGHT, | 223 return; |
224 true); | |
225 } | 224 } |
226 | 225 |
227 // MemoryMenuButton, views::View implementation: | 226 views::MenuItemView* MemoryMenuButton::CreateMenu() { |
228 | |
229 void MemoryMenuButton::EnsureMenu() { | |
230 // Just rebuild the menu each time to ensure the labels are up-to-date. | 227 // Just rebuild the menu each time to ensure the labels are up-to-date. |
231 menu_.reset(new views::MenuItemView(this)); | 228 views::MenuItemView* menu = new views::MenuItemView(this); |
232 // Text for these items will be set by GetLabel(). | 229 // Text for these items will be set by GetLabel(). |
233 menu_->AppendDelegateMenuItem(MEM_TOTAL_ITEM); | 230 menu->AppendDelegateMenuItem(MEM_TOTAL_ITEM); |
234 menu_->AppendDelegateMenuItem(MEM_FREE_ITEM); | 231 menu->AppendDelegateMenuItem(MEM_FREE_ITEM); |
235 menu_->AppendDelegateMenuItem(MEM_BUFFERS_ITEM); | 232 menu->AppendDelegateMenuItem(MEM_BUFFERS_ITEM); |
236 menu_->AppendDelegateMenuItem(MEM_CACHE_ITEM); | 233 menu->AppendDelegateMenuItem(MEM_CACHE_ITEM); |
237 menu_->AppendDelegateMenuItem(SHMEM_ITEM); | 234 menu->AppendDelegateMenuItem(SHMEM_ITEM); |
238 menu_->AppendSeparator(); | 235 menu->AppendSeparator(); |
239 menu_->AppendDelegateMenuItem(PURGE_MEMORY_ITEM); | 236 menu->AppendDelegateMenuItem(PURGE_MEMORY_ITEM); |
240 #if defined(USE_TCMALLOC) | 237 #if defined(USE_TCMALLOC) |
241 menu_->AppendSeparator(); | 238 menu->AppendSeparator(); |
242 menu_->AppendDelegateMenuItem(TOGGLE_PROFILING_ITEM); | 239 menu->AppendDelegateMenuItem(TOGGLE_PROFILING_ITEM); |
243 if (IsHeapProfilerRunning()) | 240 if (IsHeapProfilerRunning()) |
244 menu_->AppendDelegateMenuItem(DUMP_PROFILING_ITEM); | 241 menu->AppendDelegateMenuItem(DUMP_PROFILING_ITEM); |
245 #endif | 242 #endif |
| 243 return menu; |
246 } | 244 } |
247 | 245 |
248 ///////////////////////////////////////////////////////////////////////////// | 246 ///////////////////////////////////////////////////////////////////////////// |
249 // NotificationObserver overrides. | 247 // NotificationObserver overrides. |
250 | 248 |
251 void MemoryMenuButton::Observe(int type, | 249 void MemoryMenuButton::Observe(int type, |
252 const NotificationSource& source, | 250 const NotificationSource& source, |
253 const NotificationDetails& details) { | 251 const NotificationDetails& details) { |
254 switch (type) { | 252 switch (type) { |
255 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { | 253 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { |
256 RenderProcessHost::RendererClosedDetails* process_details = | 254 RenderProcessHost::RendererClosedDetails* process_details = |
257 Details<RenderProcessHost::RendererClosedDetails>(details).ptr(); | 255 Details<RenderProcessHost::RendererClosedDetails>(details).ptr(); |
258 if (process_details->status == | 256 if (process_details->status == |
259 base::TERMINATION_STATUS_PROCESS_WAS_KILLED) { | 257 base::TERMINATION_STATUS_PROCESS_WAS_KILLED) { |
260 renderer_kills_++; | 258 renderer_kills_++; |
261 // A kill is a very interesting event, so repaint immediately. | 259 // A kill is a very interesting event, so repaint immediately. |
262 UpdateText(); | 260 UpdateText(); |
263 } | 261 } |
264 break; | 262 break; |
265 } | 263 } |
266 default: | 264 default: |
267 NOTREACHED() << L"Received unexpected notification"; | 265 NOTREACHED() << L"Received unexpected notification"; |
268 break; | 266 break; |
269 } | 267 } |
270 } | 268 } |
271 | 269 |
272 } // namespace chromeos | 270 } // namespace chromeos |
OLD | NEW |