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 "webkit/plugins/ppapi/resource_tracker.h" | 5 #include "webkit/plugins/ppapi/resource_tracker.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
13 #include "ppapi/c/pp_resource.h" | 13 #include "ppapi/c/pp_resource.h" |
14 #include "ppapi/c/pp_var.h" | 14 #include "ppapi/c/pp_var.h" |
| 15 #include "webkit/plugins/ppapi/plugin_module.h" |
15 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 16 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
16 #include "webkit/plugins/ppapi/resource.h" | 17 #include "webkit/plugins/ppapi/resource.h" |
17 #include "webkit/plugins/ppapi/var.h" | 18 #include "webkit/plugins/ppapi/var.h" |
18 | 19 |
19 enum PPIdType { | 20 enum PPIdType { |
20 PP_ID_TYPE_MODULE, | 21 PP_ID_TYPE_MODULE, |
21 PP_ID_TYPE_INSTANCE, | 22 PP_ID_TYPE_INSTANCE, |
22 PP_ID_TYPE_RESOURCE, | 23 PP_ID_TYPE_RESOURCE, |
23 PP_ID_TYPE_VAR, | 24 PP_ID_TYPE_VAR, |
24 PP_ID_TYPE_COUNT | 25 PP_ID_TYPE_COUNT |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 | 273 |
273 // Use a random number for the instance ID. This helps prevent some | 274 // Use a random number for the instance ID. This helps prevent some |
274 // accidents. See also AddModule below. | 275 // accidents. See also AddModule below. |
275 // | 276 // |
276 // Need to make sure the random number isn't a duplicate or 0. | 277 // Need to make sure the random number isn't a duplicate or 0. |
277 PP_Instance new_instance; | 278 PP_Instance new_instance; |
278 do { | 279 do { |
279 new_instance = MakeTypedId(static_cast<PP_Instance>(base::RandUint64()), | 280 new_instance = MakeTypedId(static_cast<PP_Instance>(base::RandUint64()), |
280 PP_ID_TYPE_INSTANCE); | 281 PP_ID_TYPE_INSTANCE); |
281 } while (!new_instance || | 282 } while (!new_instance || |
282 instance_map_.find(new_instance) != instance_map_.end()); | 283 instance_map_.find(new_instance) != instance_map_.end() || |
| 284 !instance->module()->ReserveInstanceID(new_instance)); |
283 | 285 |
284 instance_map_[new_instance].instance = instance; | 286 instance_map_[new_instance].instance = instance; |
285 return new_instance; | 287 return new_instance; |
286 } | 288 } |
287 | 289 |
288 void ResourceTracker::InstanceDeleted(PP_Instance instance) { | 290 void ResourceTracker::InstanceDeleted(PP_Instance instance) { |
289 CleanupInstanceData(instance, true); | 291 CleanupInstanceData(instance, true); |
290 } | 292 } |
291 | 293 |
292 void ResourceTracker::InstanceCrashed(PP_Instance instance) { | 294 void ResourceTracker::InstanceCrashed(PP_Instance instance) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 | 351 |
350 // static | 352 // static |
351 void ResourceTracker::ClearSingletonOverride() { | 353 void ResourceTracker::ClearSingletonOverride() { |
352 DCHECK(singleton_override_); | 354 DCHECK(singleton_override_); |
353 singleton_override_ = NULL; | 355 singleton_override_ = NULL; |
354 } | 356 } |
355 | 357 |
356 } // namespace ppapi | 358 } // namespace ppapi |
357 } // namespace webkit | 359 } // namespace webkit |
358 | 360 |
OLD | NEW |