| 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" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 // Initialize the WorkerService. OK to be called multiple times. | 25 // Initialize the WorkerService. OK to be called multiple times. |
| 26 void Initialize(ResourceDispatcherHost* rdh); | 26 void Initialize(ResourceDispatcherHost* rdh); |
| 27 | 27 |
| 28 // Creates a dedicated worker. Returns true on success. | 28 // Creates a dedicated worker. Returns true on success. |
| 29 bool CreateWorker(const GURL &url, | 29 bool CreateWorker(const GURL &url, |
| 30 bool is_shared, | 30 bool is_shared, |
| 31 const string16& name, | 31 const string16& name, |
| 32 int renderer_pid, | 32 int renderer_pid, |
| 33 int render_view_route_id, | 33 int render_view_route_id, |
| 34 IPC::Message::Sender* sender, | 34 IPC::Message::Sender* sender, |
| 35 int sender_id, | |
| 36 int sender_route_id); | 35 int sender_route_id); |
| 37 | 36 |
| 37 // Validates the passed URL and checks for the existence of matching shared |
| 38 // worker. Returns true if the url was found, and sets the url_mismatch out |
| 39 // param to true/false depending on whether there's a url mismatch with an |
| 40 // existing shared worker with the same name. |
| 41 bool LookupSharedWorker(const GURL &url, |
| 42 const string16& name, |
| 43 unsigned long long document_id, |
| 44 IPC::Message::Sender* sender, |
| 45 int sender_route_id, |
| 46 bool* url_mismatch); |
| 47 |
| 48 // Notification from the renderer that a given document has detached, so any |
| 49 // associated shared workers can be shut down. |
| 50 void DocumentDetached(IPC::Message::Sender* sender, |
| 51 unsigned long long document_id); |
| 52 |
| 38 // Cancel creation of a dedicated worker that hasn't started yet. | 53 // Cancel creation of a dedicated worker that hasn't started yet. |
| 39 void CancelCreateDedicatedWorker(int sender_id, int sender_route_id); | 54 void CancelCreateDedicatedWorker(IPC::Message::Sender* sender, |
| 55 int sender_route_id); |
| 40 | 56 |
| 41 // Called by the worker creator when a message arrives that should be | 57 // Called by the worker creator when a message arrives that should be |
| 42 // forwarded to the worker process. | 58 // forwarded to the worker process. |
| 43 void ForwardMessage(const IPC::Message& message, int sender_id); | 59 void ForwardMessage(const IPC::Message& message, |
| 60 IPC::Message::Sender* sender); |
| 44 | 61 |
| 45 int next_worker_route_id() { return ++next_worker_route_id_; } | 62 int next_worker_route_id() { return ++next_worker_route_id_; } |
| 46 | 63 |
| 47 // TODO(dimich): This code assumes there is 1 worker per worker process, which | 64 // TODO(dimich): This code assumes there is 1 worker per worker process, which |
| 48 // is how it is today until V8 can run in separate threads. | 65 // is how it is today until V8 can run in separate threads. |
| 49 const WorkerProcessHost::WorkerInstance* FindWorkerInstance( | 66 const WorkerProcessHost::WorkerInstance* FindWorkerInstance( |
| 50 int worker_process_id); | 67 int worker_process_id); |
| 51 | 68 |
| 69 WorkerProcessHost::WorkerInstance* FindSharedWorkerInstance( |
| 70 const GURL& url, const string16& name); |
| 71 |
| 52 // Used when multiple workers can run in the same process. | 72 // Used when multiple workers can run in the same process. |
| 53 static const int kMaxWorkerProcessesWhenSharing; | 73 static const int kMaxWorkerProcessesWhenSharing; |
| 54 | 74 |
| 55 // Used when we run each worker in a separate process. | 75 // Used when we run each worker in a separate process. |
| 56 static const int kMaxWorkersWhenSeparate; | 76 static const int kMaxWorkersWhenSeparate; |
| 57 static const int kMaxWorkersPerTabWhenSeparate; | 77 static const int kMaxWorkersPerTabWhenSeparate; |
| 58 | 78 |
| 59 private: | 79 private: |
| 60 friend struct DefaultSingletonTraits<WorkerService>; | 80 friend struct DefaultSingletonTraits<WorkerService>; |
| 61 | 81 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 83 void Observe(NotificationType type, | 103 void Observe(NotificationType type, |
| 84 const NotificationSource& source, | 104 const NotificationSource& source, |
| 85 const NotificationDetails& details); | 105 const NotificationDetails& details); |
| 86 | 106 |
| 87 // Notifies us that a process that's talking to a worker has shut down. | 107 // Notifies us that a process that's talking to a worker has shut down. |
| 88 void SenderShutdown(IPC::Message::Sender* sender); | 108 void SenderShutdown(IPC::Message::Sender* sender); |
| 89 | 109 |
| 90 // Notifies us that a worker process has closed. | 110 // Notifies us that a worker process has closed. |
| 91 void WorkerProcessDestroyed(WorkerProcessHost* process); | 111 void WorkerProcessDestroyed(WorkerProcessHost* process); |
| 92 | 112 |
| 113 // APIs for manipulating our set of pending shared worker instances. |
| 114 WorkerProcessHost::WorkerInstance* CreatePendingInstance( |
| 115 const GURL& url, const string16& name); |
| 116 WorkerProcessHost::WorkerInstance* FindPendingInstance( |
| 117 const GURL& url, const string16& name); |
| 118 void RemovePendingInstance(const GURL& url, const string16& name); |
| 119 |
| 93 NotificationRegistrar registrar_; | 120 NotificationRegistrar registrar_; |
| 94 int next_worker_route_id_; | 121 int next_worker_route_id_; |
| 95 ResourceDispatcherHost* resource_dispatcher_host_; | 122 ResourceDispatcherHost* resource_dispatcher_host_; |
| 96 | 123 |
| 97 WorkerProcessHost::Instances queued_workers_; | 124 WorkerProcessHost::Instances queued_workers_; |
| 98 | 125 |
| 126 // These are shared workers that have been looked up, but not created yet. |
| 127 // We need to keep a list of these to synchronously detect shared worker |
| 128 // URL mismatches when two pages launch shared workers simultaneously. |
| 129 WorkerProcessHost::Instances pending_shared_workers_; |
| 130 |
| 99 DISALLOW_COPY_AND_ASSIGN(WorkerService); | 131 DISALLOW_COPY_AND_ASSIGN(WorkerService); |
| 100 }; | 132 }; |
| 101 | 133 |
| 102 #endif // CHROME_BROWSER_WORKER_HOST_WORKER_SERVICE_H_ | 134 #endif // CHROME_BROWSER_WORKER_HOST_WORKER_SERVICE_H_ |
| OLD | NEW |