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.
5 #ifndef CHROME_BROWSER_TASK_MANAGER_CHILD_PROCESS_RESOURCE_PROVIDER_H_
6 #define CHROME_BROWSER_TASK_MANAGER_CHILD_PROCESS_RESOURCE_PROVIDER_H_
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"
19 struct ChildProcessData
;
22 namespace task_manager
{
24 class ChildProcessResource
;
26 class ChildProcessResourceProvider
27 : public ResourceProvider
,
28 public content::BrowserChildProcessObserver
{
30 explicit ChildProcessResourceProvider(TaskManager
* task_manager
);
32 virtual Resource
* GetResource(int origin_pid
,
34 int route_id
) OVERRIDE
;
35 virtual void StartUpdating() OVERRIDE
;
36 virtual void StopUpdating() OVERRIDE
;
38 // content::BrowserChildProcessObserver methods:
39 virtual void BrowserChildProcessHostConnected(
40 const content::ChildProcessData
& data
) OVERRIDE
;
41 virtual void BrowserChildProcessHostDisconnected(
42 const content::ChildProcessData
& data
) OVERRIDE
;
45 virtual ~ChildProcessResourceProvider();
47 // Retrieves information about the running ChildProcessHosts (performed in the
49 virtual void RetrieveChildProcessData();
51 // Notifies the UI thread that the ChildProcessHosts information have been
53 virtual void ChildProcessDataRetreived(
54 const std::vector
<content::ChildProcessData
>& child_processes
);
56 void AddToTaskManager(const content::ChildProcessData
& child_process_data
);
58 TaskManager
* task_manager_
;
60 // Whether we are currently reporting to the task manager. Used to ignore
61 // notifications sent after StopUpdating().
64 // Maps the actual resources (the ChildProcessData) to the Task Manager
66 typedef std::map
<base::ProcessHandle
, ChildProcessResource
*>
68 ChildProcessMap resources_
;
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_
;
75 // A scoped container for notification registries.
76 content::NotificationRegistrar registrar_
;
78 DISALLOW_COPY_AND_ASSIGN(ChildProcessResourceProvider
);
81 } // namespace task_manager
83 #endif // CHROME_BROWSER_TASK_MANAGER_CHILD_PROCESS_RESOURCE_PROVIDER_H_