Convert TestOldCompletionCallback in WebSocketJobTest.
[chromium-blink-merge.git] / ppapi / proxy / dispatcher.h
blobb0af8eafecac227f44e7780c4e629d0e0e4950b8
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_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/tracked_objects.h"
14 #include "ipc/ipc_channel_proxy.h"
15 #include "ppapi/c/pp_instance.h"
16 #include "ppapi/c/pp_module.h"
17 #include "ppapi/proxy/proxy_channel.h"
18 #include "ppapi/proxy/interface_list.h"
19 #include "ppapi/proxy/interface_proxy.h"
20 #include "ppapi/proxy/plugin_var_tracker.h"
21 #include "ppapi/shared_impl/api_id.h"
23 namespace ppapi {
25 namespace proxy {
27 class VarSerializationRules;
29 // An interface proxy can represent either end of a cross-process interface
30 // call. The "source" side is where the call is invoked, and the "target" side
31 // is where the call ends up being executed.
33 // Plugin side | Browser side
34 // -------------------------------------|--------------------------------------
35 // |
36 // "Source" | "Target"
37 // InterfaceProxy ----------------------> InterfaceProxy
38 // |
39 // |
40 // "Target" | "Source"
41 // InterfaceProxy <---------------------- InterfaceProxy
42 // |
43 class PPAPI_PROXY_EXPORT Dispatcher : public ProxyChannel {
44 public:
45 typedef const void* (*GetInterfaceFunc)(const char*);
46 typedef int32_t (*InitModuleFunc)(PP_Module, GetInterfaceFunc);
48 virtual ~Dispatcher();
50 // Returns true if the dispatcher is on the plugin side, or false if it's the
51 // browser side.
52 virtual bool IsPlugin() const = 0;
54 VarSerializationRules* serialization_rules() const {
55 return serialization_rules_.get();
58 // Returns a non-owning pointer to the interface proxy for the given ID, or
59 // NULL if the ID isn't found. This will create the proxy if it hasn't been
60 // created so far.
61 InterfaceProxy* GetInterfaceProxy(ApiID id);
63 // Returns the pointer to the IO thread for processing IPC messages.
64 // TODO(brettw) remove this. It's a hack to support the Flash
65 // ModuleLocalThreadAdapter. When the thread stuff is sorted out, this
66 // implementation detail should be hidden.
67 base::MessageLoopProxy* GetIPCMessageLoop();
69 // Adds the given filter to the IO thread. Takes ownership of the pointer.
70 // TODO(brettw) remove this. It's a hack to support the Flash
71 // ModuleLocalThreadAdapter. When the thread stuff is sorted out, this
72 // implementation detail should be hidden.
73 void AddIOThreadMessageFilter(IPC::ChannelProxy::MessageFilter* filter);
75 // TODO(brettw): What is this comment referring to?
76 // Called if the remote side is declaring to us which interfaces it supports
77 // so we don't have to query for each one. We'll pre-create proxies for
78 // each of the given interfaces.
80 // IPC::Channel::Listener implementation.
81 virtual bool OnMessageReceived(const IPC::Message& msg);
83 GetInterfaceFunc local_get_interface() const { return local_get_interface_; }
85 protected:
86 Dispatcher(base::ProcessHandle remote_process_handle,
87 GetInterfaceFunc local_get_interface);
89 // Setter for the derived classes to set the appropriate var serialization.
90 // Takes ownership of the given pointer, which must be on the heap.
91 void SetSerializationRules(VarSerializationRules* var_serialization_rules);
93 // Called when an invalid message is received from the remote site. The
94 // default implementation does nothing, derived classes can override.
95 virtual void OnInvalidMessageReceived();
97 bool disallow_trusted_interfaces() const {
98 return disallow_trusted_interfaces_;
101 private:
102 friend class HostDispatcherTest;
103 friend class PluginDispatcherTest;
105 // Lists all lazily-created interface proxies.
106 scoped_ptr<InterfaceProxy> proxies_[API_ID_COUNT];
108 bool disallow_trusted_interfaces_;
110 GetInterfaceFunc local_get_interface_;
112 scoped_ptr<VarSerializationRules> serialization_rules_;
114 DISALLOW_COPY_AND_ASSIGN(Dispatcher);
117 } // namespace proxy
118 } // namespace ppapi
120 #endif // PPAPI_PROXY_DISPATCHER_H_