summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/browser.cc7
-rw-r--r--chrome/browser/browser_window.h3
-rw-r--r--chrome/browser/cocoa/browser_window_cocoa.h1
-rw-r--r--chrome/browser/cocoa/browser_window_cocoa.mm4
-rw-r--r--chrome/browser/gtk/browser_window_gtk.cc4
-rw-r--r--chrome/browser/gtk/browser_window_gtk.h1
-rw-r--r--chrome/browser/gtk/task_manager_gtk.cc42
-rw-r--r--chrome/browser/task_manager.cc81
-rw-r--r--chrome/browser/task_manager.h49
-rw-r--r--chrome/browser/task_manager_browsertest.cc10
-rw-r--r--chrome/browser/task_manager_linux.cc75
-rw-r--r--chrome/browser/task_manager_unittest.cc1
-rw-r--r--chrome/browser/views/browser_dialogs.h3
-rw-r--r--chrome/browser/views/frame/browser_view.cc4
-rw-r--r--chrome/browser/views/frame/browser_view.h1
-rw-r--r--chrome/browser/views/task_manager_view.cc (renamed from chrome/browser/task_manager_win.cc)217
-rw-r--r--chrome/chrome.gyp4
-rw-r--r--chrome/test/test_browser_window.h1
18 files changed, 205 insertions, 303 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc
index 0fe72e6..4bf03ea 100644
--- a/chrome/browser/browser.cc
+++ b/chrome/browser/browser.cc
@@ -1103,12 +1103,7 @@ void Browser::OpenJavaScriptConsole() {
void Browser::OpenTaskManager() {
UserMetrics::RecordAction(L"TaskManager", profile_);
-// TODO(port)
-#if defined(OS_WIN)
- TaskManager::Open();
-#else
- NOTIMPLEMENTED();
-#endif
+ window_->ShowTaskManager();
}
void Browser::OpenSelectProfileDialog() {
diff --git a/chrome/browser/browser_window.h b/chrome/browser/browser_window.h
index f7999be..d11db56 100644
--- a/chrome/browser/browser_window.h
+++ b/chrome/browser/browser_window.h
@@ -135,6 +135,9 @@ class BrowserWindow {
// Shows the About Chrome dialog box.
virtual void ShowAboutChromeDialog() = 0;
+ // Shows the Task manager.
+ virtual void ShowTaskManager() = 0;
+
// Shows the Bookmark Manager window.
virtual void ShowBookmarkManager() = 0;
diff --git a/chrome/browser/cocoa/browser_window_cocoa.h b/chrome/browser/cocoa/browser_window_cocoa.h
index 9dc9e72..047a73e 100644
--- a/chrome/browser/cocoa/browser_window_cocoa.h
+++ b/chrome/browser/cocoa/browser_window_cocoa.h
@@ -55,6 +55,7 @@ class BrowserWindowCocoa : public BrowserWindow,
virtual gfx::Rect GetRootWindowResizerRect() const;
virtual void ToggleBookmarkBar();
virtual void ShowAboutChromeDialog();
+ virtual void ShowTaskManager();
virtual void ShowBookmarkManager();
virtual void ShowBookmarkBubble(const GURL& url, bool already_bookmarked);
virtual bool IsDownloadShelfVisible() const;
diff --git a/chrome/browser/cocoa/browser_window_cocoa.mm b/chrome/browser/cocoa/browser_window_cocoa.mm
index 28f87ae9..047dffc 100644
--- a/chrome/browser/cocoa/browser_window_cocoa.mm
+++ b/chrome/browser/cocoa/browser_window_cocoa.mm
@@ -179,6 +179,10 @@ void BrowserWindowCocoa::ShowAboutChromeDialog() {
NOTIMPLEMENTED();
}
+void BrowserWindowCocoa::ShowTaskManager() {
+ NOTIMPLEMENTED();
+}
+
void BrowserWindowCocoa::ShowBookmarkManager() {
NOTIMPLEMENTED();
}
diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc
index 246411a..fa3cbd7 100644
--- a/chrome/browser/gtk/browser_window_gtk.cc
+++ b/chrome/browser/gtk/browser_window_gtk.cc
@@ -604,6 +604,10 @@ void BrowserWindowGtk::ShowAboutChromeDialog() {
ShowAboutDialogForProfile(window_, browser_->profile());
}
+void BrowserWindowGtk::ShowTaskManager() {
+ NOTIMPLEMENTED();
+}
+
void BrowserWindowGtk::ShowBookmarkManager() {
NOTIMPLEMENTED();
}
diff --git a/chrome/browser/gtk/browser_window_gtk.h b/chrome/browser/gtk/browser_window_gtk.h
index b347288..249c695 100644
--- a/chrome/browser/gtk/browser_window_gtk.h
+++ b/chrome/browser/gtk/browser_window_gtk.h
@@ -75,6 +75,7 @@ class BrowserWindowGtk : public BrowserWindow,
virtual gfx::Rect GetRootWindowResizerRect() const;
virtual void ToggleBookmarkBar();
virtual void ShowAboutChromeDialog();
+ virtual void ShowTaskManager();
virtual void ShowBookmarkManager();
virtual void ShowBookmarkBubble(const GURL& url, bool already_bookmarked);
virtual bool IsDownloadShelfVisible() const;
diff --git a/chrome/browser/gtk/task_manager_gtk.cc b/chrome/browser/gtk/task_manager_gtk.cc
new file mode 100644
index 0000000..511e3a8
--- /dev/null
+++ b/chrome/browser/gtk/task_manager_gtk.cc
@@ -0,0 +1,42 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/task_manager.h"
+
+#include <vector>
+
+#include "base/logging.h"
+
+namespace {
+
+class TaskManagerGtk : public TaskManagerModelObserver {
+ public:
+ TaskManagerGtk(TaskManagerModel* model) {
+ model->SetObserver(this);
+ }
+
+ // TaskManagerModelObserver
+ virtual void OnModelChanged();
+ virtual void OnItemsChanged(int start, int length);
+ virtual void OnItemsAdded(int start, int length);
+ virtual void OnItemsRemoved(int start, int length);
+};
+
+void TaskManagerGtk::OnModelChanged() {
+ NOTIMPLEMENTED();
+}
+
+void TaskManagerGtk::OnItemsChanged(int start, int length) {
+ NOTIMPLEMENTED();
+}
+
+void TaskManagerGtk::OnItemsAdded(int start, int length) {
+ NOTIMPLEMENTED();
+}
+
+void TaskManagerGtk::OnItemsRemoved(int start, int length) {
+ NOTIMPLEMENTED();
+}
+
+} // namespace
diff --git a/chrome/browser/task_manager.cc b/chrome/browser/task_manager.cc
index 8f174cc..0a671e3 100644
--- a/chrome/browser/task_manager.cc
+++ b/chrome/browser/task_manager.cc
@@ -698,86 +698,34 @@ void TaskManager::RegisterPrefs(PrefService* prefs) {
}
TaskManager::TaskManager()
- : ALLOW_THIS_IN_INITIALIZER_LIST(model_(new TaskManagerModel(this))),
- view_(NULL) {
+ : ALLOW_THIS_IN_INITIALIZER_LIST(model_(new TaskManagerModel(this))) {
}
TaskManager::~TaskManager() {
}
-// static
-void TaskManager::Open() {
- TaskManager* task_manager = GetInstance();
- if (task_manager->view_) {
- task_manager->view_->ActivateWindow();
- } else {
- task_manager->CreateView();
- task_manager->view_->OpenWindow();
- }
+bool TaskManager::IsBrowserProcess(int index) const {
+ // If some of the selection is out of bounds, ignore. This may happen when
+ // killing a process that manages several pages.
+ return index < model_->ResourceCount() &&
+ model_->GetResourceProcessHandle(index) ==
+ base::GetCurrentProcessHandle();
}
-// static
-void TaskManager::Close() {
- TaskManager* task_manager = GetInstance();
- task_manager->view_->CloseWindow();
-}
-
-bool TaskManager::BrowserProcessIsSelected() {
- if (!view_)
- return false;
- std::vector<int> selection;
- view_->GetSelection(&selection);
- for (std::vector<int>::const_iterator iter = selection.begin();
- iter != selection.end(); ++iter) {
- // If some of the selection is out of bounds, ignore. This may happen when
- // killing a process that manages several pages.
- if (*iter >= model_->ResourceCount())
- continue;
- if (model_->GetResourceProcessHandle(*iter) ==
- base::GetCurrentProcessHandle())
- return true;
- }
- return false;
-}
-
-void TaskManager::KillSelectedProcesses() {
- std::vector<int> selection;
- view_->GetSelection(&selection);
- for (std::vector<int>::const_iterator iter = selection.begin();
- iter != selection.end(); ++iter) {
- base::ProcessHandle process = model_->GetResourceProcessHandle(*iter);
- DCHECK(process);
- if (process == base::GetCurrentProcessHandle())
- continue;
+void TaskManager::KillProcess(int index) {
+ base::ProcessHandle process = model_->GetResourceProcessHandle(index);
+ DCHECK(process);
+ if (process != base::GetCurrentProcessHandle())
base::KillProcess(process, base::PROCESS_END_KILLED_BY_USER, false);
- }
}
-void TaskManager::ActivateFocusedTab() {
- std::vector<int> focused;
- view_->GetFocused(&focused);
- int focused_size = static_cast<int>(focused.size());
-
- DCHECK(focused_size == 1);
-
- // Gracefully return if there is not exactly one item in focus.
- if (focused_size != 1)
- return;
-
- // Otherwise, the one focused thing should be one the user intends to bring
- // forth, so get see if GetTabContents returns non-null. If it does, activate
- // those contents.
- int index = focused[0];
-
+void TaskManager::ActivateProcess(int index) {
// GetResourceTabContents returns a pointer to the relevant tab contents for
// the resource. If the index doesn't correspond to a Tab (i.e. refers to
// the Browser process or a plugin), GetTabContents will return NULL.
TabContents* chosen_tab_contents = model_->GetResourceTabContents(index);
-
- if (!chosen_tab_contents)
- return;
-
- chosen_tab_contents->Activate();
+ if (chosen_tab_contents)
+ chosen_tab_contents->Activate();
}
void TaskManager::AddResourceProvider(ResourceProvider* provider) {
@@ -799,7 +747,6 @@ void TaskManager::RemoveResource(Resource* resource) {
void TaskManager::OnWindowClosed() {
model_->StopUpdating();
model_->Clear();
- view_ = NULL;
}
// static
diff --git a/chrome/browser/task_manager.h b/chrome/browser/task_manager.h
index c0f312e..c574b4a 100644
--- a/chrome/browser/task_manager.h
+++ b/chrome/browser/task_manager.h
@@ -24,7 +24,6 @@
class MessageLoop;
class SkBitmap;
class TaskManager;
-class TaskManagerView;
class TaskManagerModel;
struct BytesReadParam;
@@ -89,24 +88,15 @@ class TaskManager {
static void RegisterPrefs(PrefService* prefs);
- // Call this method to show the Task Manager.
- // Only one instance of Task Manager is created, so if the Task Manager has
- // already be opened, it is reopened. If it is currently opened, then it is
- // moved to the front.
- static void Open();
+ // Returns true if the process at the specified index is the browser process.
+ bool IsBrowserProcess(int index) const;
- // Close the task manager if it's currently opened.
- static void Close();
+ // Terminates the process at the specified index.
+ void KillProcess(int index);
- // Returns true if the current selection includes the browser process.
- bool BrowserProcessIsSelected();
-
- // Terminates the selected tab(s) in the list.
- void KillSelectedProcesses();
-
- // Activates the browser tab associated with the focused row in the task
- // manager table. This happens when the user double clicks or hits return.
- void ActivateFocusedTab();
+ // Activates the browser tab associated with the process in the specified
+ // index.
+ void ActivateProcess(int index);
void AddResourceProvider(ResourceProvider* provider);
void RemoveResourceProvider(ResourceProvider* provider);
@@ -120,6 +110,11 @@ class TaskManager {
void OnWindowClosed();
+ // Returns the singleton instance (and initializes it if necessary).
+ static TaskManager* GetInstance();
+
+ TaskManagerModel* model() const { return model_.get(); }
+
private:
FRIEND_TEST(TaskManagerTest, Basic);
FRIEND_TEST(TaskManagerTest, Resources);
@@ -130,18 +125,10 @@ class TaskManager {
~TaskManager();
- void CreateView();
-
- // Returns the singleton instance (and initializes it if necessary).
- static TaskManager* GetInstance();
-
// The model used for gathering and processing task data. It is ref counted
// because it is passed as a parameter to MessageLoop::InvokeLater().
scoped_refptr<TaskManagerModel> model_;
- // A container containing the buttons and table.
- TaskManagerView* view_;
-
DISALLOW_COPY_AND_ASSIGN(TaskManager);
};
@@ -348,16 +335,4 @@ class TaskManagerModel : public URLRequestJobTracker::JobObserver,
DISALLOW_COPY_AND_ASSIGN(TaskManagerModel);
};
-class TaskManagerView {
- public:
- virtual ~TaskManagerView() {}
-
- virtual void GetSelection(std::vector<int>* selection) = 0;
- virtual void GetFocused(std::vector<int>* focused) = 0;
-
- virtual void OpenWindow() = 0;
- virtual void ActivateWindow() = 0;
- virtual void CloseWindow() = 0;
-};
-
#endif // CHROME_BROWSER_TASK_MANAGER_H_
diff --git a/chrome/browser/task_manager_browsertest.cc b/chrome/browser/task_manager_browsertest.cc
index 35aa462..8aa343f 100644
--- a/chrome/browser/task_manager_browsertest.cc
+++ b/chrome/browser/task_manager_browsertest.cc
@@ -4,18 +4,14 @@
#include "chrome/browser/task_manager.h"
+#include "chrome/browser/browser.h"
+#include "chrome/browser/browser_window.h"
#include "chrome/test/in_process_browser_test.h"
#include "testing/gtest/include/gtest/gtest.h"
class TaskManagerBrowserTest : public InProcessBrowserTest {
};
-// Regression test for http://crbug.com/11180
-IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, OpenClose) {
- TaskManager::Open();
- TaskManager::Close();
-}
-
IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, ShutdownWhileOpen) {
- TaskManager::Open();
+ browser()->window()->ShowTaskManager();
}
diff --git a/chrome/browser/task_manager_linux.cc b/chrome/browser/task_manager_linux.cc
deleted file mode 100644
index 17baa3c..0000000
--- a/chrome/browser/task_manager_linux.cc
+++ /dev/null
@@ -1,75 +0,0 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/task_manager.h"
-
-#include <vector>
-
-#include "base/logging.h"
-
-namespace {
-
-class TaskManagerViewImpl : public TaskManagerView,
- public TaskManagerModelObserver {
- public:
- TaskManagerViewImpl(TaskManagerModel* model) {
- model->SetObserver(this);
- }
-
- // TaskManagerView
- virtual void GetSelection(std::vector<int>* selection);
- virtual void GetFocused(std::vector<int>* focused);
- virtual void OpenWindow();
- virtual void ActivateWindow();
- virtual void CloseWindow();
-
- // TaskManagerModelObserver
- virtual void OnModelChanged();
- virtual void OnItemsChanged(int start, int length);
- virtual void OnItemsAdded(int start, int length);
- virtual void OnItemsRemoved(int start, int length);
-};
-
-void TaskManagerViewImpl::GetSelection(std::vector<int>* selection) {
- NOTIMPLEMENTED();
-}
-
-void TaskManagerViewImpl::GetFocused(std::vector<int>* focused) {
- NOTIMPLEMENTED();
-}
-
-void TaskManagerViewImpl::OpenWindow() {
- NOTIMPLEMENTED();
-}
-
-void TaskManagerViewImpl::ActivateWindow() {
- NOTIMPLEMENTED();
-}
-
-void TaskManagerViewImpl::CloseWindow() {
- NOTIMPLEMENTED();
-}
-
-void TaskManagerViewImpl::OnModelChanged() {
- NOTIMPLEMENTED();
-}
-
-void TaskManagerViewImpl::OnItemsChanged(int start, int length) {
- NOTIMPLEMENTED();
-}
-
-void TaskManagerViewImpl::OnItemsAdded(int start, int length) {
- NOTIMPLEMENTED();
-}
-
-void TaskManagerViewImpl::OnItemsRemoved(int start, int length) {
- NOTIMPLEMENTED();
-}
-
-} // namespace
-
-void TaskManager::CreateView() {
- DCHECK(!view_);
- view_= new TaskManagerViewImpl(model_.get());
-}
diff --git a/chrome/browser/task_manager_unittest.cc b/chrome/browser/task_manager_unittest.cc
index 70bb710..1ce3e55 100644
--- a/chrome/browser/task_manager_unittest.cc
+++ b/chrome/browser/task_manager_unittest.cc
@@ -33,7 +33,6 @@ class TaskManagerTest : public testing::Test {
TEST_F(TaskManagerTest, Basic) {
TaskManager task_manager;
TaskManagerModel* model = task_manager.model_;
- EXPECT_FALSE(task_manager.BrowserProcessIsSelected());
EXPECT_EQ(0, model->ResourceCount());
}
diff --git a/chrome/browser/views/browser_dialogs.h b/chrome/browser/views/browser_dialogs.h
index ebd532a..fd81d7b 100644
--- a/chrome/browser/views/browser_dialogs.h
+++ b/chrome/browser/views/browser_dialogs.h
@@ -82,6 +82,9 @@ void ShowKeywordEditorView(Profile* profile);
// Shows the "new profile" dialog box. See NewProfileDialog.
void ShowNewProfileDialog();
+// Shows the Task Manager.
+void ShowTaskManager();
+
} // namespace browser
#endif // CHROME_BROWSER_VIEWS_BROWSER_DIALOGS_H_
diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc
index 8aa44b6..bfb85f8 100644
--- a/chrome/browser/views/frame/browser_view.cc
+++ b/chrome/browser/views/frame/browser_view.cc
@@ -817,6 +817,10 @@ void BrowserView::ShowAboutChromeDialog() {
browser::ShowAboutChromeView(GetWidget(), browser_->profile());
}
+void BrowserView::ShowTaskManager() {
+ browser::ShowTaskManager();
+}
+
void BrowserView::ShowBookmarkManager() {
browser::ShowBookmarkManagerView(browser_->profile());
}
diff --git a/chrome/browser/views/frame/browser_view.h b/chrome/browser/views/frame/browser_view.h
index b7a552e..03b75a3 100644
--- a/chrome/browser/views/frame/browser_view.h
+++ b/chrome/browser/views/frame/browser_view.h
@@ -215,6 +215,7 @@ class BrowserView : public BrowserWindow,
virtual void DisableInactiveFrame();
virtual void ToggleBookmarkBar();
virtual void ShowAboutChromeDialog();
+ virtual void ShowTaskManager();
virtual void ShowBookmarkManager();
virtual void ShowBookmarkBubble(const GURL& url, bool already_bookmarked);
virtual void SetDownloadShelfVisible(bool visible);
diff --git a/chrome/browser/task_manager_win.cc b/chrome/browser/views/task_manager_view.cc
index 42b835a..32fe975 100644
--- a/chrome/browser/task_manager_win.cc
+++ b/chrome/browser/views/task_manager_view.cc
@@ -11,6 +11,7 @@
#include "chrome/browser/browser_list.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_window.h"
+#include "chrome/browser/views/browser_dialogs.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/pref_service.h"
#include "grit/chromium_strings.h"
@@ -158,39 +159,27 @@ void TaskManagerTableModel::OnItemsRemoved(int start, int length) {
observer_->OnItemsRemoved(start, length);
}
-////////////////////////////////////////////////////////////////////////////////
-// TaskManagerViewImpl class
-//
-// The view containing the different widgets.
-//
-////////////////////////////////////////////////////////////////////////////////
-
-class TaskManagerViewImpl : public TaskManagerView,
- public views::View,
- public views::ButtonListener,
- public views::DialogDelegate,
- public views::TableViewObserver,
- public views::LinkController,
- public views::ContextMenuController,
- public views::Menu::Delegate {
+// The Task manager UI container.
+class TaskManagerView : public views::View,
+ public views::ButtonListener,
+ public views::DialogDelegate,
+ public views::TableViewObserver,
+ public views::LinkController,
+ public views::ContextMenuController,
+ public views::Menu::Delegate {
public:
- TaskManagerViewImpl(TaskManager* task_manager,
- TaskManagerModel* model);
- virtual ~TaskManagerViewImpl();
+ TaskManagerView();
+ virtual ~TaskManagerView();
- void Init();
+ // Shows the Task manager window, or re-activates an existing one.
+ static void Show();
+
+ // views::View
virtual void Layout();
virtual gfx::Size GetPreferredSize();
virtual void ViewHierarchyChanged(bool is_add, views::View* parent,
views::View* child);
- // TaskManagerView
- virtual void GetSelection(std::vector<int>* selection);
- virtual void GetFocused(std::vector<int>* focused);
- virtual void OpenWindow();
- virtual void ActivateWindow();
- virtual void CloseWindow();
-
// ButtonListener implementation.
virtual void ButtonPressed(views::Button* sender);
@@ -226,9 +215,15 @@ class TaskManagerViewImpl : public TaskManagerView,
virtual void ExecuteCommand(int id);
private:
+ // Creates the child controls.
+ void Init();
+
// Initializes the state of the always-on-top setting as the window is shown.
void InitAlwaysOnTopState();
+ // Activates the tab associated with the focused row.
+ void ActivateFocusedTab();
+
// Adds an always on top item to the window's system menu.
void AddAlwaysOnTopSystemMenuItem();
@@ -254,18 +249,25 @@ class TaskManagerViewImpl : public TaskManagerView,
// We need to own the text of the menu, the Windows API does not copy it.
std::wstring always_on_top_menu_text_;
- DISALLOW_COPY_AND_ASSIGN(TaskManagerViewImpl);
+ // An open Task manager window. There can only be one open at a time. This
+ // is reset to NULL when the window is closed.
+ static TaskManagerView* instance_;
+
+ DISALLOW_COPY_AND_ASSIGN(TaskManagerView);
};
-TaskManagerViewImpl::TaskManagerViewImpl(TaskManager* task_manager,
- TaskManagerModel* model)
- : task_manager_(task_manager),
- model_(model),
+// static
+TaskManagerView* TaskManagerView::instance_ = NULL;
+
+
+TaskManagerView::TaskManagerView()
+ : task_manager_(TaskManager::GetInstance()),
+ model_(TaskManager::GetInstance()->model()),
is_always_on_top_(false) {
Init();
}
-TaskManagerViewImpl::~TaskManagerViewImpl() {
+TaskManagerView::~TaskManagerView() {
// Delete child views now, while our table model still exists.
RemoveAllChildViews(true);
@@ -274,7 +276,7 @@ TaskManagerViewImpl::~TaskManagerViewImpl() {
tab_table_->SetModel(NULL);
}
-void TaskManagerViewImpl::Init() {
+void TaskManagerView::Init() {
table_model_.reset(new TaskManagerTableModel(model_));
columns_.push_back(TableColumn(IDS_TASK_MANAGER_PAGE_COLUMN,
@@ -302,7 +304,6 @@ void TaskManagerViewImpl::Init() {
tab_table_ = new views::GroupTableView(table_model_.get(), columns_,
views::ICON_AND_TEXT, false, true,
true);
- tab_table_->SetParentOwned(false);
// Hide some columns by default
tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_PROCESS_ID_COLUMN, false);
@@ -329,7 +330,7 @@ void TaskManagerViewImpl::Init() {
OnSelectionChanged();
}
-void TaskManagerViewImpl::UpdateStatsCounters() {
+void TaskManagerView::UpdateStatsCounters() {
StatsTable* stats = StatsTable::current();
if (stats != NULL) {
int max = stats->GetMaxCounters();
@@ -351,9 +352,9 @@ void TaskManagerViewImpl::UpdateStatsCounters() {
}
}
-void TaskManagerViewImpl::ViewHierarchyChanged(bool is_add,
- views::View* parent,
- views::View* child) {
+void TaskManagerView::ViewHierarchyChanged(bool is_add,
+ views::View* parent,
+ views::View* child) {
// Since we want the Kill button and the Memory Details link to show up in
// the same visual row as the close button, which is provided by the
// framework, we must add the buttons to the non-client view, which is the
@@ -371,7 +372,7 @@ void TaskManagerViewImpl::ViewHierarchyChanged(bool is_add,
}
}
-void TaskManagerViewImpl::Layout() {
+void TaskManagerView::Layout() {
// kPanelHorizMargin is too big.
const int kTableButtonSpacing = 12;
@@ -406,65 +407,43 @@ void TaskManagerViewImpl::Layout() {
link_prefered_height);
}
-gfx::Size TaskManagerViewImpl::GetPreferredSize() {
+gfx::Size TaskManagerView::GetPreferredSize() {
return gfx::Size(kDefaultWidth, kDefaultHeight);
}
-void TaskManagerViewImpl::GetSelection(std::vector<int>* selection) {
- DCHECK(selection);
- for (views::TableSelectionIterator iter = tab_table_->SelectionBegin();
- iter != tab_table_->SelectionEnd(); ++iter) {
- // The TableView returns the selection starting from the end.
- selection->insert(selection->begin(), *iter);
- }
-}
-
-void TaskManagerViewImpl::GetFocused(std::vector<int>* focused) {
- DCHECK(focused);
- int row_count = tab_table_->RowCount();
- for (int i = 0; i < row_count; ++i) {
- // The TableView returns the selection starting from the end.
- if (tab_table_->ItemHasTheFocus(i))
- focused->insert(focused->begin(), i);
+// static
+void TaskManagerView::Show() {
+ if (instance_) {
+ // If there's a Task manager window open already, just activate it.
+ instance_->window()->Activate();
+ } else {
+ instance_ = new TaskManagerView;
+ views::Window::CreateChromeWindow(NULL, gfx::Rect(), instance_);
+ instance_->InitAlwaysOnTopState();
+ instance_->model_->StartUpdating();
+ instance_->window()->Show();
}
}
-void TaskManagerViewImpl::OpenWindow() {
- DCHECK(!window());
- views::Window::CreateChromeWindow(NULL, gfx::Rect(), this);
- InitAlwaysOnTopState();
- model_->StartUpdating();
- window()->Show();
-}
-
-void TaskManagerViewImpl::ActivateWindow() {
- DCHECK(window());
- window()->Activate();
-}
-
-void TaskManagerViewImpl::CloseWindow() {
- if (!window())
- return;
- // TODO(phajdan.jr): Destroy the window, not just hide it.
- window()->HideWindow();
-}
-
// ButtonListener implementation.
-void TaskManagerViewImpl::ButtonPressed(views::Button* sender) {
- if (sender == kill_button_)
- task_manager_->KillSelectedProcesses();
+void TaskManagerView::ButtonPressed(views::Button* sender) {
+ DCHECK(sender == kill_button_);
+ for (views::TableSelectionIterator iter = tab_table_->SelectionBegin();
+ iter != tab_table_->SelectionEnd(); ++iter) {
+ task_manager_->KillProcess(*iter);
+ }
}
// DialogDelegate implementation.
-bool TaskManagerViewImpl::CanResize() const {
+bool TaskManagerView::CanResize() const {
return true;
}
-bool TaskManagerViewImpl::CanMaximize() const {
+bool TaskManagerView::CanMaximize() const {
return true;
}
-bool TaskManagerViewImpl::ExecuteWindowsCommand(int command_id) {
+bool TaskManagerView::ExecuteWindowsCommand(int command_id) {
if (command_id == IDC_ALWAYS_ON_TOP) {
is_always_on_top_ = !is_always_on_top_;
@@ -496,48 +475,57 @@ bool TaskManagerViewImpl::ExecuteWindowsCommand(int command_id) {
return false;
}
-std::wstring TaskManagerViewImpl::GetWindowTitle() const {
+std::wstring TaskManagerView::GetWindowTitle() const {
return l10n_util::GetString(IDS_TASK_MANAGER_TITLE);
}
-std::wstring TaskManagerViewImpl::GetWindowName() const {
+std::wstring TaskManagerView::GetWindowName() const {
return prefs::kTaskManagerWindowPlacement;
}
-int TaskManagerViewImpl::GetDialogButtons() const {
+int TaskManagerView::GetDialogButtons() const {
return MessageBoxFlags::DIALOGBUTTON_NONE;
}
-void TaskManagerViewImpl::WindowClosing() {
+void TaskManagerView::WindowClosing() {
+ // Now that the window is closed, we can allow a new one to be opened.
+ instance_ = NULL;
task_manager_->OnWindowClosed();
}
-void TaskManagerViewImpl::DeleteDelegate() {
+void TaskManagerView::DeleteDelegate() {
ReleaseWindow();
}
-views::View* TaskManagerViewImpl::GetContentsView() {
+views::View* TaskManagerView::GetContentsView() {
return this;
}
// views::TableViewObserver implementation.
-void TaskManagerViewImpl::OnSelectionChanged() {
- kill_button_->SetEnabled(!task_manager_->BrowserProcessIsSelected() &&
+void TaskManagerView::OnSelectionChanged() {
+ bool selection_contains_browser_process = false;
+ for (views::TableSelectionIterator iter = tab_table_->SelectionBegin();
+ iter != tab_table_->SelectionEnd(); ++iter) {
+ if (task_manager_->IsBrowserProcess(*iter)) {
+ selection_contains_browser_process = true;
+ break;
+ }
+ }
+ kill_button_->SetEnabled(!selection_contains_browser_process &&
tab_table_->SelectedRowCount() > 0);
}
-void TaskManagerViewImpl::OnDoubleClick() {
- task_manager_->ActivateFocusedTab();
+void TaskManagerView::OnDoubleClick() {
+ ActivateFocusedTab();
}
-void TaskManagerViewImpl::OnKeyDown(unsigned short virtual_keycode) {
+void TaskManagerView::OnKeyDown(unsigned short virtual_keycode) {
if (virtual_keycode == VK_RETURN)
- task_manager_->ActivateFocusedTab();
+ ActivateFocusedTab();
}
// views::LinkController implementation
-void TaskManagerViewImpl::LinkActivated(views::Link* source,
- int event_flags) {
+void TaskManagerView::LinkActivated(views::Link* source, int event_flags) {
DCHECK(source == about_memory_link_);
Browser* browser = BrowserList::GetLastActive();
DCHECK(browser);
@@ -555,10 +543,8 @@ void TaskManagerViewImpl::LinkActivated(views::Link* source,
browser->window()->Show();
}
-void TaskManagerViewImpl::ShowContextMenu(views::View* source,
- int x,
- int y,
- bool is_mouse_gesture) {
+void TaskManagerView::ShowContextMenu(views::View* source, int x, int y,
+ bool is_mouse_gesture) {
UpdateStatsCounters();
scoped_ptr<views::Menu> menu(views::Menu::Create(
this, views::Menu::TOPLEFT, source->GetWidget()->GetNativeView()));
@@ -569,22 +555,32 @@ void TaskManagerViewImpl::ShowContextMenu(views::View* source,
menu->RunMenuAt(x, y);
}
-bool TaskManagerViewImpl::IsItemChecked(int id) const {
+bool TaskManagerView::IsItemChecked(int id) const {
return tab_table_->IsColumnVisible(id);
}
-void TaskManagerViewImpl::ExecuteCommand(int id) {
+void TaskManagerView::ExecuteCommand(int id) {
tab_table_->SetColumnVisibility(id, !tab_table_->IsColumnVisible(id));
}
-void TaskManagerViewImpl::InitAlwaysOnTopState() {
+void TaskManagerView::InitAlwaysOnTopState() {
is_always_on_top_ = false;
if (GetSavedAlwaysOnTopState(&is_always_on_top_))
window()->SetIsAlwaysOnTop(is_always_on_top_);
AddAlwaysOnTopSystemMenuItem();
}
-void TaskManagerViewImpl::AddAlwaysOnTopSystemMenuItem() {
+void TaskManagerView::ActivateFocusedTab() {
+ int row_count = tab_table_->RowCount();
+ for (int i = 0; i < row_count; ++i) {
+ if (tab_table_->ItemHasTheFocus(i)) {
+ task_manager_->ActivateProcess(i);
+ break;
+ }
+ }
+}
+
+void TaskManagerView::AddAlwaysOnTopSystemMenuItem() {
// The Win32 API requires that we own the text.
always_on_top_menu_text_ = l10n_util::GetString(IDS_ALWAYS_ON_TOP);
@@ -615,7 +611,7 @@ void TaskManagerViewImpl::AddAlwaysOnTopSystemMenuItem() {
::InsertMenuItem(system_menu, index, TRUE, &menu_info);
}
-bool TaskManagerViewImpl::GetSavedAlwaysOnTopState(bool* always_on_top) const {
+bool TaskManagerView::GetSavedAlwaysOnTopState(bool* always_on_top) const {
if (!g_browser_process->local_state())
return false;
@@ -627,7 +623,12 @@ bool TaskManagerViewImpl::GetSavedAlwaysOnTopState(bool* always_on_top) const {
} // namespace
-void TaskManager::CreateView() {
- DCHECK(!view_);
- view_ = new TaskManagerViewImpl(this, model_.get());
+namespace browser {
+
+// Declared in browser_dialogs.h so others don't need to depend on our header.
+void ShowTaskManager() {
+ TaskManagerView::Show();
}
+
+} // namespace browser
+
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index 9db0997c..8f28bb0 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -1045,6 +1045,7 @@
'browser/gtk/tabs/tab_renderer_gtk.h',
'browser/gtk/tabs/tab_strip_gtk.cc',
'browser/gtk/tabs/tab_strip_gtk.h',
+ 'browser/gtk/task_manager_gtk.cc',
'browser/gtk/toolbar_star_toggle_gtk.cc',
'browser/gtk/toolbar_star_toggle_gtk.h',
'browser/hang_monitor/hung_plugin_action.cc',
@@ -1443,8 +1444,6 @@
'browser/tabs/tab_strip_model_order_controller.h',
'browser/task_manager.cc',
'browser/task_manager.h',
- 'browser/task_manager_linux.cc',
- 'browser/task_manager_win.cc',
'browser/task_manager_resource_providers.cc',
'browser/task_manager_resource_providers.h',
'browser/theme_resources_util.cc',
@@ -1662,6 +1661,7 @@
'browser/views/tabs/tab_renderer.h',
'browser/views/tabs/tab_strip.cc',
'browser/views/tabs/tab_strip.h',
+ 'browser/views/task_manager_view.cc',
'browser/views/theme_helpers.cc',
'browser/views/theme_helpers.h',
'browser/views/toolbar_star_toggle.cc',
diff --git a/chrome/test/test_browser_window.h b/chrome/test/test_browser_window.h
index 0e25938..665fd47 100644
--- a/chrome/test/test_browser_window.h
+++ b/chrome/test/test_browser_window.h
@@ -50,6 +50,7 @@ class TestBrowserWindow : public BrowserWindow {
virtual gfx::Rect GetRootWindowResizerRect() const { return gfx::Rect(); }
virtual void ToggleBookmarkBar() {}
virtual void ShowAboutChromeDialog() {}
+ virtual void ShowTaskManager() {}
virtual void ShowBookmarkManager() {}
virtual void ShowBookmarkBubble(const GURL& url, bool already_bookmarked) {}
virtual bool IsDownloadShelfVisible() const { return false; }