| 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());
|
| +}
|
|
|