| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ppapi/proxy/plugin_var_tracker.h" | 5 #include "ppapi/proxy/plugin_var_tracker.h" |
| 6 | 6 |
| 7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.h" |
| 9 #include "ppapi/c/ppb_var.h" | 9 #include "ppapi/c/ppb_var.h" |
| 10 #include "ppapi/proxy/plugin_array_buffer_var.h" | 10 #include "ppapi/proxy/plugin_array_buffer_var.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 } | 31 } |
| 32 | 32 |
| 33 PluginVarTracker::PluginVarTracker() { | 33 PluginVarTracker::PluginVarTracker() { |
| 34 } | 34 } |
| 35 | 35 |
| 36 PluginVarTracker::~PluginVarTracker() { | 36 PluginVarTracker::~PluginVarTracker() { |
| 37 } | 37 } |
| 38 | 38 |
| 39 PP_Var PluginVarTracker::ReceiveObjectPassRef(const PP_Var& host_var, | 39 PP_Var PluginVarTracker::ReceiveObjectPassRef(const PP_Var& host_var, |
| 40 PluginDispatcher* dispatcher) { | 40 PluginDispatcher* dispatcher) { |
| 41 DCHECK(CalledOnValidThread()); |
| 41 DCHECK(host_var.type == PP_VARTYPE_OBJECT); | 42 DCHECK(host_var.type == PP_VARTYPE_OBJECT); |
| 42 | 43 |
| 43 // Get the object. | 44 // Get the object. |
| 44 scoped_refptr<ProxyObjectVar> object( | 45 scoped_refptr<ProxyObjectVar> object( |
| 45 FindOrMakePluginVarFromHostVar(host_var, dispatcher)); | 46 FindOrMakePluginVarFromHostVar(host_var, dispatcher)); |
| 46 | 47 |
| 47 // Actually create the PP_Var, this will add all the tracking info but not | 48 // Actually create the PP_Var, this will add all the tracking info but not |
| 48 // adjust any refcounts. | 49 // adjust any refcounts. |
| 49 PP_Var ret = GetOrCreateObjectVarID(object.get()); | 50 PP_Var ret = GetOrCreateObjectVarID(object.get()); |
| 50 | 51 |
| 51 VarInfo& info = GetLiveVar(ret)->second; | 52 VarInfo& info = GetLiveVar(ret)->second; |
| 52 if (info.ref_count > 0) { | 53 if (info.ref_count > 0) { |
| 53 // We already had a reference to it before. That means the renderer now has | 54 // We already had a reference to it before. That means the renderer now has |
| 54 // two references on our behalf. We want to transfer that extra reference | 55 // two references on our behalf. We want to transfer that extra reference |
| 55 // to our list. This means we addref in the plugin, and release the extra | 56 // to our list. This means we addref in the plugin, and release the extra |
| 56 // one in the renderer. | 57 // one in the renderer. |
| 57 SendReleaseObjectMsg(*object); | 58 SendReleaseObjectMsg(*object); |
| 58 } | 59 } |
| 59 info.ref_count++; | 60 info.ref_count++; |
| 60 return ret; | 61 return ret; |
| 61 } | 62 } |
| 62 | 63 |
| 63 PP_Var PluginVarTracker::TrackObjectWithNoReference( | 64 PP_Var PluginVarTracker::TrackObjectWithNoReference( |
| 64 const PP_Var& host_var, | 65 const PP_Var& host_var, |
| 65 PluginDispatcher* dispatcher) { | 66 PluginDispatcher* dispatcher) { |
| 67 DCHECK(CalledOnValidThread()); |
| 66 DCHECK(host_var.type == PP_VARTYPE_OBJECT); | 68 DCHECK(host_var.type == PP_VARTYPE_OBJECT); |
| 67 | 69 |
| 68 // Get the object. | 70 // Get the object. |
| 69 scoped_refptr<ProxyObjectVar> object( | 71 scoped_refptr<ProxyObjectVar> object( |
| 70 FindOrMakePluginVarFromHostVar(host_var, dispatcher)); | 72 FindOrMakePluginVarFromHostVar(host_var, dispatcher)); |
| 71 | 73 |
| 72 // Actually create the PP_Var, this will add all the tracking info but not | 74 // Actually create the PP_Var, this will add all the tracking info but not |
| 73 // adjust any refcounts. | 75 // adjust any refcounts. |
| 74 PP_Var ret = GetOrCreateObjectVarID(object.get()); | 76 PP_Var ret = GetOrCreateObjectVarID(object.get()); |
| 75 | 77 |
| 76 VarInfo& info = GetLiveVar(ret)->second; | 78 VarInfo& info = GetLiveVar(ret)->second; |
| 77 info.track_with_no_reference_count++; | 79 info.track_with_no_reference_count++; |
| 78 return ret; | 80 return ret; |
| 79 } | 81 } |
| 80 | 82 |
| 81 void PluginVarTracker::StopTrackingObjectWithNoReference( | 83 void PluginVarTracker::StopTrackingObjectWithNoReference( |
| 82 const PP_Var& plugin_var) { | 84 const PP_Var& plugin_var) { |
| 85 DCHECK(CalledOnValidThread()); |
| 83 DCHECK(plugin_var.type == PP_VARTYPE_OBJECT); | 86 DCHECK(plugin_var.type == PP_VARTYPE_OBJECT); |
| 87 |
| 84 VarMap::iterator found = GetLiveVar(plugin_var); | 88 VarMap::iterator found = GetLiveVar(plugin_var); |
| 85 if (found == live_vars_.end()) { | 89 if (found == live_vars_.end()) { |
| 86 NOTREACHED(); | 90 NOTREACHED(); |
| 87 return; | 91 return; |
| 88 } | 92 } |
| 89 | 93 |
| 90 DCHECK(found->second.track_with_no_reference_count > 0); | 94 DCHECK(found->second.track_with_no_reference_count > 0); |
| 91 found->second.track_with_no_reference_count--; | 95 found->second.track_with_no_reference_count--; |
| 92 DeleteObjectInfoIfNecessary(found); | 96 DeleteObjectInfoIfNecessary(found); |
| 93 } | 97 } |
| 94 | 98 |
| 95 PP_Var PluginVarTracker::GetHostObject(const PP_Var& plugin_object) const { | 99 PP_Var PluginVarTracker::GetHostObject(const PP_Var& plugin_object) const { |
| 100 DCHECK(CalledOnValidThread()); |
| 101 |
| 96 if (plugin_object.type != PP_VARTYPE_OBJECT) { | 102 if (plugin_object.type != PP_VARTYPE_OBJECT) { |
| 97 NOTREACHED(); | 103 NOTREACHED(); |
| 98 return PP_MakeUndefined(); | 104 return PP_MakeUndefined(); |
| 99 } | 105 } |
| 100 | 106 |
| 101 Var* var = GetVar(plugin_object); | 107 Var* var = GetVar(plugin_object); |
| 102 ProxyObjectVar* object = var->AsProxyObjectVar(); | 108 ProxyObjectVar* object = var->AsProxyObjectVar(); |
| 103 if (!object) { | 109 if (!object) { |
| 104 NOTREACHED(); | 110 NOTREACHED(); |
| 105 return PP_MakeUndefined(); | 111 return PP_MakeUndefined(); |
| 106 } | 112 } |
| 107 | 113 |
| 108 // Make a var with the host ID. | 114 // Make a var with the host ID. |
| 109 PP_Var ret = { PP_VARTYPE_OBJECT }; | 115 PP_Var ret = { PP_VARTYPE_OBJECT }; |
| 110 ret.value.as_id = object->host_var_id(); | 116 ret.value.as_id = object->host_var_id(); |
| 111 return ret; | 117 return ret; |
| 112 } | 118 } |
| 113 | 119 |
| 114 PluginDispatcher* PluginVarTracker::DispatcherForPluginObject( | 120 PluginDispatcher* PluginVarTracker::DispatcherForPluginObject( |
| 115 const PP_Var& plugin_object) const { | 121 const PP_Var& plugin_object) const { |
| 122 DCHECK(CalledOnValidThread()); |
| 123 |
| 116 if (plugin_object.type != PP_VARTYPE_OBJECT) | 124 if (plugin_object.type != PP_VARTYPE_OBJECT) |
| 117 return NULL; | 125 return NULL; |
| 118 | 126 |
| 119 VarMap::const_iterator found = GetLiveVar(plugin_object); | 127 VarMap::const_iterator found = GetLiveVar(plugin_object); |
| 120 if (found == live_vars_.end()) | 128 if (found == live_vars_.end()) |
| 121 return NULL; | 129 return NULL; |
| 122 | 130 |
| 123 ProxyObjectVar* object = found->second.var->AsProxyObjectVar(); | 131 ProxyObjectVar* object = found->second.var->AsProxyObjectVar(); |
| 124 if (!object) | 132 if (!object) |
| 125 return NULL; | 133 return NULL; |
| 126 return object->dispatcher(); | 134 return object->dispatcher(); |
| 127 } | 135 } |
| 128 | 136 |
| 129 void PluginVarTracker::ReleaseHostObject(PluginDispatcher* dispatcher, | 137 void PluginVarTracker::ReleaseHostObject(PluginDispatcher* dispatcher, |
| 130 const PP_Var& host_object) { | 138 const PP_Var& host_object) { |
| 139 DCHECK(CalledOnValidThread()); |
| 140 DCHECK(host_object.type == PP_VARTYPE_OBJECT); |
| 141 |
| 131 // Convert the host object to a normal var valid in the plugin. | 142 // Convert the host object to a normal var valid in the plugin. |
| 132 DCHECK(host_object.type == PP_VARTYPE_OBJECT); | |
| 133 HostVarToPluginVarMap::iterator found = host_var_to_plugin_var_.find( | 143 HostVarToPluginVarMap::iterator found = host_var_to_plugin_var_.find( |
| 134 HostVar(dispatcher, static_cast<int32>(host_object.value.as_id))); | 144 HostVar(dispatcher, static_cast<int32>(host_object.value.as_id))); |
| 135 if (found == host_var_to_plugin_var_.end()) { | 145 if (found == host_var_to_plugin_var_.end()) { |
| 136 NOTREACHED(); | 146 NOTREACHED(); |
| 137 return; | 147 return; |
| 138 } | 148 } |
| 139 | 149 |
| 140 // Now just release the object given the plugin var ID. | 150 // Now just release the object given the plugin var ID. |
| 141 ReleaseVar(found->second); | 151 ReleaseVar(found->second); |
| 142 } | 152 } |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 VarMap::iterator ret = live_vars_.find(found->second); | 265 VarMap::iterator ret = live_vars_.find(found->second); |
| 256 DCHECK(ret != live_vars_.end()); | 266 DCHECK(ret != live_vars_.end()); |
| 257 | 267 |
| 258 // All objects should be proxy objects. | 268 // All objects should be proxy objects. |
| 259 DCHECK(ret->second.var->AsProxyObjectVar()); | 269 DCHECK(ret->second.var->AsProxyObjectVar()); |
| 260 return scoped_refptr<ProxyObjectVar>(ret->second.var->AsProxyObjectVar()); | 270 return scoped_refptr<ProxyObjectVar>(ret->second.var->AsProxyObjectVar()); |
| 261 } | 271 } |
| 262 | 272 |
| 263 } // namesace proxy | 273 } // namesace proxy |
| 264 } // namespace ppapi | 274 } // namespace ppapi |
| OLD | NEW |