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
3 // found in the LICENSE file.
5 #include "chrome/browser/task_manager/task_manager.h"
7 #include "base/compiler_specific.h"
8 #include "base/prefs/pref_service.h"
9 #include "base/prefs/scoped_user_pref_update.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/app/chrome_command_ids.h"
12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_list.h"
15 #include "chrome/browser/ui/browser_window.h"
16 #include "chrome/browser/ui/host_desktop.h"
17 #include "chrome/browser/ui/views/browser_dialogs.h"
18 #include "chrome/browser/ui/views/new_task_manager_view.h"
19 #include "chrome/common/chrome_switches.h"
20 #include "chrome/common/pref_names.h"
21 #include "chrome/grit/chromium_strings.h"
22 #include "chrome/grit/generated_resources.h"
23 #include "ui/base/accelerators/accelerator.h"
24 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/base/models/simple_menu_model.h"
26 #include "ui/base/models/table_model.h"
27 #include "ui/base/models/table_model_observer.h"
28 #include "ui/events/event_constants.h"
29 #include "ui/events/keycodes/keyboard_codes.h"
30 #include "ui/gfx/canvas.h"
31 #include "ui/views/context_menu_controller.h"
32 #include "ui/views/controls/button/label_button.h"
33 #include "ui/views/controls/link.h"
34 #include "ui/views/controls/link_listener.h"
35 #include "ui/views/controls/menu/menu_runner.h"
36 #include "ui/views/controls/table/table_grouper.h"
37 #include "ui/views/controls/table/table_view.h"
38 #include "ui/views/controls/table/table_view_observer.h"
39 #include "ui/views/layout/layout_constants.h"
40 #include "ui/views/widget/widget.h"
41 #include "ui/views/window/dialog_delegate.h"
44 #include "ash/shelf/shelf_util.h"
45 #include "ash/wm/window_util.h"
46 #include "grit/ash_resources.h"
50 #include "chrome/browser/shell_integration.h"
51 #include "ui/base/win/shell.h"
52 #include "ui/views/win/hwnd_util.h"
57 ////////////////////////////////////////////////////////////////////////////////
58 // TaskManagerTableModel class
59 ////////////////////////////////////////////////////////////////////////////////
61 class TaskManagerTableModel
62 : public ui::TableModel
,
63 public views::TableGrouper
,
64 public TaskManagerModelObserver
{
66 explicit TaskManagerTableModel(TaskManagerModel
* model
)
69 model_
->AddObserver(this);
72 ~TaskManagerTableModel() override
{ model_
->RemoveObserver(this); }
74 // TableModel overrides:
75 int RowCount() override
;
76 base::string16
GetText(int row
, int column
) override
;
77 gfx::ImageSkia
GetIcon(int row
) override
;
78 void SetObserver(ui::TableModelObserver
* observer
) override
;
79 int CompareValues(int row1
, int row2
, int column_id
) override
;
81 // TableGrouper overrides:
82 void GetGroupRange(int model_index
, views::GroupRange
* range
) override
;
84 // TaskManagerModelObserver overrides:
85 void OnModelChanged() override
;
86 void OnItemsChanged(int start
, int length
) override
;
87 void OnItemsAdded(int start
, int length
) override
;
88 void OnItemsRemoved(int start
, int length
) override
;
91 TaskManagerModel
* model_
;
92 ui::TableModelObserver
* observer_
;
94 DISALLOW_COPY_AND_ASSIGN(TaskManagerTableModel
);
97 int TaskManagerTableModel::RowCount() {
98 return model_
->ResourceCount();
101 base::string16
TaskManagerTableModel::GetText(int row
, int col_id
) {
102 return model_
->GetResourceById(row
, col_id
);
105 gfx::ImageSkia
TaskManagerTableModel::GetIcon(int row
) {
106 return model_
->GetResourceIcon(row
);
109 void TaskManagerTableModel::SetObserver(ui::TableModelObserver
* observer
) {
110 observer_
= observer
;
113 int TaskManagerTableModel::CompareValues(int row1
, int row2
, int column_id
) {
114 return model_
->CompareValues(row1
, row2
, column_id
);
117 void TaskManagerTableModel::GetGroupRange(int model_index
,
118 views::GroupRange
* range
) {
119 TaskManagerModel::GroupRange range_pair
=
120 model_
->GetGroupRangeForResource(model_index
);
121 range
->start
= range_pair
.first
;
122 range
->length
= range_pair
.second
;
125 void TaskManagerTableModel::OnModelChanged() {
127 observer_
->OnModelChanged();
130 void TaskManagerTableModel::OnItemsChanged(int start
, int length
) {
132 observer_
->OnItemsChanged(start
, length
);
135 void TaskManagerTableModel::OnItemsAdded(int start
, int length
) {
137 observer_
->OnItemsAdded(start
, length
);
140 void TaskManagerTableModel::OnItemsRemoved(int start
, int length
) {
142 observer_
->OnItemsRemoved(start
, length
);
145 // The Task Manager UI container.
146 class TaskManagerView
: public views::ButtonListener
,
147 public views::DialogDelegateView
,
148 public views::TableViewObserver
,
149 public views::LinkListener
,
150 public views::ContextMenuController
,
151 public ui::SimpleMenuModel::Delegate
{
153 explicit TaskManagerView(chrome::HostDesktopType desktop_type
);
154 ~TaskManagerView() override
;
156 // Shows the Task Manager window, or re-activates an existing one.
157 static void Show(Browser
* browser
);
159 // Hides the Task Manager if it is showing.
163 void Layout() override
;
164 gfx::Size
GetPreferredSize() const override
;
165 bool AcceleratorPressed(const ui::Accelerator
& accelerator
) override
;
166 void ViewHierarchyChanged(
167 const ViewHierarchyChangedDetails
& details
) override
;
169 // views::ButtonListener:
170 void ButtonPressed(views::Button
* sender
, const ui::Event
& event
) override
;
172 // views::DialogDelegateView:
173 bool CanResize() const override
;
174 bool CanMaximize() const override
;
175 bool CanMinimize() const override
;
176 bool ExecuteWindowsCommand(int command_id
) override
;
177 base::string16
GetWindowTitle() const override
;
178 std::string
GetWindowName() const override
;
179 int GetDialogButtons() const override
;
180 void WindowClosing() override
;
181 bool UseNewStyleForThisDialog() const override
;
183 // views::TableViewObserver:
184 void OnSelectionChanged() override
;
185 void OnDoubleClick() override
;
186 void OnKeyDown(ui::KeyboardCode keycode
) override
;
188 // views::LinkListener:
189 void LinkClicked(views::Link
* source
, int event_flags
) override
;
191 // views::ContextMenuController:
192 void ShowContextMenuForView(views::View
* source
,
193 const gfx::Point
& point
,
194 ui::MenuSourceType source_type
) override
;
196 // ui::SimpleMenuModel::Delegate:
197 bool IsCommandIdChecked(int id
) const override
;
198 bool IsCommandIdEnabled(int id
) const override
;
199 bool GetAcceleratorForCommandId(int command_id
,
200 ui::Accelerator
* accelerator
) override
;
201 void ExecuteCommand(int id
, int event_flags
) override
;
204 // Creates the child controls.
207 // Initializes the state of the always-on-top setting as the window is shown.
208 void InitAlwaysOnTopState();
210 // Activates the tab associated with the focused row.
211 void ActivateFocusedTab();
213 // Restores saved always on top state from a previous session.
214 bool GetSavedAlwaysOnTopState(bool* always_on_top
) const;
216 views::LabelButton
* kill_button_
;
217 views::Link
* about_memory_link_
;
218 views::TableView
* tab_table_
;
219 views::View
* tab_table_parent_
;
221 TaskManager
* task_manager_
;
223 TaskManagerModel
* model_
;
225 // all possible columns, not necessarily visible
226 std::vector
<ui::TableColumn
> columns_
;
228 scoped_ptr
<TaskManagerTableModel
> table_model_
;
230 // True when the Task Manager window should be shown on top of other windows.
231 bool is_always_on_top_
;
233 // The host desktop type this task manager belongs to.
234 const chrome::HostDesktopType desktop_type_
;
236 // We need to own the text of the menu, the Windows API does not copy it.
237 base::string16 always_on_top_menu_text_
;
239 // An open Task manager window. There can only be one open at a time. This
240 // is reset to NULL when the window is closed.
241 static TaskManagerView
* instance_
;
243 scoped_ptr
<views::MenuRunner
> menu_runner_
;
245 DISALLOW_COPY_AND_ASSIGN(TaskManagerView
);
249 TaskManagerView
* TaskManagerView::instance_
= NULL
;
252 TaskManagerView::TaskManagerView(chrome::HostDesktopType desktop_type
)
253 : kill_button_(NULL
),
254 about_memory_link_(NULL
),
256 tab_table_parent_(NULL
),
257 task_manager_(TaskManager::GetInstance()),
258 model_(TaskManager::GetInstance()->model()),
259 is_always_on_top_(false),
260 desktop_type_(desktop_type
) {
264 TaskManagerView::~TaskManagerView() {
265 // Delete child views now, while our table model still exists.
266 RemoveAllChildViews(true);
269 void TaskManagerView::Init() {
270 table_model_
.reset(new TaskManagerTableModel(model_
));
272 // Page column has no header label.
273 columns_
.push_back(ui::TableColumn(IDS_TASK_MANAGER_TASK_COLUMN
,
274 ui::TableColumn::LEFT
, -1, 1));
275 columns_
.back().sortable
= true;
276 columns_
.push_back(ui::TableColumn(IDS_TASK_MANAGER_PROFILE_NAME_COLUMN
,
277 ui::TableColumn::LEFT
, -1, 0));
278 columns_
.back().sortable
= true;
279 columns_
.push_back(ui::TableColumn(IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN
,
280 ui::TableColumn::RIGHT
, -1, 0));
281 columns_
.back().sortable
= true;
282 columns_
.back().initial_sort_is_ascending
= false;
283 columns_
.push_back(ui::TableColumn(IDS_TASK_MANAGER_SHARED_MEM_COLUMN
,
284 ui::TableColumn::RIGHT
, -1, 0));
285 columns_
.back().sortable
= true;
286 columns_
.back().initial_sort_is_ascending
= false;
287 columns_
.push_back(ui::TableColumn(IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN
,
288 ui::TableColumn::RIGHT
, -1, 0));
289 columns_
.back().sortable
= true;
290 columns_
.back().initial_sort_is_ascending
= false;
291 columns_
.push_back(ui::TableColumn(IDS_TASK_MANAGER_CPU_COLUMN
,
292 ui::TableColumn::RIGHT
, -1, 0));
293 columns_
.back().sortable
= true;
294 columns_
.back().initial_sort_is_ascending
= false;
295 columns_
.push_back(ui::TableColumn(IDS_TASK_MANAGER_NET_COLUMN
,
296 ui::TableColumn::RIGHT
, -1, 0));
297 columns_
.back().sortable
= true;
298 columns_
.back().initial_sort_is_ascending
= false;
299 columns_
.push_back(ui::TableColumn(IDS_TASK_MANAGER_PROCESS_ID_COLUMN
,
300 ui::TableColumn::RIGHT
, -1, 0));
301 columns_
.back().sortable
= true;
303 columns_
.push_back(ui::TableColumn(IDS_TASK_MANAGER_GDI_HANDLES_COLUMN
,
304 ui::TableColumn::RIGHT
, -1, 0));
305 columns_
.back().sortable
= true;
306 columns_
.back().initial_sort_is_ascending
= false;
307 columns_
.push_back(ui::TableColumn(IDS_TASK_MANAGER_USER_HANDLES_COLUMN
,
308 ui::TableColumn::RIGHT
, -1, 0));
309 columns_
.back().sortable
= true;
310 columns_
.back().initial_sort_is_ascending
= false;
312 columns_
.push_back(ui::TableColumn(
313 IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN
,
314 ui::TableColumn::RIGHT
, -1, 0));
315 columns_
.back().sortable
= true;
316 columns_
.back().initial_sort_is_ascending
= false;
317 columns_
.push_back(ui::TableColumn(
318 IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN
,
319 ui::TableColumn::RIGHT
, -1, 0));
320 columns_
.back().sortable
= true;
321 columns_
.back().initial_sort_is_ascending
= false;
322 columns_
.push_back(ui::TableColumn(IDS_TASK_MANAGER_WEBCORE_CSS_CACHE_COLUMN
,
323 ui::TableColumn::RIGHT
, -1, 0));
324 columns_
.back().sortable
= true;
325 columns_
.back().initial_sort_is_ascending
= false;
326 columns_
.push_back(ui::TableColumn(IDS_TASK_MANAGER_VIDEO_MEMORY_COLUMN
,
327 ui::TableColumn::RIGHT
, -1, 0));
328 columns_
.back().sortable
= true;
329 columns_
.back().initial_sort_is_ascending
= false;
330 columns_
.push_back(ui::TableColumn(IDS_TASK_MANAGER_SQLITE_MEMORY_USED_COLUMN
,
331 ui::TableColumn::RIGHT
, -1, 0));
332 columns_
.back().sortable
= true;
333 columns_
.back().initial_sort_is_ascending
= false;
334 columns_
.push_back(ui::TableColumn(
335 IDS_TASK_MANAGER_NACL_DEBUG_STUB_PORT_COLUMN
,
336 ui::TableColumn::RIGHT
, -1, 0));
337 columns_
.back().sortable
= true;
339 ui::TableColumn(IDS_TASK_MANAGER_JAVASCRIPT_MEMORY_ALLOCATED_COLUMN
,
340 ui::TableColumn::RIGHT
, -1, 0));
341 columns_
.back().sortable
= true;
342 columns_
.back().initial_sort_is_ascending
= false;
343 // TODO(port) http://crbug.com/120488 for non-Linux.
344 #if defined(OS_LINUX)
345 columns_
.push_back(ui::TableColumn(IDS_TASK_MANAGER_IDLE_WAKEUPS_COLUMN
,
346 ui::TableColumn::RIGHT
, -1, 0));
347 columns_
.back().sortable
= true;
348 columns_
.back().initial_sort_is_ascending
= false;
351 tab_table_
= new views::TableView(
352 table_model_
.get(), columns_
, views::ICON_AND_TEXT
, false);
353 tab_table_
->SetGrouper(table_model_
.get());
355 // Hide some columns by default
356 tab_table_
->SetColumnVisibility(IDS_TASK_MANAGER_PROFILE_NAME_COLUMN
, false);
357 tab_table_
->SetColumnVisibility(IDS_TASK_MANAGER_SHARED_MEM_COLUMN
, false);
358 tab_table_
->SetColumnVisibility(IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN
, false);
359 tab_table_
->SetColumnVisibility(IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN
,
361 tab_table_
->SetColumnVisibility(IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN
,
363 tab_table_
->SetColumnVisibility(IDS_TASK_MANAGER_WEBCORE_CSS_CACHE_COLUMN
,
365 tab_table_
->SetColumnVisibility(IDS_TASK_MANAGER_VIDEO_MEMORY_COLUMN
,
367 tab_table_
->SetColumnVisibility(IDS_TASK_MANAGER_SQLITE_MEMORY_USED_COLUMN
,
369 tab_table_
->SetColumnVisibility(IDS_TASK_MANAGER_NACL_DEBUG_STUB_PORT_COLUMN
,
371 tab_table_
->SetColumnVisibility(
372 IDS_TASK_MANAGER_JAVASCRIPT_MEMORY_ALLOCATED_COLUMN
, false);
373 tab_table_
->SetColumnVisibility(IDS_TASK_MANAGER_GDI_HANDLES_COLUMN
, false);
374 tab_table_
->SetColumnVisibility(IDS_TASK_MANAGER_USER_HANDLES_COLUMN
, false);
375 tab_table_
->SetColumnVisibility(IDS_TASK_MANAGER_IDLE_WAKEUPS_COLUMN
, false);
377 tab_table_
->SetObserver(this);
378 tab_table_
->set_context_menu_controller(this);
379 set_context_menu_controller(this);
380 kill_button_
= new views::LabelButton(this,
381 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_KILL
));
382 kill_button_
->SetStyle(views::Button::STYLE_BUTTON
);
383 about_memory_link_
= new views::Link(
384 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_ABOUT_MEMORY_LINK
));
385 about_memory_link_
->set_listener(this);
387 // Makes sure our state is consistent.
388 OnSelectionChanged();
390 ui::Accelerator
ctrl_w(ui::VKEY_W
, ui::EF_CONTROL_DOWN
);
391 AddAccelerator(ctrl_w
);
394 void TaskManagerView::ViewHierarchyChanged(
395 const ViewHierarchyChangedDetails
& details
) {
396 views::DialogDelegateView::ViewHierarchyChanged(details
);
397 // Since we want the Kill button and the Memory Details link to show up in
398 // the same visual row as the close button, which is provided by the
399 // framework, we must add the buttons to the non-client view, which is the
400 // parent of this view. Similarly, when we're removed from the view
401 // hierarchy, we must take care to clean up those items as well.
402 if (details
.child
== this) {
403 if (details
.is_add
) {
404 details
.parent
->AddChildView(about_memory_link_
);
405 details
.parent
->AddChildView(kill_button_
);
406 tab_table_parent_
= tab_table_
->CreateParentIfNecessary();
407 AddChildView(tab_table_parent_
);
409 details
.parent
->RemoveChildView(kill_button_
);
410 details
.parent
->RemoveChildView(about_memory_link_
);
415 void TaskManagerView::Layout() {
416 gfx::Size size
= kill_button_
->GetPreferredSize();
417 gfx::Rect parent_bounds
= parent()->GetContentsBounds();
418 const int horizontal_margin
= views::kPanelHorizMargin
;
419 const int vertical_margin
= views::kButtonVEdgeMargin
;
420 int x
= width() - size
.width() - horizontal_margin
;
421 int y_buttons
= parent_bounds
.bottom() - size
.height() - vertical_margin
;
422 kill_button_
->SetBounds(x
, y_buttons
, size
.width(), size
.height());
424 size
= about_memory_link_
->GetPreferredSize();
425 about_memory_link_
->SetBounds(
427 y_buttons
+ (kill_button_
->height() - size
.height()) / 2,
428 size
.width(), size
.height());
430 gfx::Rect rect
= GetLocalBounds();
431 rect
.Inset(horizontal_margin
, views::kPanelVertMargin
);
433 kill_button_
->height() + views::kUnrelatedControlVerticalSpacing
);
434 tab_table_parent_
->SetBoundsRect(rect
);
437 gfx::Size
TaskManagerView::GetPreferredSize() const {
438 return gfx::Size(460, 270);
441 bool TaskManagerView::AcceleratorPressed(const ui::Accelerator
& accelerator
) {
442 DCHECK_EQ(ui::VKEY_W
, accelerator
.key_code());
443 DCHECK_EQ(ui::EF_CONTROL_DOWN
, accelerator
.modifiers());
444 GetWidget()->Close();
449 void TaskManagerView::Show(Browser
* browser
) {
450 // In ash we can come here through the ChromeShellDelegate. If there is no
451 // browser window at that time of the call, browser could be passed as NULL.
452 const chrome::HostDesktopType desktop_type
=
453 browser
? browser
->host_desktop_type() : chrome::HOST_DESKTOP_TYPE_ASH
;
456 // If there's a Task manager window open already, just activate it.
457 instance_
->GetWidget()->Activate();
460 instance_
= new TaskManagerView(desktop_type
);
461 gfx::NativeWindow window
=
462 browser
? browser
->window()->GetNativeWindow() : NULL
;
465 window
= ash::wm::GetActiveWindow();
467 DialogDelegate::CreateDialogWidget(instance_
, window
, NULL
);
468 instance_
->InitAlwaysOnTopState();
469 instance_
->model_
->StartUpdating();
471 // Set the app id for the task manager to the app id of its parent browser. If
472 // no parent is specified, the app id will default to that of the initial
475 ui::win::SetAppIdForWindow(
476 ShellIntegration::GetChromiumModelIdForProfile(
477 browser
->profile()->GetPath()),
478 views::HWNDForWidget(instance_
->GetWidget()));
481 instance_
->GetWidget()->Show();
483 // Set the initial focus to the list of tasks.
484 views::FocusManager
* focus_manager
= instance_
->GetFocusManager();
486 focus_manager
->SetFocusedView(instance_
->tab_table_
);
489 gfx::NativeWindow native_window
= instance_
->GetWidget()->GetNativeWindow();
490 ash::SetShelfItemDetailsForDialogWindow(
491 native_window
, IDR_ASH_SHELF_ICON_TASK_MANAGER
, native_window
->title());
496 void TaskManagerView::Hide() {
498 instance_
->GetWidget()->Close();
501 // ButtonListener implementation.
502 void TaskManagerView::ButtonPressed(
503 views::Button
* sender
,
504 const ui::Event
& event
) {
505 typedef ui::ListSelectionModel::SelectedIndices SelectedIndices
;
506 DCHECK_EQ(kill_button_
, sender
);
507 SelectedIndices
selection(tab_table_
->selection_model().selected_indices());
508 for (SelectedIndices::const_reverse_iterator i
= selection
.rbegin();
509 i
!= selection
.rend(); ++i
) {
510 task_manager_
->KillProcess(*i
);
514 // DialogDelegate implementation.
515 bool TaskManagerView::CanResize() const {
519 bool TaskManagerView::CanMaximize() const {
523 bool TaskManagerView::CanMinimize() const {
527 bool TaskManagerView::ExecuteWindowsCommand(int command_id
) {
531 base::string16
TaskManagerView::GetWindowTitle() const {
532 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_TITLE
);
535 std::string
TaskManagerView::GetWindowName() const {
536 return prefs::kTaskManagerWindowPlacement
;
539 int TaskManagerView::GetDialogButtons() const {
540 return ui::DIALOG_BUTTON_NONE
;
543 void TaskManagerView::WindowClosing() {
544 // Now that the window is closed, we can allow a new one to be opened.
545 // (WindowClosing comes in asynchronously from the call to Close() and we
546 // may have already opened a new instance).
547 if (instance_
== this)
549 task_manager_
->OnWindowClosed();
552 bool TaskManagerView::UseNewStyleForThisDialog() const {
556 // views::TableViewObserver implementation.
557 void TaskManagerView::OnSelectionChanged() {
558 const ui::ListSelectionModel::SelectedIndices
& selection(
559 tab_table_
->selection_model().selected_indices());
560 bool selection_contains_browser_process
= false;
561 for (size_t i
= 0; i
< selection
.size(); ++i
) {
562 if (task_manager_
->IsBrowserProcess(selection
[i
])) {
563 selection_contains_browser_process
= true;
567 kill_button_
->SetEnabled(!selection_contains_browser_process
&&
571 void TaskManagerView::OnDoubleClick() {
572 ActivateFocusedTab();
575 void TaskManagerView::OnKeyDown(ui::KeyboardCode keycode
) {
576 if (keycode
== ui::VKEY_RETURN
)
577 ActivateFocusedTab();
580 void TaskManagerView::LinkClicked(views::Link
* source
, int event_flags
) {
581 DCHECK_EQ(about_memory_link_
, source
);
582 task_manager_
->OpenAboutMemory(desktop_type_
);
585 void TaskManagerView::ShowContextMenuForView(views::View
* source
,
586 const gfx::Point
& point
,
587 ui::MenuSourceType source_type
) {
588 ui::SimpleMenuModel
menu_model(this);
589 for (std::vector
<ui::TableColumn
>::iterator
i(columns_
.begin());
590 i
!= columns_
.end(); ++i
) {
591 menu_model
.AddCheckItem(i
->id
, l10n_util::GetStringUTF16(i
->id
));
594 new views::MenuRunner(&menu_model
, views::MenuRunner::CONTEXT_MENU
));
595 if (menu_runner_
->RunMenuAt(GetWidget(),
597 gfx::Rect(point
, gfx::Size()),
598 views::MENU_ANCHOR_TOPLEFT
,
599 source_type
) == views::MenuRunner::MENU_DELETED
) {
604 bool TaskManagerView::IsCommandIdChecked(int id
) const {
605 return tab_table_
->IsColumnVisible(id
);
608 bool TaskManagerView::IsCommandIdEnabled(int id
) const {
612 bool TaskManagerView::GetAcceleratorForCommandId(
614 ui::Accelerator
* accelerator
) {
618 void TaskManagerView::ExecuteCommand(int id
, int event_flags
) {
619 tab_table_
->SetColumnVisibility(id
, !tab_table_
->IsColumnVisible(id
));
622 void TaskManagerView::InitAlwaysOnTopState() {
623 is_always_on_top_
= false;
624 if (GetSavedAlwaysOnTopState(&is_always_on_top_
))
625 GetWidget()->SetAlwaysOnTop(is_always_on_top_
);
628 void TaskManagerView::ActivateFocusedTab() {
629 const int active_row
= tab_table_
->selection_model().active();
630 if (active_row
!= -1)
631 task_manager_
->ActivateProcess(active_row
);
634 bool TaskManagerView::GetSavedAlwaysOnTopState(bool* always_on_top
) const {
635 if (!g_browser_process
->local_state())
638 const base::DictionaryValue
* dictionary
=
639 g_browser_process
->local_state()->GetDictionary(GetWindowName());
641 dictionary
->GetBoolean("always_on_top", always_on_top
) && always_on_top
;
648 // Declared in browser_dialogs.h so others don't need to depend on our header.
649 void ShowTaskManager(Browser
* browser
) {
650 if (switches::NewTaskManagerEnabled()) {
651 task_management::NewTaskManagerView::Show(browser
);
655 TaskManagerView::Show(browser
);
658 void HideTaskManager() {
659 if (switches::NewTaskManagerEnabled()) {
660 task_management::NewTaskManagerView::Hide();
664 TaskManagerView::Hide();
667 } // namespace chrome