Rent syncemove all uses of the global Dispatcher Get function.

This reqired reworking how plugin->host GetInterface works. Previously,
interface requests were symmetric where each side would first do a
SupportsInterface to see if the remote side supports the interface, then create
the proxy. Since the plugin may talk to multiple renderers, we don't know where
to send these requests. The solution is to make the assumption that the
renderer always supports all PPB interfaces (which is possible since the proxy
is compiled with the executable).

This also adds some better lookup for interfaces to avoid having multiple lists
of interfaces. We now have a list of interfaces and factory functions in
dispatcher.cc.

Add some additional testing infrastructure for the dispatchers with simple tests.
Review URL: http://codereview.chromium.org/6286070

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@74121 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/ppapi/proxy/dispatcher.h b/ppapi/proxy/dispatcher.h
index 1aac12d..b3b520d 100644
--- a/ppapi/proxy/dispatcher.h
+++ b/ppapi/proxy/dispatcher.h
@@ -18,6 +18,7 @@
 #include "ppapi/c/pp_module.h"
 #include "ppapi/proxy/callback_tracker.h"
 #include "ppapi/proxy/interface_id.h"
+#include "ppapi/proxy/interface_proxy.h"
 #include "ppapi/proxy/plugin_var_tracker.h"
 
 class MessageLoop;
@@ -35,7 +36,6 @@
 namespace pp {
 namespace proxy {
 
-class InterfaceProxy;
 class VarSerializationRules;
 
 // An interface proxy can represent either end of a cross-process interface
@@ -86,13 +86,6 @@
   // Wrapper for calling the local GetInterface function.
   const void* GetLocalInterface(const char* interface);
 
-  // Implements PPP_GetInterface and PPB_GetInterface on the "source" side. It
-  // will check if the remote side supports this interface as a target, and
-  // create a proxy if it does. A local implementation of that interface backed
-  // by the proxy will be returned on success. If the interface is unproxyable
-  // or not supported by the remote side, returns NULL.
-  const void* GetProxiedInterface(const std::string& interface);
-
   // Returns the remote process' handle. For the host dispatcher, this will be
   // the plugin process, and for the plugin dispatcher, this will be the
   // renderer process. This is used for sharing memory and such and is
@@ -120,6 +113,17 @@
     return callback_tracker_;
   }
 
+  // Retrieves the information associated with the given interface, identified
+  // either by name or ID. Each function searches either PPP or PPB interfaces.
+  static const InterfaceProxy::Info* GetPPBInterfaceInfo(
+      const std::string& name);
+  static const InterfaceProxy::Info* GetPPBInterfaceInfo(
+      InterfaceID id);
+  static const InterfaceProxy::Info* GetPPPInterfaceInfo(
+      const std::string& name);
+  static const InterfaceProxy::Info* GetPPPInterfaceInfo(
+      InterfaceID id);
+
  protected:
   Dispatcher(base::ProcessHandle remote_process_handle,
              GetInterfaceFunc local_get_interface);
@@ -132,41 +136,11 @@
     pp_module_ = module;
   }
 
-  // Allows the PluginDispatcher to add a magic proxy for PPP_Class, bypassing
-  // the normal "do you support this proxy" stuff and the big lookup of
-  // name to proxy object. Takes ownership of the pointer.
-  void InjectProxy(InterfaceID id,
-                   const std::string& name,
-                   InterfaceProxy* proxy);
+  bool disallow_trusted_interfaces() const {
+    return disallow_trusted_interfaces_;
+  }
 
  private:
-  typedef std::map< std::string, linked_ptr<InterfaceProxy> > ProxyMap;
-
-  // Message handlers
-  void OnMsgSupportsInterface(const std::string& interface_name, bool* result);
-  void OnMsgDeclareInterfaces(const std::vector<std::string>& interfaces);
-
-  // Allocates a new proxy on the heap corresponding to the given interface
-  // name, or returns NULL if that interface name isn't known proxyable. The
-  // caller owns the returned pointer.
-  //
-  // The interface_functions gives the pointer to the local interfece when this
-  // is a target proxy. When creating a source proxy, set this to NULL.
-  InterfaceProxy* CreateProxyForInterface(
-      const std::string& interface_name,
-      const void* interface_functions);
-
-  // Returns true if the remote side supports the given interface as the
-  // target of an IPC call.
-  bool RemoteSupportsTargetInterface(const std::string& interface);
-
-  // Sets up a proxy as the target for the given interface, if it is supported.
-  // Returns true if this process implements the given interface and it is
-  // proxyable.
-  bool SetupProxyForTargetInterface(const std::string& interface);
-
-  bool IsInterfaceTrusted(const std::string& interface);
-
   // Set by the derived classed to indicate the module ID corresponding to
   // this dispatcher.
   PP_Module pp_module_;
@@ -185,20 +159,6 @@
 
   GetInterfaceFunc local_get_interface_;
 
-  ProxyMap proxies_;
-  InterfaceProxy* id_to_proxy_[INTERFACE_ID_COUNT];
-
-  // True if the remote side has declared which interfaces it supports in
-  // advance. When set, it means if we don't already have a source proxy for
-  // the requested interface, that the remote side doesn't support it and
-  // we don't need to query.
-  //
-  // This is just an optimization. The browser has a fixed set of interfaces
-  // it supports, and the many plugins will end up querying many of them. By
-  // having the browser just send all of those interfaces in one message, we
-  // can avoid a bunch of IPC chatter to set up each interface.
-  bool declared_supported_remote_interfaces_;
-
   CallbackTracker callback_tracker_;
 
   scoped_ptr<VarSerializationRules> serialization_rules_;