| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/browser/worker_host/worker_process_host.h" | 5 #include "chrome/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/callback.h" | 10 #include "base/callback.h" |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 return true; | 269 return true; |
| 270 } | 270 } |
| 271 } | 271 } |
| 272 | 272 |
| 273 return false; | 273 return false; |
| 274 } | 274 } |
| 275 | 275 |
| 276 void WorkerProcessHost::OnProcessLaunched() { | 276 void WorkerProcessHost::OnProcessLaunched() { |
| 277 } | 277 } |
| 278 | 278 |
| 279 void WorkerProcessHost::OnMessageReceived(const IPC::Message& message) { | 279 bool WorkerProcessHost::OnMessageReceived(const IPC::Message& message) { |
| 280 bool msg_is_ok = true; | 280 bool msg_is_ok = true; |
| 281 bool handled = true; | 281 bool handled = true; |
| 282 IPC_BEGIN_MESSAGE_MAP_EX(WorkerProcessHost, message, msg_is_ok) | 282 IPC_BEGIN_MESSAGE_MAP_EX(WorkerProcessHost, message, msg_is_ok) |
| 283 IPC_MESSAGE_HANDLER(WorkerHostMsg_WorkerContextClosed, | 283 IPC_MESSAGE_HANDLER(WorkerHostMsg_WorkerContextClosed, |
| 284 OnWorkerContextClosed) | 284 OnWorkerContextClosed) |
| 285 IPC_MESSAGE_HANDLER(WorkerProcessHostMsg_AllowDatabase, OnAllowDatabase) | 285 IPC_MESSAGE_HANDLER(WorkerProcessHostMsg_AllowDatabase, OnAllowDatabase) |
| 286 IPC_MESSAGE_UNHANDLED(handled = false) | 286 IPC_MESSAGE_UNHANDLED(handled = false) |
| 287 IPC_END_MESSAGE_MAP_EX() | 287 IPC_END_MESSAGE_MAP_EX() |
| 288 | 288 |
| 289 if (!msg_is_ok) { | 289 if (!msg_is_ok) { |
| 290 NOTREACHED(); | 290 NOTREACHED(); |
| 291 UserMetrics::RecordAction(UserMetricsAction("BadMessageTerminate_WPH")); | 291 UserMetrics::RecordAction(UserMetricsAction("BadMessageTerminate_WPH")); |
| 292 base::KillProcess(handle(), ResultCodes::KILLED_BAD_MESSAGE, false); | 292 base::KillProcess(handle(), ResultCodes::KILLED_BAD_MESSAGE, false); |
| 293 } | 293 } |
| 294 | 294 |
| 295 if (handled) | 295 if (handled) |
| 296 return; | 296 return true; |
| 297 | 297 |
| 298 for (Instances::iterator i = instances_.begin(); i != instances_.end(); ++i) { | 298 for (Instances::iterator i = instances_.begin(); i != instances_.end(); ++i) { |
| 299 if (i->worker_route_id() == message.routing_id()) { | 299 if (i->worker_route_id() == message.routing_id()) { |
| 300 if (!i->shared()) { | 300 if (!i->shared()) { |
| 301 // Don't relay messages from shared workers (all communication is via | 301 // Don't relay messages from shared workers (all communication is via |
| 302 // the message port). | 302 // the message port). |
| 303 WorkerInstance::FilterInfo info = i->GetFilter(); | 303 WorkerInstance::FilterInfo info = i->GetFilter(); |
| 304 RelayMessage(message, info.first, info.second); | 304 RelayMessage(message, info.first, info.second); |
| 305 } | 305 } |
| 306 | 306 |
| 307 if (message.type() == WorkerHostMsg_WorkerContextDestroyed::ID) { | 307 if (message.type() == WorkerHostMsg_WorkerContextDestroyed::ID) { |
| 308 instances_.erase(i); | 308 instances_.erase(i); |
| 309 UpdateTitle(); | 309 UpdateTitle(); |
| 310 } | 310 } |
| 311 break; | 311 return true; |
| 312 } | 312 } |
| 313 } | 313 } |
| 314 return false; |
| 314 } | 315 } |
| 315 | 316 |
| 316 // Sent to notify the browser process when a worker context invokes close(), so | 317 // Sent to notify the browser process when a worker context invokes close(), so |
| 317 // no new connections are sent to shared workers. | 318 // no new connections are sent to shared workers. |
| 318 void WorkerProcessHost::OnWorkerContextClosed(int worker_route_id) { | 319 void WorkerProcessHost::OnWorkerContextClosed(int worker_route_id) { |
| 319 for (Instances::iterator i = instances_.begin(); i != instances_.end(); ++i) { | 320 for (Instances::iterator i = instances_.begin(); i != instances_.end(); ++i) { |
| 320 if (i->worker_route_id() == worker_route_id) { | 321 if (i->worker_route_id() == worker_route_id) { |
| 321 // Set the closed flag - this will stop any further messages from | 322 // Set the closed flag - this will stop any further messages from |
| 322 // being sent to the worker (messages can still be sent from the worker, | 323 // being sent to the worker (messages can still be sent from the worker, |
| 323 // for exception reporting, etc). | 324 // for exception reporting, etc). |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 } | 607 } |
| 607 } | 608 } |
| 608 return false; | 609 return false; |
| 609 } | 610 } |
| 610 | 611 |
| 611 WorkerProcessHost::WorkerInstance::FilterInfo | 612 WorkerProcessHost::WorkerInstance::FilterInfo |
| 612 WorkerProcessHost::WorkerInstance::GetFilter() const { | 613 WorkerProcessHost::WorkerInstance::GetFilter() const { |
| 613 DCHECK(NumFilters() == 1); | 614 DCHECK(NumFilters() == 1); |
| 614 return *filters_.begin(); | 615 return *filters_.begin(); |
| 615 } | 616 } |
| OLD | NEW |