chrome/browser/ui: Remove use of MessageLoopProxy and deprecated MessageLoop APIs
[chromium-blink-merge.git] / ppapi / proxy / plugin_message_filter.h
blobb41a71dbd5d54e06064d1d070acad3cc6bd072c6
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
3 // found in the LICENSE file.
5 #ifndef PPAPI_PROXY_PLUGIN_MESSAGE_FILTER_H_
6 #define PPAPI_PROXY_PLUGIN_MESSAGE_FILTER_H_
8 #include <set>
9 #include <vector>
11 #include "base/compiler_specific.h"
12 #include "base/memory/ref_counted.h"
13 #include "ipc/ipc_sender.h"
14 #include "ipc/message_filter.h"
15 #include "ppapi/c/pp_instance.h"
16 #include "ppapi/proxy/ppapi_proxy_export.h"
17 #include "ppapi/proxy/resource_message_filter.h"
19 namespace ppapi {
20 namespace proxy {
22 class ResourceMessageReplyParams;
23 class ResourceReplyThreadRegistrar;
25 // Listens for messages on the I/O thread of the plugin and handles some of
26 // them to avoid needing to block on the plugin.
28 // There is one instance of this class for each renderer channel (same as for
29 // the PluginDispatchers).
30 class PPAPI_PROXY_EXPORT PluginMessageFilter : public IPC::MessageFilter,
31 public IPC::Sender {
32 public:
33 // |seen_instance_ids| is a pointer to a set that will be used to uniquify
34 // PP_Instances across all renderer channels. The same pointer should be
35 // passed to each MessageFilter to ensure uniqueness, and the value should
36 // outlive this class. It could be NULL if this filter is for a browser
37 // channel.
38 // |thread_registrar| is used to look up handling threads for resource
39 // reply messages. It shouldn't be NULL.
40 PluginMessageFilter(
41 std::set<PP_Instance>* seen_instance_ids,
42 scoped_refptr<ResourceReplyThreadRegistrar> thread_registrar);
43 ~PluginMessageFilter() override;
45 // MessageFilter implementation.
46 void OnFilterAdded(IPC::Sender* sender) override;
47 void OnFilterRemoved() override;
48 bool OnMessageReceived(const IPC::Message& message) override;
50 // IPC::Sender implementation.
51 bool Send(IPC::Message* msg) override;
53 void AddResourceMessageFilter(
54 const scoped_refptr<ResourceMessageFilter>& filter);
56 // Simulates an incoming resource reply that is handled on the calling thread.
57 // For testing only.
58 static void DispatchResourceReplyForTest(
59 const ResourceMessageReplyParams& reply_params,
60 const IPC::Message& nested_msg);
62 private:
63 void OnMsgReserveInstanceId(PP_Instance instance, bool* usable);
64 void OnMsgResourceReply(const ResourceMessageReplyParams& reply_params,
65 const IPC::Message& nested_msg);
67 // Dispatches the given resource reply to the appropriate resource in the
68 // plugin process.
69 static void DispatchResourceReply(
70 const ResourceMessageReplyParams& reply_params,
71 const IPC::Message& nested_msg);
73 // All instance IDs ever queried by any renderer on this plugin. This is used
74 // to make sure that new instance IDs are unique. This is a non-owning
75 // pointer. It is managed by PluginDispatcher::PluginDelegate.
76 std::set<PP_Instance>* seen_instance_ids_;
78 scoped_refptr<ResourceReplyThreadRegistrar> resource_reply_thread_registrar_;
80 std::vector<scoped_refptr<ResourceMessageFilter>> resource_filters_;
82 // The IPC sender to the renderer. May be NULL if we're not currently
83 // attached as a filter.
84 IPC::Sender* sender_;
87 } // namespace proxy
88 } // namespace ppapi
90 #endif // PPAPI_PROXY_PLUGIN_MESSAGE_FILTER_H_