OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_PROXY_PLUGIN_MESSAGE_FILTER_H_ | 5 #ifndef PPAPI_PROXY_PLUGIN_MESSAGE_FILTER_H_ |
6 #define PPAPI_PROXY_PLUGIN_MESSAGE_FILTER_H_ | 6 #define PPAPI_PROXY_PLUGIN_MESSAGE_FILTER_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/memory/ref_counted.h" |
11 #include "ipc/ipc_channel_proxy.h" | 12 #include "ipc/ipc_channel_proxy.h" |
12 #include "ipc/ipc_sender.h" | 13 #include "ipc/ipc_sender.h" |
13 #include "ppapi/c/pp_instance.h" | 14 #include "ppapi/c/pp_instance.h" |
| 15 #include "ppapi/proxy/ppapi_proxy_export.h" |
14 | 16 |
15 namespace ppapi { | 17 namespace ppapi { |
16 namespace proxy { | 18 namespace proxy { |
17 | 19 |
| 20 class ResourceMessageReplyParams; |
| 21 class ResourceReplyThreadRegistrar; |
| 22 |
18 // Listens for messages on the I/O thread of the plugin and handles some of | 23 // Listens for messages on the I/O thread of the plugin and handles some of |
19 // them to avoid needing to block on the plugin. | 24 // them to avoid needing to block on the plugin. |
20 // | 25 // |
21 // There is one instance of this class for each renderer channel (same as for | 26 // There is one instance of this class for each renderer channel (same as for |
22 // the PluginDispatchers). | 27 // the PluginDispatchers). |
23 class PluginMessageFilter : public IPC::ChannelProxy::MessageFilter, | 28 class PPAPI_PROXY_EXPORT PluginMessageFilter |
24 public IPC::Sender { | 29 : public IPC::ChannelProxy::MessageFilter, |
| 30 public IPC::Sender { |
25 public: | 31 public: |
26 // The input is a pointer to a set that will be used to uniquify PP_Instances | 32 // |seen_instance_ids| is a pointer to a set that will be used to uniquify |
27 // across all renderer channels. The same pointer should be passed to each | 33 // PP_Instances across all renderer channels. The same pointer should be |
28 // MessageFilter to ensure uniqueness, and the value should outlive this | 34 // passed to each MessageFilter to ensure uniqueness, and the value should |
29 // class. | 35 // outlive this class. It could be NULL if this filter is for a browser |
30 PluginMessageFilter(std::set<PP_Instance>* seen_instance_ids); | 36 // channel. |
| 37 // |thread_registrar| is used to look up handling threads for resource |
| 38 // reply messages. It shouldn't be NULL. |
| 39 PluginMessageFilter( |
| 40 std::set<PP_Instance>* seen_instance_ids, |
| 41 scoped_refptr<ResourceReplyThreadRegistrar> thread_registrar); |
31 virtual ~PluginMessageFilter(); | 42 virtual ~PluginMessageFilter(); |
32 | 43 |
33 // MessageFilter implementation. | 44 // MessageFilter implementation. |
34 virtual void OnFilterAdded(IPC::Channel* channel) OVERRIDE; | 45 virtual void OnFilterAdded(IPC::Channel* channel) OVERRIDE; |
35 virtual void OnFilterRemoved() OVERRIDE; | 46 virtual void OnFilterRemoved() OVERRIDE; |
36 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 47 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
37 | 48 |
38 // IPC::Sender implementation. | 49 // IPC::Sender implementation. |
39 virtual bool Send(IPC::Message* msg) OVERRIDE; | 50 virtual bool Send(IPC::Message* msg) OVERRIDE; |
40 | 51 |
| 52 // Simulates an incoming resource reply that is handled on the calling thread. |
| 53 // For testing only. |
| 54 static void DispatchResourceReplyForTest( |
| 55 const ResourceMessageReplyParams& reply_params, |
| 56 const IPC::Message& nested_msg); |
| 57 |
41 private: | 58 private: |
42 void OnMsgReserveInstanceId(PP_Instance instance, bool* usable); | 59 void OnMsgReserveInstanceId(PP_Instance instance, bool* usable); |
| 60 void OnMsgResourceReply(const ResourceMessageReplyParams& reply_params, |
| 61 const IPC::Message& nested_msg); |
43 | 62 |
44 // All instance IDs every queried by any renderer on this plugin. This is | 63 // Dispatches the given resource reply to the appropriate resource in the |
45 // used to make sure that new instance IDs are unique. This is a non-owning | 64 // plugin process. |
46 // pointer, it will be managed by the later that creates this class. | 65 static void DispatchResourceReply( |
| 66 const ResourceMessageReplyParams& reply_params, |
| 67 const IPC::Message& nested_msg); |
| 68 |
| 69 // All instance IDs ever queried by any renderer on this plugin. This is used |
| 70 // to make sure that new instance IDs are unique. This is a non-owning |
| 71 // pointer. It is managed by PluginDispatcher::PluginDelegate. |
47 std::set<PP_Instance>* seen_instance_ids_; | 72 std::set<PP_Instance>* seen_instance_ids_; |
48 | 73 |
| 74 scoped_refptr<ResourceReplyThreadRegistrar> resource_reply_thread_registrar_; |
| 75 |
49 // The IPC channel to the renderer. May be NULL if we're not currently | 76 // The IPC channel to the renderer. May be NULL if we're not currently |
50 // attached as a filter. | 77 // attached as a filter. |
51 IPC::Channel* channel_; | 78 IPC::Channel* channel_; |
52 }; | 79 }; |
53 | 80 |
54 } // namespace proxy | 81 } // namespace proxy |
55 } // namespace ppapi | 82 } // namespace ppapi |
56 | 83 |
57 #endif // PPAPI_PROXY_PLUGIN_MESSAGE_FILTER_H_ | 84 #endif // PPAPI_PROXY_PLUGIN_MESSAGE_FILTER_H_ |
OLD | NEW |