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_PROCESS_HOST_H_ | 5 #ifndef CHROME_BROWSER_WORKER_HOST_WORKER_PROCESS_HOST_H_ |
6 #define CHROME_BROWSER_WORKER_HOST_WORKER_PROCESS_HOST_H_ | 6 #define CHROME_BROWSER_WORKER_HOST_WORKER_PROCESS_HOST_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/task.h" | 11 #include "base/task.h" |
12 #include "chrome/common/child_process_host.h" | 12 #include "chrome/common/child_process_host.h" |
13 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
14 #include "ipc/ipc_channel.h" | 14 #include "ipc/ipc_channel.h" |
15 | 15 |
16 class WorkerProcessHost : public ChildProcessHost { | 16 class WorkerProcessHost : public ChildProcessHost { |
17 public: | 17 public: |
18 // Contains information about each worker instance, needed to forward messages | 18 // Contains information about each worker instance, needed to forward messages |
19 // between the renderer and worker processes. | 19 // between the renderer and worker processes. |
20 struct WorkerInstance { | 20 class WorkerInstance { |
jam
2009/11/12 20:11:23
nit: If this is a class, then it's against the cod
| |
21 public: | |
22 WorkerInstance() : closed(false) {}; | |
23 | |
24 // Checks if this WorkerInstance matches the passed url/name params | |
jam
2009/11/12 20:11:23
nit: just to make it clear to someone reading the
| |
25 // (per the comparison algorithm in the WebWorkers spec). | |
26 bool Matches(const GURL& url, const string16& name) const; | |
27 | |
28 // Adds a document to a shared worker's document set. | |
29 void AddToDocumentSet(IPC::Message::Sender* parent, | |
30 unsigned long long document_id); | |
31 | |
32 // Checks to see if a document is in the worker's document set. | |
33 bool IsInDocumentSet(IPC::Message::Sender* parent, | |
34 unsigned long long document_id) const; | |
35 | |
36 // Removes a specific document from the set when that document is detached. | |
37 void RemoveFromDocumentSet(IPC::Message::Sender* parent, | |
38 unsigned long long document_id); | |
39 | |
40 // Invoked when a render process exits, to remove all associated documents | |
41 // from the set. | |
42 void RemoveAllAssociatedDocuments(IPC::Message::Sender* parent); | |
43 | |
44 // APIs to manage the sender list for a given instance. | |
45 void AddSender(IPC::Message::Sender* sender, int sender_route_id); | |
46 void RemoveSender(IPC::Message::Sender* sender, int sender_route_id); | |
47 void RemoveSenders(IPC::Message::Sender* sender); | |
48 bool HasSender(IPC::Message::Sender* sender, int sender_route_id) const; | |
49 | |
50 // Unique identifier for an associated document. | |
51 typedef std::pair<IPC::Message::Sender*, unsigned long long> DocumentInfo; | |
52 typedef std::set<DocumentInfo> DocumentSet; | |
53 | |
54 typedef std::pair<IPC::Message::Sender*, int> SenderInfo; | |
55 typedef std::set<SenderInfo> SenderList; | |
56 | |
21 GURL url; | 57 GURL url; |
22 bool is_shared; | 58 bool is_shared; |
59 bool closed; | |
23 string16 name; | 60 string16 name; |
24 int renderer_id; | 61 int renderer_id; |
25 int render_view_route_id; | 62 int render_view_route_id; |
26 int worker_route_id; | 63 int worker_route_id; |
27 IPC::Message::Sender* sender; | 64 SenderList senders; |
28 int sender_id; | 65 DocumentSet document_set; |
29 int sender_route_id; | |
30 }; | 66 }; |
31 | 67 |
32 WorkerProcessHost(ResourceDispatcherHost* resource_dispatcher_host_); | 68 WorkerProcessHost(ResourceDispatcherHost* resource_dispatcher_host_); |
33 ~WorkerProcessHost(); | 69 ~WorkerProcessHost(); |
34 | 70 |
35 // Starts the process. Returns true iff it succeeded. | 71 // Starts the process. Returns true iff it succeeded. |
36 bool Init(); | 72 bool Init(); |
37 | 73 |
38 // Creates a worker object in the process. | 74 // Creates a worker object in the process. |
39 void CreateWorker(const WorkerInstance& instance); | 75 void CreateWorker(const WorkerInstance& instance); |
40 | 76 |
41 // Returns true iff the given message from a renderer process was forwarded to | 77 // Returns true iff the given message from a renderer process was forwarded to |
42 // the worker. | 78 // the worker. |
43 bool FilterMessage(const IPC::Message& message, int sender_pid); | 79 bool FilterMessage(const IPC::Message& message, IPC::Message::Sender* sender); |
44 | 80 |
45 void SenderShutdown(IPC::Message::Sender* sender); | 81 void SenderShutdown(IPC::Message::Sender* sender); |
46 | 82 |
83 // Shuts down any shared workers that are no longer referenced by active | |
84 // documents. | |
85 void DocumentDetached(IPC::Message::Sender* sender, | |
86 unsigned long long document_id); | |
87 | |
47 protected: | 88 protected: |
48 friend class WorkerService; | 89 friend class WorkerService; |
49 | 90 |
50 typedef std::list<WorkerInstance> Instances; | 91 typedef std::list<WorkerInstance> Instances; |
51 const Instances& instances() const { return instances_; } | 92 const Instances& instances() const { return instances_; } |
93 Instances& mutable_instances() { return instances_; } | |
52 | 94 |
53 private: | 95 private: |
54 // ResourceDispatcherHost::Receiver implementation: | 96 // ResourceDispatcherHost::Receiver implementation: |
55 virtual URLRequestContext* GetRequestContext( | 97 virtual URLRequestContext* GetRequestContext( |
56 uint32 request_id, | 98 uint32 request_id, |
57 const ViewHostMsg_Resource_Request& request_data); | 99 const ViewHostMsg_Resource_Request& request_data); |
58 | 100 |
59 // Called when a message arrives from the worker process. | 101 // Called when a message arrives from the worker process. |
60 void OnMessageReceived(const IPC::Message& message); | 102 void OnMessageReceived(const IPC::Message& message); |
61 | 103 |
104 // Called when the app invokes close() from within worker context. | |
105 void OnWorkerContextClosed(int worker_route_id); | |
106 | |
62 // Given a Sender, returns the callback that generates a new routing id. | 107 // Given a Sender, returns the callback that generates a new routing id. |
63 static CallbackWithReturnValue<int>::Type* GetNextRouteIdCallback( | 108 static CallbackWithReturnValue<int>::Type* GetNextRouteIdCallback( |
64 IPC::Message::Sender* sender); | 109 IPC::Message::Sender* sender); |
65 | 110 |
66 // Relays a message to the given endpoint. Takes care of parsing the message | 111 // Relays a message to the given endpoint. Takes care of parsing the message |
67 // if it contains a message port and sending it a valid route id. | 112 // if it contains a message port and sending it a valid route id. |
68 static void RelayMessage(const IPC::Message& message, | 113 static void RelayMessage(const IPC::Message& message, |
69 IPC::Message::Sender* sender, | 114 IPC::Message::Sender* sender, |
70 int route_id, | 115 int route_id, |
71 CallbackWithReturnValue<int>::Type* next_route_id); | 116 CallbackWithReturnValue<int>::Type* next_route_id); |
(...skipping 13 matching lines...) Expand all Loading... | |
85 | 130 |
86 Instances instances_; | 131 Instances instances_; |
87 | 132 |
88 // A callback to create a routing id for the associated worker process. | 133 // A callback to create a routing id for the associated worker process. |
89 scoped_ptr<CallbackWithReturnValue<int>::Type> next_route_id_callback_; | 134 scoped_ptr<CallbackWithReturnValue<int>::Type> next_route_id_callback_; |
90 | 135 |
91 DISALLOW_COPY_AND_ASSIGN(WorkerProcessHost); | 136 DISALLOW_COPY_AND_ASSIGN(WorkerProcessHost); |
92 }; | 137 }; |
93 | 138 |
94 #endif // CHROME_BROWSER_WORKER_HOST_WORKER_PROCESS_HOST_H_ | 139 #endif // CHROME_BROWSER_WORKER_HOST_WORKER_PROCESS_HOST_H_ |
OLD | NEW |