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 #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 <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 return process_->Send(message); | 146 return process_->Send(message); |
147 } | 147 } |
148 | 148 |
149 bool WorkerProcessHost::Init(int render_process_id) { | 149 bool WorkerProcessHost::Init(int render_process_id) { |
150 std::string channel_id = process_->GetHost()->CreateChannel(); | 150 std::string channel_id = process_->GetHost()->CreateChannel(); |
151 if (channel_id.empty()) | 151 if (channel_id.empty()) |
152 return false; | 152 return false; |
153 | 153 |
154 #if defined(OS_LINUX) | 154 #if defined(OS_LINUX) |
155 int flags = ChildProcessHost::CHILD_ALLOW_SELF; | 155 int flags = ChildProcessHost::CHILD_ALLOW_SELF; |
| 156 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDebugChildren)) |
| 157 flags = ChildProcessHost::CHILD_NORMAL; |
156 #else | 158 #else |
157 int flags = ChildProcessHost::CHILD_NORMAL; | 159 int flags = ChildProcessHost::CHILD_NORMAL; |
158 #endif | 160 #endif |
159 | 161 |
160 base::FilePath exe_path = ChildProcessHost::GetChildPath(flags); | 162 base::FilePath exe_path = ChildProcessHost::GetChildPath(flags); |
161 if (exe_path.empty()) | 163 if (exe_path.empty()) |
162 return false; | 164 return false; |
163 | 165 |
164 CommandLine* cmd_line = new CommandLine(exe_path); | 166 CommandLine* cmd_line = new CommandLine(exe_path); |
165 cmd_line->AppendSwitchASCII(switches::kProcessType, switches::kWorkerProcess); | 167 cmd_line->AppendSwitchASCII(switches::kProcessType, switches::kWorkerProcess); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 } | 199 } |
198 } | 200 } |
199 | 201 |
200 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDebugChildren)) { | 202 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDebugChildren)) { |
201 // Look to pass-on the kDebugOnStart flag. | 203 // Look to pass-on the kDebugOnStart flag. |
202 std::string value = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 204 std::string value = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
203 switches::kDebugChildren); | 205 switches::kDebugChildren); |
204 if (value.empty() || value == switches::kWorkerProcess) { | 206 if (value.empty() || value == switches::kWorkerProcess) { |
205 // launches a new xterm, and runs the worker process in gdb, reading | 207 // launches a new xterm, and runs the worker process in gdb, reading |
206 // optional commands from gdb_chrome file in the working directory. | 208 // optional commands from gdb_chrome file in the working directory. |
207 cmd_line->PrependWrapper("xterm -e gdb -x gdb_chrome --args"); | 209 cmd_line->PrependWrapper("xterm -e gdb --args"); |
208 use_zygote = false; | 210 use_zygote = false; |
209 } | 211 } |
210 } | 212 } |
211 #endif | 213 #endif |
212 | 214 |
213 process_->Launch( | 215 process_->Launch( |
214 #if defined(OS_WIN) | 216 #if defined(OS_WIN) |
215 new WorkerSandboxedProcessLauncherDelegate, | 217 new WorkerSandboxedProcessLauncherDelegate, |
216 #elif defined(OS_POSIX) | 218 #elif defined(OS_POSIX) |
217 use_zygote, | 219 use_zygote, |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 process_->GetData().id, instance.url()); | 290 process_->GetData().id, instance.url()); |
289 | 291 |
290 instances_.push_back(instance); | 292 instances_.push_back(instance); |
291 | 293 |
292 WorkerProcessMsg_CreateWorker_Params params; | 294 WorkerProcessMsg_CreateWorker_Params params; |
293 params.url = instance.url(); | 295 params.url = instance.url(); |
294 params.name = instance.name(); | 296 params.name = instance.name(); |
295 params.route_id = instance.worker_route_id(); | 297 params.route_id = instance.worker_route_id(); |
296 params.creator_process_id = instance.parent_process_id(); | 298 params.creator_process_id = instance.parent_process_id(); |
297 params.shared_worker_appcache_id = instance.main_resource_appcache_id(); | 299 params.shared_worker_appcache_id = instance.main_resource_appcache_id(); |
| 300 params.is_controller = false; // originating from a renderer, so |
| 301 // definitely not a controller |
298 Send(new WorkerProcessMsg_CreateWorker(params)); | 302 Send(new WorkerProcessMsg_CreateWorker(params)); |
299 | 303 |
300 UpdateTitle(); | 304 UpdateTitle(); |
301 | 305 |
302 // Walk all pending filters and let them know the worker has been created | 306 // Walk all pending filters and let them know the worker has been created |
303 // (could be more than one in the case where we had to queue up worker | 307 // (could be more than one in the case where we had to queue up worker |
304 // creation because the worker process limit was reached). | 308 // creation because the worker process limit was reached). |
305 for (WorkerInstance::FilterList::const_iterator i = | 309 for (WorkerInstance::FilterList::const_iterator i = |
306 instance.filters().begin(); | 310 instance.filters().begin(); |
307 i != instance.filters().end(); ++i) { | 311 i != instance.filters().end(); ++i) { |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 | 483 |
480 // SocketStreamDispatcherHost should be notified now that the worker | 484 // SocketStreamDispatcherHost should be notified now that the worker |
481 // process will shutdown soon. | 485 // process will shutdown soon. |
482 socket_stream_dispatcher_host_->Shutdown(); | 486 socket_stream_dispatcher_host_->Shutdown(); |
483 socket_stream_dispatcher_host_ = NULL; | 487 socket_stream_dispatcher_host_ = NULL; |
484 } | 488 } |
485 } | 489 } |
486 | 490 |
487 void WorkerProcessHost::FilterShutdown(WorkerMessageFilter* filter) { | 491 void WorkerProcessHost::FilterShutdown(WorkerMessageFilter* filter) { |
488 for (Instances::iterator i = instances_.begin(); i != instances_.end();) { | 492 for (Instances::iterator i = instances_.begin(); i != instances_.end();) { |
489 bool shutdown = false; | 493 if (i->is_embedded_worker_) { |
| 494 ++i; |
| 495 continue; |
| 496 } |
490 i->RemoveFilters(filter); | 497 i->RemoveFilters(filter); |
491 | |
492 i->worker_document_set()->RemoveAll(filter); | 498 i->worker_document_set()->RemoveAll(filter); |
493 if (i->worker_document_set()->IsEmpty()) { | 499 if (i->worker_document_set()->IsEmpty()) { |
494 shutdown = true; | |
495 } | |
496 if (shutdown) { | |
497 Send(new WorkerMsg_TerminateWorkerContext(i->worker_route_id())); | 500 Send(new WorkerMsg_TerminateWorkerContext(i->worker_route_id())); |
498 i = instances_.erase(i); | 501 i = instances_.erase(i); |
499 } else { | 502 } else { |
500 ++i; | 503 ++i; |
501 } | 504 } |
502 } | 505 } |
503 ShutdownSocketStreamDispatcherHostIfNecessary(); | 506 ShutdownSocketStreamDispatcherHostIfNecessary(); |
504 } | 507 } |
505 | 508 |
506 bool WorkerProcessHost::CanShutdown() { | 509 bool WorkerProcessHost::CanShutdown() { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 display_title += *i; | 541 display_title += *i; |
539 } | 542 } |
540 | 543 |
541 process_->SetName(UTF8ToUTF16(display_title)); | 544 process_->SetName(UTF8ToUTF16(display_title)); |
542 } | 545 } |
543 | 546 |
544 void WorkerProcessHost::DocumentDetached(WorkerMessageFilter* filter, | 547 void WorkerProcessHost::DocumentDetached(WorkerMessageFilter* filter, |
545 unsigned long long document_id) { | 548 unsigned long long document_id) { |
546 // Walk all instances and remove the document from their document set. | 549 // Walk all instances and remove the document from their document set. |
547 for (Instances::iterator i = instances_.begin(); i != instances_.end();) { | 550 for (Instances::iterator i = instances_.begin(); i != instances_.end();) { |
| 551 if (i->is_embedded_worker_) { |
| 552 ++i; |
| 553 continue; |
| 554 } |
548 i->worker_document_set()->Remove(filter, document_id); | 555 i->worker_document_set()->Remove(filter, document_id); |
549 if (i->worker_document_set()->IsEmpty()) { | 556 if (i->worker_document_set()->IsEmpty()) { |
550 // This worker has no more associated documents - shut it down. | 557 // This worker has no more associated documents - shut it down. |
551 Send(new WorkerMsg_TerminateWorkerContext(i->worker_route_id())); | 558 Send(new WorkerMsg_TerminateWorkerContext(i->worker_route_id())); |
552 i = instances_.erase(i); | 559 i = instances_.erase(i); |
553 } else { | 560 } else { |
554 ++i; | 561 ++i; |
555 } | 562 } |
556 } | 563 } |
557 ShutdownSocketStreamDispatcherHostIfNecessary(); | 564 ShutdownSocketStreamDispatcherHostIfNecessary(); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 return false; | 725 return false; |
719 } | 726 } |
720 | 727 |
721 WorkerProcessHost::WorkerInstance::FilterInfo | 728 WorkerProcessHost::WorkerInstance::FilterInfo |
722 WorkerProcessHost::WorkerInstance::GetFilter() const { | 729 WorkerProcessHost::WorkerInstance::GetFilter() const { |
723 DCHECK(NumFilters() == 1); | 730 DCHECK(NumFilters() == 1); |
724 return *filters_.begin(); | 731 return *filters_.begin(); |
725 } | 732 } |
726 | 733 |
727 } // namespace content | 734 } // namespace content |
OLD | NEW |