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/shared_impl/var_tracker.h" | 5 #include "ppapi/shared_impl/var_tracker.h" |
6 | 6 |
| 7 #include <string.h> |
| 8 |
7 #include <limits> | 9 #include <limits> |
8 | 10 |
9 #include "base/logging.h" | 11 #include "base/logging.h" |
10 #include "ppapi/shared_impl/id_assignment.h" | 12 #include "ppapi/shared_impl/id_assignment.h" |
11 #include "ppapi/shared_impl/var.h" | 13 #include "ppapi/shared_impl/var.h" |
12 | 14 |
13 namespace ppapi { | 15 namespace ppapi { |
14 | 16 |
15 VarTracker::VarInfo::VarInfo() | 17 VarTracker::VarInfo::VarInfo() |
16 : var(), | 18 : var(), |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 return type >= PP_VARTYPE_STRING; | 159 return type >= PP_VARTYPE_STRING; |
158 } | 160 } |
159 | 161 |
160 PP_Var VarTracker::MakeArrayBufferPPVar(uint32 size_in_bytes) { | 162 PP_Var VarTracker::MakeArrayBufferPPVar(uint32 size_in_bytes) { |
161 scoped_refptr<ArrayBufferVar> array_buffer(CreateArrayBuffer(size_in_bytes)); | 163 scoped_refptr<ArrayBufferVar> array_buffer(CreateArrayBuffer(size_in_bytes)); |
162 if (!array_buffer) | 164 if (!array_buffer) |
163 return PP_MakeNull(); | 165 return PP_MakeNull(); |
164 return array_buffer->GetPPVar(); | 166 return array_buffer->GetPPVar(); |
165 } | 167 } |
166 | 168 |
| 169 PP_Var VarTracker::MakeArrayBufferPPVar(uint32 size_in_bytes, |
| 170 const void* data) { |
| 171 scoped_refptr<ArrayBufferVar> array_buffer(CreateArrayBuffer(size_in_bytes)); |
| 172 if (!array_buffer) |
| 173 return PP_MakeNull(); |
| 174 memcpy(array_buffer->Map(), data, size_in_bytes); |
| 175 return array_buffer->GetPPVar(); |
| 176 } |
| 177 |
167 std::vector<PP_Var> VarTracker::GetLiveVars() { | 178 std::vector<PP_Var> VarTracker::GetLiveVars() { |
168 std::vector<PP_Var> var_vector; | 179 std::vector<PP_Var> var_vector; |
169 var_vector.reserve(live_vars_.size()); | 180 var_vector.reserve(live_vars_.size()); |
170 for (VarMap::const_iterator iter = live_vars_.begin(); | 181 for (VarMap::const_iterator iter = live_vars_.begin(); |
171 iter != live_vars_.end(); | 182 iter != live_vars_.end(); |
172 ++iter) { | 183 ++iter) { |
173 var_vector.push_back(iter->second.var->GetPPVar()); | 184 var_vector.push_back(iter->second.var->GetPPVar()); |
174 } | 185 } |
175 return var_vector; | 186 return var_vector; |
176 } | 187 } |
(...skipping 10 matching lines...) Expand all Loading... |
187 bool VarTracker::DeleteObjectInfoIfNecessary(VarMap::iterator iter) { | 198 bool VarTracker::DeleteObjectInfoIfNecessary(VarMap::iterator iter) { |
188 if (iter->second.ref_count != 0 || | 199 if (iter->second.ref_count != 0 || |
189 iter->second.track_with_no_reference_count != 0) | 200 iter->second.track_with_no_reference_count != 0) |
190 return false; // Object still alive. | 201 return false; // Object still alive. |
191 iter->second.var->ResetVarID(); | 202 iter->second.var->ResetVarID(); |
192 live_vars_.erase(iter); | 203 live_vars_.erase(iter); |
193 return true; | 204 return true; |
194 } | 205 } |
195 | 206 |
196 } // namespace ppapi | 207 } // namespace ppapi |
OLD | NEW |