nick | 22bcc772 | 2016-05-10 18:43:41 | [diff] [blame] | 1 | // Copyright 2016 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. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_TASK_MANAGEMENT_TASK_MANAGER_TESTER_H_ |
| 6 | #define CHROME_BROWSER_TASK_MANAGEMENT_TASK_MANAGER_TESTER_H_ |
| 7 | |
nick | 50b0649 | 2016-05-10 23:40:27 | [diff] [blame] | 8 | #include <stdint.h> |
nick | 22bcc772 | 2016-05-10 18:43:41 | [diff] [blame] | 9 | |
| 10 | #include <memory> |
| 11 | |
| 12 | #include "base/callback_forward.h" |
| 13 | #include "base/strings/string16.h" |
nick | 50b0649 | 2016-05-10 23:40:27 | [diff] [blame] | 14 | #include "chrome/browser/task_management/task_manager_browsertest_util.h" |
nick | 22bcc772 | 2016-05-10 18:43:41 | [diff] [blame] | 15 | |
| 16 | namespace task_management { |
| 17 | |
| 18 | // An adapter that abstracts away the difference of old vs. new task manager. |
| 19 | class TaskManagerTester { |
| 20 | public: |
nick | 50b0649 | 2016-05-10 23:40:27 | [diff] [blame] | 21 | using ColumnSpecifier = browsertest_util::ColumnSpecifier; |
nick | 22bcc772 | 2016-05-10 18:43:41 | [diff] [blame] | 22 | |
| 23 | // Creates a TaskManagerTester backed by the current task manager. The task |
| 24 | // manager should already be visible when you call this function. |callback|, |
| 25 | // if not a null callback, will be invoked when the underlying model changes. |
| 26 | static std::unique_ptr<TaskManagerTester> Create( |
| 27 | const base::Closure& callback); |
| 28 | |
afakhry | 17406972 | 2016-05-24 19:16:16 | [diff] [blame] | 29 | // If using a legacy task manager, refresh the model. |
| 30 | static void MaybeRefreshLegacyInstance(); |
| 31 | |
nick | 22bcc772 | 2016-05-10 18:43:41 | [diff] [blame] | 32 | virtual ~TaskManagerTester() {} |
| 33 | |
| 34 | // Get the number of rows currently in the task manager. |
| 35 | virtual int GetRowCount() = 0; |
| 36 | |
| 37 | // Get the title text of a particular |row|. |
| 38 | virtual base::string16 GetRowTitle(int row) = 0; |
| 39 | |
| 40 | // Hide or show a column. If a column is not visible its stats are not |
| 41 | // necessarily gathered. |
| 42 | virtual void ToggleColumnVisibility(ColumnSpecifier column) = 0; |
| 43 | |
| 44 | // Get the value of a column as an int64. Memory values are in bytes. |
| 45 | virtual int64_t GetColumnValue(ColumnSpecifier column, int row) = 0; |
| 46 | |
| 47 | // If |row| is associated with a WebContents, return its SessionID. Otherwise, |
| 48 | // return -1. |
| 49 | virtual int32_t GetTabId(int row) = 0; |
| 50 | |
| 51 | // Kill the process of |row|. |
| 52 | virtual void Kill(int row) = 0; |
afakhry | 17406972 | 2016-05-24 19:16:16 | [diff] [blame] | 53 | |
avi | 1c6f3ff8 | 2016-08-01 22:33:35 | [diff] [blame^] | 54 | // Gets the start index and length of the group to which the task at |
| 55 | // |row_index| belongs. |
| 56 | virtual void GetRowsGroupRange(int row, int* out_start, int* out_length) = 0; |
| 57 | |
afakhry | 17406972 | 2016-05-24 19:16:16 | [diff] [blame] | 58 | private: |
| 59 | // Always creates a tester for the non-legacy TaskManager. |
| 60 | static std::unique_ptr<TaskManagerTester> CreateDefault( |
| 61 | const base::Closure& callback); |
nick | 22bcc772 | 2016-05-10 18:43:41 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | } // namespace task_management |
| 65 | |
| 66 | #endif // CHROME_BROWSER_TASK_MANAGEMENT_TASK_MANAGER_TESTER_H_ |