OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/worker_service.h" |
| 6 |
| 7 #include "base/singleton.h" |
| 8 #include "base/thread.h" |
| 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/plugin_service.h" |
| 11 #include "chrome/browser/worker_process_host.h" |
| 12 #include "chrome/browser/renderer_host/render_process_host.h" |
| 13 #include "chrome/browser/renderer_host/resource_message_filter.h" |
| 14 |
| 15 WorkerService* WorkerService::GetInstance() { |
| 16 return Singleton<WorkerService>::get(); |
| 17 } |
| 18 |
| 19 WorkerService::WorkerService() : next_route_id_(0) { |
| 20 } |
| 21 |
| 22 WorkerService::~WorkerService() { |
| 23 } |
| 24 |
| 25 int WorkerService::CreateDedicatedWorker(const GURL &url) { |
| 26 WorkerProcessHost* worker = NULL; |
| 27 // One worker process for quick bringup! |
| 28 for (ChildProcessHost::Iterator iter(ChildProcessInfo::WORKER_PROCESS); |
| 29 !iter.Done(); ++iter) { |
| 30 worker = static_cast<WorkerProcessHost*>(*iter); |
| 31 break; |
| 32 } |
| 33 |
| 34 if (!worker) { |
| 35 // TODO(jabdelmalek): there has to be a better way to get the main message |
| 36 // loop. |
| 37 worker = new WorkerProcessHost( |
| 38 PluginService::GetInstance()->main_message_loop()); |
| 39 if (!worker->Init()) { |
| 40 delete worker; |
| 41 return MSG_ROUTING_NONE; |
| 42 } |
| 43 } |
| 44 |
| 45 // Generate a new route id for this worker instance that's unique among all |
| 46 // worker processes. The route id must be globally unique so that when the |
| 47 // renderer or worker process send a wrapped IPC message through us, we know |
| 48 // which WorkerProcessHost/RendererProcesHost to send it through. |
| 49 worker->CreateWorker(url, ++next_route_id_); |
| 50 return next_route_id_; |
| 51 } |
| 52 |
| 53 void WorkerService::ForwardMessage(const IPC::Message& message) { |
| 54 for (ChildProcessHost::Iterator iter(ChildProcessInfo::WORKER_PROCESS); |
| 55 !iter.Done(); ++iter) { |
| 56 WorkerProcessHost* worker = static_cast<WorkerProcessHost*>(*iter); |
| 57 if (worker->HasRouteId(message.routing_id())) { |
| 58 worker->Send(new IPC::Message(message)); |
| 59 return; |
| 60 } |
| 61 } |
| 62 |
| 63 // TODO(jabdelmalek): tell sender that callee is gone |
| 64 } |
OLD | NEW |