cc: Skip commit state timer on sync compositor
[chromium-blink-merge.git] / ppapi / proxy / dispatcher.h
blob06483f72f97ff1725ea587849a3b372ca49b5e37
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
3 // found in the LICENSE file.
5 #ifndef PPAPI_PROXY_DISPATCHER_H_
6 #define PPAPI_PROXY_DISPATCHER_H_
8 #include <set>
9 #include <string>
10 #include <vector>
12 #include "base/callback_forward.h"
13 #include "base/compiler_specific.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/tracked_objects.h"
16 #include "ipc/ipc_channel_proxy.h"
17 #include "ppapi/c/pp_instance.h"
18 #include "ppapi/c/pp_module.h"
19 #include "ppapi/c/ppp.h"
20 #include "ppapi/proxy/proxy_channel.h"
21 #include "ppapi/proxy/interface_list.h"
22 #include "ppapi/proxy/interface_proxy.h"
23 #include "ppapi/proxy/plugin_var_tracker.h"
24 #include "ppapi/shared_impl/api_id.h"
26 namespace ppapi {
27 namespace proxy {
29 class VarSerializationRules;
31 // An interface proxy can represent either end of a cross-process interface
32 // call. The "source" side is where the call is invoked, and the "target" side
33 // is where the call ends up being executed.
35 // Plugin side | Browser side
36 // -------------------------------------|--------------------------------------
37 // |
38 // "Source" | "Target"
39 // InterfaceProxy ----------------------> InterfaceProxy
40 // |
41 // |
42 // "Target" | "Source"
43 // InterfaceProxy <---------------------- InterfaceProxy
44 // |
45 class PPAPI_PROXY_EXPORT Dispatcher : public ProxyChannel {
46 public:
47 virtual ~Dispatcher();
49 // Returns true if the dispatcher is on the plugin side, or false if it's the
50 // browser side.
51 virtual bool IsPlugin() const = 0;
53 VarSerializationRules* serialization_rules() const {
54 return serialization_rules_.get();
57 // Returns a non-owning pointer to the interface proxy for the given ID, or
58 // NULL if the ID isn't found. This will create the proxy if it hasn't been
59 // created so far.
60 InterfaceProxy* GetInterfaceProxy(ApiID id);
62 // Adds the given filter to the IO thread. Takes ownership of the pointer.
63 void AddIOThreadMessageFilter(IPC::ChannelProxy::MessageFilter* filter);
65 // IPC::Listener implementation.
66 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
68 PP_GetInterface_Func local_get_interface() const {
69 return local_get_interface_;
72 const PpapiPermissions& permissions() const { return permissions_; }
74 protected:
75 explicit Dispatcher(PP_GetInterface_Func local_get_interface,
76 const PpapiPermissions& permissions);
78 // Setter for the derived classes to set the appropriate var serialization.
79 // Takes one reference of the given pointer, which must be on the heap.
80 void SetSerializationRules(VarSerializationRules* var_serialization_rules);
82 // Called when an invalid message is received from the remote site. The
83 // default implementation does nothing, derived classes can override.
84 virtual void OnInvalidMessageReceived();
86 private:
87 friend class PluginDispatcherTest;
89 // Lists all lazily-created interface proxies.
90 scoped_ptr<InterfaceProxy> proxies_[API_ID_COUNT];
92 PP_GetInterface_Func local_get_interface_;
94 scoped_refptr<VarSerializationRules> serialization_rules_;
96 PpapiPermissions permissions_;
98 DISALLOW_COPY_AND_ASSIGN(Dispatcher);
101 } // namespace proxy
102 } // namespace ppapi
104 #endif // PPAPI_PROXY_DISPATCHER_H_