Index: chrome/browser/worker_service.cc |
=================================================================== |
--- chrome/browser/worker_service.cc (revision 0) |
+++ chrome/browser/worker_service.cc (revision 0) |
@@ -0,0 +1,64 @@ |
+// Copyright (c) 2009 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/worker_service.h" |
+ |
+#include "base/singleton.h" |
+#include "base/thread.h" |
+#include "chrome/browser/browser_process.h" |
+#include "chrome/browser/plugin_service.h" |
+#include "chrome/browser/worker_process_host.h" |
+#include "chrome/browser/renderer_host/render_process_host.h" |
+#include "chrome/browser/renderer_host/resource_message_filter.h" |
+ |
+WorkerService* WorkerService::GetInstance() { |
+ return Singleton<WorkerService>::get(); |
+} |
+ |
+WorkerService::WorkerService() : next_route_id_(0) { |
+} |
+ |
+WorkerService::~WorkerService() { |
+} |
+ |
+int WorkerService::CreateDedicatedWorker(const GURL &url) { |
+ WorkerProcessHost* worker = NULL; |
+ // One worker process for quick bringup! |
+ for (ChildProcessHost::Iterator iter(ChildProcessInfo::WORKER_PROCESS); |
+ !iter.Done(); ++iter) { |
+ worker = static_cast<WorkerProcessHost*>(*iter); |
+ break; |
+ } |
+ |
+ if (!worker) { |
+ // TODO(jabdelmalek): there has to be a better way to get the main message |
+ // loop. |
+ worker = new WorkerProcessHost( |
+ PluginService::GetInstance()->main_message_loop()); |
+ if (!worker->Init()) { |
+ delete worker; |
+ return MSG_ROUTING_NONE; |
+ } |
+ } |
+ |
+ // Generate a new route id for this worker instance that's unique among all |
+ // worker processes. The route id must be globally unique so that when the |
+ // renderer or worker process send a wrapped IPC message through us, we know |
+ // which WorkerProcessHost/RendererProcesHost to send it through. |
+ worker->CreateWorker(url, ++next_route_id_); |
+ return next_route_id_; |
+} |
+ |
+void WorkerService::ForwardMessage(const IPC::Message& message) { |
+ for (ChildProcessHost::Iterator iter(ChildProcessInfo::WORKER_PROCESS); |
+ !iter.Done(); ++iter) { |
+ WorkerProcessHost* worker = static_cast<WorkerProcessHost*>(*iter); |
+ if (worker->HasRouteId(message.routing_id())) { |
+ worker->Send(new IPC::Message(message)); |
+ return; |
+ } |
+ } |
+ |
+ // TODO(jabdelmalek): tell sender that callee is gone |
+} |