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/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "ppapi/c/pp_stdint.h" | 10 #include "ppapi/c/pp_stdint.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 // If this is the case, the message handler will always be called but a reply | 45 // If this is the case, the message handler will always be called but a reply |
46 // may not be sent back to the host. | 46 // may not be sent back to the host. |
47 // | 47 // |
48 // To handle a resource message on another thread you should implement a | 48 // To handle a resource message on another thread you should implement a |
49 // subclass as follows: | 49 // subclass as follows: |
50 // class MyMessageFilter : public ResourceMessageFilter { | 50 // class MyMessageFilter : public ResourceMessageFilter { |
51 // protected: | 51 // protected: |
52 // scoped_refptr<base::TaskRunner> OverrideTaskRunnerForMessage( | 52 // scoped_refptr<base::TaskRunner> OverrideTaskRunnerForMessage( |
53 // const IPC::Message& message) override { | 53 // const IPC::Message& message) override { |
54 // if (message.type() == MyMessage::ID) | 54 // if (message.type() == MyMessage::ID) |
55 // return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); | 55 // return BrowserThread::GetTaskRunnerForThread(BrowserThread::UI); |
56 // return NULL; | 56 // return NULL; |
57 // } | 57 // } |
58 // | 58 // |
59 // int32_t OnResourceMessageReceived(const IPC::Message& msg, | 59 // int32_t OnResourceMessageReceived(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 // } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 friend class base::RefCountedThreadSafe< | 120 friend class base::RefCountedThreadSafe< |
121 ResourceMessageFilter, internal::ResourceMessageFilterDeleteTraits>; | 121 ResourceMessageFilter, internal::ResourceMessageFilterDeleteTraits>; |
122 friend struct internal::ResourceMessageFilterDeleteTraits; | 122 friend struct internal::ResourceMessageFilterDeleteTraits; |
123 | 123 |
124 // This method is posted to the target thread and runs the message handler. | 124 // This method is posted to the target thread and runs the message handler. |
125 void DispatchMessage(const IPC::Message& msg, | 125 void DispatchMessage(const IPC::Message& msg, |
126 HostMessageContext context); | 126 HostMessageContext context); |
127 | 127 |
128 scoped_refptr<base::SingleThreadTaskRunner> deletion_task_runner_; | 128 scoped_refptr<base::SingleThreadTaskRunner> deletion_task_runner_; |
129 | 129 |
130 // Message loop to send resource message replies on. This will be the message | 130 // Task runner to send resource message replies on. This will be the task |
131 // loop proxy of the IO thread for the browser process or the main thread for | 131 // runner of the IO thread for the browser process or the main thread for a |
132 // the renderer process. | 132 // renderer process. |
133 scoped_refptr<base::SingleThreadTaskRunner> reply_thread_task_runner_; | 133 scoped_refptr<base::SingleThreadTaskRunner> reply_thread_task_runner_; |
134 | 134 |
135 // Non-owning pointer to the resource host owning this filter. Should only be | 135 // Non-owning pointer to the resource host owning this filter. Should only be |
136 // accessed from the thread which sends messages to the plugin resource (i.e. | 136 // accessed from the thread which sends messages to the plugin resource (i.e. |
137 // the IO thread for the browser process or the main thread for the renderer). | 137 // the IO thread for the browser process or the main thread for the renderer). |
138 // This will be NULL upon creation of the filter and is set to the owning | 138 // This will be NULL upon creation of the filter and is set to the owning |
139 // ResourceHost when |OnFilterAdded| is called. When the owning ResourceHost | 139 // ResourceHost when |OnFilterAdded| is called. When the owning ResourceHost |
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 |