From f24448db9f893c5dde10ed1ae4cead436e18f64f Mon Sep 17 00:00:00 2001 From: "brettw@chromium.org" Date: Thu, 27 Jan 2011 20:40:39 +0000 Subject: 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 --- ppapi/proxy/serialized_var_unittest.cc | 74 ++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 ppapi/proxy/serialized_var_unittest.cc (limited to 'ppapi/proxy/serialized_var_unittest.cc') diff --git a/ppapi/proxy/serialized_var_unittest.cc b/ppapi/proxy/serialized_var_unittest.cc new file mode 100644 index 0000000..3cc4e61 --- /dev/null +++ b/ppapi/proxy/serialized_var_unittest.cc @@ -0,0 +1,74 @@ +// 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/proxy/serialized_var.h" + +namespace pp { +namespace proxy { + +namespace { + +PP_Var MakeStringVar(int64_t string_id) { + PP_Var ret; + ret.type = PP_VARTYPE_STRING; + ret.value.as_id = string_id; + return ret; +} + +PP_Var MakeObjectVar(int64_t object_id) { + PP_Var ret; + ret.type = PP_VARTYPE_OBJECT; + ret.value.as_id = object_id; + return ret; +} + +class SerializedVarTest : public PluginProxyTest { + public: + SerializedVarTest() {} +}; + +} // namespace + +// Tests output arguments. +TEST_F(SerializedVarTest, PluginSerializedVarOutParam) { + PP_Var host_object = MakeObjectVar(0x31337); + + // Start tracking this object in the plugin. + PP_Var plugin_object = var_tracker().ReceiveObjectPassRef( + host_object, plugin_dispatcher()); + EXPECT_EQ(1, var_tracker().GetRefCountForObject(plugin_object)); + + { + SerializedVar sv; + { + // The "OutParam" does its work in its destructor, it will write the + // information to the SerializedVar we passed in the constructor. + SerializedVarOutParam out_param(&sv); + *out_param.OutParam(plugin_dispatcher()) = plugin_object; + } + + // The object should have transformed the plugin object back to the host + // object ID. Nothing in the var tracker should have changed yet, and no + // messages should have been sent. + SerializedVarTestReader reader(sv); + EXPECT_EQ(host_object.value.as_id, reader.GetIncompleteVar().value.as_id); + EXPECT_EQ(1, var_tracker().GetRefCountForObject(plugin_object)); + EXPECT_EQ(0u, sink().message_count()); + } + + // The out param should have done an "end send pass ref" on the plugin + // var serialization rules, which should have in turn released the reference + // in the var tracker. Since we only had one reference, this should have sent + // a release to the browser. + EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_object)); + EXPECT_EQ(1u, sink().message_count()); + + // We don't bother validating that message since it's nontrivial and the + // PluginVarTracker test has cases that cover that this message is correct. +} + +} // namespace proxy +} // namespace pp -- cgit v1.1