| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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.h" | 5 #include "chrome/browser/task_manager.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/table_model_observer.h" |
| 8 #include "base/stats_table.h" | 9 #include "base/stats_table.h" |
| 9 #include "chrome/app/chrome_dll_resource.h" | 10 #include "chrome/app/chrome_dll_resource.h" |
| 10 #include "chrome/browser/browser_list.h" | 11 #include "chrome/browser/browser_list.h" |
| 11 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/browser_window.h" | 13 #include "chrome/browser/browser_window.h" |
| 13 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
| 14 #include "chrome/common/pref_service.h" | 15 #include "chrome/common/pref_service.h" |
| 15 #include "grit/chromium_strings.h" | 16 #include "grit/chromium_strings.h" |
| 16 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
| 17 #include "grit/theme_resources.h" | 18 #include "grit/theme_resources.h" |
| 18 #include "views/accelerator.h" | 19 #include "views/accelerator.h" |
| 19 #include "views/background.h" | 20 #include "views/background.h" |
| 20 #include "views/controls/button/native_button.h" | 21 #include "views/controls/button/native_button.h" |
| 21 #include "views/controls/link.h" | 22 #include "views/controls/link.h" |
| 22 #include "views/controls/menu/menu.h" | 23 #include "views/controls/menu/menu.h" |
| 23 #include "views/controls/table/group_table_view.h" | 24 #include "views/controls/table/group_table_view.h" |
| 24 #include "views/controls/table/table_view_observer.h" | |
| 25 #include "views/standard_layout.h" | 25 #include "views/standard_layout.h" |
| 26 #include "views/widget/widget.h" | 26 #include "views/widget/widget.h" |
| 27 #include "views/window/dialog_delegate.h" | 27 #include "views/window/dialog_delegate.h" |
| 28 #include "views/window/window.h" | 28 #include "views/window/window.h" |
| 29 | 29 |
| 30 // The task manager window default size. | 30 // The task manager window default size. |
| 31 static const int kDefaultWidth = 460; | 31 static const int kDefaultWidth = 460; |
| 32 static const int kDefaultHeight = 270; | 32 static const int kDefaultHeight = 270; |
| 33 | 33 |
| 34 // An id for the most important column, made sufficiently large so as not to | 34 // An id for the most important column, made sufficiently large so as not to |
| (...skipping 17 matching lines...) Expand all Loading... |
| 52 observer_(NULL) { | 52 observer_(NULL) { |
| 53 model->SetObserver(this); | 53 model->SetObserver(this); |
| 54 } | 54 } |
| 55 ~TaskManagerTableModel() {} | 55 ~TaskManagerTableModel() {} |
| 56 | 56 |
| 57 // GroupTableModel. | 57 // GroupTableModel. |
| 58 int RowCount(); | 58 int RowCount(); |
| 59 std::wstring GetText(int row, int column); | 59 std::wstring GetText(int row, int column); |
| 60 SkBitmap GetIcon(int row); | 60 SkBitmap GetIcon(int row); |
| 61 void GetGroupRangeForItem(int item, views::GroupRange* range); | 61 void GetGroupRangeForItem(int item, views::GroupRange* range); |
| 62 void SetObserver(views::TableModelObserver* observer); | 62 void SetObserver(TableModelObserver* observer); |
| 63 virtual int CompareValues(int row1, int row2, int column_id); | 63 virtual int CompareValues(int row1, int row2, int column_id); |
| 64 | 64 |
| 65 // TaskManagerModelObserver. | 65 // TaskManagerModelObserver. |
| 66 virtual void OnModelChanged(); | 66 virtual void OnModelChanged(); |
| 67 virtual void OnItemsChanged(int start, int length); | 67 virtual void OnItemsChanged(int start, int length); |
| 68 virtual void OnItemsAdded(int start, int length); | 68 virtual void OnItemsAdded(int start, int length); |
| 69 virtual void OnItemsRemoved(int start, int length); | 69 virtual void OnItemsRemoved(int start, int length); |
| 70 | 70 |
| 71 private: | 71 private: |
| 72 const TaskManagerModel* model_; | 72 const TaskManagerModel* model_; |
| 73 views::TableModelObserver* observer_; | 73 TableModelObserver* observer_; |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 int TaskManagerTableModel::RowCount() { | 76 int TaskManagerTableModel::RowCount() { |
| 77 return model_->ResourceCount(); | 77 return model_->ResourceCount(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 std::wstring TaskManagerTableModel::GetText(int row, int col_id) { | 80 std::wstring TaskManagerTableModel::GetText(int row, int col_id) { |
| 81 switch (col_id) { | 81 switch (col_id) { |
| 82 case IDS_TASK_MANAGER_PAGE_COLUMN: // Process | 82 case IDS_TASK_MANAGER_PAGE_COLUMN: // Process |
| 83 return model_->GetResourceTitle(row); | 83 return model_->GetResourceTitle(row); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 return model_->GetResourceIcon(row); | 122 return model_->GetResourceIcon(row); |
| 123 } | 123 } |
| 124 | 124 |
| 125 void TaskManagerTableModel::GetGroupRangeForItem(int item, | 125 void TaskManagerTableModel::GetGroupRangeForItem(int item, |
| 126 views::GroupRange* range) { | 126 views::GroupRange* range) { |
| 127 std::pair<int, int> range_pair = model_->GetGroupRangeForResource(item); | 127 std::pair<int, int> range_pair = model_->GetGroupRangeForResource(item); |
| 128 range->start = range_pair.first; | 128 range->start = range_pair.first; |
| 129 range->length = range_pair.second; | 129 range->length = range_pair.second; |
| 130 } | 130 } |
| 131 | 131 |
| 132 void TaskManagerTableModel::SetObserver(views::TableModelObserver* observer) { | 132 void TaskManagerTableModel::SetObserver(TableModelObserver* observer) { |
| 133 observer_ = observer; | 133 observer_ = observer; |
| 134 } | 134 } |
| 135 | 135 |
| 136 int TaskManagerTableModel::CompareValues(int row1, int row2, int column_id) { | 136 int TaskManagerTableModel::CompareValues(int row1, int row2, int column_id) { |
| 137 return model_->CompareValues(row1, row2, column_id); | 137 return model_->CompareValues(row1, row2, column_id); |
| 138 } | 138 } |
| 139 | 139 |
| 140 void TaskManagerTableModel::OnModelChanged() { | 140 void TaskManagerTableModel::OnModelChanged() { |
| 141 if (observer_) | 141 if (observer_) |
| 142 observer_->OnModelChanged(); | 142 observer_->OnModelChanged(); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 | 236 |
| 237 views::NativeButton* kill_button_; | 237 views::NativeButton* kill_button_; |
| 238 views::Link* about_memory_link_; | 238 views::Link* about_memory_link_; |
| 239 views::GroupTableView* tab_table_; | 239 views::GroupTableView* tab_table_; |
| 240 | 240 |
| 241 TaskManager* task_manager_; | 241 TaskManager* task_manager_; |
| 242 | 242 |
| 243 TaskManagerModel* model_; | 243 TaskManagerModel* model_; |
| 244 | 244 |
| 245 // all possible columns, not necessarily visible | 245 // all possible columns, not necessarily visible |
| 246 std::vector<views::TableColumn> columns_; | 246 std::vector<TableColumn> columns_; |
| 247 | 247 |
| 248 scoped_ptr<TaskManagerTableModel> table_model_; | 248 scoped_ptr<TaskManagerTableModel> table_model_; |
| 249 | 249 |
| 250 // True when the Task Manager window should be shown on top of other windows. | 250 // True when the Task Manager window should be shown on top of other windows. |
| 251 bool is_always_on_top_; | 251 bool is_always_on_top_; |
| 252 | 252 |
| 253 // We need to own the text of the menu, the Windows API does not copy it. | 253 // We need to own the text of the menu, the Windows API does not copy it. |
| 254 std::wstring always_on_top_menu_text_; | 254 std::wstring always_on_top_menu_text_; |
| 255 | 255 |
| 256 DISALLOW_COPY_AND_ASSIGN(TaskManagerViewImpl); | 256 DISALLOW_COPY_AND_ASSIGN(TaskManagerViewImpl); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 269 RemoveAllChildViews(true); | 269 RemoveAllChildViews(true); |
| 270 | 270 |
| 271 // Prevent the table from accessing the model as part of its destruction, as | 271 // Prevent the table from accessing the model as part of its destruction, as |
| 272 // the model might already be destroyed. | 272 // the model might already be destroyed. |
| 273 tab_table_->SetModel(NULL); | 273 tab_table_->SetModel(NULL); |
| 274 } | 274 } |
| 275 | 275 |
| 276 void TaskManagerViewImpl::Init() { | 276 void TaskManagerViewImpl::Init() { |
| 277 table_model_.reset(new TaskManagerTableModel(model_)); | 277 table_model_.reset(new TaskManagerTableModel(model_)); |
| 278 | 278 |
| 279 columns_.push_back(views::TableColumn(IDS_TASK_MANAGER_PAGE_COLUMN, | 279 columns_.push_back(TableColumn(IDS_TASK_MANAGER_PAGE_COLUMN, |
| 280 views::TableColumn::LEFT, -1, 1)); | 280 TableColumn::LEFT, -1, 1)); |
| 281 columns_.back().sortable = true; | 281 columns_.back().sortable = true; |
| 282 columns_.push_back(views::TableColumn(IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN, | 282 columns_.push_back(TableColumn(IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN, |
| 283 views::TableColumn::RIGHT, -1, 0)); | 283 TableColumn::RIGHT, -1, 0)); |
| 284 columns_.back().sortable = true; | 284 columns_.back().sortable = true; |
| 285 columns_.push_back(views::TableColumn(IDS_TASK_MANAGER_SHARED_MEM_COLUMN, | 285 columns_.push_back(TableColumn(IDS_TASK_MANAGER_SHARED_MEM_COLUMN, |
| 286 views::TableColumn::RIGHT, -1, 0)); | 286 TableColumn::RIGHT, -1, 0)); |
| 287 columns_.back().sortable = true; | 287 columns_.back().sortable = true; |
| 288 columns_.push_back(views::TableColumn(IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN, | 288 columns_.push_back(TableColumn(IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN, |
| 289 views::TableColumn::RIGHT, -1, 0)); | 289 TableColumn::RIGHT, -1, 0)); |
| 290 columns_.back().sortable = true; | 290 columns_.back().sortable = true; |
| 291 columns_.push_back(views::TableColumn(IDS_TASK_MANAGER_CPU_COLUMN, | 291 columns_.push_back(TableColumn(IDS_TASK_MANAGER_CPU_COLUMN, |
| 292 views::TableColumn::RIGHT, -1, 0)); | 292 TableColumn::RIGHT, -1, 0)); |
| 293 columns_.back().sortable = true; | 293 columns_.back().sortable = true; |
| 294 columns_.push_back(views::TableColumn(IDS_TASK_MANAGER_NET_COLUMN, | 294 columns_.push_back(TableColumn(IDS_TASK_MANAGER_NET_COLUMN, |
| 295 views::TableColumn::RIGHT, -1, 0)); | 295 TableColumn::RIGHT, -1, 0)); |
| 296 columns_.back().sortable = true; | 296 columns_.back().sortable = true; |
| 297 columns_.push_back(views::TableColumn(IDS_TASK_MANAGER_PROCESS_ID_COLUMN, | 297 columns_.push_back(TableColumn(IDS_TASK_MANAGER_PROCESS_ID_COLUMN, |
| 298 views::TableColumn::RIGHT, -1, 0)); | 298 TableColumn::RIGHT, -1, 0)); |
| 299 columns_.back().sortable = true; | 299 columns_.back().sortable = true; |
| 300 | 300 |
| 301 tab_table_ = new views::GroupTableView(table_model_.get(), columns_, | 301 tab_table_ = new views::GroupTableView(table_model_.get(), columns_, |
| 302 views::ICON_AND_TEXT, false, true, | 302 views::ICON_AND_TEXT, false, true, |
| 303 true); | 303 true); |
| 304 tab_table_->SetParentOwned(false); | 304 tab_table_->SetParentOwned(false); |
| 305 | 305 |
| 306 // Hide some columns by default | 306 // Hide some columns by default |
| 307 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_PROCESS_ID_COLUMN, false); | 307 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_PROCESS_ID_COLUMN, false); |
| 308 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_SHARED_MEM_COLUMN, false); | 308 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_SHARED_MEM_COLUMN, false); |
| 309 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN, false); | 309 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN, false); |
| 310 | 310 |
| 311 UpdateStatsCounters(); | 311 UpdateStatsCounters(); |
| 312 views::TableColumn col(kGoatsTeleportedColumn, L"Goats Teleported", | 312 TableColumn col(kGoatsTeleportedColumn, L"Goats Teleported", |
| 313 views::TableColumn::RIGHT, -1, 0); | 313 TableColumn::RIGHT, -1, 0); |
| 314 col.sortable = true; | 314 col.sortable = true; |
| 315 columns_.push_back(col); | 315 columns_.push_back(col); |
| 316 tab_table_->AddColumn(col); | 316 tab_table_->AddColumn(col); |
| 317 tab_table_->SetObserver(this); | 317 tab_table_->SetObserver(this); |
| 318 SetContextMenuController(this); | 318 SetContextMenuController(this); |
| 319 kill_button_ = new views::NativeButton( | 319 kill_button_ = new views::NativeButton( |
| 320 this, l10n_util::GetString(IDS_TASK_MANAGER_KILL)); | 320 this, l10n_util::GetString(IDS_TASK_MANAGER_KILL)); |
| 321 kill_button_->AddAccelerator(views::Accelerator('E', false, false, false)); | 321 kill_button_->AddAccelerator(views::Accelerator('E', false, false, false)); |
| 322 kill_button_->SetAccessibleKeyboardShortcut(L"E"); | 322 kill_button_->SetAccessibleKeyboardShortcut(L"E"); |
| 323 about_memory_link_ = new views::Link( | 323 about_memory_link_ = new views::Link( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 334 int max = stats->GetMaxCounters(); | 334 int max = stats->GetMaxCounters(); |
| 335 // skip the first row (it's header data) | 335 // skip the first row (it's header data) |
| 336 for (int i = 1; i < max; i++) { | 336 for (int i = 1; i < max; i++) { |
| 337 const char* row = stats->GetRowName(i); | 337 const char* row = stats->GetRowName(i); |
| 338 if (row != NULL && row[0] != '\0' && !tab_table_->HasColumn(i)) { | 338 if (row != NULL && row[0] != '\0' && !tab_table_->HasColumn(i)) { |
| 339 // TODO(erikkay): Use l10n to get display names for stats. Right | 339 // TODO(erikkay): Use l10n to get display names for stats. Right |
| 340 // now we're just displaying the internal counter name. Perhaps | 340 // now we're just displaying the internal counter name. Perhaps |
| 341 // stat names not in the string table would be filtered out. | 341 // stat names not in the string table would be filtered out. |
| 342 // TODO(erikkay): Width is hard-coded right now, so many column | 342 // TODO(erikkay): Width is hard-coded right now, so many column |
| 343 // names are clipped. | 343 // names are clipped. |
| 344 views::TableColumn col(i, ASCIIToWide(row), views::TableColumn::RIGHT, | 344 TableColumn col(i, ASCIIToWide(row), TableColumn::RIGHT, 90, 0); |
| 345 90, 0); | |
| 346 col.sortable = true; | 345 col.sortable = true; |
| 347 columns_.push_back(col); | 346 columns_.push_back(col); |
| 348 tab_table_->AddColumn(col); | 347 tab_table_->AddColumn(col); |
| 349 } | 348 } |
| 350 } | 349 } |
| 351 } | 350 } |
| 352 } | 351 } |
| 353 | 352 |
| 354 void TaskManagerViewImpl::ViewHierarchyChanged(bool is_add, | 353 void TaskManagerViewImpl::ViewHierarchyChanged(bool is_add, |
| 355 views::View* parent, | 354 views::View* parent, |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 browser->window()->Show(); | 554 browser->window()->Show(); |
| 556 } | 555 } |
| 557 | 556 |
| 558 void TaskManagerViewImpl::ShowContextMenu(views::View* source, | 557 void TaskManagerViewImpl::ShowContextMenu(views::View* source, |
| 559 int x, | 558 int x, |
| 560 int y, | 559 int y, |
| 561 bool is_mouse_gesture) { | 560 bool is_mouse_gesture) { |
| 562 UpdateStatsCounters(); | 561 UpdateStatsCounters(); |
| 563 scoped_ptr<views::Menu> menu(views::Menu::Create( | 562 scoped_ptr<views::Menu> menu(views::Menu::Create( |
| 564 this, views::Menu::TOPLEFT, source->GetWidget()->GetNativeView())); | 563 this, views::Menu::TOPLEFT, source->GetWidget()->GetNativeView())); |
| 565 for (std::vector<views::TableColumn>::iterator i = | 564 for (std::vector<TableColumn>::iterator i = |
| 566 columns_.begin(); i != columns_.end(); ++i) { | 565 columns_.begin(); i != columns_.end(); ++i) { |
| 567 menu->AppendMenuItem(i->id, i->title, views::Menu::CHECKBOX); | 566 menu->AppendMenuItem(i->id, i->title, views::Menu::CHECKBOX); |
| 568 } | 567 } |
| 569 menu->RunMenuAt(x, y); | 568 menu->RunMenuAt(x, y); |
| 570 } | 569 } |
| 571 | 570 |
| 572 bool TaskManagerViewImpl::IsItemChecked(int id) const { | 571 bool TaskManagerViewImpl::IsItemChecked(int id) const { |
| 573 return tab_table_->IsColumnVisible(id); | 572 return tab_table_->IsColumnVisible(id); |
| 574 } | 573 } |
| 575 | 574 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 return dictionary && | 623 return dictionary && |
| 625 dictionary->GetBoolean(L"always_on_top", always_on_top) && always_on_top; | 624 dictionary->GetBoolean(L"always_on_top", always_on_top) && always_on_top; |
| 626 } | 625 } |
| 627 | 626 |
| 628 } // namespace | 627 } // namespace |
| 629 | 628 |
| 630 void TaskManager::CreateView() { | 629 void TaskManager::CreateView() { |
| 631 DCHECK(!view_); | 630 DCHECK(!view_); |
| 632 view_ = new TaskManagerViewImpl(this, model_.get()); | 631 view_ = new TaskManagerViewImpl(this, model_.get()); |
| 633 } | 632 } |
| OLD | NEW |