Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: content/browser/worker_host/worker_process_host.h

Issue 9150017: Add a Content API around BrowserChildProcessHost, similar to what was done with ChildProcessHost.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix?! Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/file_path.h" 13 #include "base/file_path.h"
14 #include "content/browser/browser_child_process_host.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "content/common/content_export.h" 15 #include "content/common/content_export.h"
16 #include "content/browser/worker_host/worker_document_set.h" 16 #include "content/browser/worker_host/worker_document_set.h"
17 #include "content/public/browser/browser_child_process_host_delegate.h"
18 #include "content/public/browser/browser_child_process_host_iterator.h"
17 #include "googleurl/src/gurl.h" 19 #include "googleurl/src/gurl.h"
20 #include "ipc/ipc_message.h"
21
22 class BrowserChildProcessHost;
18 23
19 namespace content { 24 namespace content {
20 class ResourceContext; 25 class ResourceContext;
21 class WorkerServiceImpl; 26 class WorkerServiceImpl;
22 } // namespace content 27 } // namespace content
23 28
24 // The WorkerProcessHost is the interface that represents the browser side of 29 // The WorkerProcessHost is the interface that represents the browser side of
25 // the browser <-> worker communication channel. There will be one 30 // the browser <-> worker communication channel. There will be one
26 // WorkerProcessHost per worker process. Currently each worker runs in its own 31 // WorkerProcessHost per worker process. Currently each worker runs in its own
27 // 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
28 // net::URLRequestContext) that a WorkerProcessHost serves a single 33 // net::URLRequestContext) that a WorkerProcessHost serves a single
29 // BrowserContext. 34 // BrowserContext.
30 class WorkerProcessHost : public BrowserChildProcessHost { 35 class WorkerProcessHost : public content::BrowserChildProcessHostDelegate,
36 public IPC::Message::Sender {
31 public: 37 public:
32 // Contains information about each worker instance, needed to forward messages 38 // Contains information about each worker instance, needed to forward messages
33 // between the renderer and worker processes. 39 // between the renderer and worker processes.
34 class WorkerInstance { 40 class WorkerInstance {
35 public: 41 public:
36 WorkerInstance(const GURL& url, 42 WorkerInstance(const GURL& url,
37 const string16& name, 43 const string16& name,
38 int worker_route_id, 44 int worker_route_id,
39 int parent_process_id, 45 int parent_process_id,
40 int64 main_resource_appcache_id, 46 int64 main_resource_appcache_id,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 int parent_process_id_; 109 int parent_process_id_;
104 int64 main_resource_appcache_id_; 110 int64 main_resource_appcache_id_;
105 FilterList filters_; 111 FilterList filters_;
106 scoped_refptr<WorkerDocumentSet> worker_document_set_; 112 scoped_refptr<WorkerDocumentSet> worker_document_set_;
107 const content::ResourceContext* const resource_context_; 113 const content::ResourceContext* const resource_context_;
108 }; 114 };
109 115
110 explicit WorkerProcessHost(const content::ResourceContext* resource_context); 116 explicit WorkerProcessHost(const content::ResourceContext* resource_context);
111 virtual ~WorkerProcessHost(); 117 virtual ~WorkerProcessHost();
112 118
119 // IPC::Message::Sender implementation:
120 virtual bool Send(IPC::Message* message) OVERRIDE;
121
113 // Starts the process. Returns true iff it succeeded. 122 // Starts the process. Returns true iff it succeeded.
114 // |render_process_id| is the renderer process responsible for starting this 123 // |render_process_id| is the renderer process responsible for starting this
115 // worker. 124 // worker.
116 bool Init(int render_process_id); 125 bool Init(int render_process_id);
117 126
118 // Creates a worker object in the process. 127 // Creates a worker object in the process.
119 void CreateWorker(const WorkerInstance& instance); 128 void CreateWorker(const WorkerInstance& instance);
120 129
121 // Returns true iff the given message from a renderer process was forwarded to 130 // Returns true iff the given message from a renderer process was forwarded to
122 // the worker. 131 // the worker.
123 bool FilterMessage(const IPC::Message& message, WorkerMessageFilter* filter); 132 bool FilterMessage(const IPC::Message& message, WorkerMessageFilter* filter);
124 133
125 void FilterShutdown(WorkerMessageFilter* filter); 134 void FilterShutdown(WorkerMessageFilter* filter);
126 135
127 // Shuts down any shared workers that are no longer referenced by active 136 // Shuts down any shared workers that are no longer referenced by active
128 // documents. 137 // documents.
129 void DocumentDetached(WorkerMessageFilter* filter, 138 void DocumentDetached(WorkerMessageFilter* filter,
130 unsigned long long document_id); 139 unsigned long long document_id);
131 140
132 // Terminates the given worker, i.e. based on a UI action. 141 // Terminates the given worker, i.e. based on a UI action.
133 CONTENT_EXPORT void TerminateWorker(int worker_route_id); 142 CONTENT_EXPORT void TerminateWorker(int worker_route_id);
134 143
144 CONTENT_EXPORT const content::ChildProcessData& GetData();
145
135 typedef std::list<WorkerInstance> Instances; 146 typedef std::list<WorkerInstance> Instances;
136 const Instances& instances() const { return instances_; } 147 const Instances& instances() const { return instances_; }
137 148
138 const content::ResourceContext* resource_context() const { 149 const content::ResourceContext* resource_context() const {
139 return resource_context_; 150 return resource_context_;
140 } 151 }
141 152
142 protected: 153 protected:
143 friend class content::WorkerServiceImpl; 154 friend class content::WorkerServiceImpl;
144 155
145 Instances& mutable_instances() { return instances_; } 156 Instances& mutable_instances() { return instances_; }
146 157
147 private: 158 private:
148 // Called when the process has been launched successfully. 159 // BrowserChildProcessHostDelegate implementation:
149 virtual void OnProcessLaunched() OVERRIDE; 160 virtual void OnProcessLaunched() OVERRIDE;
161 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
150 162
151 // Creates and adds the message filters. 163 // Creates and adds the message filters.
152 void CreateMessageFilters(int render_process_id); 164 void CreateMessageFilters(int render_process_id);
153 165
154 // IPC::Channel::Listener implementation:
155 // Called when a message arrives from the worker process.
156 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
157
158 void OnWorkerContextClosed(int worker_route_id); 166 void OnWorkerContextClosed(int worker_route_id);
159 void OnAllowDatabase(int worker_route_id, 167 void OnAllowDatabase(int worker_route_id,
160 const GURL& url, 168 const GURL& url,
161 const string16& name, 169 const string16& name,
162 const string16& display_name, 170 const string16& display_name,
163 unsigned long estimated_size, 171 unsigned long estimated_size,
164 bool* result); 172 bool* result);
165 void OnAllowFileSystem(int worker_route_id, 173 void OnAllowFileSystem(int worker_route_id,
166 const GURL& url, 174 const GURL& url,
167 bool* result); 175 bool* result);
(...skipping 11 matching lines...) Expand all
179 187
180 Instances instances_; 188 Instances instances_;
181 189
182 const content::ResourceContext* const resource_context_; 190 const content::ResourceContext* const resource_context_;
183 191
184 // A reference to the filter associated with this worker process. We need to 192 // A reference to the filter associated with this worker process. We need to
185 // keep this around since we'll use it when forward messages to the worker 193 // keep this around since we'll use it when forward messages to the worker
186 // process. 194 // process.
187 scoped_refptr<WorkerMessageFilter> worker_message_filter_; 195 scoped_refptr<WorkerMessageFilter> worker_message_filter_;
188 196
197 scoped_ptr<BrowserChildProcessHost> process_;
198
189 DISALLOW_COPY_AND_ASSIGN(WorkerProcessHost); 199 DISALLOW_COPY_AND_ASSIGN(WorkerProcessHost);
190 }; 200 };
191 201
202 class WorkerProcessHostIterator
203 : public content::BrowserChildProcessHostTypeIterator<WorkerProcessHost> {
204 public:
205 WorkerProcessHostIterator()
206 : content::BrowserChildProcessHostTypeIterator<WorkerProcessHost>(
207 content::PROCESS_TYPE_WORKER) {
208 }
209 };
210
192 #endif // CONTENT_BROWSER_WORKER_HOST_WORKER_PROCESS_HOST_H_ 211 #endif // CONTENT_BROWSER_WORKER_HOST_WORKER_PROCESS_HOST_H_
OLDNEW
« no previous file with comments | « content/browser/utility_process_host.cc ('k') | content/browser/worker_host/worker_process_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698