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/cpp/instance.h" | 5 #include "ppapi/cpp/instance.h" |
6 | 6 |
7 #include "ppapi/c/pp_errors.h" | 7 #include "ppapi/c/pp_errors.h" |
8 #include "ppapi/c/ppb_input_event.h" | 8 #include "ppapi/c/ppb_input_event.h" |
9 #include "ppapi/c/ppb_instance.h" | 9 #include "ppapi/c/ppb_instance.h" |
10 #include "ppapi/c/ppb_messaging.h" | 10 #include "ppapi/c/ppb_messaging.h" |
11 #include "ppapi/cpp/graphics_2d.h" | 11 #include "ppapi/cpp/graphics_2d.h" |
12 #include "ppapi/cpp/graphics_3d.h" | 12 #include "ppapi/cpp/graphics_3d.h" |
13 #include "ppapi/cpp/image_data.h" | 13 #include "ppapi/cpp/image_data.h" |
14 #include "ppapi/cpp/instance_handle.h" | |
14 #include "ppapi/cpp/logging.h" | 15 #include "ppapi/cpp/logging.h" |
15 #include "ppapi/cpp/module.h" | 16 #include "ppapi/cpp/module.h" |
16 #include "ppapi/cpp/module_impl.h" | 17 #include "ppapi/cpp/module_impl.h" |
17 #include "ppapi/cpp/point.h" | 18 #include "ppapi/cpp/point.h" |
18 #include "ppapi/cpp/resource.h" | 19 #include "ppapi/cpp/resource.h" |
19 #include "ppapi/cpp/var.h" | 20 #include "ppapi/cpp/var.h" |
20 #include "ppapi/cpp/view.h" | 21 #include "ppapi/cpp/view.h" |
21 | 22 |
22 namespace pp { | 23 namespace pp { |
23 | 24 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 | 131 |
131 void Instance::AddPerInstanceObject(const std::string& interface_name, | 132 void Instance::AddPerInstanceObject(const std::string& interface_name, |
132 void* object) { | 133 void* object) { |
133 // Ensure we're not trying to register more than one object per interface | 134 // Ensure we're not trying to register more than one object per interface |
134 // type. Otherwise, we'll get confused in GetPerInstanceObject. | 135 // type. Otherwise, we'll get confused in GetPerInstanceObject. |
135 PP_DCHECK(interface_name_to_objects_.find(interface_name) == | 136 PP_DCHECK(interface_name_to_objects_.find(interface_name) == |
136 interface_name_to_objects_.end()); | 137 interface_name_to_objects_.end()); |
137 interface_name_to_objects_[interface_name] = object; | 138 interface_name_to_objects_[interface_name] = object; |
138 } | 139 } |
139 | 140 |
141 // static | |
142 void Instance::AddPerInstanceObject(const InstanceHandle& instance, | |
143 const std::string& interface_name, | |
144 void* object) { | |
145 // TODO(brettw) assert we're on the main thread. | |
dmichael (off chromium)
2012/02/21 23:38:02
May be worth adding a brief comment why the stuff
| |
146 Instance* that = Module::Get()->InstanceForPPInstance(instance.pp_instance()); | |
147 if (!that) | |
148 return; | |
149 that->AddPerInstanceObject(interface_name, object); | |
150 } | |
151 | |
140 void Instance::RemovePerInstanceObject(const std::string& interface_name, | 152 void Instance::RemovePerInstanceObject(const std::string& interface_name, |
141 void* object) { | 153 void* object) { |
142 InterfaceNameToObjectMap::iterator found = interface_name_to_objects_.find( | 154 InterfaceNameToObjectMap::iterator found = interface_name_to_objects_.find( |
143 interface_name); | 155 interface_name); |
144 if (found == interface_name_to_objects_.end()) { | 156 if (found == interface_name_to_objects_.end()) { |
145 // Attempting to unregister an object that doesn't exist or was already | 157 // Attempting to unregister an object that doesn't exist or was already |
146 // unregistered. | 158 // unregistered. |
147 PP_DCHECK(false); | 159 PP_DCHECK(false); |
148 return; | 160 return; |
149 } | 161 } |
150 | 162 |
151 // Validate that we're removing the object we thing we are. | 163 // Validate that we're removing the object we thing we are. |
152 PP_DCHECK(found->second == object); | 164 PP_DCHECK(found->second == object); |
153 (void)object; // Prevent warning in release mode. | 165 (void)object; // Prevent warning in release mode. |
154 | 166 |
155 interface_name_to_objects_.erase(found); | 167 interface_name_to_objects_.erase(found); |
156 } | 168 } |
157 | 169 |
158 // static | 170 // static |
171 void Instance::RemovePerInstanceObject(const InstanceHandle& instance, | |
172 const std::string& interface_name, | |
173 void* object) { | |
174 // TODO(brettw) assert we're on the main thread. | |
175 Instance* that = Module::Get()->InstanceForPPInstance(instance.pp_instance()); | |
176 if (!that) | |
177 return; | |
178 that->RemovePerInstanceObject(interface_name, object); | |
179 } | |
180 | |
181 // static | |
159 void* Instance::GetPerInstanceObject(PP_Instance instance, | 182 void* Instance::GetPerInstanceObject(PP_Instance instance, |
160 const std::string& interface_name) { | 183 const std::string& interface_name) { |
161 Instance* that = Module::Get()->InstanceForPPInstance(instance); | 184 Instance* that = Module::Get()->InstanceForPPInstance(instance); |
162 if (!that) | 185 if (!that) |
163 return NULL; | 186 return NULL; |
164 InterfaceNameToObjectMap::iterator found = | 187 InterfaceNameToObjectMap::iterator found = |
165 that->interface_name_to_objects_.find(interface_name); | 188 that->interface_name_to_objects_.find(interface_name); |
166 if (found == that->interface_name_to_objects_.end()) | 189 if (found == that->interface_name_to_objects_.end()) |
167 return NULL; | 190 return NULL; |
168 return found->second; | 191 return found->second; |
169 } | 192 } |
170 | 193 |
171 } // namespace pp | 194 } // namespace pp |
OLD | NEW |