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_PROCESS_HOST_H_ | 5 #ifndef CONTENT_BROWSER_WORKER_HOST_WORKER_PROCESS_HOST_H_ |
6 #define CONTENT_BROWSER_WORKER_HOST_WORKER_PROCESS_HOST_H_ | 6 #define CONTENT_BROWSER_WORKER_HOST_WORKER_PROCESS_HOST_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
15 #include "content/browser/worker_host/worker_document_set.h" | 15 #include "content/browser/worker_host/worker_document_set.h" |
16 #include "content/public/browser/browser_child_process_host_delegate.h" | 16 #include "content/public/browser/browser_child_process_host_delegate.h" |
17 #include "content/public/browser/browser_child_process_host_iterator.h" | 17 #include "content/public/browser/browser_child_process_host_iterator.h" |
18 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
19 #include "ipc/ipc_sender.h" | 19 #include "ipc/ipc_sender.h" |
20 | 20 |
21 class BrowserChildProcessHostImpl; | 21 class BrowserChildProcessHostImpl; |
22 | 22 |
23 namespace content { | 23 namespace content { |
24 class ResourceContext; | 24 class ResourceContext; |
| 25 class StoragePartitionImpl; |
25 class WorkerServiceImpl; | 26 class WorkerServiceImpl; |
26 } // namespace content | 27 } // namespace content |
27 | 28 |
28 // The WorkerProcessHost is the interface that represents the browser side of | 29 // The WorkerProcessHost is the interface that represents the browser side of |
29 // the browser <-> worker communication channel. There will be one | 30 // the browser <-> worker communication channel. There will be one |
30 // WorkerProcessHost per worker process. Currently each worker runs in its own | 31 // WorkerProcessHost per worker process. Currently each worker runs in its own |
31 // process, but that may change. However, we do assume (by storing a | 32 // process, but that may change. However, we do assume (by storing a |
32 // net::URLRequestContext) that a WorkerProcessHost serves a single | 33 // net::URLRequestContext) that a WorkerProcessHost serves a single |
33 // BrowserContext. | 34 // BrowserContext. |
34 class WorkerProcessHost : public content::BrowserChildProcessHostDelegate, | 35 class WorkerProcessHost : public content::BrowserChildProcessHostDelegate, |
35 public IPC::Sender { | 36 public IPC::Sender { |
36 public: | 37 public: |
37 // Contains information about each worker instance, needed to forward messages | 38 // Contains information about each worker instance, needed to forward messages |
38 // between the renderer and worker processes. | 39 // between the renderer and worker processes. |
39 class WorkerInstance { | 40 class WorkerInstance { |
40 public: | 41 public: |
41 WorkerInstance(const GURL& url, | 42 WorkerInstance(const GURL& url, |
42 const string16& name, | 43 const string16& name, |
43 int worker_route_id, | 44 int worker_route_id, |
44 int parent_process_id, | 45 int parent_process_id, |
45 int64 main_resource_appcache_id, | 46 int64 main_resource_appcache_id, |
46 content::ResourceContext* resource_context); | 47 content::ResourceContext* resource_context, |
| 48 content::StoragePartitionImpl* storage_partition); |
47 // Used for pending instances. Rest of the parameters are ignored. | 49 // Used for pending instances. Rest of the parameters are ignored. |
48 WorkerInstance(const GURL& url, | 50 WorkerInstance(const GURL& url, |
49 bool shared, | 51 bool shared, |
50 const string16& name, | 52 const string16& name, |
51 content::ResourceContext* resource_context); | 53 content::ResourceContext* resource_context, |
| 54 content::StoragePartitionImpl* storage_partition); |
52 ~WorkerInstance(); | 55 ~WorkerInstance(); |
53 | 56 |
54 // Unique identifier for a worker client. | 57 // Unique identifier for a worker client. |
55 typedef std::pair<WorkerMessageFilter*, int> FilterInfo; | 58 typedef std::pair<WorkerMessageFilter*, int> FilterInfo; |
56 | 59 |
57 // APIs to manage the filter list for a given instance. | 60 // APIs to manage the filter list for a given instance. |
58 void AddFilter(WorkerMessageFilter* filter, int route_id); | 61 void AddFilter(WorkerMessageFilter* filter, int route_id); |
59 void RemoveFilter(WorkerMessageFilter* filter, int route_id); | 62 void RemoveFilter(WorkerMessageFilter* filter, int route_id); |
60 void RemoveFilters(WorkerMessageFilter* filter); | 63 void RemoveFilters(WorkerMessageFilter* filter); |
61 bool HasFilter(WorkerMessageFilter* filter, int route_id) const; | 64 bool HasFilter(WorkerMessageFilter* filter, int route_id) const; |
62 bool RendererIsParent(int render_process_id, int render_view_id) const; | 65 bool RendererIsParent(int render_process_id, int render_view_id) const; |
63 int NumFilters() const { return filters_.size(); } | 66 int NumFilters() const { return filters_.size(); } |
64 // Returns the single filter (must only be one). | 67 // Returns the single filter (must only be one). |
65 FilterInfo GetFilter() const; | 68 FilterInfo GetFilter() const; |
66 | 69 |
67 typedef std::list<FilterInfo> FilterList; | 70 typedef std::list<FilterInfo> FilterList; |
68 const FilterList& filters() const { return filters_; } | 71 const FilterList& filters() const { return filters_; } |
69 | 72 |
70 // Checks if this WorkerInstance matches the passed url/name params | 73 // Checks if this WorkerInstance matches the passed url/name params |
71 // (per the comparison algorithm in the WebWorkers spec). This API only | 74 // (per the comparison algorithm in the WebWorkers spec). This API only |
72 // applies to shared workers. | 75 // applies to shared workers. |
73 bool Matches( | 76 bool Matches( |
74 const GURL& url, | 77 const GURL& url, |
75 const string16& name, | 78 const string16& name, |
76 content::ResourceContext* resource_context) const; | 79 content::ResourceContext* resource_context, |
| 80 content::StoragePartitionImpl* storage_partition) const; |
77 | 81 |
78 // Shares the passed instance's WorkerDocumentSet with this instance. This | 82 // Shares the passed instance's WorkerDocumentSet with this instance. This |
79 // instance's current WorkerDocumentSet is dereferenced (and freed if this | 83 // instance's current WorkerDocumentSet is dereferenced (and freed if this |
80 // is the only reference) as a result. | 84 // is the only reference) as a result. |
81 void ShareDocumentSet(const WorkerInstance& instance) { | 85 void ShareDocumentSet(const WorkerInstance& instance) { |
82 worker_document_set_ = instance.worker_document_set_; | 86 worker_document_set_ = instance.worker_document_set_; |
83 }; | 87 }; |
84 | 88 |
85 // Accessors | 89 // Accessors |
86 bool closed() const { return closed_; } | 90 bool closed() const { return closed_; } |
87 void set_closed(bool closed) { closed_ = closed; } | 91 void set_closed(bool closed) { closed_ = closed; } |
88 const GURL& url() const { return url_; } | 92 const GURL& url() const { return url_; } |
89 const string16 name() const { return name_; } | 93 const string16 name() const { return name_; } |
90 int worker_route_id() const { return worker_route_id_; } | 94 int worker_route_id() const { return worker_route_id_; } |
91 int parent_process_id() const { return parent_process_id_; } | 95 int parent_process_id() const { return parent_process_id_; } |
92 int64 main_resource_appcache_id() const { | 96 int64 main_resource_appcache_id() const { |
93 return main_resource_appcache_id_; | 97 return main_resource_appcache_id_; |
94 } | 98 } |
95 WorkerDocumentSet* worker_document_set() const { | 99 WorkerDocumentSet* worker_document_set() const { |
96 return worker_document_set_; | 100 return worker_document_set_; |
97 } | 101 } |
98 content::ResourceContext* resource_context() const { | 102 content::ResourceContext* resource_context() const { |
99 return resource_context_; | 103 return resource_context_; |
100 } | 104 } |
101 | 105 content::StoragePartitionImpl* storage_partition() const { |
| 106 return storage_partition_; |
| 107 } |
102 private: | 108 private: |
103 // Set of all filters (clients) associated with this worker. | 109 // Set of all filters (clients) associated with this worker. |
104 GURL url_; | 110 GURL url_; |
105 bool closed_; | 111 bool closed_; |
106 string16 name_; | 112 string16 name_; |
107 int worker_route_id_; | 113 int worker_route_id_; |
108 int parent_process_id_; | 114 int parent_process_id_; |
109 int64 main_resource_appcache_id_; | 115 int64 main_resource_appcache_id_; |
110 FilterList filters_; | 116 FilterList filters_; |
111 scoped_refptr<WorkerDocumentSet> worker_document_set_; | 117 scoped_refptr<WorkerDocumentSet> worker_document_set_; |
112 content::ResourceContext* const resource_context_; | 118 content::ResourceContext* const resource_context_; |
| 119 scoped_refptr<content::StoragePartitionImpl> storage_partition_; |
113 }; | 120 }; |
114 | 121 |
115 explicit WorkerProcessHost(content::ResourceContext* resource_context); | 122 explicit WorkerProcessHost(content::ResourceContext* resource_context, |
| 123 content::StoragePartitionImpl* storage_partition); |
116 virtual ~WorkerProcessHost(); | 124 virtual ~WorkerProcessHost(); |
117 | 125 |
118 // IPC::Sender implementation: | 126 // IPC::Sender implementation: |
119 virtual bool Send(IPC::Message* message) OVERRIDE; | 127 virtual bool Send(IPC::Message* message) OVERRIDE; |
120 | 128 |
121 // Starts the process. Returns true iff it succeeded. | 129 // Starts the process. Returns true iff it succeeded. |
122 // |render_process_id| is the renderer process responsible for starting this | 130 // |render_process_id| is the renderer process responsible for starting this |
123 // worker. | 131 // worker. |
124 bool Init(int render_process_id); | 132 bool Init(int render_process_id); |
125 | 133 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 // Updates the title shown in the task manager. | 196 // Updates the title shown in the task manager. |
189 void UpdateTitle(); | 197 void UpdateTitle(); |
190 | 198 |
191 // Return a vector of all the render process/render view IDs that use the | 199 // Return a vector of all the render process/render view IDs that use the |
192 // given worker. | 200 // given worker. |
193 std::vector<std::pair<int, int> > GetRenderViewIDsForWorker(int route_id); | 201 std::vector<std::pair<int, int> > GetRenderViewIDsForWorker(int route_id); |
194 | 202 |
195 Instances instances_; | 203 Instances instances_; |
196 | 204 |
197 content::ResourceContext* const resource_context_; | 205 content::ResourceContext* const resource_context_; |
| 206 scoped_refptr<content::StoragePartitionImpl> storage_partition_; |
198 | 207 |
199 // A reference to the filter associated with this worker process. We need to | 208 // A reference to the filter associated with this worker process. We need to |
200 // keep this around since we'll use it when forward messages to the worker | 209 // keep this around since we'll use it when forward messages to the worker |
201 // process. | 210 // process. |
202 scoped_refptr<WorkerMessageFilter> worker_message_filter_; | 211 scoped_refptr<WorkerMessageFilter> worker_message_filter_; |
203 | 212 |
204 scoped_ptr<BrowserChildProcessHostImpl> process_; | 213 scoped_ptr<BrowserChildProcessHostImpl> process_; |
205 | 214 |
206 DISALLOW_COPY_AND_ASSIGN(WorkerProcessHost); | 215 DISALLOW_COPY_AND_ASSIGN(WorkerProcessHost); |
207 }; | 216 }; |
208 | 217 |
209 class WorkerProcessHostIterator | 218 class WorkerProcessHostIterator |
210 : public content::BrowserChildProcessHostTypeIterator<WorkerProcessHost> { | 219 : public content::BrowserChildProcessHostTypeIterator<WorkerProcessHost> { |
211 public: | 220 public: |
212 WorkerProcessHostIterator() | 221 WorkerProcessHostIterator() |
213 : content::BrowserChildProcessHostTypeIterator<WorkerProcessHost>( | 222 : content::BrowserChildProcessHostTypeIterator<WorkerProcessHost>( |
214 content::PROCESS_TYPE_WORKER) { | 223 content::PROCESS_TYPE_WORKER) { |
215 } | 224 } |
216 }; | 225 }; |
217 | 226 |
218 #endif // CONTENT_BROWSER_WORKER_HOST_WORKER_PROCESS_HOST_H_ | 227 #endif // CONTENT_BROWSER_WORKER_HOST_WORKER_PROCESS_HOST_H_ |
OLD | NEW |