Home | History | Annotate | Download | only in task_manager
      1 // Copyright 2013 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_MANAGER_CHILD_PROCESS_RESOURCE_PROVIDER_H_
      6 #define CHROME_BROWSER_TASK_MANAGER_CHILD_PROCESS_RESOURCE_PROVIDER_H_
      7 
      8 #include <map>
      9 #include <vector>
     10 
     11 #include "base/basictypes.h"
     12 #include "chrome/browser/task_manager/resource_provider.h"
     13 #include "content/public/browser/browser_child_process_observer.h"
     14 #include "content/public/browser/notification_registrar.h"
     15 
     16 class TaskManager;
     17 
     18 namespace content {
     19 struct ChildProcessData;
     20 }
     21 
     22 namespace task_manager {
     23 
     24 class ChildProcessResource;
     25 
     26 class ChildProcessResourceProvider
     27     : public ResourceProvider,
     28       public content::BrowserChildProcessObserver {
     29  public:
     30   explicit ChildProcessResourceProvider(TaskManager* task_manager);
     31 
     32   virtual Resource* GetResource(int origin_pid,
     33                                 int child_id,
     34                                 int route_id) OVERRIDE;
     35   virtual void StartUpdating() OVERRIDE;
     36   virtual void StopUpdating() OVERRIDE;
     37 
     38   // content::BrowserChildProcessObserver methods:
     39   virtual void BrowserChildProcessHostConnected(
     40       const content::ChildProcessData& data) OVERRIDE;
     41   virtual void BrowserChildProcessHostDisconnected(
     42       const content::ChildProcessData& data) OVERRIDE;
     43 
     44  private:
     45   virtual ~ChildProcessResourceProvider();
     46 
     47   // Retrieves information about the running ChildProcessHosts (performed in the
     48   // IO thread).
     49   virtual void RetrieveChildProcessData();
     50 
     51   // Notifies the UI thread that the ChildProcessHosts information have been
     52   // retrieved.
     53   virtual void ChildProcessDataRetreived(
     54       const std::vector<content::ChildProcessData>& child_processes);
     55 
     56   void AddToTaskManager(const content::ChildProcessData& child_process_data);
     57 
     58   TaskManager* task_manager_;
     59 
     60   // Whether we are currently reporting to the task manager. Used to ignore
     61   // notifications sent after StopUpdating().
     62   bool updating_;
     63 
     64   // Maps the actual resources (the ChildProcessData) to the Task Manager
     65   // resources.
     66   typedef std::map<base::ProcessHandle, ChildProcessResource*>
     67       ChildProcessMap;
     68   ChildProcessMap resources_;
     69 
     70   // Maps the pids to the resources (used for quick access to the resource on
     71   // byte read notifications).
     72   typedef std::map<int, ChildProcessResource*> PidResourceMap;
     73   PidResourceMap pid_to_resources_;
     74 
     75   // A scoped container for notification registries.
     76   content::NotificationRegistrar registrar_;
     77 
     78   DISALLOW_COPY_AND_ASSIGN(ChildProcessResourceProvider);
     79 };
     80 
     81 }  // namespace task_manager
     82 
     83 #endif  // CHROME_BROWSER_TASK_MANAGER_CHILD_PROCESS_RESOURCE_PROVIDER_H_
     84