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/task_manager/task_manager.h" | 5 #include "chrome/browser/task_manager/task_manager.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/metrics/stats_table.h" | 9 #include "base/metrics/stats_table.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
23 #include "grit/chromium_strings.h" | 23 #include "grit/chromium_strings.h" |
24 #include "grit/generated_resources.h" | 24 #include "grit/generated_resources.h" |
25 #include "grit/theme_resources.h" | 25 #include "grit/theme_resources.h" |
26 #include "ui/base/accelerators/accelerator.h" | 26 #include "ui/base/accelerators/accelerator.h" |
27 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
28 #include "ui/base/models/simple_menu_model.h" | 28 #include "ui/base/models/simple_menu_model.h" |
29 #include "ui/base/models/table_model.h" | 29 #include "ui/base/models/table_model.h" |
30 #include "ui/base/models/table_model_observer.h" | 30 #include "ui/base/models/table_model_observer.h" |
31 #include "ui/gfx/canvas.h" | 31 #include "ui/gfx/canvas.h" |
32 #include "ui/views/background.h" | |
33 #include "ui/views/context_menu_controller.h" | 32 #include "ui/views/context_menu_controller.h" |
34 #include "ui/views/controls/button/label_button.h" | 33 #include "ui/views/controls/button/label_button.h" |
35 #include "ui/views/controls/link.h" | 34 #include "ui/views/controls/link.h" |
36 #include "ui/views/controls/link_listener.h" | 35 #include "ui/views/controls/link_listener.h" |
37 #include "ui/views/controls/menu/menu_runner.h" | 36 #include "ui/views/controls/menu/menu_runner.h" |
38 #include "ui/views/controls/table/table_grouper.h" | 37 #include "ui/views/controls/table/table_grouper.h" |
39 #include "ui/views/controls/table/table_view.h" | 38 #include "ui/views/controls/table/table_view.h" |
40 #include "ui/views/controls/table/table_view_observer.h" | 39 #include "ui/views/controls/table/table_view_observer.h" |
41 #include "ui/views/controls/table/table_view_row_background_painter.h" | |
42 #include "ui/views/layout/layout_constants.h" | 40 #include "ui/views/layout/layout_constants.h" |
43 #include "ui/views/widget/widget.h" | 41 #include "ui/views/widget/widget.h" |
44 #include "ui/views/window/dialog_delegate.h" | 42 #include "ui/views/window/dialog_delegate.h" |
45 | 43 |
46 #if defined(USE_ASH) | 44 #if defined(USE_ASH) |
47 #include "ash/wm/window_util.h" | 45 #include "ash/wm/window_util.h" |
48 #endif | 46 #endif |
49 | 47 |
50 #if defined(OS_WIN) | 48 #if defined(OS_WIN) |
51 #include "win8/util/win8_util.h" | 49 #include "win8/util/win8_util.h" |
52 #endif | 50 #endif |
53 | 51 |
54 // Yellow highlight used when highlighting background resources. | |
55 static const SkColor kBackgroundResourceHighlight = | |
56 SkColorSetRGB(0xff, 0xf1, 0xcd); | |
57 | |
58 namespace { | 52 namespace { |
59 | 53 |
60 //////////////////////////////////////////////////////////////////////////////// | 54 //////////////////////////////////////////////////////////////////////////////// |
61 // TaskManagerTableModel class | 55 // TaskManagerTableModel class |
62 //////////////////////////////////////////////////////////////////////////////// | 56 //////////////////////////////////////////////////////////////////////////////// |
63 | 57 |
64 class TaskManagerTableModel | 58 class TaskManagerTableModel |
65 : public ui::TableModel, | 59 : public ui::TableModel, |
66 public views::TableGrouper, | 60 public views::TableGrouper, |
67 public TaskManagerModelObserver { | 61 public TaskManagerModelObserver { |
(...skipping 18 matching lines...) Expand all Loading... |
86 // TableGrouper overrides: | 80 // TableGrouper overrides: |
87 virtual void GetGroupRange(int model_index, | 81 virtual void GetGroupRange(int model_index, |
88 views::GroupRange* range) OVERRIDE; | 82 views::GroupRange* range) OVERRIDE; |
89 | 83 |
90 // TaskManagerModelObserver overrides: | 84 // TaskManagerModelObserver overrides: |
91 virtual void OnModelChanged() OVERRIDE; | 85 virtual void OnModelChanged() OVERRIDE; |
92 virtual void OnItemsChanged(int start, int length) OVERRIDE; | 86 virtual void OnItemsChanged(int start, int length) OVERRIDE; |
93 virtual void OnItemsAdded(int start, int length) OVERRIDE; | 87 virtual void OnItemsAdded(int start, int length) OVERRIDE; |
94 virtual void OnItemsRemoved(int start, int length) OVERRIDE; | 88 virtual void OnItemsRemoved(int start, int length) OVERRIDE; |
95 | 89 |
96 // Returns true if resource corresponding to |row| is a background resource. | |
97 bool IsBackgroundResource(int row); | |
98 | |
99 private: | 90 private: |
100 TaskManagerModel* model_; | 91 TaskManagerModel* model_; |
101 ui::TableModelObserver* observer_; | 92 ui::TableModelObserver* observer_; |
102 | 93 |
103 DISALLOW_COPY_AND_ASSIGN(TaskManagerTableModel); | 94 DISALLOW_COPY_AND_ASSIGN(TaskManagerTableModel); |
104 }; | 95 }; |
105 | 96 |
106 int TaskManagerTableModel::RowCount() { | 97 int TaskManagerTableModel::RowCount() { |
107 return model_->ResourceCount(); | 98 return model_->ResourceCount(); |
108 } | 99 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 | 154 |
164 void TaskManagerTableModel::OnItemsRemoved(int start, int length) { | 155 void TaskManagerTableModel::OnItemsRemoved(int start, int length) { |
165 if (observer_) | 156 if (observer_) |
166 observer_->OnItemsRemoved(start, length); | 157 observer_->OnItemsRemoved(start, length); |
167 | 158 |
168 // We may need to change the indentation of some items if the topmost item | 159 // We may need to change the indentation of some items if the topmost item |
169 // in the group was removed, so update the view. | 160 // in the group was removed, so update the view. |
170 OnModelChanged(); | 161 OnModelChanged(); |
171 } | 162 } |
172 | 163 |
173 bool TaskManagerTableModel::IsBackgroundResource(int row) { | |
174 return model_->IsBackgroundResource(row); | |
175 } | |
176 | |
177 class BackgroundPainter : public views::TableViewRowBackgroundPainter { | |
178 public: | |
179 explicit BackgroundPainter(TaskManagerTableModel* model) : model_(model) {} | |
180 virtual ~BackgroundPainter() {} | |
181 | |
182 virtual void PaintRowBackground(int model_index, | |
183 const gfx::Rect& row_bounds, | |
184 gfx::Canvas* canvas) OVERRIDE { | |
185 if (model_->IsBackgroundResource(model_index)) | |
186 canvas->FillRect(row_bounds, kBackgroundResourceHighlight); | |
187 } | |
188 | |
189 private: | |
190 TaskManagerTableModel* model_; | |
191 | |
192 DISALLOW_COPY_AND_ASSIGN(BackgroundPainter); | |
193 }; | |
194 | |
195 // The Task manager UI container. | 164 // The Task manager UI container. |
196 class TaskManagerView : public views::ButtonListener, | 165 class TaskManagerView : public views::ButtonListener, |
197 public views::DialogDelegateView, | 166 public views::DialogDelegateView, |
198 public views::TableViewObserver, | 167 public views::TableViewObserver, |
199 public views::LinkListener, | 168 public views::LinkListener, |
200 public views::ContextMenuController, | 169 public views::ContextMenuController, |
201 public ui::SimpleMenuModel::Delegate { | 170 public ui::SimpleMenuModel::Delegate { |
202 public: | 171 public: |
203 TaskManagerView(bool highlight_background_resources, | 172 explicit TaskManagerView(chrome::HostDesktopType desktop_type); |
204 chrome::HostDesktopType desktop_type); | |
205 virtual ~TaskManagerView(); | 173 virtual ~TaskManagerView(); |
206 | 174 |
207 // Shows the Task manager window, or re-activates an existing one. If | 175 // Shows the Task manager window, or re-activates an existing one. |
208 // |highlight_background_resources| is true, highlights the background | 176 static void Show(Browser* browser); |
209 // resources in the resource display. | |
210 static void Show(bool highlight_background_resources, Browser* browser); | |
211 | 177 |
212 // views::View: | 178 // views::View: |
213 virtual void Layout() OVERRIDE; | 179 virtual void Layout() OVERRIDE; |
214 virtual gfx::Size GetPreferredSize() OVERRIDE; | 180 virtual gfx::Size GetPreferredSize() OVERRIDE; |
215 virtual void ViewHierarchyChanged( | 181 virtual void ViewHierarchyChanged( |
216 const ViewHierarchyChangedDetails& details) OVERRIDE; | 182 const ViewHierarchyChangedDetails& details) OVERRIDE; |
217 | 183 |
218 // views::ButtonListener: | 184 // views::ButtonListener: |
219 virtual void ButtonPressed(views::Button* sender, | 185 virtual void ButtonPressed(views::Button* sender, |
220 const ui::Event& event) OVERRIDE; | 186 const ui::Event& event) OVERRIDE; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 TaskManagerModel* model_; | 247 TaskManagerModel* model_; |
282 | 248 |
283 // all possible columns, not necessarily visible | 249 // all possible columns, not necessarily visible |
284 std::vector<ui::TableColumn> columns_; | 250 std::vector<ui::TableColumn> columns_; |
285 | 251 |
286 scoped_ptr<TaskManagerTableModel> table_model_; | 252 scoped_ptr<TaskManagerTableModel> table_model_; |
287 | 253 |
288 // True when the Task Manager window should be shown on top of other windows. | 254 // True when the Task Manager window should be shown on top of other windows. |
289 bool is_always_on_top_; | 255 bool is_always_on_top_; |
290 | 256 |
291 // True when the Task Manager should highlight background resources. | |
292 const bool highlight_background_resources_; | |
293 | |
294 // The host desktop type this task manager belongs to. | 257 // The host desktop type this task manager belongs to. |
295 const chrome::HostDesktopType desktop_type_; | 258 const chrome::HostDesktopType desktop_type_; |
296 | 259 |
297 // We need to own the text of the menu, the Windows API does not copy it. | 260 // We need to own the text of the menu, the Windows API does not copy it. |
298 string16 always_on_top_menu_text_; | 261 string16 always_on_top_menu_text_; |
299 | 262 |
300 // An open Task manager window. There can only be one open at a time. This | 263 // An open Task manager window. There can only be one open at a time. This |
301 // is reset to NULL when the window is closed. | 264 // is reset to NULL when the window is closed. |
302 static TaskManagerView* instance_; | 265 static TaskManagerView* instance_; |
303 | 266 |
304 scoped_ptr<views::MenuRunner> menu_runner_; | 267 scoped_ptr<views::MenuRunner> menu_runner_; |
305 | 268 |
306 DISALLOW_COPY_AND_ASSIGN(TaskManagerView); | 269 DISALLOW_COPY_AND_ASSIGN(TaskManagerView); |
307 }; | 270 }; |
308 | 271 |
309 // static | 272 // static |
310 TaskManagerView* TaskManagerView::instance_ = NULL; | 273 TaskManagerView* TaskManagerView::instance_ = NULL; |
311 | 274 |
312 | 275 |
313 TaskManagerView::TaskManagerView(bool highlight_background_resources, | 276 TaskManagerView::TaskManagerView(chrome::HostDesktopType desktop_type) |
314 chrome::HostDesktopType desktop_type) | |
315 : purge_memory_button_(NULL), | 277 : purge_memory_button_(NULL), |
316 kill_button_(NULL), | 278 kill_button_(NULL), |
317 about_memory_link_(NULL), | 279 about_memory_link_(NULL), |
318 tab_table_(NULL), | 280 tab_table_(NULL), |
319 tab_table_parent_(NULL), | 281 tab_table_parent_(NULL), |
320 task_manager_(TaskManager::GetInstance()), | 282 task_manager_(TaskManager::GetInstance()), |
321 model_(TaskManager::GetInstance()->model()), | 283 model_(TaskManager::GetInstance()->model()), |
322 is_always_on_top_(false), | 284 is_always_on_top_(false), |
323 highlight_background_resources_(highlight_background_resources), | |
324 desktop_type_(desktop_type) { | 285 desktop_type_(desktop_type) { |
325 Init(); | 286 Init(); |
326 } | 287 } |
327 | 288 |
328 TaskManagerView::~TaskManagerView() { | 289 TaskManagerView::~TaskManagerView() { |
329 // Delete child views now, while our table model still exists. | 290 // Delete child views now, while our table model still exists. |
330 RemoveAllChildViews(true); | 291 RemoveAllChildViews(true); |
331 } | 292 } |
332 | 293 |
333 void TaskManagerView::Init() { | 294 void TaskManagerView::Init() { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 ui::TableColumn::RIGHT, -1, 0)); | 348 ui::TableColumn::RIGHT, -1, 0)); |
388 columns_.back().sortable = true; | 349 columns_.back().sortable = true; |
389 columns_.push_back( | 350 columns_.push_back( |
390 ui::TableColumn(IDS_TASK_MANAGER_JAVASCRIPT_MEMORY_ALLOCATED_COLUMN, | 351 ui::TableColumn(IDS_TASK_MANAGER_JAVASCRIPT_MEMORY_ALLOCATED_COLUMN, |
391 ui::TableColumn::RIGHT, -1, 0)); | 352 ui::TableColumn::RIGHT, -1, 0)); |
392 columns_.back().sortable = true; | 353 columns_.back().sortable = true; |
393 | 354 |
394 tab_table_ = new views::TableView( | 355 tab_table_ = new views::TableView( |
395 table_model_.get(), columns_, views::ICON_AND_TEXT, false); | 356 table_model_.get(), columns_, views::ICON_AND_TEXT, false); |
396 tab_table_->SetGrouper(table_model_.get()); | 357 tab_table_->SetGrouper(table_model_.get()); |
397 if (highlight_background_resources_) { | |
398 scoped_ptr<BackgroundPainter> painter( | |
399 new BackgroundPainter(table_model_.get())); | |
400 tab_table_->SetRowBackgroundPainter( | |
401 painter.PassAs<views::TableViewRowBackgroundPainter>()); | |
402 } | |
403 | 358 |
404 // Hide some columns by default | 359 // Hide some columns by default |
405 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_PROFILE_NAME_COLUMN, false); | 360 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_PROFILE_NAME_COLUMN, false); |
406 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_SHARED_MEM_COLUMN, false); | 361 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_SHARED_MEM_COLUMN, false); |
407 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN, false); | 362 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN, false); |
408 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN, | 363 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN, |
409 false); | 364 false); |
410 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN, | 365 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN, |
411 false); | 366 false); |
412 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_WEBCORE_CSS_CACHE_COLUMN, | 367 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_WEBCORE_CSS_CACHE_COLUMN, |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 rect.Inset(0, 0, 0, | 477 rect.Inset(0, 0, 0, |
523 kill_button_->height() + views::kUnrelatedControlVerticalSpacing); | 478 kill_button_->height() + views::kUnrelatedControlVerticalSpacing); |
524 tab_table_parent_->SetBoundsRect(rect); | 479 tab_table_parent_->SetBoundsRect(rect); |
525 } | 480 } |
526 | 481 |
527 gfx::Size TaskManagerView::GetPreferredSize() { | 482 gfx::Size TaskManagerView::GetPreferredSize() { |
528 return gfx::Size(460, 270); | 483 return gfx::Size(460, 270); |
529 } | 484 } |
530 | 485 |
531 // static | 486 // static |
532 void TaskManagerView::Show(bool highlight_background_resources, | 487 void TaskManagerView::Show(Browser* browser) { |
533 Browser* browser) { | |
534 #if defined(OS_WIN) | 488 #if defined(OS_WIN) |
535 // In Windows Metro it's not good to open this native window. | 489 // In Windows Metro it's not good to open this native window. |
536 DCHECK(!win8::IsSingleWindowMetroMode()); | 490 DCHECK(!win8::IsSingleWindowMetroMode()); |
537 #endif | 491 #endif |
538 // In ash we can come here through the ChromeShellDelegate. If there is no | 492 // In ash we can come here through the ChromeShellDelegate. If there is no |
539 // browser window at that time of the call, browser could be passed as NULL. | 493 // browser window at that time of the call, browser could be passed as NULL. |
540 const chrome::HostDesktopType desktop_type = | 494 const chrome::HostDesktopType desktop_type = |
541 browser ? browser->host_desktop_type() : chrome::HOST_DESKTOP_TYPE_ASH; | 495 browser ? browser->host_desktop_type() : chrome::HOST_DESKTOP_TYPE_ASH; |
542 | 496 |
543 if (instance_) { | 497 if (instance_) { |
544 if (instance_->highlight_background_resources_ != | 498 // If there's a Task manager window open already, just activate it. |
545 highlight_background_resources || | 499 instance_->GetWidget()->Activate(); |
546 instance_->desktop_type_ != desktop_type) { | 500 return; |
547 instance_->GetWidget()->Close(); | |
548 } else { | |
549 // If there's a Task manager window open already, just activate it. | |
550 instance_->GetWidget()->Activate(); | |
551 return; | |
552 } | |
553 } | 501 } |
554 instance_ = new TaskManagerView(highlight_background_resources, desktop_type); | 502 instance_ = new TaskManagerView(desktop_type); |
555 gfx::NativeWindow window = | 503 gfx::NativeWindow window = |
556 browser ? browser->window()->GetNativeWindow() : NULL; | 504 browser ? browser->window()->GetNativeWindow() : NULL; |
557 #if defined(USE_ASH) | 505 #if defined(USE_ASH) |
558 if (!window) | 506 if (!window) |
559 window = ash::wm::GetActiveWindow(); | 507 window = ash::wm::GetActiveWindow(); |
560 #endif | 508 #endif |
561 DialogDelegate::CreateDialogWidget(instance_, window, NULL); | 509 DialogDelegate::CreateDialogWidget(instance_, window, NULL); |
562 instance_->InitAlwaysOnTopState(); | 510 instance_->InitAlwaysOnTopState(); |
563 instance_->model_->StartUpdating(); | 511 instance_->model_->StartUpdating(); |
564 instance_->GetWidget()->Show(); | 512 instance_->GetWidget()->Show(); |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
772 g_browser_process->local_state()->GetDictionary(GetWindowName().c_str()); | 720 g_browser_process->local_state()->GetDictionary(GetWindowName().c_str()); |
773 return dictionary && | 721 return dictionary && |
774 dictionary->GetBoolean("always_on_top", always_on_top) && always_on_top; | 722 dictionary->GetBoolean("always_on_top", always_on_top) && always_on_top; |
775 } | 723 } |
776 | 724 |
777 } // namespace | 725 } // namespace |
778 | 726 |
779 namespace chrome { | 727 namespace chrome { |
780 | 728 |
781 // Declared in browser_dialogs.h so others don't need to depend on our header. | 729 // Declared in browser_dialogs.h so others don't need to depend on our header. |
782 void ShowTaskManager(Browser* browser, bool highlight_background_resources) { | 730 void ShowTaskManager(Browser* browser) { |
783 TaskManagerView::Show(highlight_background_resources, browser); | 731 TaskManagerView::Show(browser); |
784 } | 732 } |
785 | 733 |
786 } // namespace chrome | 734 } // namespace chrome |
OLD | NEW |