| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 PPAPI_HOST_RESOURCE_MESSAGE_FILTER_H_ | 5 #ifndef PPAPI_HOST_RESOURCE_MESSAGE_FILTER_H_ |
| 6 #define PPAPI_HOST_RESOURCE_MESSAGE_FILTER_H_ | 6 #define PPAPI_HOST_RESOURCE_MESSAGE_FILTER_H_ |
| 7 | 7 |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "ppapi/c/pp_stdint.h" | 9 #include "ppapi/c/pp_stdint.h" |
| 10 #include "ppapi/host/host_message_context.h" | 10 #include "ppapi/host/host_message_context.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 // similar to a BrowserMessageFilter but for resource messages. Note that the | 41 // similar to a BrowserMessageFilter but for resource messages. Note that the |
| 42 // liftetime of a ResourceHost is managed by a PpapiHost and may be destroyed | 42 // liftetime of a ResourceHost is managed by a PpapiHost and may be destroyed |
| 43 // before or while your message is being processed on another thread. | 43 // before or while your message is being processed on another thread. |
| 44 // If this is the case, the message handler will always be called but a reply | 44 // If this is the case, the message handler will always be called but a reply |
| 45 // may not be sent back to the host. | 45 // may not be sent back to the host. |
| 46 // | 46 // |
| 47 // To handle a resource message on another thread you should implement a | 47 // To handle a resource message on another thread you should implement a |
| 48 // subclass as follows: | 48 // subclass as follows: |
| 49 // class MyMessageFilter : public ResourceMessageFilter { | 49 // class MyMessageFilter : public ResourceMessageFilter { |
| 50 // protected: | 50 // protected: |
| 51 // virtual scoped_refptr<base::TaskRunner> OverrideTaskRunnerForMessage( | 51 // scoped_refptr<base::TaskRunner> OverrideTaskRunnerForMessage( |
| 52 // const IPC::Message& message) override { | 52 // const IPC::Message& message) override { |
| 53 // if (message.type() == MyMessage::ID) | 53 // if (message.type() == MyMessage::ID) |
| 54 // return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); | 54 // return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); |
| 55 // return NULL; | 55 // return NULL; |
| 56 // } | 56 // } |
| 57 // | 57 // |
| 58 // virtual int32_t OnResourceMessageReceived( | 58 // int32_t OnResourceMessageReceived(const IPC::Message& msg, |
| 59 // const IPC::Message& msg, | 59 // HostMessageContext* context) override { |
| 60 // HostMessageContext* context) override { | |
| 61 // IPC_BEGIN_MESSAGE_MAP(MyMessageFilter, msg) | 60 // IPC_BEGIN_MESSAGE_MAP(MyMessageFilter, msg) |
| 62 // PPAPI_DISPATCH_HOST_RESOURCE_CALL(MyMessage, OnMyMessage) | 61 // PPAPI_DISPATCH_HOST_RESOURCE_CALL(MyMessage, OnMyMessage) |
| 63 // IPC_END_MESSAGE_MAP() | 62 // IPC_END_MESSAGE_MAP() |
| 64 // return PP_ERROR_FAILED; | 63 // return PP_ERROR_FAILED; |
| 65 // } | 64 // } |
| 66 // | 65 // |
| 67 // private: | 66 // private: |
| 68 // int32_t OnMyMessage(ppapi::host::HostMessageContext* context, ...) { | 67 // int32_t OnMyMessage(ppapi::host::HostMessageContext* context, ...) { |
| 69 // // Will be run on the UI thread. | 68 // // Will be run on the UI thread. |
| 70 // } | 69 // } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 89 ResourceMessageFilter( | 88 ResourceMessageFilter( |
| 90 scoped_refptr<base::MessageLoopProxy> reply_thread_message_loop_proxy); | 89 scoped_refptr<base::MessageLoopProxy> reply_thread_message_loop_proxy); |
| 91 | 90 |
| 92 // Called when a filter is added to a ResourceHost. | 91 // Called when a filter is added to a ResourceHost. |
| 93 void OnFilterAdded(ResourceHost* resource_host); | 92 void OnFilterAdded(ResourceHost* resource_host); |
| 94 // Called when a filter is removed from a ResourceHost. | 93 // Called when a filter is removed from a ResourceHost. |
| 95 void OnFilterDestroyed(); | 94 void OnFilterDestroyed(); |
| 96 | 95 |
| 97 // This will dispatch the message handler on the target thread. It returns | 96 // This will dispatch the message handler on the target thread. It returns |
| 98 // true if the message was handled by this filter and false otherwise. | 97 // true if the message was handled by this filter and false otherwise. |
| 99 virtual bool HandleMessage(const IPC::Message& msg, | 98 bool HandleMessage(const IPC::Message& msg, |
| 100 HostMessageContext* context) override; | 99 HostMessageContext* context) override; |
| 101 | 100 |
| 102 // This can be called from any thread. | 101 // This can be called from any thread. |
| 103 virtual void SendReply(const ReplyMessageContext& context, | 102 void SendReply(const ReplyMessageContext& context, |
| 104 const IPC::Message& msg) override; | 103 const IPC::Message& msg) override; |
| 105 | 104 |
| 106 protected: | 105 protected: |
| 107 virtual ~ResourceMessageFilter(); | 106 ~ResourceMessageFilter() override; |
| 108 | 107 |
| 109 // Please see the comments of |resource_host_| for on which thread it can be | 108 // Please see the comments of |resource_host_| for on which thread it can be |
| 110 // used and when it is NULL. | 109 // used and when it is NULL. |
| 111 ResourceHost* resource_host() const { return resource_host_; } | 110 ResourceHost* resource_host() const { return resource_host_; } |
| 112 | 111 |
| 113 // If you want the message to be handled on another thread, return a non-null | 112 // If you want the message to be handled on another thread, return a non-null |
| 114 // task runner which will target tasks accordingly. | 113 // task runner which will target tasks accordingly. |
| 115 virtual scoped_refptr<base::TaskRunner> OverrideTaskRunnerForMessage( | 114 virtual scoped_refptr<base::TaskRunner> OverrideTaskRunnerForMessage( |
| 116 const IPC::Message& message); | 115 const IPC::Message& message); |
| 117 | 116 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 140 // is destroyed, |OnFilterDestroyed| is called and this will be set to NULL. | 139 // is destroyed, |OnFilterDestroyed| is called and this will be set to NULL. |
| 141 ResourceHost* resource_host_; | 140 ResourceHost* resource_host_; |
| 142 | 141 |
| 143 DISALLOW_COPY_AND_ASSIGN(ResourceMessageFilter); | 142 DISALLOW_COPY_AND_ASSIGN(ResourceMessageFilter); |
| 144 }; | 143 }; |
| 145 | 144 |
| 146 } // namespace host | 145 } // namespace host |
| 147 } // namespace ppapi | 146 } // namespace ppapi |
| 148 | 147 |
| 149 #endif // PPAPI_HOST_RESOURCE_MESSAGE_FILTER_H_ | 148 #endif // PPAPI_HOST_RESOURCE_MESSAGE_FILTER_H_ |
| OLD | NEW |