Rename GDataSystemService to DriveSystemService
[chromium-blink-merge.git] / ppapi / proxy / host_dispatcher.h
blobda64467d2ed91ee8255eceb5f6f47a8c2ca56359
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_HOST_DISPATCHER_H_
6 #define PPAPI_PROXY_HOST_DISPATCHER_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "base/compiler_specific.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/process.h"
15 #include "ipc/ipc_channel_proxy.h"
16 #include "ppapi/c/pp_instance.h"
17 #include "ppapi/proxy/dispatcher.h"
19 struct PPB_Proxy_Private;
21 namespace ppapi {
23 struct Preferences;
25 namespace proxy {
27 class PPAPI_PROXY_EXPORT HostDispatcher : public Dispatcher {
28 public:
29 // This interface receives notifications about sync messages being sent by
30 // the dispatcher to the plugin process. It is used to detect a hung plugin.
32 // Note that there can be nested sync messages, so the begin/end status
33 // actually represents a stack of blocking messages.
34 class SyncMessageStatusReceiver : public IPC::ChannelProxy::MessageFilter {
35 public:
36 // Notification that a sync message is about to be sent out.
37 virtual void BeginBlockOnSyncMessage() = 0;
39 // Notification that a sync message reply was received and the dispatcher
40 // is no longer blocked on a sync message.
41 virtual void EndBlockOnSyncMessage() = 0;
43 protected:
44 virtual ~SyncMessageStatusReceiver() {}
47 // Constructor for the renderer side. This will take a reference to the
48 // SyncMessageStatusReceiver.
50 // You must call InitHostWithChannel after the constructor.
51 HostDispatcher(PP_Module module,
52 PP_GetInterface_Func local_get_interface,
53 SyncMessageStatusReceiver* sync_status);
54 ~HostDispatcher();
56 // You must call this function before anything else. Returns true on success.
57 // The delegate pointer must outlive this class, ownership is not
58 // transferred.
59 virtual bool InitHostWithChannel(Delegate* delegate,
60 const IPC::ChannelHandle& channel_handle,
61 bool is_client,
62 const Preferences& preferences);
64 // The host side maintains a mapping from PP_Instance to Dispatcher so
65 // that we can send the messages to the right channel.
66 static HostDispatcher* GetForInstance(PP_Instance instance);
67 static void SetForInstance(PP_Instance instance,
68 HostDispatcher* dispatcher);
69 static void RemoveForInstance(PP_Instance instance);
71 // Returns the host's notion of our PP_Module. This will be different than
72 // the plugin's notion of its PP_Module because the plugin process may be
73 // used by multiple renderer processes.
75 // Use this value instead of a value from the plugin whenever talking to the
76 // host.
77 PP_Module pp_module() const { return pp_module_; }
79 // Dispatcher overrides.
80 virtual bool IsPlugin() const;
81 virtual bool Send(IPC::Message* msg);
83 // IPC::Listener.
84 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
85 virtual void OnChannelError() OVERRIDE;
87 // Proxied version of calling GetInterface on the plugin. This will check
88 // if the plugin supports the given interface (with caching) and returns the
89 // pointer to the proxied interface if it is supported. Returns NULL if the
90 // given interface isn't supported by the plugin or the proxy.
91 const void* GetProxiedInterface(const std::string& iface_name);
93 // See the value below. Call this when processing a scripting message from
94 // the plugin that can be reentered. This is set to false at the beginning
95 // of processing of each message from the plugin.
96 void set_allow_plugin_reentrancy() {
97 allow_plugin_reentrancy_ = true;
100 // Returns the proxy interface for talking to the implementation.
101 const PPB_Proxy_Private* ppb_proxy() const { return ppb_proxy_; }
103 protected:
104 // Overridden from Dispatcher.
105 virtual void OnInvalidMessageReceived();
107 private:
108 void OnHostMsgLogWithSource(PP_Instance instance,
109 int int_log_level,
110 const std::string& source,
111 const std::string& value);
113 scoped_refptr<SyncMessageStatusReceiver> sync_status_;
115 PP_Module pp_module_;
117 // Maps interface name to whether that interface is supported. If an interface
118 // name is not in the map, that implies that we haven't queried for it yet.
119 typedef base::hash_map<std::string, bool> PluginSupportedMap;
120 PluginSupportedMap plugin_supported_;
122 // Guaranteed non-NULL.
123 const PPB_Proxy_Private* ppb_proxy_;
125 // Set to true when the plugin is in a state that it can be reentered by a
126 // sync message from the host. We allow reentrancy only when we're processing
127 // a sync message from the renderer that is a scripting command. When the
128 // plugin is in this state, it needs to accept reentrancy since scripting may
129 // ultimately call back into the plugin.
130 bool allow_plugin_reentrancy_;
132 DISALLOW_COPY_AND_ASSIGN(HostDispatcher);
135 // Create this object on the stack to prevent the module (and hence the
136 // dispatcher) from being deleted out from under you. This is necessary when
137 // calling some scripting functions that may delete the plugin.
139 // This class does nothing if used on the plugin side.
140 class ScopedModuleReference {
141 public:
142 explicit ScopedModuleReference(Dispatcher* dispatcher);
143 ~ScopedModuleReference();
145 private:
146 HostDispatcher* dispatcher_;
148 DISALLOW_COPY_AND_ASSIGN(ScopedModuleReference);
151 } // namespace proxy
152 } // namespace ppapi
154 #endif // PPAPI_PROXY_HOST_DISPATCHER_H_