1 // Copyright 2013 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.
5 #include "content/child/service_worker/service_worker_message_filter.h"
7 #include "ipc/ipc_message_macros.h"
9 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/pickle.h"
11 #include "content/child/service_worker/service_worker_dispatcher.h"
12 #include "content/child/thread_safe_sender.h"
13 #include "webkit/child/worker_task_runner.h"
15 using webkit_glue::WorkerTaskRunner;
19 ServiceWorkerMessageFilter::ServiceWorkerMessageFilter(ThreadSafeSender* sender)
20 : main_thread_loop_proxy_(base::MessageLoopProxy::current()),
21 thread_safe_sender_(sender) {}
23 ServiceWorkerMessageFilter::~ServiceWorkerMessageFilter() {}
25 bool ServiceWorkerMessageFilter::OnMessageReceived(const IPC::Message& msg) {
26 if (IPC_MESSAGE_CLASS(msg) != ServiceWorkerMsgStart)
29 bool result = PickleIterator(msg).ReadInt(&thread_id);
31 base::Closure closure =
32 base::Bind(&ServiceWorkerMessageFilter::DispatchMessage, this, msg);
34 main_thread_loop_proxy_->PostTask(FROM_HERE, closure);
37 WorkerTaskRunner::Instance()->PostTask(thread_id, closure);
41 void ServiceWorkerMessageFilter::DispatchMessage(const IPC::Message& msg) {
42 ServiceWorkerDispatcher::ThreadSpecificInstance(thread_safe_sender_.get())
43 ->OnMessageReceived(msg);
46 } // namespace content