Integrate SIMD optimisations for zlib
[chromium-blink-merge.git] / ppapi / proxy / dispatcher.h
blob38ec51ceb006b4eba61d67c6daa552f88efb895d
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/message_filter.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 IPC {
27 class MessageFilter;
30 namespace ppapi {
31 namespace proxy {
33 class VarSerializationRules;
35 // An interface proxy can represent either end of a cross-process interface
36 // call. The "source" side is where the call is invoked, and the "target" side
37 // is where the call ends up being executed.
39 // Plugin side | Browser side
40 // -------------------------------------|--------------------------------------
41 // |
42 // "Source" | "Target"
43 // InterfaceProxy ----------------------> InterfaceProxy
44 // |
45 // |
46 // "Target" | "Source"
47 // InterfaceProxy <---------------------- InterfaceProxy
48 // |
49 class PPAPI_PROXY_EXPORT Dispatcher : public ProxyChannel {
50 public:
51 virtual ~Dispatcher();
53 // Returns true if the dispatcher is on the plugin side, or false if it's the
54 // browser side.
55 virtual bool IsPlugin() const = 0;
57 VarSerializationRules* serialization_rules() const {
58 return serialization_rules_.get();
61 // Returns a non-owning pointer to the interface proxy for the given ID, or
62 // NULL if the ID isn't found. This will create the proxy if it hasn't been
63 // created so far.
64 InterfaceProxy* GetInterfaceProxy(ApiID id);
66 // Adds the given filter to the IO thread.
67 void AddIOThreadMessageFilter(scoped_refptr<IPC::MessageFilter> filter);
69 // IPC::Listener implementation.
70 virtual bool OnMessageReceived(const IPC::Message& msg) override;
72 PP_GetInterface_Func local_get_interface() const {
73 return local_get_interface_;
76 const PpapiPermissions& permissions() const { return permissions_; }
78 protected:
79 explicit Dispatcher(PP_GetInterface_Func local_get_interface,
80 const PpapiPermissions& permissions);
82 // Setter for the derived classes to set the appropriate var serialization.
83 // Takes one reference of the given pointer, which must be on the heap.
84 void SetSerializationRules(VarSerializationRules* var_serialization_rules);
86 // Called when an invalid message is received from the remote site. The
87 // default implementation does nothing, derived classes can override.
88 virtual void OnInvalidMessageReceived();
90 private:
91 friend class PluginDispatcherTest;
93 // Lists all lazily-created interface proxies.
94 scoped_ptr<InterfaceProxy> proxies_[API_ID_COUNT];
96 PP_GetInterface_Func local_get_interface_;
98 scoped_refptr<VarSerializationRules> serialization_rules_;
100 PpapiPermissions permissions_;
102 DISALLOW_COPY_AND_ASSIGN(Dispatcher);
105 } // namespace proxy
106 } // namespace ppapi
108 #endif // PPAPI_PROXY_DISPATCHER_H_