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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_TASK_MANAGER_WORKER_RESOURCE_PROVIDER_H_ 6 #define CHROME_BROWSER_TASK_MANAGER_WORKER_RESOURCE_PROVIDER_H_ 7 8 #include <map> 9 #include <vector> 10 11 #include "base/basictypes.h" 12 #include "base/memory/singleton.h" 13 #include "chrome/browser/task_manager/resource_provider.h" 14 #include "content/public/browser/browser_child_process_observer.h" 15 #include "content/public/browser/worker_service_observer.h" 16 17 class TaskManager; 18 19 namespace task_manager { 20 21 class SharedWorkerResource; 22 23 class WorkerResourceProvider : public ResourceProvider, 24 public content::BrowserChildProcessObserver, 25 private content::WorkerServiceObserver { 26 public: 27 explicit WorkerResourceProvider(TaskManager* task_manager); 28 29 private: 30 class WorkerResourceListHolder; 31 typedef std::vector<SharedWorkerResource*> WorkerResourceList; 32 typedef scoped_ptr<SharedWorkerResource> WorkerResourceHolder; 33 typedef std::map<int, WorkerResourceList> ProcessIdToWorkerResources; 34 35 virtual ~WorkerResourceProvider(); 36 37 // ResourceProvider implementation. 38 virtual Resource* GetResource(int origin_pid, 39 int child_id, 40 int route_id) OVERRIDE; 41 virtual void StartUpdating() OVERRIDE; 42 virtual void StopUpdating() OVERRIDE; 43 44 // content::BrowserChildProcessObserver implementation. 45 virtual void BrowserChildProcessHostConnected( 46 const content::ChildProcessData& data) OVERRIDE; 47 virtual void BrowserChildProcessHostDisconnected( 48 const content::ChildProcessData& data) OVERRIDE; 49 50 // content::WorkerServiceObserver implementation. 51 virtual void WorkerCreated(const GURL& url, 52 const base::string16& name, 53 int process_id, 54 int route_id) OVERRIDE; 55 virtual void WorkerDestroyed(int process_id, int route_id) OVERRIDE; 56 57 void NotifyWorkerCreated(WorkerResourceHolder* resource_holder); 58 void NotifyWorkerDestroyed(int process_id, int routing_id); 59 60 void StartObservingWorkers(); 61 void StopObservingWorkers(); 62 63 void AddWorkerResourceList(WorkerResourceListHolder* resource_list_holder); 64 void AddResource(SharedWorkerResource* resource); 65 void DeleteAllResources(); 66 67 bool updating_; 68 TaskManager* task_manager_; 69 WorkerResourceList resources_; 70 // Map from worker process id to the list of its workers. This list contains 71 // entries for worker processes which has not launched yet but for which we 72 // have already received WorkerCreated event. We don't add such workers to 73 // the task manager until the process is launched. 74 ProcessIdToWorkerResources launching_workers_; 75 76 DISALLOW_COPY_AND_ASSIGN(WorkerResourceProvider); 77 }; 78 79 } // namespace task_manager 80 81 #endif // CHROME_BROWSER_TASK_MANAGER_WORKER_RESOURCE_PROVIDER_H_ 82