diff options
author | Sadrul Habib Chowdhury <sadrul@chromium.org> | 2015-02-04 09:19:02 -0500 |
---|---|---|
committer | Sadrul Habib Chowdhury <sadrul@chromium.org> | 2015-02-04 14:20:09 +0000 |
commit | 869b89123602a51ac523d97054262bc4ab6a6933 (patch) | |
tree | 8b196172bb0190ea29708b55be6a4653ac616d29 /content/child/geofencing | |
parent | 2f1f356587f1716abf6e78747e65db9e1f514c8e (diff) | |
download | chromium_src-869b89123602a51ac523d97054262bc4ab6a6933.zip chromium_src-869b89123602a51ac523d97054262bc4ab6a6933.tar.gz chromium_src-869b89123602a51ac523d97054262bc4ab6a6933.tar.bz2 |
workers: Introduce a WorkerThreadMessageFilter to ease routing/processing worker messages.
Move the task of managing the task-runners for the worker-thread/main-thread in
a common implementation in WorkerThreadMessageFilter, and use that from the rest
of the message filters.
BUG=none
R=jochen@chromium.org, kinuko@chromium.org
Review URL: https://codereview.chromium.org/892543002
Cr-Commit-Position: refs/heads/master@{#314556}
Diffstat (limited to 'content/child/geofencing')
-rw-r--r-- | content/child/geofencing/geofencing_message_filter.cc | 33 | ||||
-rw-r--r-- | content/child/geofencing/geofencing_message_filter.h | 22 |
2 files changed, 20 insertions, 35 deletions
diff --git a/content/child/geofencing/geofencing_message_filter.cc b/content/child/geofencing/geofencing_message_filter.cc index a833457..a866b37 100644 --- a/content/child/geofencing/geofencing_message_filter.cc +++ b/content/child/geofencing/geofencing_message_filter.cc @@ -4,40 +4,33 @@ #include "content/child/geofencing/geofencing_message_filter.h" -#include "base/message_loop/message_loop_proxy.h" #include "content/child/geofencing/geofencing_dispatcher.h" -#include "content/child/thread_safe_sender.h" -#include "content/child/worker_thread_task_runner.h" #include "ipc/ipc_message_macros.h" namespace content { GeofencingMessageFilter::GeofencingMessageFilter(ThreadSafeSender* sender) - : main_thread_loop_proxy_(base::MessageLoopProxy::current()), - thread_safe_sender_(sender) { + : WorkerThreadMessageFilter(sender) { } GeofencingMessageFilter::~GeofencingMessageFilter() { } -base::TaskRunner* GeofencingMessageFilter::OverrideTaskRunnerForMessage( +bool GeofencingMessageFilter::ShouldHandleMessage( + const IPC::Message& msg) const { + return IPC_MESSAGE_CLASS(msg) == GeofencingMsgStart; +} + +void GeofencingMessageFilter::OnFilteredMessageReceived( const IPC::Message& msg) { - if (IPC_MESSAGE_CLASS(msg) != GeofencingMsgStart) - return NULL; - int ipc_thread_id = 0; - const bool success = PickleIterator(msg).ReadInt(&ipc_thread_id); - DCHECK(success); - if (!ipc_thread_id) - return main_thread_loop_proxy_.get(); - return new WorkerThreadTaskRunner(ipc_thread_id); + GeofencingDispatcher::GetOrCreateThreadSpecificInstance(thread_safe_sender()) + ->OnMessageReceived(msg); } -bool GeofencingMessageFilter::OnMessageReceived(const IPC::Message& msg) { - if (IPC_MESSAGE_CLASS(msg) != GeofencingMsgStart) - return false; - GeofencingDispatcher::GetOrCreateThreadSpecificInstance( - thread_safe_sender_.get())->OnMessageReceived(msg); - return true; +bool GeofencingMessageFilter::GetWorkerThreadIdForMessage( + const IPC::Message& msg, + int* ipc_thread_id) { + return PickleIterator(msg).ReadInt(ipc_thread_id); } } // namespace content diff --git a/content/child/geofencing/geofencing_message_filter.h b/content/child/geofencing/geofencing_message_filter.h index 3a95d42..34a05c2 100644 --- a/content/child/geofencing/geofencing_message_filter.h +++ b/content/child/geofencing/geofencing_message_filter.h @@ -5,30 +5,22 @@ #ifndef CONTENT_CHILD_GEOFENCING_GEOFENCING_MESSAGE_FILTER_H_ #define CONTENT_CHILD_GEOFENCING_GEOFENCING_MESSAGE_FILTER_H_ -#include "content/child/child_message_filter.h" - -namespace base { -class MessageLoopProxy; -} +#include "content/child/worker_thread_message_filter.h" namespace content { -class ThreadSafeSender; - -class GeofencingMessageFilter : public ChildMessageFilter { +class GeofencingMessageFilter : public WorkerThreadMessageFilter { public: explicit GeofencingMessageFilter(ThreadSafeSender* thread_safe_sender); private: ~GeofencingMessageFilter() override; - // ChildMessageFilter implementation: - base::TaskRunner* OverrideTaskRunnerForMessage( - const IPC::Message& msg) override; - bool OnMessageReceived(const IPC::Message& msg) override; - - scoped_refptr<base::MessageLoopProxy> main_thread_loop_proxy_; - scoped_refptr<ThreadSafeSender> thread_safe_sender_; + // WorkerThreadMessageFilter: + bool ShouldHandleMessage(const IPC::Message& msg) const override; + void OnFilteredMessageReceived(const IPC::Message& msg) override; + bool GetWorkerThreadIdForMessage(const IPC::Message& msg, + int* ipc_thread_id) override; DISALLOW_COPY_AND_ASSIGN(GeofencingMessageFilter); }; |