Home | History | Annotate | Download | only in task_manager
      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.
      4 
      5 #ifndef CHROME_BROWSER_UI_WEBUI_TASK_MANAGER_TASK_MANAGER_HANDLER_H_
      6 #define CHROME_BROWSER_UI_WEBUI_TASK_MANAGER_TASK_MANAGER_HANDLER_H_
      7 
      8 #include <set>
      9 #include <string>
     10 #include <vector>
     11 
     12 #include "content/public/browser/web_ui_message_handler.h"
     13 #include "chrome/browser/task_manager/task_manager.h"
     14 
     15 namespace base {
     16 class ListValue;
     17 class Value;
     18 }
     19 
     20 class TaskManagerHandler : public content::WebUIMessageHandler,
     21                            public TaskManagerModelObserver {
     22  public:
     23   explicit TaskManagerHandler(TaskManager* tm);
     24   virtual ~TaskManagerHandler();
     25 
     26   // TaskManagerModelObserver implementation.
     27   // Invoked when the model has been completely changed.
     28   virtual void OnModelChanged() OVERRIDE;
     29   // Invoked when a range of items has changed.
     30   virtual void OnItemsChanged(int start, int length) OVERRIDE;
     31   // Invoked when new items are added.
     32   virtual void OnItemsAdded(int start, int length) OVERRIDE;
     33   // Invoked when a range of items has been removed.
     34   virtual void OnItemsRemoved(int start, int length) OVERRIDE;
     35 
     36   // Invoked when the initialization of the model has been finished and
     37   // periodic updates is started.
     38   virtual void OnReadyPeriodicalUpdate() OVERRIDE;
     39 
     40   // WebUIMessageHandler implementation.
     41   virtual void RegisterMessages() OVERRIDE;
     42 
     43   // Callback for the "killProcesses" message.
     44   void HandleKillProcesses(const base::ListValue* indexes);
     45 
     46   // Callback for the "activatePage" message.
     47   void HandleActivatePage(const base::ListValue* resource_index);
     48 
     49   // Callback for the "inspect" message.
     50   void HandleInspect(const base::ListValue* resource_index);
     51 
     52   void EnableTaskManager(const base::ListValue* indexes);
     53   void DisableTaskManager(const base::ListValue* indexes);
     54   void OpenAboutMemory(const base::ListValue* indexes);
     55 
     56   // Callback for the "setUpdateColumn" message.
     57   void HandleSetUpdateColumn(const base::ListValue* args);
     58 
     59  private:
     60   bool is_alive();
     61 
     62   // Models
     63   TaskManager* task_manager_;
     64   TaskManagerModel* model_;
     65 
     66   bool is_enabled_;
     67 
     68   // Set to store the enabled columns.
     69   std::set<std::string> enabled_columns_;
     70 
     71   // Invoked when group(s) are added/changed/removed.
     72   // These method are called from OnItemAdded/-Changed/-Removed internally.
     73   void OnGroupAdded(int start, int length);
     74   void OnGroupChanged(int start, int length);
     75   void OnGroupRemoved(int start, int length);
     76 
     77   // Creates or updates information for a single task group. A task group is a
     78   // group of tasks associated with a single process ID. |group_index| is the
     79   // integer index of the target process within the data model.
     80   base::DictionaryValue* CreateTaskGroupValue(int group_index);
     81 
     82   // Creates a list of values to display within a single column of the task
     83   // manager for a single task group. |columnn_name| is the name of the column.
     84   // |index| is the index of the resources associated with a process group.
     85   // |length| is the number of values associated with the group, and is either
     86   // 1 if all tasks within the group share a common value or equal to the
     87   // number of tasks within the group.
     88   void CreateGroupColumnList(const std::string& column_name,
     89                              const int index,
     90                              const int length,
     91                              base::DictionaryValue* val);
     92 
     93   // Retrieves the value of a property for a single task. |column_name| is the
     94   // name of the property, which is associated with a column within the task
     95   // manager or "about memory" page. |i| is the index of the task. Tasks are
     96   // grouped by process ID, and the index of the task is the sum of the group
     97   // offset and the index of the task within the group.
     98   base::Value* CreateColumnValue(const std::string& column_name,
     99                                  const int i);
    100 
    101   DISALLOW_COPY_AND_ASSIGN(TaskManagerHandler);
    102 };
    103 
    104 #endif  // CHROME_BROWSER_UI_WEBUI_TASK_MANAGER_TASK_MANAGER_HANDLER_H_
    105