Delete unused downloads page asset.
[chromium-blink-merge.git] / ppapi / proxy / host_var_serialization_rules.cc
blob35faace5dd33b23d76d55b326c4ab4704ee6e391
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 #include "ppapi/proxy/host_var_serialization_rules.h"
7 #include "ppapi/shared_impl/ppapi_globals.h"
8 #include "ppapi/shared_impl/var_tracker.h"
10 using ppapi::PpapiGlobals;
11 using ppapi::VarTracker;
13 namespace ppapi {
14 namespace proxy {
16 HostVarSerializationRules::HostVarSerializationRules() {
19 HostVarSerializationRules::~HostVarSerializationRules() {
22 PP_Var HostVarSerializationRules::SendCallerOwned(const PP_Var& var) {
23 return var;
26 PP_Var HostVarSerializationRules::BeginReceiveCallerOwned(const PP_Var& var) {
27 return var;
30 void HostVarSerializationRules::EndReceiveCallerOwned(const PP_Var& var) {
31 if (var.type != PP_VARTYPE_OBJECT && var.type >= PP_VARTYPE_STRING) {
32 // Release our reference to the local Var.
33 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(var);
37 PP_Var HostVarSerializationRules::ReceivePassRef(const PP_Var& var) {
38 // See PluginVarSerialization::BeginSendPassRef for an example.
39 if (var.type == PP_VARTYPE_OBJECT)
40 PpapiGlobals::Get()->GetVarTracker()->AddRefVar(var);
41 return var;
44 PP_Var HostVarSerializationRules::BeginSendPassRef(const PP_Var& var) {
45 return var;
48 void HostVarSerializationRules::EndSendPassRef(const PP_Var& var) {
49 // See PluginVarSerializationRules::ReceivePassRef for an example. We don't
50 // need to do anything here for "Object" vars; we continue holding one ref on
51 // behalf of the plugin.
52 if (var.type != PP_VARTYPE_OBJECT) {
53 // But for other ref-counted types (like String, Array, and Dictionary),
54 // the value will be re-constituted on the other side as a new Var with no
55 // connection to the host-side reference counting. We must therefore release
56 // our reference count; this is roughly equivalent to passing the ref to the
57 // plugin.
58 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(var);
62 void HostVarSerializationRules::ReleaseObjectRef(const PP_Var& var) {
63 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(var);
66 } // namespace proxy
67 } // namespace ppapi