| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_CHILD_CROSS_MESSAGE_FILTER_H_ | 5 #ifndef CONTENT_CHILD_CROSS_MESSAGE_FILTER_H_ |
| 6 #define CONTENT_CHILD_CROSS_MESSAGE_FILTER_H_ | 6 #define CONTENT_CHILD_CROSS_MESSAGE_FILTER_H_ |
| 7 | 7 |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "ipc/ipc_sender.h" | 9 #include "ipc/ipc_sender.h" |
| 10 | 10 |
| 11 namespace base { | 11 namespace base { |
| 12 class TaskRunner; | 12 class TaskRunner; |
| 13 } | 13 } |
| 14 | 14 |
| 15 namespace IPC { | 15 namespace IPC { |
| 16 class MessageFilter; | 16 class MessageFilter; |
| 17 } | 17 } |
| 18 | 18 |
| 19 namespace content { | 19 namespace content { |
| 20 | 20 |
| 21 class ThreadSafeSender; | 21 class ThreadSafeSender; |
| 22 | 22 |
| 23 // A base class for implementing IPC MessageFilter's that run on a different | 23 // A base class for implementing IPC MessageFilter's that run on a different |
| 24 // thread or TaskRunner than the main thread. | 24 // thread or TaskRunner than the main thread. |
| 25 class ChildMessageFilter | 25 class ChildMessageFilter |
| 26 : public base::RefCountedThreadSafe<ChildMessageFilter>, | 26 : public base::RefCountedThreadSafe<ChildMessageFilter>, |
| 27 public IPC::Sender { | 27 public IPC::Sender { |
| 28 public: | 28 public: |
| 29 // IPC::Sender implementation. Can be called on any threads. | 29 // IPC::Sender implementation. Can be called on any threads. |
| 30 virtual bool Send(IPC::Message* message) override; | 30 bool Send(IPC::Message* message) override; |
| 31 | 31 |
| 32 // If implementers want to run OnMessageReceived on a different task | 32 // If implementers want to run OnMessageReceived on a different task |
| 33 // runner it should override this and return the TaskRunner for the message. | 33 // runner it should override this and return the TaskRunner for the message. |
| 34 // Returning NULL runs OnMessageReceived() on the current IPC thread. | 34 // Returning NULL runs OnMessageReceived() on the current IPC thread. |
| 35 virtual base::TaskRunner* OverrideTaskRunnerForMessage( | 35 virtual base::TaskRunner* OverrideTaskRunnerForMessage( |
| 36 const IPC::Message& msg) = 0; | 36 const IPC::Message& msg) = 0; |
| 37 | 37 |
| 38 // If OverrideTaskRunnerForMessage is overriden and returns non-null | 38 // If OverrideTaskRunnerForMessage is overriden and returns non-null |
| 39 // this will be called on the returned TaskRunner. | 39 // this will be called on the returned TaskRunner. |
| 40 virtual bool OnMessageReceived(const IPC::Message& msg) = 0; | 40 virtual bool OnMessageReceived(const IPC::Message& msg) = 0; |
| 41 | 41 |
| 42 // This method is called when WorkerTaskRunner::PostTask() returned false | 42 // This method is called when WorkerTaskRunner::PostTask() returned false |
| 43 // for the target thread. Note that there's still a little chance that | 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 | 44 // PostTask() returns true but OnMessageReceived() is never called on the |
| 45 // target thread. By default this does nothing. | 45 // target thread. By default this does nothing. |
| 46 virtual void OnStaleMessageReceived(const IPC::Message& msg) {} | 46 virtual void OnStaleMessageReceived(const IPC::Message& msg) {} |
| 47 | 47 |
| 48 protected: | 48 protected: |
| 49 ChildMessageFilter(); | 49 ChildMessageFilter(); |
| 50 virtual ~ChildMessageFilter(); | 50 ~ChildMessageFilter() override; |
| 51 | 51 |
| 52 private: | 52 private: |
| 53 class Internal; | 53 class Internal; |
| 54 friend class ChildThread; | 54 friend class ChildThread; |
| 55 friend class RenderThreadImpl; | 55 friend class RenderThreadImpl; |
| 56 friend class WorkerThread; | 56 friend class WorkerThread; |
| 57 | 57 |
| 58 friend class base::RefCountedThreadSafe<ChildMessageFilter>; | 58 friend class base::RefCountedThreadSafe<ChildMessageFilter>; |
| 59 | 59 |
| 60 IPC::MessageFilter* GetFilter(); | 60 IPC::MessageFilter* GetFilter(); |
| 61 | 61 |
| 62 // This implements IPC::MessageFilter to hide the actual filter methods from | 62 // This implements IPC::MessageFilter to hide the actual filter methods from |
| 63 // child classes. | 63 // child classes. |
| 64 Internal* internal_; | 64 Internal* internal_; |
| 65 | 65 |
| 66 scoped_refptr<ThreadSafeSender> thread_safe_sender_; | 66 scoped_refptr<ThreadSafeSender> thread_safe_sender_; |
| 67 | 67 |
| 68 DISALLOW_COPY_AND_ASSIGN(ChildMessageFilter); | 68 DISALLOW_COPY_AND_ASSIGN(ChildMessageFilter); |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 } // namespace content | 71 } // namespace content |
| 72 | 72 |
| 73 #endif // CONTENT_CHILD_CROSS_MESSAGE_FILTER_H_ | 73 #endif // CONTENT_CHILD_CROSS_MESSAGE_FILTER_H_ |
| OLD | NEW |