[Android WebView] Fix webview perf bot switchover to use org.chromium.webview_shell...
[chromium-blink-merge.git] / content / child / child_message_filter.h
blob73002e7b2606bd119f8958c34684115a42dd28dc
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 #ifndef CONTENT_CHILD_CHILD_MESSAGE_FILTER_H_
6 #define CONTENT_CHILD_CHILD_MESSAGE_FILTER_H_
8 #include "base/memory/ref_counted.h"
9 #include "ipc/ipc_sender.h"
11 namespace base {
12 class TaskRunner;
15 namespace IPC {
16 class MessageFilter;
19 namespace content {
21 class ThreadSafeSender;
23 // A base class for implementing IPC MessageFilter's that run on a different
24 // thread or TaskRunner than the main thread.
25 class ChildMessageFilter
26 : public base::RefCountedThreadSafe<ChildMessageFilter>,
27 public IPC::Sender {
28 public:
29 // IPC::Sender implementation. Can be called on any threads.
30 bool Send(IPC::Message* message) override;
32 // If implementers want to run OnMessageReceived on a different task
33 // runner it should override this and return the TaskRunner for the message.
34 // Returning NULL runs OnMessageReceived() on the current IPC thread.
35 virtual base::TaskRunner* OverrideTaskRunnerForMessage(
36 const IPC::Message& msg) = 0;
38 // If OverrideTaskRunnerForMessage is overriden and returns non-null
39 // this will be called on the returned TaskRunner.
40 virtual bool OnMessageReceived(const IPC::Message& msg) = 0;
42 // This method is called when WorkerTaskRunner::PostTask() returned false
43 // for the target thread. Note that there's still a little chance that
44 // PostTask() returns true but OnMessageReceived() is never called on the
45 // target thread. By default this does nothing.
46 virtual void OnStaleMessageReceived(const IPC::Message& msg) {}
48 protected:
49 ChildMessageFilter();
50 ~ChildMessageFilter() override;
52 private:
53 class Internal;
54 friend class ChildThreadImpl;
55 friend class RenderThreadImpl;
56 friend class WorkerThread;
58 friend class base::RefCountedThreadSafe<ChildMessageFilter>;
60 IPC::MessageFilter* GetFilter();
62 // This implements IPC::MessageFilter to hide the actual filter methods from
63 // child classes.
64 Internal* internal_;
66 scoped_refptr<ThreadSafeSender> thread_safe_sender_;
68 DISALLOW_COPY_AND_ASSIGN(ChildMessageFilter);
71 } // namespace content
73 #endif // CONTENT_CHILD_CHILD_MESSAGE_FILTER_H_