Refactor PPAPI proxy resource handling to maintain which host they came from,
and to map back to that host when calling functions on them. Adds a mapping
between resources generated by the hosts to a new list inside the plugin so
there can't be overlaps.

This means there are now two meanings for a PP_Resource, one in the plugin
process and one in the host process. This is potentially very confusing. I
introduced a new object called a HostResource that always represents a
"host" PP_Resource to try to prevent errors. In the plugin side of the proxy,
it only deals with PP_Resources valid in the plugin, and SerializedResources
valid in the host. It also encapsulates the associated instance, which
simplifies some code.

Each PluginResource object maintains its SerializedResource which the proxy
uses to send to the host for requests. This requires getting the PluginResource
object in more proxy calls.

This fixes a bug in var sending introduced in my previous patch. The var
releasing from EndSendPassRef used the host var rather than the plugin var. I
had to add more plumbing to get the dispatcher at this location and convert
to a plugin var.

I removed the separate file for ImageData and put it in ppb_image_data_proxy
like for the other resource types.

TEST=some unit tests included
BUG=none
Review URL: http://codereview.chromium.org/6334016

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72879 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/ppapi/proxy/ppapi_proxy_test.cc b/ppapi/proxy/ppapi_proxy_test.cc
new file mode 100644
index 0000000..240860c
--- /dev/null
+++ b/ppapi/proxy/ppapi_proxy_test.cc
@@ -0,0 +1,59 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ppapi/proxy/ppapi_proxy_test.h"
+
+#include "ppapi/c/pp_errors.h"
+
+namespace pp {
+namespace proxy {
+
+namespace {
+
+const void* MockGetInterface(const char*) {
+  return NULL;
+}
+
+int32_t MockInitModule(PP_Module, Dispatcher::GetInterfaceFunc) {
+  return PP_OK;
+}
+
+void MockShutdownModuleFunc() {
+}
+
+}  // namespace
+
+PluginProxyTest::PluginProxyTest() {
+}
+
+PluginProxyTest::~PluginProxyTest() {
+}
+
+void PluginProxyTest::SetUp() {
+  // These must be first since the dispatcher set-up uses them.
+  PluginResourceTracker::SetInstanceForTest(&resource_tracker_);
+  PluginVarTracker::SetInstanceForTest(&var_tracker_);
+
+  pp_instance_ = 0x1234;
+  plugin_dispatcher_.reset(new PluginDispatcher(
+      base::Process::Current().handle(),
+      &MockGetInterface,
+      &MockInitModule,
+      &MockShutdownModuleFunc));
+  plugin_dispatcher_->InitWithTestSink(&sink_);
+  // When the plugin dispatcher is per-instance, this is the line to use:
+  // PluginDispatcher::SetForInstance(pp_instance_, plugin_dispatcher_.get());
+  PluginDispatcher::SetGlobal(plugin_dispatcher_.get());
+}
+
+void PluginProxyTest::TearDown() {
+  PluginDispatcher::SetGlobal(NULL);
+  plugin_dispatcher_.reset();
+
+  PluginVarTracker::SetInstanceForTest(NULL);
+  PluginResourceTracker::SetInstanceForTest(NULL);
+}
+
+}  // namespace proxy
+}  // namespace pp