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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 // virtual 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 // virtual int32_t OnResourceMessageReceived( |
59 // const IPC::Message& msg, | 59 // const IPC::Message& msg, |
60 // HostMessageContext* context) OVERRIDE { | 60 // HostMessageContext* context) override { |
61 // IPC_BEGIN_MESSAGE_MAP(MyMessageFilter, msg) | 61 // IPC_BEGIN_MESSAGE_MAP(MyMessageFilter, msg) |
62 // PPAPI_DISPATCH_HOST_RESOURCE_CALL(MyMessage, OnMyMessage) | 62 // PPAPI_DISPATCH_HOST_RESOURCE_CALL(MyMessage, OnMyMessage) |
63 // IPC_END_MESSAGE_MAP() | 63 // IPC_END_MESSAGE_MAP() |
64 // return PP_ERROR_FAILED; | 64 // return PP_ERROR_FAILED; |
65 // } | 65 // } |
66 // | 66 // |
67 // private: | 67 // private: |
68 // int32_t OnMyMessage(ppapi::host::HostMessageContext* context, ...) { | 68 // int32_t OnMyMessage(ppapi::host::HostMessageContext* context, ...) { |
69 // // Will be run on the UI thread. | 69 // // Will be run on the UI thread. |
70 // } | 70 // } |
(...skipping 19 matching lines...) Expand all Loading... |
90 scoped_refptr<base::MessageLoopProxy> reply_thread_message_loop_proxy); | 90 scoped_refptr<base::MessageLoopProxy> reply_thread_message_loop_proxy); |
91 | 91 |
92 // Called when a filter is added to a ResourceHost. | 92 // Called when a filter is added to a ResourceHost. |
93 void OnFilterAdded(ResourceHost* resource_host); | 93 void OnFilterAdded(ResourceHost* resource_host); |
94 // Called when a filter is removed from a ResourceHost. | 94 // Called when a filter is removed from a ResourceHost. |
95 void OnFilterDestroyed(); | 95 void OnFilterDestroyed(); |
96 | 96 |
97 // This will dispatch the message handler on the target thread. It returns | 97 // 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. | 98 // true if the message was handled by this filter and false otherwise. |
99 virtual bool HandleMessage(const IPC::Message& msg, | 99 virtual bool HandleMessage(const IPC::Message& msg, |
100 HostMessageContext* context) OVERRIDE; | 100 HostMessageContext* context) override; |
101 | 101 |
102 // This can be called from any thread. | 102 // This can be called from any thread. |
103 virtual void SendReply(const ReplyMessageContext& context, | 103 virtual void SendReply(const ReplyMessageContext& context, |
104 const IPC::Message& msg) OVERRIDE; | 104 const IPC::Message& msg) override; |
105 | 105 |
106 protected: | 106 protected: |
107 virtual ~ResourceMessageFilter(); | 107 virtual ~ResourceMessageFilter(); |
108 | 108 |
109 // Please see the comments of |resource_host_| for on which thread it can be | 109 // Please see the comments of |resource_host_| for on which thread it can be |
110 // used and when it is NULL. | 110 // used and when it is NULL. |
111 ResourceHost* resource_host() const { return resource_host_; } | 111 ResourceHost* resource_host() const { return resource_host_; } |
112 | 112 |
113 // If you want the message to be handled on another thread, return a non-null | 113 // If you want the message to be handled on another thread, return a non-null |
114 // task runner which will target tasks accordingly. | 114 // task runner which will target tasks accordingly. |
(...skipping 25 matching lines...) Expand all Loading... |
140 // is destroyed, |OnFilterDestroyed| is called and this will be set to NULL. | 140 // is destroyed, |OnFilterDestroyed| is called and this will be set to NULL. |
141 ResourceHost* resource_host_; | 141 ResourceHost* resource_host_; |
142 | 142 |
143 DISALLOW_COPY_AND_ASSIGN(ResourceMessageFilter); | 143 DISALLOW_COPY_AND_ASSIGN(ResourceMessageFilter); |
144 }; | 144 }; |
145 | 145 |
146 } // namespace host | 146 } // namespace host |
147 } // namespace ppapi | 147 } // namespace ppapi |
148 | 148 |
149 #endif // PPAPI_HOST_RESOURCE_MESSAGE_FILTER_H_ | 149 #endif // PPAPI_HOST_RESOURCE_MESSAGE_FILTER_H_ |
OLD | NEW |