OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <list> | 9 #include <list> |
10 #include <utility> | 10 #include <utility> |
(...skipping 26 matching lines...) Expand all Loading... |
37 public: | 37 public: |
38 // Contains information about each worker instance, needed to forward messages | 38 // Contains information about each worker instance, needed to forward messages |
39 // between the renderer and worker processes. | 39 // between the renderer and worker processes. |
40 class WorkerInstance { | 40 class WorkerInstance { |
41 public: | 41 public: |
42 WorkerInstance(const GURL& url, | 42 WorkerInstance(const GURL& url, |
43 const string16& name, | 43 const string16& name, |
44 int worker_route_id, | 44 int worker_route_id, |
45 int parent_process_id, | 45 int parent_process_id, |
46 int64 main_resource_appcache_id, | 46 int64 main_resource_appcache_id, |
47 const content::ResourceContext* resource_context); | 47 content::ResourceContext* resource_context); |
48 // Used for pending instances. Rest of the parameters are ignored. | 48 // Used for pending instances. Rest of the parameters are ignored. |
49 WorkerInstance(const GURL& url, | 49 WorkerInstance(const GURL& url, |
50 bool shared, | 50 bool shared, |
51 const string16& name, | 51 const string16& name, |
52 const content::ResourceContext* resource_context); | 52 content::ResourceContext* resource_context); |
53 ~WorkerInstance(); | 53 ~WorkerInstance(); |
54 | 54 |
55 // Unique identifier for a worker client. | 55 // Unique identifier for a worker client. |
56 typedef std::pair<WorkerMessageFilter*, int> FilterInfo; | 56 typedef std::pair<WorkerMessageFilter*, int> FilterInfo; |
57 | 57 |
58 // APIs to manage the filter list for a given instance. | 58 // APIs to manage the filter list for a given instance. |
59 void AddFilter(WorkerMessageFilter* filter, int route_id); | 59 void AddFilter(WorkerMessageFilter* filter, int route_id); |
60 void RemoveFilter(WorkerMessageFilter* filter, int route_id); | 60 void RemoveFilter(WorkerMessageFilter* filter, int route_id); |
61 void RemoveFilters(WorkerMessageFilter* filter); | 61 void RemoveFilters(WorkerMessageFilter* filter); |
62 bool HasFilter(WorkerMessageFilter* filter, int route_id) const; | 62 bool HasFilter(WorkerMessageFilter* filter, int route_id) const; |
63 bool RendererIsParent(int render_process_id, int render_view_id) const; | 63 bool RendererIsParent(int render_process_id, int render_view_id) const; |
64 int NumFilters() const { return filters_.size(); } | 64 int NumFilters() const { return filters_.size(); } |
65 // Returns the single filter (must only be one). | 65 // Returns the single filter (must only be one). |
66 FilterInfo GetFilter() const; | 66 FilterInfo GetFilter() const; |
67 | 67 |
68 typedef std::list<FilterInfo> FilterList; | 68 typedef std::list<FilterInfo> FilterList; |
69 const FilterList& filters() const { return filters_; } | 69 const FilterList& filters() const { return filters_; } |
70 | 70 |
71 // Checks if this WorkerInstance matches the passed url/name params | 71 // Checks if this WorkerInstance matches the passed url/name params |
72 // (per the comparison algorithm in the WebWorkers spec). This API only | 72 // (per the comparison algorithm in the WebWorkers spec). This API only |
73 // applies to shared workers. | 73 // applies to shared workers. |
74 bool Matches( | 74 bool Matches( |
75 const GURL& url, | 75 const GURL& url, |
76 const string16& name, | 76 const string16& name, |
77 const content::ResourceContext* resource_context) const; | 77 content::ResourceContext* resource_context) const; |
78 | 78 |
79 // Shares the passed instance's WorkerDocumentSet with this instance. This | 79 // Shares the passed instance's WorkerDocumentSet with this instance. This |
80 // instance's current WorkerDocumentSet is dereferenced (and freed if this | 80 // instance's current WorkerDocumentSet is dereferenced (and freed if this |
81 // is the only reference) as a result. | 81 // is the only reference) as a result. |
82 void ShareDocumentSet(const WorkerInstance& instance) { | 82 void ShareDocumentSet(const WorkerInstance& instance) { |
83 worker_document_set_ = instance.worker_document_set_; | 83 worker_document_set_ = instance.worker_document_set_; |
84 }; | 84 }; |
85 | 85 |
86 // Accessors | 86 // Accessors |
87 bool closed() const { return closed_; } | 87 bool closed() const { return closed_; } |
88 void set_closed(bool closed) { closed_ = closed; } | 88 void set_closed(bool closed) { closed_ = closed; } |
89 const GURL& url() const { return url_; } | 89 const GURL& url() const { return url_; } |
90 const string16 name() const { return name_; } | 90 const string16 name() const { return name_; } |
91 int worker_route_id() const { return worker_route_id_; } | 91 int worker_route_id() const { return worker_route_id_; } |
92 int parent_process_id() const { return parent_process_id_; } | 92 int parent_process_id() const { return parent_process_id_; } |
93 int64 main_resource_appcache_id() const { | 93 int64 main_resource_appcache_id() const { |
94 return main_resource_appcache_id_; | 94 return main_resource_appcache_id_; |
95 } | 95 } |
96 WorkerDocumentSet* worker_document_set() const { | 96 WorkerDocumentSet* worker_document_set() const { |
97 return worker_document_set_; | 97 return worker_document_set_; |
98 } | 98 } |
99 const content::ResourceContext* resource_context() const { | 99 content::ResourceContext* resource_context() const { |
100 return resource_context_; | 100 return resource_context_; |
101 } | 101 } |
102 | 102 |
103 private: | 103 private: |
104 // Set of all filters (clients) associated with this worker. | 104 // Set of all filters (clients) associated with this worker. |
105 GURL url_; | 105 GURL url_; |
106 bool closed_; | 106 bool closed_; |
107 string16 name_; | 107 string16 name_; |
108 int worker_route_id_; | 108 int worker_route_id_; |
109 int parent_process_id_; | 109 int parent_process_id_; |
110 int64 main_resource_appcache_id_; | 110 int64 main_resource_appcache_id_; |
111 FilterList filters_; | 111 FilterList filters_; |
112 scoped_refptr<WorkerDocumentSet> worker_document_set_; | 112 scoped_refptr<WorkerDocumentSet> worker_document_set_; |
113 const content::ResourceContext* const resource_context_; | 113 content::ResourceContext* const resource_context_; |
114 }; | 114 }; |
115 | 115 |
116 explicit WorkerProcessHost(const content::ResourceContext* resource_context); | 116 explicit WorkerProcessHost(content::ResourceContext* resource_context); |
117 virtual ~WorkerProcessHost(); | 117 virtual ~WorkerProcessHost(); |
118 | 118 |
119 // IPC::Message::Sender implementation: | 119 // IPC::Message::Sender implementation: |
120 virtual bool Send(IPC::Message* message) OVERRIDE; | 120 virtual bool Send(IPC::Message* message) OVERRIDE; |
121 | 121 |
122 // Starts the process. Returns true iff it succeeded. | 122 // Starts the process. Returns true iff it succeeded. |
123 // |render_process_id| is the renderer process responsible for starting this | 123 // |render_process_id| is the renderer process responsible for starting this |
124 // worker. | 124 // worker. |
125 bool Init(int render_process_id); | 125 bool Init(int render_process_id); |
126 | 126 |
(...skipping 12 matching lines...) Expand all Loading... |
139 unsigned long long document_id); | 139 unsigned long long document_id); |
140 | 140 |
141 // Terminates the given worker, i.e. based on a UI action. | 141 // Terminates the given worker, i.e. based on a UI action. |
142 CONTENT_EXPORT void TerminateWorker(int worker_route_id); | 142 CONTENT_EXPORT void TerminateWorker(int worker_route_id); |
143 | 143 |
144 CONTENT_EXPORT const content::ChildProcessData& GetData(); | 144 CONTENT_EXPORT const content::ChildProcessData& GetData(); |
145 | 145 |
146 typedef std::list<WorkerInstance> Instances; | 146 typedef std::list<WorkerInstance> Instances; |
147 const Instances& instances() const { return instances_; } | 147 const Instances& instances() const { return instances_; } |
148 | 148 |
149 const content::ResourceContext* resource_context() const { | 149 content::ResourceContext* resource_context() const { |
150 return resource_context_; | 150 return resource_context_; |
151 } | 151 } |
152 | 152 |
153 protected: | 153 protected: |
154 friend class content::WorkerServiceImpl; | 154 friend class content::WorkerServiceImpl; |
155 | 155 |
156 Instances& mutable_instances() { return instances_; } | 156 Instances& mutable_instances() { return instances_; } |
157 | 157 |
158 private: | 158 private: |
159 // BrowserChildProcessHostDelegate implementation: | 159 // BrowserChildProcessHostDelegate implementation: |
(...skipping 24 matching lines...) Expand all Loading... |
184 | 184 |
185 // Updates the title shown in the task manager. | 185 // Updates the title shown in the task manager. |
186 void UpdateTitle(); | 186 void UpdateTitle(); |
187 | 187 |
188 // Return a vector of all the render process/render view IDs that use the | 188 // Return a vector of all the render process/render view IDs that use the |
189 // given worker. | 189 // given worker. |
190 std::vector<std::pair<int, int> > GetRenderViewIDsForWorker(int route_id); | 190 std::vector<std::pair<int, int> > GetRenderViewIDsForWorker(int route_id); |
191 | 191 |
192 Instances instances_; | 192 Instances instances_; |
193 | 193 |
194 const content::ResourceContext* const resource_context_; | 194 content::ResourceContext* const resource_context_; |
195 | 195 |
196 // A reference to the filter associated with this worker process. We need to | 196 // A reference to the filter associated with this worker process. We need to |
197 // keep this around since we'll use it when forward messages to the worker | 197 // keep this around since we'll use it when forward messages to the worker |
198 // process. | 198 // process. |
199 scoped_refptr<WorkerMessageFilter> worker_message_filter_; | 199 scoped_refptr<WorkerMessageFilter> worker_message_filter_; |
200 | 200 |
201 scoped_ptr<BrowserChildProcessHostImpl> process_; | 201 scoped_ptr<BrowserChildProcessHostImpl> process_; |
202 | 202 |
203 DISALLOW_COPY_AND_ASSIGN(WorkerProcessHost); | 203 DISALLOW_COPY_AND_ASSIGN(WorkerProcessHost); |
204 }; | 204 }; |
205 | 205 |
206 class WorkerProcessHostIterator | 206 class WorkerProcessHostIterator |
207 : public content::BrowserChildProcessHostTypeIterator<WorkerProcessHost> { | 207 : public content::BrowserChildProcessHostTypeIterator<WorkerProcessHost> { |
208 public: | 208 public: |
209 WorkerProcessHostIterator() | 209 WorkerProcessHostIterator() |
210 : content::BrowserChildProcessHostTypeIterator<WorkerProcessHost>( | 210 : content::BrowserChildProcessHostTypeIterator<WorkerProcessHost>( |
211 content::PROCESS_TYPE_WORKER) { | 211 content::PROCESS_TYPE_WORKER) { |
212 } | 212 } |
213 }; | 213 }; |
214 | 214 |
215 #endif // CONTENT_BROWSER_WORKER_HOST_WORKER_PROCESS_HOST_H_ | 215 #endif // CONTENT_BROWSER_WORKER_HOST_WORKER_PROCESS_HOST_H_ |
OLD | NEW |