Add ENABLE_MEDIA_ROUTER define to builds other than Android and iOS.
[chromium-blink-merge.git] / chrome / browser / ui / views / task_manager_view.cc
blobbdfe4f8d6c52317ecd8ba3e09a65da1f0a9cc93e
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/common/pref_names.h"
19 #include "chrome/grit/chromium_strings.h"
20 #include "chrome/grit/generated_resources.h"
21 #include "ui/base/accelerators/accelerator.h"
22 #include "ui/base/l10n/l10n_util.h"
23 #include "ui/base/models/simple_menu_model.h"
24 #include "ui/base/models/table_model.h"
25 #include "ui/base/models/table_model_observer.h"
26 #include "ui/events/event_constants.h"
27 #include "ui/events/keycodes/keyboard_codes.h"
28 #include "ui/gfx/canvas.h"
29 #include "ui/views/context_menu_controller.h"
30 #include "ui/views/controls/button/label_button.h"
31 #include "ui/views/controls/link.h"
32 #include "ui/views/controls/link_listener.h"
33 #include "ui/views/controls/menu/menu_runner.h"
34 #include "ui/views/controls/table/table_grouper.h"
35 #include "ui/views/controls/table/table_view.h"
36 #include "ui/views/controls/table/table_view_observer.h"
37 #include "ui/views/layout/layout_constants.h"
38 #include "ui/views/widget/widget.h"
39 #include "ui/views/window/dialog_delegate.h"
41 #if defined(USE_ASH)
42 #include "ash/shelf/shelf_util.h"
43 #include "ash/wm/window_util.h"
44 #include "grit/ash_resources.h"
45 #endif
47 #if defined(OS_WIN)
48 #include "chrome/browser/shell_integration.h"
49 #include "ui/base/win/shell.h"
50 #include "ui/views/win/hwnd_util.h"
51 #endif
53 namespace {
55 ////////////////////////////////////////////////////////////////////////////////
56 // TaskManagerTableModel class
57 ////////////////////////////////////////////////////////////////////////////////
59 class TaskManagerTableModel
60 : public ui::TableModel,
61 public views::TableGrouper,
62 public TaskManagerModelObserver {
63 public:
64 explicit TaskManagerTableModel(TaskManagerModel* model)
65 : model_(model),
66 observer_(NULL) {
67 model_->AddObserver(this);
70 ~TaskManagerTableModel() override { model_->RemoveObserver(this); }
72 // TableModel overrides:
73 int RowCount() override;
74 base::string16 GetText(int row, int column) override;
75 gfx::ImageSkia GetIcon(int row) override;
76 void SetObserver(ui::TableModelObserver* observer) override;
77 int CompareValues(int row1, int row2, int column_id) override;
79 // TableGrouper overrides:
80 void GetGroupRange(int model_index, views::GroupRange* range) override;
82 // TaskManagerModelObserver overrides:
83 void OnModelChanged() override;
84 void OnItemsChanged(int start, int length) override;
85 void OnItemsAdded(int start, int length) override;
86 void OnItemsRemoved(int start, int length) override;
88 private:
89 TaskManagerModel* model_;
90 ui::TableModelObserver* observer_;
92 DISALLOW_COPY_AND_ASSIGN(TaskManagerTableModel);
95 int TaskManagerTableModel::RowCount() {
96 return model_->ResourceCount();
99 base::string16 TaskManagerTableModel::GetText(int row, int col_id) {
100 return model_->GetResourceById(row, col_id);
103 gfx::ImageSkia TaskManagerTableModel::GetIcon(int row) {
104 return model_->GetResourceIcon(row);
107 void TaskManagerTableModel::SetObserver(ui::TableModelObserver* observer) {
108 observer_ = observer;
111 int TaskManagerTableModel::CompareValues(int row1, int row2, int column_id) {
112 return model_->CompareValues(row1, row2, column_id);
115 void TaskManagerTableModel::GetGroupRange(int model_index,
116 views::GroupRange* range) {
117 TaskManagerModel::GroupRange range_pair =
118 model_->GetGroupRangeForResource(model_index);
119 range->start = range_pair.first;
120 range->length = range_pair.second;
123 void TaskManagerTableModel::OnModelChanged() {
124 if (observer_)
125 observer_->OnModelChanged();
128 void TaskManagerTableModel::OnItemsChanged(int start, int length) {
129 if (observer_)
130 observer_->OnItemsChanged(start, length);
133 void TaskManagerTableModel::OnItemsAdded(int start, int length) {
134 if (observer_)
135 observer_->OnItemsAdded(start, length);
138 void TaskManagerTableModel::OnItemsRemoved(int start, int length) {
139 if (observer_)
140 observer_->OnItemsRemoved(start, length);
143 // The Task Manager UI container.
144 class TaskManagerView : public views::ButtonListener,
145 public views::DialogDelegateView,
146 public views::TableViewObserver,
147 public views::LinkListener,
148 public views::ContextMenuController,
149 public ui::SimpleMenuModel::Delegate {
150 public:
151 explicit TaskManagerView(chrome::HostDesktopType desktop_type);
152 ~TaskManagerView() override;
154 // Shows the Task Manager window, or re-activates an existing one.
155 static void Show(Browser* browser);
157 // Hides the Task Manager if it is showing.
158 static void Hide();
160 // views::View:
161 void Layout() override;
162 gfx::Size GetPreferredSize() const override;
163 bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
164 void ViewHierarchyChanged(
165 const ViewHierarchyChangedDetails& details) override;
167 // views::ButtonListener:
168 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
170 // views::DialogDelegateView:
171 bool CanResize() const override;
172 bool CanMaximize() const override;
173 bool CanMinimize() const override;
174 bool ExecuteWindowsCommand(int command_id) override;
175 base::string16 GetWindowTitle() const override;
176 std::string GetWindowName() const override;
177 int GetDialogButtons() const override;
178 void WindowClosing() override;
179 bool UseNewStyleForThisDialog() const override;
181 // views::TableViewObserver:
182 void OnSelectionChanged() override;
183 void OnDoubleClick() override;
184 void OnKeyDown(ui::KeyboardCode keycode) override;
186 // views::LinkListener:
187 void LinkClicked(views::Link* source, int event_flags) override;
189 // views::ContextMenuController:
190 void ShowContextMenuForView(views::View* source,
191 const gfx::Point& point,
192 ui::MenuSourceType source_type) override;
194 // ui::SimpleMenuModel::Delegate:
195 bool IsCommandIdChecked(int id) const override;
196 bool IsCommandIdEnabled(int id) const override;
197 bool GetAcceleratorForCommandId(int command_id,
198 ui::Accelerator* accelerator) override;
199 void ExecuteCommand(int id, int event_flags) override;
201 private:
202 // Creates the child controls.
203 void Init();
205 // Initializes the state of the always-on-top setting as the window is shown.
206 void InitAlwaysOnTopState();
208 // Activates the tab associated with the focused row.
209 void ActivateFocusedTab();
211 // Restores saved always on top state from a previous session.
212 bool GetSavedAlwaysOnTopState(bool* always_on_top) const;
214 views::LabelButton* kill_button_;
215 views::Link* about_memory_link_;
216 views::TableView* tab_table_;
217 views::View* tab_table_parent_;
219 TaskManager* task_manager_;
221 TaskManagerModel* model_;
223 // all possible columns, not necessarily visible
224 std::vector<ui::TableColumn> columns_;
226 scoped_ptr<TaskManagerTableModel> table_model_;
228 // True when the Task Manager window should be shown on top of other windows.
229 bool is_always_on_top_;
231 // The host desktop type this task manager belongs to.
232 const chrome::HostDesktopType desktop_type_;
234 // We need to own the text of the menu, the Windows API does not copy it.
235 base::string16 always_on_top_menu_text_;
237 // An open Task manager window. There can only be one open at a time. This
238 // is reset to NULL when the window is closed.
239 static TaskManagerView* instance_;
241 scoped_ptr<views::MenuRunner> menu_runner_;
243 DISALLOW_COPY_AND_ASSIGN(TaskManagerView);
246 // static
247 TaskManagerView* TaskManagerView::instance_ = NULL;
250 TaskManagerView::TaskManagerView(chrome::HostDesktopType desktop_type)
251 : kill_button_(NULL),
252 about_memory_link_(NULL),
253 tab_table_(NULL),
254 tab_table_parent_(NULL),
255 task_manager_(TaskManager::GetInstance()),
256 model_(TaskManager::GetInstance()->model()),
257 is_always_on_top_(false),
258 desktop_type_(desktop_type) {
259 Init();
262 TaskManagerView::~TaskManagerView() {
263 // Delete child views now, while our table model still exists.
264 RemoveAllChildViews(true);
267 void TaskManagerView::Init() {
268 table_model_.reset(new TaskManagerTableModel(model_));
270 // Page column has no header label.
271 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_TASK_COLUMN,
272 ui::TableColumn::LEFT, -1, 1));
273 columns_.back().sortable = true;
274 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_PROFILE_NAME_COLUMN,
275 ui::TableColumn::LEFT, -1, 0));
276 columns_.back().sortable = true;
277 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN,
278 ui::TableColumn::RIGHT, -1, 0));
279 columns_.back().sortable = true;
280 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_SHARED_MEM_COLUMN,
281 ui::TableColumn::RIGHT, -1, 0));
282 columns_.back().sortable = true;
283 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN,
284 ui::TableColumn::RIGHT, -1, 0));
285 columns_.back().sortable = true;
286 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_CPU_COLUMN,
287 ui::TableColumn::RIGHT, -1, 0));
288 columns_.back().sortable = true;
289 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_NET_COLUMN,
290 ui::TableColumn::RIGHT, -1, 0));
291 columns_.back().sortable = true;
292 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_PROCESS_ID_COLUMN,
293 ui::TableColumn::RIGHT, -1, 0));
294 columns_.back().sortable = true;
295 #if defined(OS_WIN)
296 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_GDI_HANDLES_COLUMN,
297 ui::TableColumn::RIGHT, -1, 0));
298 columns_.back().sortable = true;
299 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_USER_HANDLES_COLUMN,
300 ui::TableColumn::RIGHT, -1, 0));
301 columns_.back().sortable = true;
302 #endif
303 columns_.push_back(ui::TableColumn(
304 IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN,
305 ui::TableColumn::RIGHT, -1, 0));
306 columns_.back().sortable = true;
307 columns_.push_back(ui::TableColumn(
308 IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN,
309 ui::TableColumn::RIGHT, -1, 0));
310 columns_.back().sortable = true;
311 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_WEBCORE_CSS_CACHE_COLUMN,
312 ui::TableColumn::RIGHT, -1, 0));
313 columns_.back().sortable = true;
314 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_VIDEO_MEMORY_COLUMN,
315 ui::TableColumn::RIGHT, -1, 0));
316 columns_.back().sortable = true;
317 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_SQLITE_MEMORY_USED_COLUMN,
318 ui::TableColumn::RIGHT, -1, 0));
319 columns_.back().sortable = true;
320 columns_.push_back(ui::TableColumn(
321 IDS_TASK_MANAGER_NACL_DEBUG_STUB_PORT_COLUMN,
322 ui::TableColumn::RIGHT, -1, 0));
323 columns_.back().sortable = true;
324 columns_.push_back(
325 ui::TableColumn(IDS_TASK_MANAGER_JAVASCRIPT_MEMORY_ALLOCATED_COLUMN,
326 ui::TableColumn::RIGHT, -1, 0));
327 columns_.back().sortable = true;
328 // TODO(port) http://crbug.com/120488 for non-Linux.
329 #if defined(OS_LINUX)
330 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_IDLE_WAKEUPS_COLUMN,
331 ui::TableColumn::RIGHT, -1, 0));
332 columns_.back().sortable = true;
333 #endif
335 tab_table_ = new views::TableView(
336 table_model_.get(), columns_, views::ICON_AND_TEXT, false);
337 tab_table_->SetGrouper(table_model_.get());
339 // Hide some columns by default
340 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_PROFILE_NAME_COLUMN, false);
341 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_SHARED_MEM_COLUMN, false);
342 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN, false);
343 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN,
344 false);
345 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN,
346 false);
347 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_WEBCORE_CSS_CACHE_COLUMN,
348 false);
349 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_VIDEO_MEMORY_COLUMN,
350 false);
351 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_SQLITE_MEMORY_USED_COLUMN,
352 false);
353 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_NACL_DEBUG_STUB_PORT_COLUMN,
354 false);
355 tab_table_->SetColumnVisibility(
356 IDS_TASK_MANAGER_JAVASCRIPT_MEMORY_ALLOCATED_COLUMN, false);
357 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_GDI_HANDLES_COLUMN, false);
358 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_USER_HANDLES_COLUMN, false);
359 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_IDLE_WAKEUPS_COLUMN, false);
361 tab_table_->SetObserver(this);
362 tab_table_->set_context_menu_controller(this);
363 set_context_menu_controller(this);
364 kill_button_ = new views::LabelButton(this,
365 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_KILL));
366 kill_button_->SetStyle(views::Button::STYLE_BUTTON);
367 about_memory_link_ = new views::Link(
368 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_ABOUT_MEMORY_LINK));
369 about_memory_link_->set_listener(this);
371 // Makes sure our state is consistent.
372 OnSelectionChanged();
374 ui::Accelerator ctrl_w(ui::VKEY_W, ui::EF_CONTROL_DOWN);
375 AddAccelerator(ctrl_w);
378 void TaskManagerView::ViewHierarchyChanged(
379 const ViewHierarchyChangedDetails& details) {
380 views::DialogDelegateView::ViewHierarchyChanged(details);
381 // Since we want the Kill button and the Memory Details link to show up in
382 // the same visual row as the close button, which is provided by the
383 // framework, we must add the buttons to the non-client view, which is the
384 // parent of this view. Similarly, when we're removed from the view
385 // hierarchy, we must take care to clean up those items as well.
386 if (details.child == this) {
387 if (details.is_add) {
388 details.parent->AddChildView(about_memory_link_);
389 details.parent->AddChildView(kill_button_);
390 tab_table_parent_ = tab_table_->CreateParentIfNecessary();
391 AddChildView(tab_table_parent_);
392 } else {
393 details.parent->RemoveChildView(kill_button_);
394 details.parent->RemoveChildView(about_memory_link_);
399 void TaskManagerView::Layout() {
400 gfx::Size size = kill_button_->GetPreferredSize();
401 gfx::Rect parent_bounds = parent()->GetContentsBounds();
402 const int horizontal_margin = views::kPanelHorizMargin;
403 const int vertical_margin = views::kButtonVEdgeMargin;
404 int x = width() - size.width() - horizontal_margin;
405 int y_buttons = parent_bounds.bottom() - size.height() - vertical_margin;
406 kill_button_->SetBounds(x, y_buttons, size.width(), size.height());
408 size = about_memory_link_->GetPreferredSize();
409 about_memory_link_->SetBounds(
410 horizontal_margin,
411 y_buttons + (kill_button_->height() - size.height()) / 2,
412 size.width(), size.height());
414 gfx::Rect rect = GetLocalBounds();
415 rect.Inset(horizontal_margin, views::kPanelVertMargin);
416 rect.Inset(0, 0, 0,
417 kill_button_->height() + views::kUnrelatedControlVerticalSpacing);
418 tab_table_parent_->SetBoundsRect(rect);
421 gfx::Size TaskManagerView::GetPreferredSize() const {
422 return gfx::Size(460, 270);
425 bool TaskManagerView::AcceleratorPressed(const ui::Accelerator& accelerator) {
426 DCHECK_EQ(ui::VKEY_W, accelerator.key_code());
427 DCHECK_EQ(ui::EF_CONTROL_DOWN, accelerator.modifiers());
428 GetWidget()->Close();
429 return true;
432 // static
433 void TaskManagerView::Show(Browser* browser) {
434 // In ash we can come here through the ChromeShellDelegate. If there is no
435 // browser window at that time of the call, browser could be passed as NULL.
436 const chrome::HostDesktopType desktop_type =
437 browser ? browser->host_desktop_type() : chrome::HOST_DESKTOP_TYPE_ASH;
439 if (instance_) {
440 // If there's a Task manager window open already, just activate it.
441 instance_->GetWidget()->Activate();
442 return;
444 instance_ = new TaskManagerView(desktop_type);
445 gfx::NativeWindow window =
446 browser ? browser->window()->GetNativeWindow() : NULL;
447 #if defined(USE_ASH)
448 if (!window)
449 window = ash::wm::GetActiveWindow();
450 #endif
451 DialogDelegate::CreateDialogWidget(instance_, window, NULL);
452 instance_->InitAlwaysOnTopState();
453 instance_->model_->StartUpdating();
454 #if defined(OS_WIN)
455 // Set the app id for the task manager to the app id of its parent browser. If
456 // no parent is specified, the app id will default to that of the initial
457 // process.
458 if (browser) {
459 ui::win::SetAppIdForWindow(
460 ShellIntegration::GetChromiumModelIdForProfile(
461 browser->profile()->GetPath()),
462 views::HWNDForWidget(instance_->GetWidget()));
464 #endif
465 instance_->GetWidget()->Show();
467 // Set the initial focus to the list of tasks.
468 views::FocusManager* focus_manager = instance_->GetFocusManager();
469 if (focus_manager)
470 focus_manager->SetFocusedView(instance_->tab_table_);
472 #if defined(USE_ASH)
473 gfx::NativeWindow native_window = instance_->GetWidget()->GetNativeWindow();
474 ash::SetShelfItemDetailsForDialogWindow(
475 native_window, IDR_ASH_SHELF_ICON_TASK_MANAGER, native_window->title());
476 #endif
479 // static
480 void TaskManagerView::Hide() {
481 if (instance_)
482 instance_->GetWidget()->Close();
485 // ButtonListener implementation.
486 void TaskManagerView::ButtonPressed(
487 views::Button* sender,
488 const ui::Event& event) {
489 typedef ui::ListSelectionModel::SelectedIndices SelectedIndices;
490 DCHECK_EQ(kill_button_, sender);
491 SelectedIndices selection(tab_table_->selection_model().selected_indices());
492 for (SelectedIndices::const_reverse_iterator i = selection.rbegin();
493 i != selection.rend(); ++i) {
494 task_manager_->KillProcess(*i);
498 // DialogDelegate implementation.
499 bool TaskManagerView::CanResize() const {
500 return true;
503 bool TaskManagerView::CanMaximize() const {
504 return true;
507 bool TaskManagerView::CanMinimize() const {
508 return true;
511 bool TaskManagerView::ExecuteWindowsCommand(int command_id) {
512 return false;
515 base::string16 TaskManagerView::GetWindowTitle() const {
516 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_TITLE);
519 std::string TaskManagerView::GetWindowName() const {
520 return prefs::kTaskManagerWindowPlacement;
523 int TaskManagerView::GetDialogButtons() const {
524 return ui::DIALOG_BUTTON_NONE;
527 void TaskManagerView::WindowClosing() {
528 // Now that the window is closed, we can allow a new one to be opened.
529 // (WindowClosing comes in asynchronously from the call to Close() and we
530 // may have already opened a new instance).
531 if (instance_ == this)
532 instance_ = NULL;
533 task_manager_->OnWindowClosed();
536 bool TaskManagerView::UseNewStyleForThisDialog() const {
537 return false;
540 // views::TableViewObserver implementation.
541 void TaskManagerView::OnSelectionChanged() {
542 const ui::ListSelectionModel::SelectedIndices& selection(
543 tab_table_->selection_model().selected_indices());
544 bool selection_contains_browser_process = false;
545 for (size_t i = 0; i < selection.size(); ++i) {
546 if (task_manager_->IsBrowserProcess(selection[i])) {
547 selection_contains_browser_process = true;
548 break;
551 kill_button_->SetEnabled(!selection_contains_browser_process &&
552 !selection.empty());
555 void TaskManagerView::OnDoubleClick() {
556 ActivateFocusedTab();
559 void TaskManagerView::OnKeyDown(ui::KeyboardCode keycode) {
560 if (keycode == ui::VKEY_RETURN)
561 ActivateFocusedTab();
564 void TaskManagerView::LinkClicked(views::Link* source, int event_flags) {
565 DCHECK_EQ(about_memory_link_, source);
566 task_manager_->OpenAboutMemory(desktop_type_);
569 void TaskManagerView::ShowContextMenuForView(views::View* source,
570 const gfx::Point& point,
571 ui::MenuSourceType source_type) {
572 ui::SimpleMenuModel menu_model(this);
573 for (std::vector<ui::TableColumn>::iterator i(columns_.begin());
574 i != columns_.end(); ++i) {
575 menu_model.AddCheckItem(i->id, l10n_util::GetStringUTF16(i->id));
577 menu_runner_.reset(
578 new views::MenuRunner(&menu_model, views::MenuRunner::CONTEXT_MENU));
579 if (menu_runner_->RunMenuAt(GetWidget(),
580 NULL,
581 gfx::Rect(point, gfx::Size()),
582 views::MENU_ANCHOR_TOPLEFT,
583 source_type) == views::MenuRunner::MENU_DELETED) {
584 return;
588 bool TaskManagerView::IsCommandIdChecked(int id) const {
589 return tab_table_->IsColumnVisible(id);
592 bool TaskManagerView::IsCommandIdEnabled(int id) const {
593 return true;
596 bool TaskManagerView::GetAcceleratorForCommandId(
597 int command_id,
598 ui::Accelerator* accelerator) {
599 return false;
602 void TaskManagerView::ExecuteCommand(int id, int event_flags) {
603 tab_table_->SetColumnVisibility(id, !tab_table_->IsColumnVisible(id));
606 void TaskManagerView::InitAlwaysOnTopState() {
607 is_always_on_top_ = false;
608 if (GetSavedAlwaysOnTopState(&is_always_on_top_))
609 GetWidget()->SetAlwaysOnTop(is_always_on_top_);
612 void TaskManagerView::ActivateFocusedTab() {
613 const int active_row = tab_table_->selection_model().active();
614 if (active_row != -1)
615 task_manager_->ActivateProcess(active_row);
618 bool TaskManagerView::GetSavedAlwaysOnTopState(bool* always_on_top) const {
619 if (!g_browser_process->local_state())
620 return false;
622 const base::DictionaryValue* dictionary =
623 g_browser_process->local_state()->GetDictionary(GetWindowName().c_str());
624 return dictionary &&
625 dictionary->GetBoolean("always_on_top", always_on_top) && always_on_top;
628 } // namespace
630 namespace chrome {
632 // Declared in browser_dialogs.h so others don't need to depend on our header.
633 void ShowTaskManager(Browser* browser) {
634 TaskManagerView::Show(browser);
637 void HideTaskManager() {
638 TaskManagerView::Hide();
641 } // namespace chrome