Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7146)

Unified Diff: chrome/worker/worker_thread.cc

Issue 20413: old1 (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/worker/worker_thread.h ('k') | third_party/WebKit/WebCore/dom/WorkerMessagingProxy.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/worker/worker_thread.cc
===================================================================
--- chrome/worker/worker_thread.cc (revision 0)
+++ chrome/worker/worker_thread.cc (revision 0)
@@ -0,0 +1,82 @@
+// 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 <windows.h>
+
+#include "chrome/worker/worker_thread.h"
+
+#include "chrome/common/ipc_logging.h"
+#include "chrome/common/worker_messages.h"
+#include "chrome/worker/worker_process.h"
+#include "chrome/worker/webworker_context_stub.h"
+
+WorkerThread::WorkerThread(WorkerProcess* process,
+ const std::wstring& channel_name)
+ : worker_process_(process),
+ channel_name_(channel_name),
+ owner_loop_(MessageLoop::current()),
+ Thread("Chrome_WorkerThread") {
+ DCHECK(worker_process_);
+ DCHECK(owner_loop_);
+
+ Start();
+}
+
+WorkerThread::~WorkerThread() {
+ Stop();
+}
+
+void WorkerThread::OnChannelError() {
+ owner_loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask());
+}
+
+bool WorkerThread::Send(IPC::Message* msg) {
+ return channel_.get() ? channel_->Send(msg) : false;
+}
+
+void WorkerThread::OnMessageReceived(const IPC::Message& msg) {
+ if (msg.routing_id() == MSG_ROUTING_CONTROL) {
+ IPC_BEGIN_MESSAGE_MAP(WorkerThread, msg)
+ IPC_MESSAGE_HANDLER(WorkerProcessMsg_CreateWorker, OnCreateWorker)
+ IPC_END_MESSAGE_MAP()
+ } else {
+ bool routed = router_.RouteMessage(msg);
+ if (!routed && msg.is_sync()) {
+ // The listener has gone away, so we must respond or else the caller will
+ // hang waiting for a reply.
+ IPC::Message* reply = IPC::SyncMessage::GenerateReply(&msg);
+ reply->set_reply_error();
+ Send(reply);
+ }
+ }
+}
+
+void WorkerThread::Init() {
+ channel_.reset(new IPC::SyncChannel(channel_name_,
+ IPC::Channel::MODE_CLIENT, this, NULL, owner_loop_, true,
+ WorkerProcess::GetShutDownEvent()));
+
+#ifdef IPC_MESSAGE_LOG_ENABLED
+ IPC::Logging::current()->SetIPCSender(this);
+#endif
+}
+
+void WorkerThread::CleanUp() {
+#ifdef IPC_MESSAGE_LOG_ENABLED
+ IPC::Logging::current()->SetIPCSender(NULL);
+#endif
+
+ // Need to destruct the SyncChannel to the browser before we go away because
+ // it caches a pointer to this thread.
+ channel_.reset();
+}
+
+void WorkerThread::OnCreateWorker(const GURL& url, int route_id) {
+ WebWorkerContextStub* stub = new WebWorkerContextStub(url, route_id);
+ router_.AddRoute(route_id, stub);
+}
+
+void WorkerThread::OnWorkerDestruction(WebWorkerContextStub* worker) {
+ router_.RemoveRoute(worker->route_id());
+}
« no previous file with comments | « chrome/worker/worker_thread.h ('k') | third_party/WebKit/WebCore/dom/WorkerMessagingProxy.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698