OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_WORKER_HOST_WORKER_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_WORKER_HOST_WORKER_SERVICE_H_ |
6 #define CHROME_BROWSER_WORKER_HOST_WORKER_SERVICE_H_ | 6 #define CHROME_BROWSER_WORKER_HOST_WORKER_SERVICE_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/singleton.h" | 11 #include "base/singleton.h" |
12 #include "chrome/browser/worker_host/worker_process_host.h" | 12 #include "chrome/browser/worker_host/worker_process_host.h" |
13 #include "chrome/common/notification_registrar.h" | 13 #include "chrome/common/notification_registrar.h" |
14 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
15 #include "ipc/ipc_message.h" | 15 #include "ipc/ipc_message.h" |
16 | 16 |
17 | |
18 class MessageLoop; | |
19 class WorkerProcessHost; | 17 class WorkerProcessHost; |
20 class ResourceDispatcherHost; | 18 class ResourceDispatcherHost; |
21 | 19 |
22 class WorkerService : public NotificationObserver { | 20 class WorkerService : public NotificationObserver { |
23 public: | 21 public: |
24 // Returns the WorkerService singleton. | 22 // Returns the WorkerService singleton. |
25 static WorkerService* GetInstance(); | 23 static WorkerService* GetInstance(); |
26 | 24 |
27 // Initialize the WorkerService. OK to be called multiple times. | 25 // Initialize the WorkerService. OK to be called multiple times. |
28 void Initialize(ResourceDispatcherHost* rdh, MessageLoop* ui_loop); | 26 void Initialize(ResourceDispatcherHost* rdh); |
29 | 27 |
30 // Creates a dedicated worker. Returns true on success. | 28 // Creates a dedicated worker. Returns true on success. |
31 bool CreateDedicatedWorker(const GURL &url, | 29 bool CreateDedicatedWorker(const GURL &url, |
32 int renderer_pid, | 30 int renderer_pid, |
33 int render_view_route_id, | 31 int render_view_route_id, |
34 IPC::Message::Sender* sender, | 32 IPC::Message::Sender* sender, |
35 int sender_id, | 33 int sender_id, |
36 int sender_route_id); | 34 int sender_route_id); |
37 | 35 |
38 // Cancel creation of a dedicated worker that hasn't started yet. | 36 // Cancel creation of a dedicated worker that hasn't started yet. |
39 void CancelCreateDedicatedWorker(int sender_id, int sender_route_id); | 37 void CancelCreateDedicatedWorker(int sender_id, int sender_route_id); |
40 | 38 |
41 // Called by the worker creator when a message arrives that should be | 39 // Called by the worker creator when a message arrives that should be |
42 // forwarded to the worker process. | 40 // forwarded to the worker process. |
43 void ForwardMessage(const IPC::Message& message, int sender_id); | 41 void ForwardMessage(const IPC::Message& message, int sender_id); |
44 | 42 |
45 MessageLoop* ui_loop() { return ui_loop_; } | |
46 | |
47 int next_worker_route_id() { return ++next_worker_route_id_; } | 43 int next_worker_route_id() { return ++next_worker_route_id_; } |
48 | 44 |
49 // TODO(dimich): This code assumes there is 1 worker per worker process, which | 45 // TODO(dimich): This code assumes there is 1 worker per worker process, which |
50 // is how it is today until V8 can run in separate threads. | 46 // is how it is today until V8 can run in separate threads. |
51 const WorkerProcessHost::WorkerInstance* FindWorkerInstance( | 47 const WorkerProcessHost::WorkerInstance* FindWorkerInstance( |
52 int worker_process_id); | 48 int worker_process_id); |
53 | 49 |
54 // Used when multiple workers can run in the same process. | 50 // Used when multiple workers can run in the same process. |
55 static const int kMaxWorkerProcessesWhenSharing; | 51 static const int kMaxWorkerProcessesWhenSharing; |
56 | 52 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 | 84 |
89 // Notifies us that a process that's talking to a worker has shut down. | 85 // Notifies us that a process that's talking to a worker has shut down. |
90 void SenderShutdown(IPC::Message::Sender* sender); | 86 void SenderShutdown(IPC::Message::Sender* sender); |
91 | 87 |
92 // Notifies us that a worker process has closed. | 88 // Notifies us that a worker process has closed. |
93 void WorkerProcessDestroyed(WorkerProcessHost* process); | 89 void WorkerProcessDestroyed(WorkerProcessHost* process); |
94 | 90 |
95 NotificationRegistrar registrar_; | 91 NotificationRegistrar registrar_; |
96 int next_worker_route_id_; | 92 int next_worker_route_id_; |
97 ResourceDispatcherHost* resource_dispatcher_host_; | 93 ResourceDispatcherHost* resource_dispatcher_host_; |
98 MessageLoop* ui_loop_; | |
99 | 94 |
100 WorkerProcessHost::Instances queued_workers_; | 95 WorkerProcessHost::Instances queued_workers_; |
101 | 96 |
102 DISALLOW_COPY_AND_ASSIGN(WorkerService); | 97 DISALLOW_COPY_AND_ASSIGN(WorkerService); |
103 }; | 98 }; |
104 | 99 |
105 #endif // CHROME_BROWSER_WORKER_HOST_WORKER_SERVICE_H_ | 100 #endif // CHROME_BROWSER_WORKER_HOST_WORKER_SERVICE_H_ |
OLD | NEW |