| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_TASK_MANAGER_TASK_MANAGER_WORKER_RESOURCE_PROVIDER_H_ | 5 #ifndef CHROME_BROWSER_TASK_MANAGER_TASK_MANAGER_WORKER_RESOURCE_PROVIDER_H_ |
| 6 #define CHROME_BROWSER_TASK_MANAGER_TASK_MANAGER_WORKER_RESOURCE_PROVIDER_H_ | 6 #define CHROME_BROWSER_TASK_MANAGER_TASK_MANAGER_WORKER_RESOURCE_PROVIDER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "chrome/browser/task_manager/task_manager.h" | 12 #include "chrome/browser/task_manager/task_manager.h" |
| 13 #include "content/public/browser/notification_observer.h" | 13 #include "content/public/browser/browser_child_process_observer.h" |
| 14 #include "content/public/browser/notification_registrar.h" | |
| 15 #include "content/public/browser/worker_service_observer.h" | 14 #include "content/public/browser/worker_service_observer.h" |
| 16 | 15 |
| 17 class TaskManagerSharedWorkerResource; | 16 class TaskManagerSharedWorkerResource; |
| 18 | 17 |
| 19 class TaskManagerWorkerResourceProvider | 18 class TaskManagerWorkerResourceProvider |
| 20 : public TaskManager::ResourceProvider, | 19 : public TaskManager::ResourceProvider, |
| 21 private content::WorkerServiceObserver, | 20 public content::BrowserChildProcessObserver, |
| 22 private content::NotificationObserver { | 21 private content::WorkerServiceObserver { |
| 23 public: | 22 public: |
| 24 explicit TaskManagerWorkerResourceProvider(TaskManager* task_manager); | 23 explicit TaskManagerWorkerResourceProvider(TaskManager* task_manager); |
| 25 | 24 |
| 26 private: | 25 private: |
| 27 class WorkerResourceListHolder; | 26 class WorkerResourceListHolder; |
| 28 typedef std::vector<TaskManagerSharedWorkerResource*> WorkerResourceList; | 27 typedef std::vector<TaskManagerSharedWorkerResource*> WorkerResourceList; |
| 29 typedef scoped_ptr<TaskManagerSharedWorkerResource> WorkerResourceHolder; | 28 typedef scoped_ptr<TaskManagerSharedWorkerResource> WorkerResourceHolder; |
| 30 typedef std::map<int, WorkerResourceList> ProcessIdToWorkerResources; | 29 typedef std::map<int, WorkerResourceList> ProcessIdToWorkerResources; |
| 31 | 30 |
| 32 virtual ~TaskManagerWorkerResourceProvider(); | 31 virtual ~TaskManagerWorkerResourceProvider(); |
| 33 | 32 |
| 34 // TaskManager::ResourceProvider implementation. | 33 // TaskManager::ResourceProvider implementation. |
| 35 virtual TaskManager::Resource* GetResource(int origin_pid, | 34 virtual TaskManager::Resource* GetResource(int origin_pid, |
| 36 int render_process_host_id, | 35 int render_process_host_id, |
| 37 int routing_id) OVERRIDE; | 36 int routing_id) OVERRIDE; |
| 38 virtual void StartUpdating() OVERRIDE; | 37 virtual void StartUpdating() OVERRIDE; |
| 39 virtual void StopUpdating() OVERRIDE; | 38 virtual void StopUpdating() OVERRIDE; |
| 40 | 39 |
| 40 // content::BrowserChildProcessObserver implementation. |
| 41 virtual void BrowserChildProcessHostConnected( |
| 42 const content::ChildProcessData& data) OVERRIDE; |
| 43 virtual void BrowserChildProcessHostDisconnected( |
| 44 const content::ChildProcessData& data) OVERRIDE; |
| 45 |
| 41 // content::WorkerServiceObserver implementation. | 46 // content::WorkerServiceObserver implementation. |
| 42 virtual void WorkerCreated(const GURL& url, | 47 virtual void WorkerCreated(const GURL& url, |
| 43 const string16& name, | 48 const string16& name, |
| 44 int process_id, | 49 int process_id, |
| 45 int route_id) OVERRIDE; | 50 int route_id) OVERRIDE; |
| 46 virtual void WorkerDestroyed(int process_id, int route_id) OVERRIDE; | 51 virtual void WorkerDestroyed(int process_id, int route_id) OVERRIDE; |
| 47 | 52 |
| 48 // content::NotificationObserver implementation. | |
| 49 virtual void Observe(int type, | |
| 50 const content::NotificationSource& source, | |
| 51 const content::NotificationDetails& details) OVERRIDE; | |
| 52 | |
| 53 void NotifyWorkerCreated(WorkerResourceHolder* resource_holder); | 53 void NotifyWorkerCreated(WorkerResourceHolder* resource_holder); |
| 54 void NotifyWorkerDestroyed(int process_id, int routing_id); | 54 void NotifyWorkerDestroyed(int process_id, int routing_id); |
| 55 | 55 |
| 56 void StartObservingWorkers(); | 56 void StartObservingWorkers(); |
| 57 void StopObservingWorkers(); | 57 void StopObservingWorkers(); |
| 58 | 58 |
| 59 void AddWorkerResourceList(WorkerResourceListHolder* resource_list_holder); | 59 void AddWorkerResourceList(WorkerResourceListHolder* resource_list_holder); |
| 60 void AddResource(TaskManagerSharedWorkerResource* resource); | 60 void AddResource(TaskManagerSharedWorkerResource* resource); |
| 61 void DeleteAllResources(); | 61 void DeleteAllResources(); |
| 62 | 62 |
| 63 bool updating_; | 63 bool updating_; |
| 64 TaskManager* task_manager_; | 64 TaskManager* task_manager_; |
| 65 WorkerResourceList resources_; | 65 WorkerResourceList resources_; |
| 66 // Map from worker process id to the list of its workers. This list contains | 66 // Map from worker process id to the list of its workers. This list contains |
| 67 // entries for worker processes which has not launched yet but for which we | 67 // entries for worker processes which has not launched yet but for which we |
| 68 // have already received WorkerCreated event. We don't add such workers to | 68 // have already received WorkerCreated event. We don't add such workers to |
| 69 // the task manager until the process is launched. | 69 // the task manager until the process is launched. |
| 70 ProcessIdToWorkerResources launching_workers_; | 70 ProcessIdToWorkerResources launching_workers_; |
| 71 content::NotificationRegistrar registrar_; | |
| 72 | 71 |
| 73 DISALLOW_COPY_AND_ASSIGN(TaskManagerWorkerResourceProvider); | 72 DISALLOW_COPY_AND_ASSIGN(TaskManagerWorkerResourceProvider); |
| 74 }; | 73 }; |
| 75 | 74 |
| 76 #endif // CHROME_BROWSER_TASK_MANAGER_TASK_MANAGER_WORKER_RESOURCE_PROVIDER_H_ | 75 #endif // CHROME_BROWSER_TASK_MANAGER_TASK_MANAGER_WORKER_RESOURCE_PROVIDER_H_ |
| OLD | NEW |