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() { |
20 : VarTracker(SINGLE_THREADED) { | |
21 } | 20 } |
22 | 21 |
23 HostVarTracker::~HostVarTracker() { | 22 HostVarTracker::~HostVarTracker() { |
24 } | 23 } |
25 | 24 |
26 ArrayBufferVar* HostVarTracker::CreateArrayBuffer(uint32 size_in_bytes) { | 25 ArrayBufferVar* HostVarTracker::CreateArrayBuffer(uint32 size_in_bytes) { |
27 return new HostArrayBufferVar(size_in_bytes); | 26 return new HostArrayBufferVar(size_in_bytes); |
28 } | 27 } |
29 | 28 |
30 void HostVarTracker::AddNPObjectVar(NPObjectVar* object_var) { | 29 void HostVarTracker::AddNPObjectVar(NPObjectVar* object_var) { |
31 CheckThreadingPreconditions(); | 30 DCHECK(CalledOnValidThread()); |
32 | 31 |
33 InstanceMap::iterator found_instance = instance_map_.find( | 32 InstanceMap::iterator found_instance = instance_map_.find( |
34 object_var->pp_instance()); | 33 object_var->pp_instance()); |
35 if (found_instance == instance_map_.end()) { | 34 if (found_instance == instance_map_.end()) { |
36 // Lazily create the instance map. | 35 // Lazily create the instance map. |
37 DCHECK(object_var->pp_instance() != 0); | 36 DCHECK(object_var->pp_instance() != 0); |
38 found_instance = instance_map_.insert(std::make_pair( | 37 found_instance = instance_map_.insert(std::make_pair( |
39 object_var->pp_instance(), | 38 object_var->pp_instance(), |
40 linked_ptr<NPObjectToNPObjectVarMap>(new NPObjectToNPObjectVarMap))). | 39 linked_ptr<NPObjectToNPObjectVarMap>(new NPObjectToNPObjectVarMap))). |
41 first; | 40 first; |
42 } | 41 } |
43 NPObjectToNPObjectVarMap* np_object_map = found_instance->second.get(); | 42 NPObjectToNPObjectVarMap* np_object_map = found_instance->second.get(); |
44 | 43 |
45 DCHECK(np_object_map->find(object_var->np_object()) == | 44 DCHECK(np_object_map->find(object_var->np_object()) == |
46 np_object_map->end()) << "NPObjectVar already in map"; | 45 np_object_map->end()) << "NPObjectVar already in map"; |
47 np_object_map->insert(std::make_pair(object_var->np_object(), object_var)); | 46 np_object_map->insert(std::make_pair(object_var->np_object(), object_var)); |
48 } | 47 } |
49 | 48 |
50 void HostVarTracker::RemoveNPObjectVar(NPObjectVar* object_var) { | 49 void HostVarTracker::RemoveNPObjectVar(NPObjectVar* object_var) { |
51 CheckThreadingPreconditions(); | 50 DCHECK(CalledOnValidThread()); |
52 | 51 |
53 InstanceMap::iterator found_instance = instance_map_.find( | 52 InstanceMap::iterator found_instance = instance_map_.find( |
54 object_var->pp_instance()); | 53 object_var->pp_instance()); |
55 if (found_instance == instance_map_.end()) { | 54 if (found_instance == instance_map_.end()) { |
56 NOTREACHED() << "NPObjectVar has invalid instance."; | 55 NOTREACHED() << "NPObjectVar has invalid instance."; |
57 return; | 56 return; |
58 } | 57 } |
59 NPObjectToNPObjectVarMap* np_object_map = found_instance->second.get(); | 58 NPObjectToNPObjectVarMap* np_object_map = found_instance->second.get(); |
60 | 59 |
61 NPObjectToNPObjectVarMap::iterator found_object = | 60 NPObjectToNPObjectVarMap::iterator found_object = |
62 np_object_map->find(object_var->np_object()); | 61 np_object_map->find(object_var->np_object()); |
63 if (found_object == np_object_map->end()) { | 62 if (found_object == np_object_map->end()) { |
64 NOTREACHED() << "NPObjectVar not registered."; | 63 NOTREACHED() << "NPObjectVar not registered."; |
65 return; | 64 return; |
66 } | 65 } |
67 if (found_object->second != object_var) { | 66 if (found_object->second != object_var) { |
68 NOTREACHED() << "NPObjectVar doesn't match."; | 67 NOTREACHED() << "NPObjectVar doesn't match."; |
69 return; | 68 return; |
70 } | 69 } |
71 np_object_map->erase(found_object); | 70 np_object_map->erase(found_object); |
72 } | 71 } |
73 | 72 |
74 NPObjectVar* HostVarTracker::NPObjectVarForNPObject(PP_Instance instance, | 73 NPObjectVar* HostVarTracker::NPObjectVarForNPObject(PP_Instance instance, |
75 NPObject* np_object) { | 74 NPObject* np_object) { |
76 CheckThreadingPreconditions(); | 75 DCHECK(CalledOnValidThread()); |
77 | 76 |
78 InstanceMap::iterator found_instance = instance_map_.find(instance); | 77 InstanceMap::iterator found_instance = instance_map_.find(instance); |
79 if (found_instance == instance_map_.end()) | 78 if (found_instance == instance_map_.end()) |
80 return NULL; // No such instance. | 79 return NULL; // No such instance. |
81 NPObjectToNPObjectVarMap* np_object_map = found_instance->second.get(); | 80 NPObjectToNPObjectVarMap* np_object_map = found_instance->second.get(); |
82 | 81 |
83 NPObjectToNPObjectVarMap::iterator found_object = | 82 NPObjectToNPObjectVarMap::iterator found_object = |
84 np_object_map->find(np_object); | 83 np_object_map->find(np_object); |
85 if (found_object == np_object_map->end()) | 84 if (found_object == np_object_map->end()) |
86 return NULL; // No such object. | 85 return NULL; // No such object. |
87 return found_object->second; | 86 return found_object->second; |
88 } | 87 } |
89 | 88 |
90 int HostVarTracker::GetLiveNPObjectVarsForInstance(PP_Instance instance) const { | 89 int HostVarTracker::GetLiveNPObjectVarsForInstance(PP_Instance instance) const { |
91 CheckThreadingPreconditions(); | 90 DCHECK(CalledOnValidThread()); |
92 | 91 |
93 InstanceMap::const_iterator found = instance_map_.find(instance); | 92 InstanceMap::const_iterator found = instance_map_.find(instance); |
94 if (found == instance_map_.end()) | 93 if (found == instance_map_.end()) |
95 return 0; | 94 return 0; |
96 return static_cast<int>(found->second->size()); | 95 return static_cast<int>(found->second->size()); |
97 } | 96 } |
98 | 97 |
99 void HostVarTracker::DidDeleteInstance(PP_Instance instance) { | 98 void HostVarTracker::DidDeleteInstance(PP_Instance instance) { |
100 CheckThreadingPreconditions(); | 99 DCHECK(CalledOnValidThread()); |
101 | 100 |
102 InstanceMap::iterator found_instance = instance_map_.find(instance); | 101 InstanceMap::iterator found_instance = instance_map_.find(instance); |
103 if (found_instance == instance_map_.end()) | 102 if (found_instance == instance_map_.end()) |
104 return; // Nothing to do. | 103 return; // Nothing to do. |
105 NPObjectToNPObjectVarMap* np_object_map = found_instance->second.get(); | 104 NPObjectToNPObjectVarMap* np_object_map = found_instance->second.get(); |
106 | 105 |
107 // Force delete all var references. ForceReleaseNPObject() will cause | 106 // Force delete all var references. ForceReleaseNPObject() will cause |
108 // this object, and potentially others it references, to be removed from | 107 // this object, and potentially others it references, to be removed from |
109 // |np_object_map|. | 108 // |np_object_map|. |
110 while (!np_object_map->empty()) { | 109 while (!np_object_map->empty()) { |
(...skipping 12 matching lines...) Expand all Loading... |
123 NOTREACHED(); | 122 NOTREACHED(); |
124 return; | 123 return; |
125 } | 124 } |
126 iter->second.ref_count = 0; | 125 iter->second.ref_count = 0; |
127 DCHECK(iter->second.track_with_no_reference_count == 0); | 126 DCHECK(iter->second.track_with_no_reference_count == 0); |
128 DeleteObjectInfoIfNecessary(iter); | 127 DeleteObjectInfoIfNecessary(iter); |
129 } | 128 } |
130 | 129 |
131 } // namespace ppapi | 130 } // namespace ppapi |
132 } // namespace webkit | 131 } // namespace webkit |
OLD | NEW |