| 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 "webkit/plugins/ppapi/host_var_tracker.h" | 5 #include "webkit/plugins/ppapi/host_var_tracker.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "ppapi/c/pp_var.h" | 8 #include "ppapi/c/pp_var.h" |
| 9 #include "webkit/plugins/ppapi/host_array_buffer_var.h" | 9 #include "webkit/plugins/ppapi/host_array_buffer_var.h" |
| 10 #include "webkit/plugins/ppapi/npobject_var.h" | 10 #include "webkit/plugins/ppapi/npobject_var.h" |
| 11 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 11 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 12 | 12 |
| 13 using ppapi::ArrayBufferVar; | 13 using ppapi::ArrayBufferVar; |
| 14 using ppapi::NPObjectVar; | 14 using ppapi::NPObjectVar; |
| 15 | 15 |
| 16 namespace webkit { | 16 namespace webkit { |
| 17 namespace ppapi { | 17 namespace ppapi { |
| 18 | 18 |
| 19 HostVarTracker::HostVarTracker() | 19 HostVarTracker::HostVarTracker() : last_shared_memory_map_id_(0) { |
| 20 : VarTracker(SINGLE_THREADED), | |
| 21 last_shared_memory_map_id_(0) { | |
| 22 } | 20 } |
| 23 | 21 |
| 24 HostVarTracker::~HostVarTracker() { | 22 HostVarTracker::~HostVarTracker() { |
| 25 } | 23 } |
| 26 | 24 |
| 27 ArrayBufferVar* HostVarTracker::CreateArrayBuffer(uint32 size_in_bytes) { | 25 ArrayBufferVar* HostVarTracker::CreateArrayBuffer(uint32 size_in_bytes) { |
| 28 return new HostArrayBufferVar(size_in_bytes); | 26 return new HostArrayBufferVar(size_in_bytes); |
| 29 } | 27 } |
| 30 | 28 |
| 31 ArrayBufferVar* HostVarTracker::CreateShmArrayBuffer( | 29 ArrayBufferVar* HostVarTracker::CreateShmArrayBuffer( |
| 32 uint32 size_in_bytes, | 30 uint32 size_in_bytes, |
| 33 base::SharedMemoryHandle handle) { | 31 base::SharedMemoryHandle handle) { |
| 34 return new HostArrayBufferVar(size_in_bytes, handle); | 32 return new HostArrayBufferVar(size_in_bytes, handle); |
| 35 } | 33 } |
| 36 | 34 |
| 37 void HostVarTracker::AddNPObjectVar(NPObjectVar* object_var) { | 35 void HostVarTracker::AddNPObjectVar(NPObjectVar* object_var) { |
| 38 CheckThreadingPreconditions(); | 36 DCHECK(CalledOnValidThread()); |
| 39 | 37 |
| 40 InstanceMap::iterator found_instance = instance_map_.find( | 38 InstanceMap::iterator found_instance = instance_map_.find( |
| 41 object_var->pp_instance()); | 39 object_var->pp_instance()); |
| 42 if (found_instance == instance_map_.end()) { | 40 if (found_instance == instance_map_.end()) { |
| 43 // Lazily create the instance map. | 41 // Lazily create the instance map. |
| 44 DCHECK(object_var->pp_instance() != 0); | 42 DCHECK(object_var->pp_instance() != 0); |
| 45 found_instance = instance_map_.insert(std::make_pair( | 43 found_instance = instance_map_.insert(std::make_pair( |
| 46 object_var->pp_instance(), | 44 object_var->pp_instance(), |
| 47 linked_ptr<NPObjectToNPObjectVarMap>(new NPObjectToNPObjectVarMap))). | 45 linked_ptr<NPObjectToNPObjectVarMap>(new NPObjectToNPObjectVarMap))). |
| 48 first; | 46 first; |
| 49 } | 47 } |
| 50 NPObjectToNPObjectVarMap* np_object_map = found_instance->second.get(); | 48 NPObjectToNPObjectVarMap* np_object_map = found_instance->second.get(); |
| 51 | 49 |
| 52 DCHECK(np_object_map->find(object_var->np_object()) == | 50 DCHECK(np_object_map->find(object_var->np_object()) == |
| 53 np_object_map->end()) << "NPObjectVar already in map"; | 51 np_object_map->end()) << "NPObjectVar already in map"; |
| 54 np_object_map->insert(std::make_pair(object_var->np_object(), object_var)); | 52 np_object_map->insert(std::make_pair(object_var->np_object(), object_var)); |
| 55 } | 53 } |
| 56 | 54 |
| 57 void HostVarTracker::RemoveNPObjectVar(NPObjectVar* object_var) { | 55 void HostVarTracker::RemoveNPObjectVar(NPObjectVar* object_var) { |
| 58 CheckThreadingPreconditions(); | 56 DCHECK(CalledOnValidThread()); |
| 59 | 57 |
| 60 InstanceMap::iterator found_instance = instance_map_.find( | 58 InstanceMap::iterator found_instance = instance_map_.find( |
| 61 object_var->pp_instance()); | 59 object_var->pp_instance()); |
| 62 if (found_instance == instance_map_.end()) { | 60 if (found_instance == instance_map_.end()) { |
| 63 NOTREACHED() << "NPObjectVar has invalid instance."; | 61 NOTREACHED() << "NPObjectVar has invalid instance."; |
| 64 return; | 62 return; |
| 65 } | 63 } |
| 66 NPObjectToNPObjectVarMap* np_object_map = found_instance->second.get(); | 64 NPObjectToNPObjectVarMap* np_object_map = found_instance->second.get(); |
| 67 | 65 |
| 68 NPObjectToNPObjectVarMap::iterator found_object = | 66 NPObjectToNPObjectVarMap::iterator found_object = |
| 69 np_object_map->find(object_var->np_object()); | 67 np_object_map->find(object_var->np_object()); |
| 70 if (found_object == np_object_map->end()) { | 68 if (found_object == np_object_map->end()) { |
| 71 NOTREACHED() << "NPObjectVar not registered."; | 69 NOTREACHED() << "NPObjectVar not registered."; |
| 72 return; | 70 return; |
| 73 } | 71 } |
| 74 if (found_object->second != object_var) { | 72 if (found_object->second != object_var) { |
| 75 NOTREACHED() << "NPObjectVar doesn't match."; | 73 NOTREACHED() << "NPObjectVar doesn't match."; |
| 76 return; | 74 return; |
| 77 } | 75 } |
| 78 np_object_map->erase(found_object); | 76 np_object_map->erase(found_object); |
| 79 } | 77 } |
| 80 | 78 |
| 81 NPObjectVar* HostVarTracker::NPObjectVarForNPObject(PP_Instance instance, | 79 NPObjectVar* HostVarTracker::NPObjectVarForNPObject(PP_Instance instance, |
| 82 NPObject* np_object) { | 80 NPObject* np_object) { |
| 83 CheckThreadingPreconditions(); | 81 DCHECK(CalledOnValidThread()); |
| 84 | 82 |
| 85 InstanceMap::iterator found_instance = instance_map_.find(instance); | 83 InstanceMap::iterator found_instance = instance_map_.find(instance); |
| 86 if (found_instance == instance_map_.end()) | 84 if (found_instance == instance_map_.end()) |
| 87 return NULL; // No such instance. | 85 return NULL; // No such instance. |
| 88 NPObjectToNPObjectVarMap* np_object_map = found_instance->second.get(); | 86 NPObjectToNPObjectVarMap* np_object_map = found_instance->second.get(); |
| 89 | 87 |
| 90 NPObjectToNPObjectVarMap::iterator found_object = | 88 NPObjectToNPObjectVarMap::iterator found_object = |
| 91 np_object_map->find(np_object); | 89 np_object_map->find(np_object); |
| 92 if (found_object == np_object_map->end()) | 90 if (found_object == np_object_map->end()) |
| 93 return NULL; // No such object. | 91 return NULL; // No such object. |
| 94 return found_object->second; | 92 return found_object->second; |
| 95 } | 93 } |
| 96 | 94 |
| 97 int HostVarTracker::GetLiveNPObjectVarsForInstance(PP_Instance instance) const { | 95 int HostVarTracker::GetLiveNPObjectVarsForInstance(PP_Instance instance) const { |
| 98 CheckThreadingPreconditions(); | 96 DCHECK(CalledOnValidThread()); |
| 99 | 97 |
| 100 InstanceMap::const_iterator found = instance_map_.find(instance); | 98 InstanceMap::const_iterator found = instance_map_.find(instance); |
| 101 if (found == instance_map_.end()) | 99 if (found == instance_map_.end()) |
| 102 return 0; | 100 return 0; |
| 103 return static_cast<int>(found->second->size()); | 101 return static_cast<int>(found->second->size()); |
| 104 } | 102 } |
| 105 | 103 |
| 106 void HostVarTracker::DidDeleteInstance(PP_Instance instance) { | 104 void HostVarTracker::DidDeleteInstance(PP_Instance instance) { |
| 107 CheckThreadingPreconditions(); | 105 DCHECK(CalledOnValidThread()); |
| 108 | 106 |
| 109 InstanceMap::iterator found_instance = instance_map_.find(instance); | 107 InstanceMap::iterator found_instance = instance_map_.find(instance); |
| 110 if (found_instance == instance_map_.end()) | 108 if (found_instance == instance_map_.end()) |
| 111 return; // Nothing to do. | 109 return; // Nothing to do. |
| 112 NPObjectToNPObjectVarMap* np_object_map = found_instance->second.get(); | 110 NPObjectToNPObjectVarMap* np_object_map = found_instance->second.get(); |
| 113 | 111 |
| 114 // Force delete all var references. ForceReleaseNPObject() will cause | 112 // Force delete all var references. ForceReleaseNPObject() will cause |
| 115 // this object, and potentially others it references, to be removed from | 113 // this object, and potentially others it references, to be removed from |
| 116 // |np_object_map|. | 114 // |np_object_map|. |
| 117 while (!np_object_map->empty()) { | 115 while (!np_object_map->empty()) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 return false; | 162 return false; |
| 165 | 163 |
| 166 *handle = it->second.handle; | 164 *handle = it->second.handle; |
| 167 *size_in_bytes = it->second.size_in_bytes; | 165 *size_in_bytes = it->second.size_in_bytes; |
| 168 shared_memory_map_.erase(it); | 166 shared_memory_map_.erase(it); |
| 169 return true; | 167 return true; |
| 170 } | 168 } |
| 171 | 169 |
| 172 } // namespace ppapi | 170 } // namespace ppapi |
| 173 } // namespace webkit | 171 } // namespace webkit |
| OLD | NEW |