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

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

Issue 9052007: Create an API around WorkerService that chrome consumes. Rename the existing WorkerService to Wor... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' 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 #include "content/browser/worker_host/worker_process_host.h" 5 #include "content/browser/worker_host/worker_process_host.h"
6 6
7 #include <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/base_switches.h" 10 #include "base/base_switches.h"
(...skipping 11 matching lines...) Expand all
22 #include "content/browser/mime_registry_message_filter.h" 22 #include "content/browser/mime_registry_message_filter.h"
23 #include "content/browser/renderer_host/blob_message_filter.h" 23 #include "content/browser/renderer_host/blob_message_filter.h"
24 #include "content/browser/renderer_host/database_message_filter.h" 24 #include "content/browser/renderer_host/database_message_filter.h"
25 #include "content/browser/renderer_host/file_utilities_message_filter.h" 25 #include "content/browser/renderer_host/file_utilities_message_filter.h"
26 #include "content/browser/renderer_host/render_view_host.h" 26 #include "content/browser/renderer_host/render_view_host.h"
27 #include "content/browser/renderer_host/render_view_host_delegate.h" 27 #include "content/browser/renderer_host/render_view_host_delegate.h"
28 #include "content/browser/renderer_host/socket_stream_dispatcher_host.h" 28 #include "content/browser/renderer_host/socket_stream_dispatcher_host.h"
29 #include "content/browser/resource_context.h" 29 #include "content/browser/resource_context.h"
30 #include "content/browser/worker_host/message_port_service.h" 30 #include "content/browser/worker_host/message_port_service.h"
31 #include "content/browser/worker_host/worker_message_filter.h" 31 #include "content/browser/worker_host/worker_message_filter.h"
32 #include "content/browser/worker_host/worker_service.h" 32 #include "content/browser/worker_host/worker_service_impl.h"
33 #include "content/common/child_process_host_impl.h" 33 #include "content/common/child_process_host_impl.h"
34 #include "content/common/debug_flags.h" 34 #include "content/common/debug_flags.h"
35 #include "content/common/view_messages.h" 35 #include "content/common/view_messages.h"
36 #include "content/common/worker_messages.h" 36 #include "content/common/worker_messages.h"
37 #include "content/public/browser/browser_thread.h" 37 #include "content/public/browser/browser_thread.h"
38 #include "content/public/browser/content_browser_client.h" 38 #include "content/public/browser/content_browser_client.h"
39 #include "content/public/browser/user_metrics.h" 39 #include "content/public/browser/user_metrics.h"
40 #include "content/public/common/content_switches.h" 40 #include "content/public/common/content_switches.h"
41 #include "content/public/common/result_codes.h" 41 #include "content/public/common/result_codes.h"
42 #include "ipc/ipc_switches.h" 42 #include "ipc/ipc_switches.h"
43 #include "net/base/mime_util.h" 43 #include "net/base/mime_util.h"
44 #include "net/base/registry_controlled_domain.h" 44 #include "net/base/registry_controlled_domain.h"
45 #include "ui/base/ui_base_switches.h" 45 #include "ui/base/ui_base_switches.h"
46 #include "webkit/fileapi/file_system_context.h" 46 #include "webkit/fileapi/file_system_context.h"
47 #include "webkit/fileapi/file_system_path_manager.h" 47 #include "webkit/fileapi/file_system_path_manager.h"
48 #include "webkit/fileapi/sandbox_mount_point_provider.h" 48 #include "webkit/fileapi/sandbox_mount_point_provider.h"
49 #include "webkit/glue/resource_type.h" 49 #include "webkit/glue/resource_type.h"
50 50
51 using content::BrowserThread; 51 using content::BrowserThread;
52 using content::ChildProcessHost; 52 using content::ChildProcessHost;
53 using content::UserMetricsAction; 53 using content::UserMetricsAction;
54 using content::WorkerServiceImpl;
54 55
55 namespace { 56 namespace {
56 57
57 // Helper class that we pass to SocketStreamDispatcherHost so that it can find 58 // Helper class that we pass to SocketStreamDispatcherHost so that it can find
58 // the right net::URLRequestContext for a request. 59 // the right net::URLRequestContext for a request.
59 class URLRequestContextSelector 60 class URLRequestContextSelector
60 : public ResourceMessageFilter::URLRequestContextSelector { 61 : public ResourceMessageFilter::URLRequestContextSelector {
61 public: 62 public:
62 explicit URLRequestContextSelector( 63 explicit URLRequestContextSelector(
63 net::URLRequestContext* url_request_context) 64 net::URLRequestContext* url_request_context)
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 for (Instances::iterator i = instances_.begin(); i != instances_.end(); ++i) { 100 for (Instances::iterator i = instances_.begin(); i != instances_.end(); ++i) {
100 const WorkerDocumentSet::DocumentInfoSet& parents = 101 const WorkerDocumentSet::DocumentInfoSet& parents =
101 i->worker_document_set()->documents(); 102 i->worker_document_set()->documents();
102 for (WorkerDocumentSet::DocumentInfoSet::const_iterator parent_iter = 103 for (WorkerDocumentSet::DocumentInfoSet::const_iterator parent_iter =
103 parents.begin(); parent_iter != parents.end(); ++parent_iter) { 104 parents.begin(); parent_iter != parents.end(); ++parent_iter) {
104 BrowserThread::PostTask( 105 BrowserThread::PostTask(
105 BrowserThread::UI, FROM_HERE, 106 BrowserThread::UI, FROM_HERE,
106 base::Bind(&WorkerCrashCallback, parent_iter->render_process_id(), 107 base::Bind(&WorkerCrashCallback, parent_iter->render_process_id(),
107 parent_iter->render_view_id())); 108 parent_iter->render_view_id()));
108 } 109 }
109 WorkerService::GetInstance()->NotifyWorkerDestroyed(this, 110 WorkerServiceImpl::GetInstance()->NotifyWorkerDestroyed(
110 i->worker_route_id()); 111 this, i->worker_route_id());
111 } 112 }
112 113
113 ChildProcessSecurityPolicy::GetInstance()->Remove(id()); 114 ChildProcessSecurityPolicy::GetInstance()->Remove(id());
114 } 115 }
115 116
116 bool WorkerProcessHost::Init(int render_process_id) { 117 bool WorkerProcessHost::Init(int render_process_id) {
117 std::string channel_id = child_process_host()->CreateChannel(); 118 std::string channel_id = child_process_host()->CreateChannel();
118 if (channel_id.empty()) 119 if (channel_id.empty())
119 return false; 120 return false;
120 121
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 resource_context_->request_context(); 239 resource_context_->request_context();
239 240
240 ResourceMessageFilter* resource_message_filter = new ResourceMessageFilter( 241 ResourceMessageFilter* resource_message_filter = new ResourceMessageFilter(
241 id(), content::PROCESS_TYPE_WORKER, resource_context_, 242 id(), content::PROCESS_TYPE_WORKER, resource_context_,
242 new URLRequestContextSelector(request_context), 243 new URLRequestContextSelector(request_context),
243 resource_dispatcher_host_); 244 resource_dispatcher_host_);
244 child_process_host()->AddFilter(resource_message_filter); 245 child_process_host()->AddFilter(resource_message_filter);
245 246
246 worker_message_filter_ = new WorkerMessageFilter( 247 worker_message_filter_ = new WorkerMessageFilter(
247 render_process_id, resource_context_, resource_dispatcher_host_, 248 render_process_id, resource_context_, resource_dispatcher_host_,
248 base::Bind(&WorkerService::next_worker_route_id, 249 base::Bind(&WorkerServiceImpl::next_worker_route_id,
249 base::Unretained(WorkerService::GetInstance()))); 250 base::Unretained(WorkerServiceImpl::GetInstance())));
250 child_process_host()->AddFilter(worker_message_filter_); 251 child_process_host()->AddFilter(worker_message_filter_);
251 child_process_host()->AddFilter(new AppCacheDispatcherHost( 252 child_process_host()->AddFilter(new AppCacheDispatcherHost(
252 resource_context_->appcache_service(), id())); 253 resource_context_->appcache_service(), id()));
253 child_process_host()->AddFilter(new FileSystemDispatcherHost( 254 child_process_host()->AddFilter(new FileSystemDispatcherHost(
254 request_context, resource_context_->file_system_context())); 255 request_context, resource_context_->file_system_context()));
255 child_process_host()->AddFilter(new FileUtilitiesMessageFilter(id())); 256 child_process_host()->AddFilter(new FileUtilitiesMessageFilter(id()));
256 child_process_host()->AddFilter(new BlobMessageFilter( 257 child_process_host()->AddFilter(new BlobMessageFilter(
257 id(), resource_context_->blob_storage_context())); 258 id(), resource_context_->blob_storage_context()));
258 child_process_host()->AddFilter(new MimeRegistryMessageFilter()); 259 child_process_host()->AddFilter(new MimeRegistryMessageFilter());
259 child_process_host()->AddFilter(new DatabaseMessageFilter( 260 child_process_host()->AddFilter(new DatabaseMessageFilter(
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 if (!msg_is_ok) { 323 if (!msg_is_ok) {
323 NOTREACHED(); 324 NOTREACHED();
324 content::RecordAction(UserMetricsAction("BadMessageTerminate_WPH")); 325 content::RecordAction(UserMetricsAction("BadMessageTerminate_WPH"));
325 base::KillProcess(handle(), content::RESULT_CODE_KILLED_BAD_MESSAGE, false); 326 base::KillProcess(handle(), content::RESULT_CODE_KILLED_BAD_MESSAGE, false);
326 } 327 }
327 328
328 if (handled) 329 if (handled)
329 return true; 330 return true;
330 331
331 if (message.type() == WorkerHostMsg_WorkerContextDestroyed::ID) { 332 if (message.type() == WorkerHostMsg_WorkerContextDestroyed::ID) {
332 WorkerService::GetInstance()->NotifyWorkerDestroyed(this, 333 WorkerServiceImpl::GetInstance()->NotifyWorkerDestroyed(
333 message.routing_id()); 334 this, message.routing_id());
334 } 335 }
335 336
336 for (Instances::iterator i = instances_.begin(); i != instances_.end(); ++i) { 337 for (Instances::iterator i = instances_.begin(); i != instances_.end(); ++i) {
337 if (i->worker_route_id() == message.routing_id()) { 338 if (i->worker_route_id() == message.routing_id()) {
338 if (message.type() == WorkerHostMsg_WorkerContextDestroyed::ID) { 339 if (message.type() == WorkerHostMsg_WorkerContextDestroyed::ID) {
339 instances_.erase(i); 340 instances_.erase(i);
340 UpdateTitle(); 341 UpdateTitle();
341 } 342 }
342 return true; 343 return true;
343 } 344 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 filter->Send(new WorkerMsg_Connect( 426 filter->Send(new WorkerMsg_Connect(
426 route_id, sent_message_port_id, new_routing_id)); 427 route_id, sent_message_port_id, new_routing_id));
427 428
428 // Send any queued messages for the sent port. 429 // Send any queued messages for the sent port.
429 MessagePortService::GetInstance()->SendQueuedMessagesIfPossible( 430 MessagePortService::GetInstance()->SendQueuedMessagesIfPossible(
430 sent_message_port_id); 431 sent_message_port_id);
431 } else { 432 } else {
432 IPC::Message* new_message = new IPC::Message(message); 433 IPC::Message* new_message = new IPC::Message(message);
433 new_message->set_routing_id(route_id); 434 new_message->set_routing_id(route_id);
434 filter->Send(new_message); 435 filter->Send(new_message);
435 if (message.type() == WorkerMsg_StartWorkerContext::ID) 436 if (message.type() == WorkerMsg_StartWorkerContext::ID) {
436 WorkerService::GetInstance()->NotifyWorkerContextStarted(this, route_id); 437 WorkerServiceImpl::GetInstance()->NotifyWorkerContextStarted(
438 this, route_id);
439 }
437 return; 440 return;
438 } 441 }
439 } 442 }
440 443
441 void WorkerProcessHost::FilterShutdown(WorkerMessageFilter* filter) { 444 void WorkerProcessHost::FilterShutdown(WorkerMessageFilter* filter) {
442 for (Instances::iterator i = instances_.begin(); i != instances_.end();) { 445 for (Instances::iterator i = instances_.begin(); i != instances_.end();) {
443 bool shutdown = false; 446 bool shutdown = false;
444 i->RemoveFilters(filter); 447 i->RemoveFilters(filter);
445 448
446 i->worker_document_set()->RemoveAll(filter); 449 i->worker_document_set()->RemoveAll(filter);
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 } 631 }
629 } 632 }
630 return false; 633 return false;
631 } 634 }
632 635
633 WorkerProcessHost::WorkerInstance::FilterInfo 636 WorkerProcessHost::WorkerInstance::FilterInfo
634 WorkerProcessHost::WorkerInstance::GetFilter() const { 637 WorkerProcessHost::WorkerInstance::GetFilter() const {
635 DCHECK(NumFilters() == 1); 638 DCHECK(NumFilters() == 1);
636 return *filters_.begin(); 639 return *filters_.begin();
637 } 640 }
OLDNEW
« no previous file with comments | « content/browser/worker_host/worker_process_host.h ('k') | content/browser/worker_host/worker_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698