| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/shared_impl/var_tracker.h" | 5 #include "ppapi/shared_impl/var_tracker.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "ppapi/shared_impl/id_assignment.h" | 10 #include "ppapi/shared_impl/id_assignment.h" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 live_vars_.insert(std::make_pair(new_id, | 122 live_vars_.insert(std::make_pair(new_id, |
| 123 VarInfo(var, mode == ADD_VAR_TAKE_ONE_REFERENCE ? 1 : 0))); | 123 VarInfo(var, mode == ADD_VAR_TAKE_ONE_REFERENCE ? 1 : 0))); |
| 124 | 124 |
| 125 return new_id; | 125 return new_id; |
| 126 } | 126 } |
| 127 | 127 |
| 128 VarTracker::VarMap::iterator VarTracker::GetLiveVar(int32 id) { | 128 VarTracker::VarMap::iterator VarTracker::GetLiveVar(int32 id) { |
| 129 return live_vars_.find(id); | 129 return live_vars_.find(id); |
| 130 } | 130 } |
| 131 | 131 |
| 132 int VarTracker::GetRefCountForObject(const PP_Var& plugin_object) { |
| 133 VarMap::iterator found = GetLiveVar(plugin_object); |
| 134 if (found == live_vars_.end()) |
| 135 return -1; |
| 136 return found->second.ref_count; |
| 137 } |
| 138 |
| 139 int VarTracker::GetTrackedWithNoReferenceCountForObject( |
| 140 const PP_Var& plugin_object) { |
| 141 VarMap::iterator found = GetLiveVar(plugin_object); |
| 142 if (found == live_vars_.end()) |
| 143 return -1; |
| 144 return found->second.track_with_no_reference_count; |
| 145 } |
| 146 |
| 132 VarTracker::VarMap::iterator VarTracker::GetLiveVar(const PP_Var& var) { | 147 VarTracker::VarMap::iterator VarTracker::GetLiveVar(const PP_Var& var) { |
| 133 return live_vars_.find(static_cast<int32>(var.value.as_id)); | 148 return live_vars_.find(static_cast<int32>(var.value.as_id)); |
| 134 } | 149 } |
| 135 | 150 |
| 136 VarTracker::VarMap::const_iterator VarTracker::GetLiveVar( | 151 VarTracker::VarMap::const_iterator VarTracker::GetLiveVar( |
| 137 const PP_Var& var) const { | 152 const PP_Var& var) const { |
| 138 return live_vars_.find(static_cast<int32>(var.value.as_id)); | 153 return live_vars_.find(static_cast<int32>(var.value.as_id)); |
| 139 } | 154 } |
| 140 | 155 |
| 141 bool VarTracker::IsVarTypeRefcounted(PP_VarType type) const { | 156 bool VarTracker::IsVarTypeRefcounted(PP_VarType type) const { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 172 bool VarTracker::DeleteObjectInfoIfNecessary(VarMap::iterator iter) { | 187 bool VarTracker::DeleteObjectInfoIfNecessary(VarMap::iterator iter) { |
| 173 if (iter->second.ref_count != 0 || | 188 if (iter->second.ref_count != 0 || |
| 174 iter->second.track_with_no_reference_count != 0) | 189 iter->second.track_with_no_reference_count != 0) |
| 175 return false; // Object still alive. | 190 return false; // Object still alive. |
| 176 iter->second.var->ResetVarID(); | 191 iter->second.var->ResetVarID(); |
| 177 live_vars_.erase(iter); | 192 live_vars_.erase(iter); |
| 178 return true; | 193 return true; |
| 179 } | 194 } |
| 180 | 195 |
| 181 } // namespace ppapi | 196 } // namespace ppapi |
| OLD | NEW |