| 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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 RenderViewHostImpl* host = | 107 RenderViewHostImpl* host = |
| 108 RenderViewHostImpl::FromID(render_process_unique_id, render_view_id); | 108 RenderViewHostImpl::FromID(render_process_unique_id, render_view_id); |
| 109 if (host) | 109 if (host) |
| 110 host->GetDelegate()->WorkerCrashed(); | 110 host->GetDelegate()->WorkerCrashed(); |
| 111 } | 111 } |
| 112 | 112 |
| 113 WorkerProcessHost::WorkerProcessHost( | 113 WorkerProcessHost::WorkerProcessHost( |
| 114 ResourceContext* resource_context, | 114 ResourceContext* resource_context, |
| 115 const WorkerStoragePartition& partition) | 115 const WorkerStoragePartition& partition) |
| 116 : resource_context_(resource_context), | 116 : resource_context_(resource_context), |
| 117 partition_(partition) { | 117 partition_(partition), |
| 118 process_launched_(false) { |
| 118 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 119 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 119 DCHECK(resource_context_); | 120 DCHECK(resource_context_); |
| 120 process_.reset( | 121 process_.reset( |
| 121 new BrowserChildProcessHostImpl(PROCESS_TYPE_WORKER, this)); | 122 new BrowserChildProcessHostImpl(PROCESS_TYPE_WORKER, this)); |
| 122 } | 123 } |
| 123 | 124 |
| 124 WorkerProcessHost::~WorkerProcessHost() { | 125 WorkerProcessHost::~WorkerProcessHost() { |
| 125 // If we crashed, tell the RenderViewHosts. | 126 // If we crashed, tell the RenderViewHosts. |
| 126 for (Instances::iterator i = instances_.begin(); i != instances_.end(); ++i) { | 127 for (Instances::iterator i = instances_.begin(); i != instances_.end(); ++i) { |
| 127 const WorkerDocumentSet::DocumentInfoSet& parents = | 128 const WorkerDocumentSet::DocumentInfoSet& parents = |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 if (!i->closed() && i->HasFilter(filter, message.routing_id())) { | 312 if (!i->closed() && i->HasFilter(filter, message.routing_id())) { |
| 312 RelayMessage(message, worker_message_filter_, i->worker_route_id()); | 313 RelayMessage(message, worker_message_filter_, i->worker_route_id()); |
| 313 return true; | 314 return true; |
| 314 } | 315 } |
| 315 } | 316 } |
| 316 | 317 |
| 317 return false; | 318 return false; |
| 318 } | 319 } |
| 319 | 320 |
| 320 void WorkerProcessHost::OnProcessLaunched() { | 321 void WorkerProcessHost::OnProcessLaunched() { |
| 322 process_launched_ = true; |
| 323 |
| 324 WorkerServiceImpl::GetInstance()->NotifyWorkerProcessCreated(); |
| 321 } | 325 } |
| 322 | 326 |
| 323 bool WorkerProcessHost::OnMessageReceived(const IPC::Message& message) { | 327 bool WorkerProcessHost::OnMessageReceived(const IPC::Message& message) { |
| 324 bool msg_is_ok = true; | 328 bool msg_is_ok = true; |
| 325 bool handled = true; | 329 bool handled = true; |
| 326 IPC_BEGIN_MESSAGE_MAP_EX(WorkerProcessHost, message, msg_is_ok) | 330 IPC_BEGIN_MESSAGE_MAP_EX(WorkerProcessHost, message, msg_is_ok) |
| 327 IPC_MESSAGE_HANDLER(WorkerHostMsg_WorkerContextClosed, | 331 IPC_MESSAGE_HANDLER(WorkerHostMsg_WorkerContextClosed, |
| 328 OnWorkerContextClosed) | 332 OnWorkerContextClosed) |
| 329 IPC_MESSAGE_HANDLER(WorkerProcessHostMsg_AllowDatabase, OnAllowDatabase) | 333 IPC_MESSAGE_HANDLER(WorkerProcessHostMsg_AllowDatabase, OnAllowDatabase) |
| 330 IPC_MESSAGE_HANDLER(WorkerProcessHostMsg_AllowFileSystem, OnAllowFileSystem) | 334 IPC_MESSAGE_HANDLER(WorkerProcessHostMsg_AllowFileSystem, OnAllowFileSystem) |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 } else { | 534 } else { |
| 531 ++i; | 535 ++i; |
| 532 } | 536 } |
| 533 } | 537 } |
| 534 } | 538 } |
| 535 | 539 |
| 536 void WorkerProcessHost::TerminateWorker(int worker_route_id) { | 540 void WorkerProcessHost::TerminateWorker(int worker_route_id) { |
| 537 Send(new WorkerMsg_TerminateWorkerContext(worker_route_id)); | 541 Send(new WorkerMsg_TerminateWorkerContext(worker_route_id)); |
| 538 } | 542 } |
| 539 | 543 |
| 544 void WorkerProcessHost::SetBackgrounded(bool backgrounded) { |
| 545 process_->SetBackgrounded(backgrounded); |
| 546 } |
| 547 |
| 540 const ChildProcessData& WorkerProcessHost::GetData() { | 548 const ChildProcessData& WorkerProcessHost::GetData() { |
| 541 return process_->GetData(); | 549 return process_->GetData(); |
| 542 } | 550 } |
| 543 | 551 |
| 552 bool WorkerProcessHost::IsProcessLaunched() const { |
| 553 return process_launched_; |
| 554 } |
| 555 |
| 544 std::vector<std::pair<int, int> > WorkerProcessHost::GetRenderViewIDsForWorker( | 556 std::vector<std::pair<int, int> > WorkerProcessHost::GetRenderViewIDsForWorker( |
| 545 int worker_route_id) { | 557 int worker_route_id) { |
| 546 std::vector<std::pair<int, int> > result; | 558 std::vector<std::pair<int, int> > result; |
| 547 WorkerProcessHost::Instances::const_iterator i; | 559 WorkerProcessHost::Instances::const_iterator i; |
| 548 for (i = instances_.begin(); i != instances_.end(); ++i) { | 560 for (i = instances_.begin(); i != instances_.end(); ++i) { |
| 549 if (i->worker_route_id() != worker_route_id) | 561 if (i->worker_route_id() != worker_route_id) |
| 550 continue; | 562 continue; |
| 551 const WorkerDocumentSet::DocumentInfoSet& documents = | 563 const WorkerDocumentSet::DocumentInfoSet& documents = |
| 552 i->worker_document_set()->documents(); | 564 i->worker_document_set()->documents(); |
| 553 for (WorkerDocumentSet::DocumentInfoSet::const_iterator doc = | 565 for (WorkerDocumentSet::DocumentInfoSet::const_iterator doc = |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 return false; | 702 return false; |
| 691 } | 703 } |
| 692 | 704 |
| 693 WorkerProcessHost::WorkerInstance::FilterInfo | 705 WorkerProcessHost::WorkerInstance::FilterInfo |
| 694 WorkerProcessHost::WorkerInstance::GetFilter() const { | 706 WorkerProcessHost::WorkerInstance::GetFilter() const { |
| 695 DCHECK(NumFilters() == 1); | 707 DCHECK(NumFilters() == 1); |
| 696 return *filters_.begin(); | 708 return *filters_.begin(); |
| 697 } | 709 } |
| 698 | 710 |
| 699 } // namespace content | 711 } // namespace content |
| OLD | NEW |