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 Resource
* GetResource(int origin_pid
, int child_id
, int route_id
) override
;
33 void StartUpdating() override
;
34 void StopUpdating() override
;
36 // content::BrowserChildProcessObserver methods:
37 void BrowserChildProcessHostConnected(
38 const content::ChildProcessData
& data
) override
;
39 void BrowserChildProcessHostDisconnected(
40 const content::ChildProcessData
& data
) override
;
43 ~ChildProcessResourceProvider() override
;
45 // Retrieves information about the running ChildProcessHosts (performed in the
47 virtual void RetrieveChildProcessData();
49 // Notifies the UI thread that the ChildProcessHosts information have been
51 virtual void ChildProcessDataRetreived(
52 const std::vector
<content::ChildProcessData
>& child_processes
);
54 void AddToTaskManager(const content::ChildProcessData
& child_process_data
);
56 TaskManager
* task_manager_
;
58 // Whether we are currently reporting to the task manager. Used to ignore
59 // notifications sent after StopUpdating().
62 // Maps the actual resources (the ChildProcessData) to the Task Manager
64 typedef std::map
<base::ProcessHandle
, ChildProcessResource
*>
66 ChildProcessMap resources_
;
68 // Maps the pids to the resources (used for quick access to the resource on
69 // byte read notifications).
70 typedef std::map
<int, ChildProcessResource
*> PidResourceMap
;
71 PidResourceMap pid_to_resources_
;
73 // A scoped container for notification registries.
74 content::NotificationRegistrar registrar_
;
76 DISALLOW_COPY_AND_ASSIGN(ChildProcessResourceProvider
);
79 } // namespace task_manager
81 #endif // CHROME_BROWSER_TASK_MANAGER_CHILD_PROCESS_RESOURCE_PROVIDER_H_