Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CONTENT_BROWSER_WORKER_HOST_WORKER_SERVICE_H_ | 5 #ifndef CONTENT_BROWSER_WORKER_HOST_WORKER_SERVICE_H_ |
| 6 #define CONTENT_BROWSER_WORKER_HOST_WORKER_SERVICE_H_ | 6 #define CONTENT_BROWSER_WORKER_HOST_WORKER_SERVICE_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
| 11 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
| 12 #include "base/threading/non_thread_safe.h" | 12 #include "base/threading/non_thread_safe.h" |
| 13 #include "content/browser/worker_host/worker_process_host.h" | 13 #include "content/browser/worker_host/worker_process_host.h" |
| 14 #include "content/public/browser/notification_observer.h" | |
| 14 #include "content/public/browser/notification_registrar.h" | 15 #include "content/public/browser/notification_registrar.h" |
| 15 #include "content/public/browser/worker_service.h" | 16 #include "content/public/browser/worker_service.h" |
| 16 | 17 |
| 17 class GURL; | 18 class GURL; |
| 18 struct ViewHostMsg_CreateWorker_Params; | 19 struct ViewHostMsg_CreateWorker_Params; |
| 19 | 20 |
| 20 namespace content { | 21 namespace content { |
| 21 class ResourceContext; | 22 class ResourceContext; |
| 22 class WorkerServiceObserver; | 23 class WorkerServiceObserver; |
| 23 class WorkerStoragePartition; | 24 class WorkerStoragePartition; |
| 25 class WorkerPrioritySetter; | |
| 24 | 26 |
| 25 class CONTENT_EXPORT WorkerServiceImpl | 27 class CONTENT_EXPORT WorkerServiceImpl |
| 26 : public NON_EXPORTED_BASE(WorkerService) { | 28 : public NON_EXPORTED_BASE(WorkerService) { |
| 27 public: | 29 public: |
| 28 // Returns the WorkerServiceImpl singleton. | 30 // Returns the WorkerServiceImpl singleton. |
| 29 static WorkerServiceImpl* GetInstance(); | 31 static WorkerServiceImpl* GetInstance(); |
| 30 | 32 |
| 33 // Releases the priority setter to avoid memory leak error. | |
| 34 void PerformUnitTestTeardown(); | |
|
darin (slow to review)
2013/05/24 20:48:40
nitty nit: A common convention is to slap a ForTes
shatch
2013/05/28 17:52:13
Done.
| |
| 35 | |
| 31 // WorkerService implementation: | 36 // WorkerService implementation: |
| 32 virtual bool TerminateWorker(int process_id, int route_id) OVERRIDE; | 37 virtual bool TerminateWorker(int process_id, int route_id) OVERRIDE; |
| 33 virtual std::vector<WorkerInfo> GetWorkers() OVERRIDE; | 38 virtual std::vector<WorkerInfo> GetWorkers() OVERRIDE; |
| 34 virtual void AddObserver(WorkerServiceObserver* observer) OVERRIDE; | 39 virtual void AddObserver(WorkerServiceObserver* observer) OVERRIDE; |
| 35 virtual void RemoveObserver(WorkerServiceObserver* observer) OVERRIDE; | 40 virtual void RemoveObserver(WorkerServiceObserver* observer) OVERRIDE; |
| 36 | 41 |
| 37 // These methods correspond to worker related IPCs. | 42 // These methods correspond to worker related IPCs. |
| 38 void CreateWorker(const ViewHostMsg_CreateWorker_Params& params, | 43 void CreateWorker(const ViewHostMsg_CreateWorker_Params& params, |
| 39 int route_id, | 44 int route_id, |
| 40 WorkerMessageFilter* filter, | 45 WorkerMessageFilter* filter, |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 65 bool GetRendererForWorker(int worker_process_id, | 70 bool GetRendererForWorker(int worker_process_id, |
| 66 int* render_process_id, | 71 int* render_process_id, |
| 67 int* render_view_id) const; | 72 int* render_view_id) const; |
| 68 const WorkerProcessHost::WorkerInstance* FindWorkerInstance( | 73 const WorkerProcessHost::WorkerInstance* FindWorkerInstance( |
| 69 int worker_process_id); | 74 int worker_process_id); |
| 70 | 75 |
| 71 void NotifyWorkerDestroyed( | 76 void NotifyWorkerDestroyed( |
| 72 WorkerProcessHost* process, | 77 WorkerProcessHost* process, |
| 73 int worker_route_id); | 78 int worker_route_id); |
| 74 | 79 |
| 80 void NotifyWorkerProcessCreated(); | |
| 81 | |
| 75 // Used when we run each worker in a separate process. | 82 // Used when we run each worker in a separate process. |
| 76 static const int kMaxWorkersWhenSeparate; | 83 static const int kMaxWorkersWhenSeparate; |
| 77 static const int kMaxWorkersPerTabWhenSeparate; | 84 static const int kMaxWorkersPerTabWhenSeparate; |
| 78 | 85 |
| 79 private: | 86 private: |
| 80 friend struct DefaultSingletonTraits<WorkerServiceImpl>; | 87 friend struct DefaultSingletonTraits<WorkerServiceImpl>; |
| 81 | 88 |
| 82 WorkerServiceImpl(); | 89 WorkerServiceImpl(); |
| 83 virtual ~WorkerServiceImpl(); | 90 virtual ~WorkerServiceImpl(); |
| 84 | 91 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 115 const string16& name, | 122 const string16& name, |
| 116 const WorkerStoragePartition& worker_partition, | 123 const WorkerStoragePartition& worker_partition, |
| 117 ResourceContext* resource_context); | 124 ResourceContext* resource_context); |
| 118 | 125 |
| 119 WorkerProcessHost::WorkerInstance* FindSharedWorkerInstance( | 126 WorkerProcessHost::WorkerInstance* FindSharedWorkerInstance( |
| 120 const GURL& url, | 127 const GURL& url, |
| 121 const string16& name, | 128 const string16& name, |
| 122 const WorkerStoragePartition& worker_partition, | 129 const WorkerStoragePartition& worker_partition, |
| 123 ResourceContext* resource_context); | 130 ResourceContext* resource_context); |
| 124 | 131 |
| 125 NotificationRegistrar registrar_; | 132 scoped_refptr<WorkerPrioritySetter> priority_setter_; |
| 133 | |
| 126 int next_worker_route_id_; | 134 int next_worker_route_id_; |
| 127 | 135 |
| 128 WorkerProcessHost::Instances queued_workers_; | 136 WorkerProcessHost::Instances queued_workers_; |
| 129 | 137 |
| 130 // These are shared workers that have been looked up, but not created yet. | 138 // These are shared workers that have been looked up, but not created yet. |
| 131 // We need to keep a list of these to synchronously detect shared worker | 139 // We need to keep a list of these to synchronously detect shared worker |
| 132 // URL mismatches when two pages launch shared workers simultaneously. | 140 // URL mismatches when two pages launch shared workers simultaneously. |
| 133 WorkerProcessHost::Instances pending_shared_workers_; | 141 WorkerProcessHost::Instances pending_shared_workers_; |
| 134 | 142 |
| 135 ObserverList<WorkerServiceObserver> observers_; | 143 ObserverList<WorkerServiceObserver> observers_; |
| 136 | 144 |
| 137 DISALLOW_COPY_AND_ASSIGN(WorkerServiceImpl); | 145 DISALLOW_COPY_AND_ASSIGN(WorkerServiceImpl); |
| 138 }; | 146 }; |
| 139 | 147 |
| 140 } // namespace content | 148 } // namespace content |
| 141 | 149 |
| 142 #endif // CONTENT_BROWSER_WORKER_HOST_WORKER_SERVICE_H_ | 150 #endif // CONTENT_BROWSER_WORKER_HOST_WORKER_SERVICE_H_ |
| OLD | NEW |