| 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 <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 // net::URLRequestContext) that a WorkerProcessHost serves a single | 50 // net::URLRequestContext) that a WorkerProcessHost serves a single |
| 51 // BrowserContext. | 51 // BrowserContext. |
| 52 class WorkerProcessHost : public BrowserChildProcessHostDelegate, | 52 class WorkerProcessHost : public BrowserChildProcessHostDelegate, |
| 53 public IPC::Sender { | 53 public IPC::Sender { |
| 54 public: | 54 public: |
| 55 // Contains information about each worker instance, needed to forward messages | 55 // Contains information about each worker instance, needed to forward messages |
| 56 // between the renderer and worker processes. | 56 // between the renderer and worker processes. |
| 57 class WorkerInstance { | 57 class WorkerInstance { |
| 58 public: | 58 public: |
| 59 WorkerInstance(const GURL& url, | 59 WorkerInstance(const GURL& url, |
| 60 const string16& name, | 60 const base::string16& name, |
| 61 int worker_route_id, | 61 int worker_route_id, |
| 62 int parent_process_id, | 62 int parent_process_id, |
| 63 int64 main_resource_appcache_id, | 63 int64 main_resource_appcache_id, |
| 64 ResourceContext* resource_context, | 64 ResourceContext* resource_context, |
| 65 const WorkerStoragePartition& partition); | 65 const WorkerStoragePartition& partition); |
| 66 // Used for pending instances. Rest of the parameters are ignored. | 66 // Used for pending instances. Rest of the parameters are ignored. |
| 67 WorkerInstance(const GURL& url, | 67 WorkerInstance(const GURL& url, |
| 68 bool shared, | 68 bool shared, |
| 69 const string16& name, | 69 const base::string16& name, |
| 70 ResourceContext* resource_context, | 70 ResourceContext* resource_context, |
| 71 const WorkerStoragePartition& partition); | 71 const WorkerStoragePartition& partition); |
| 72 ~WorkerInstance(); | 72 ~WorkerInstance(); |
| 73 | 73 |
| 74 // Unique identifier for a worker client. | 74 // Unique identifier for a worker client. |
| 75 typedef std::pair<WorkerMessageFilter*, int> FilterInfo; | 75 typedef std::pair<WorkerMessageFilter*, int> FilterInfo; |
| 76 | 76 |
| 77 // APIs to manage the filter list for a given instance. | 77 // APIs to manage the filter list for a given instance. |
| 78 void AddFilter(WorkerMessageFilter* filter, int route_id); | 78 void AddFilter(WorkerMessageFilter* filter, int route_id); |
| 79 void RemoveFilter(WorkerMessageFilter* filter, int route_id); | 79 void RemoveFilter(WorkerMessageFilter* filter, int route_id); |
| 80 void RemoveFilters(WorkerMessageFilter* filter); | 80 void RemoveFilters(WorkerMessageFilter* filter); |
| 81 bool HasFilter(WorkerMessageFilter* filter, int route_id) const; | 81 bool HasFilter(WorkerMessageFilter* filter, int route_id) const; |
| 82 bool RendererIsParent(int render_process_id, int render_view_id) const; | 82 bool RendererIsParent(int render_process_id, int render_view_id) const; |
| 83 int NumFilters() const { return filters_.size(); } | 83 int NumFilters() const { return filters_.size(); } |
| 84 // Returns the single filter (must only be one). | 84 // Returns the single filter (must only be one). |
| 85 FilterInfo GetFilter() const; | 85 FilterInfo GetFilter() const; |
| 86 | 86 |
| 87 typedef std::list<FilterInfo> FilterList; | 87 typedef std::list<FilterInfo> FilterList; |
| 88 const FilterList& filters() const { return filters_; } | 88 const FilterList& filters() const { return filters_; } |
| 89 | 89 |
| 90 // Checks if this WorkerInstance matches the passed url/name params | 90 // Checks if this WorkerInstance matches the passed url/name params |
| 91 // (per the comparison algorithm in the WebWorkers spec). This API only | 91 // (per the comparison algorithm in the WebWorkers spec). This API only |
| 92 // applies to shared workers. | 92 // applies to shared workers. |
| 93 bool Matches( | 93 bool Matches( |
| 94 const GURL& url, | 94 const GURL& url, |
| 95 const string16& name, | 95 const base::string16& name, |
| 96 const WorkerStoragePartition& partition, | 96 const WorkerStoragePartition& partition, |
| 97 ResourceContext* resource_context) const; | 97 ResourceContext* resource_context) const; |
| 98 | 98 |
| 99 // Shares the passed instance's WorkerDocumentSet with this instance. This | 99 // Shares the passed instance's WorkerDocumentSet with this instance. This |
| 100 // instance's current WorkerDocumentSet is dereferenced (and freed if this | 100 // instance's current WorkerDocumentSet is dereferenced (and freed if this |
| 101 // is the only reference) as a result. | 101 // is the only reference) as a result. |
| 102 void ShareDocumentSet(const WorkerInstance& instance) { | 102 void ShareDocumentSet(const WorkerInstance& instance) { |
| 103 worker_document_set_ = instance.worker_document_set_; | 103 worker_document_set_ = instance.worker_document_set_; |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 // Accessors | 106 // Accessors |
| 107 bool closed() const { return closed_; } | 107 bool closed() const { return closed_; } |
| 108 void set_closed(bool closed) { closed_ = closed; } | 108 void set_closed(bool closed) { closed_ = closed; } |
| 109 const GURL& url() const { return url_; } | 109 const GURL& url() const { return url_; } |
| 110 const string16 name() const { return name_; } | 110 const base::string16 name() const { return name_; } |
| 111 int worker_route_id() const { return worker_route_id_; } | 111 int worker_route_id() const { return worker_route_id_; } |
| 112 int parent_process_id() const { return parent_process_id_; } | 112 int parent_process_id() const { return parent_process_id_; } |
| 113 int64 main_resource_appcache_id() const { | 113 int64 main_resource_appcache_id() const { |
| 114 return main_resource_appcache_id_; | 114 return main_resource_appcache_id_; |
| 115 } | 115 } |
| 116 WorkerDocumentSet* worker_document_set() const { | 116 WorkerDocumentSet* worker_document_set() const { |
| 117 return worker_document_set_.get(); | 117 return worker_document_set_.get(); |
| 118 } | 118 } |
| 119 ResourceContext* resource_context() const { | 119 ResourceContext* resource_context() const { |
| 120 return resource_context_; | 120 return resource_context_; |
| 121 } | 121 } |
| 122 const WorkerStoragePartition& partition() const { | 122 const WorkerStoragePartition& partition() const { |
| 123 return partition_; | 123 return partition_; |
| 124 } | 124 } |
| 125 | 125 |
| 126 private: | 126 private: |
| 127 // Set of all filters (clients) associated with this worker. | 127 // Set of all filters (clients) associated with this worker. |
| 128 GURL url_; | 128 GURL url_; |
| 129 bool closed_; | 129 bool closed_; |
| 130 string16 name_; | 130 base::string16 name_; |
| 131 int worker_route_id_; | 131 int worker_route_id_; |
| 132 int parent_process_id_; | 132 int parent_process_id_; |
| 133 int64 main_resource_appcache_id_; | 133 int64 main_resource_appcache_id_; |
| 134 FilterList filters_; | 134 FilterList filters_; |
| 135 scoped_refptr<WorkerDocumentSet> worker_document_set_; | 135 scoped_refptr<WorkerDocumentSet> worker_document_set_; |
| 136 ResourceContext* const resource_context_; | 136 ResourceContext* const resource_context_; |
| 137 WorkerStoragePartition partition_; | 137 WorkerStoragePartition partition_; |
| 138 }; | 138 }; |
| 139 | 139 |
| 140 WorkerProcessHost(ResourceContext* resource_context, | 140 WorkerProcessHost(ResourceContext* resource_context, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 // BrowserChildProcessHostDelegate implementation: | 189 // BrowserChildProcessHostDelegate implementation: |
| 190 virtual void OnProcessLaunched() OVERRIDE; | 190 virtual void OnProcessLaunched() OVERRIDE; |
| 191 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 191 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 192 | 192 |
| 193 // Creates and adds the message filters. | 193 // Creates and adds the message filters. |
| 194 void CreateMessageFilters(int render_process_id); | 194 void CreateMessageFilters(int render_process_id); |
| 195 | 195 |
| 196 void OnWorkerContextClosed(int worker_route_id); | 196 void OnWorkerContextClosed(int worker_route_id); |
| 197 void OnAllowDatabase(int worker_route_id, | 197 void OnAllowDatabase(int worker_route_id, |
| 198 const GURL& url, | 198 const GURL& url, |
| 199 const string16& name, | 199 const base::string16& name, |
| 200 const string16& display_name, | 200 const base::string16& display_name, |
| 201 unsigned long estimated_size, | 201 unsigned long estimated_size, |
| 202 bool* result); | 202 bool* result); |
| 203 void OnAllowFileSystem(int worker_route_id, | 203 void OnAllowFileSystem(int worker_route_id, |
| 204 const GURL& url, | 204 const GURL& url, |
| 205 bool* result); | 205 bool* result); |
| 206 void OnAllowIndexedDB(int worker_route_id, | 206 void OnAllowIndexedDB(int worker_route_id, |
| 207 const GURL& url, | 207 const GURL& url, |
| 208 const string16& name, | 208 const base::string16& name, |
| 209 bool* result); | 209 bool* result); |
| 210 void OnForceKillWorkerProcess(); | 210 void OnForceKillWorkerProcess(); |
| 211 | 211 |
| 212 // Relays a message to the given endpoint. Takes care of parsing the message | 212 // Relays a message to the given endpoint. Takes care of parsing the message |
| 213 // if it contains a message port and sending it a valid route id. | 213 // if it contains a message port and sending it a valid route id. |
| 214 void RelayMessage(const IPC::Message& message, | 214 void RelayMessage(const IPC::Message& message, |
| 215 WorkerMessageFilter* filter, | 215 WorkerMessageFilter* filter, |
| 216 int route_id); | 216 int route_id); |
| 217 | 217 |
| 218 void ShutdownSocketStreamDispatcherHostIfNecessary(); | 218 void ShutdownSocketStreamDispatcherHostIfNecessary(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 public: | 255 public: |
| 256 WorkerProcessHostIterator() | 256 WorkerProcessHostIterator() |
| 257 : BrowserChildProcessHostTypeIterator<WorkerProcessHost>( | 257 : BrowserChildProcessHostTypeIterator<WorkerProcessHost>( |
| 258 PROCESS_TYPE_WORKER) { | 258 PROCESS_TYPE_WORKER) { |
| 259 } | 259 } |
| 260 }; | 260 }; |
| 261 | 261 |
| 262 } // namespace content | 262 } // namespace content |
| 263 | 263 |
| 264 #endif // CONTENT_BROWSER_WORKER_HOST_WORKER_PROCESS_HOST_H_ | 264 #endif // CONTENT_BROWSER_WORKER_HOST_WORKER_PROCESS_HOST_H_ |
| OLD | NEW |