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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/worker/worker_thread.h ('k') | third_party/WebKit/WebCore/dom/WorkerMessagingProxy.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 <windows.h>
6
7 #include "chrome/worker/worker_thread.h"
8
9 #include "chrome/common/ipc_logging.h"
10 #include "chrome/common/worker_messages.h"
11 #include "chrome/worker/worker_process.h"
12 #include "chrome/worker/webworker_context_stub.h"
13
14 WorkerThread::WorkerThread(WorkerProcess* process,
15 const std::wstring& channel_name)
16 : worker_process_(process),
17 channel_name_(channel_name),
18 owner_loop_(MessageLoop::current()),
19 Thread("Chrome_WorkerThread") {
20 DCHECK(worker_process_);
21 DCHECK(owner_loop_);
22
23 Start();
24 }
25
26 WorkerThread::~WorkerThread() {
27 Stop();
28 }
29
30 void WorkerThread::OnChannelError() {
31 owner_loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask());
32 }
33
34 bool WorkerThread::Send(IPC::Message* msg) {
35 return channel_.get() ? channel_->Send(msg) : false;
36 }
37
38 void WorkerThread::OnMessageReceived(const IPC::Message& msg) {
39 if (msg.routing_id() == MSG_ROUTING_CONTROL) {
40 IPC_BEGIN_MESSAGE_MAP(WorkerThread, msg)
41 IPC_MESSAGE_HANDLER(WorkerProcessMsg_CreateWorker, OnCreateWorker)
42 IPC_END_MESSAGE_MAP()
43 } else {
44 bool routed = router_.RouteMessage(msg);
45 if (!routed && msg.is_sync()) {
46 // The listener has gone away, so we must respond or else the caller will
47 // hang waiting for a reply.
48 IPC::Message* reply = IPC::SyncMessage::GenerateReply(&msg);
49 reply->set_reply_error();
50 Send(reply);
51 }
52 }
53 }
54
55 void WorkerThread::Init() {
56 channel_.reset(new IPC::SyncChannel(channel_name_,
57 IPC::Channel::MODE_CLIENT, this, NULL, owner_loop_, true,
58 WorkerProcess::GetShutDownEvent()));
59
60 #ifdef IPC_MESSAGE_LOG_ENABLED
61 IPC::Logging::current()->SetIPCSender(this);
62 #endif
63 }
64
65 void WorkerThread::CleanUp() {
66 #ifdef IPC_MESSAGE_LOG_ENABLED
67 IPC::Logging::current()->SetIPCSender(NULL);
68 #endif
69
70 // Need to destruct the SyncChannel to the browser before we go away because
71 // it caches a pointer to this thread.
72 channel_.reset();
73 }
74
75 void WorkerThread::OnCreateWorker(const GURL& url, int route_id) {
76 WebWorkerContextStub* stub = new WebWorkerContextStub(url, route_id);
77 router_.AddRoute(route_id, stub);
78 }
79
80 void WorkerThread::OnWorkerDestruction(WebWorkerContextStub* worker) {
81 router_.RemoveRoute(worker->route_id());
82 }
OLDNEW
« 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