| 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 (instance is not threadsafe |
| 146 // and may be deleted from the main thread). |
| 147 Instance* that = Module::Get()->InstanceForPPInstance(instance.pp_instance()); |
| 148 if (!that) |
| 149 return; |
| 150 that->AddPerInstanceObject(interface_name, object); |
| 151 } |
| 152 |
| 140 void Instance::RemovePerInstanceObject(const std::string& interface_name, | 153 void Instance::RemovePerInstanceObject(const std::string& interface_name, |
| 141 void* object) { | 154 void* object) { |
| 142 InterfaceNameToObjectMap::iterator found = interface_name_to_objects_.find( | 155 InterfaceNameToObjectMap::iterator found = interface_name_to_objects_.find( |
| 143 interface_name); | 156 interface_name); |
| 144 if (found == interface_name_to_objects_.end()) { | 157 if (found == interface_name_to_objects_.end()) { |
| 145 // Attempting to unregister an object that doesn't exist or was already | 158 // Attempting to unregister an object that doesn't exist or was already |
| 146 // unregistered. | 159 // unregistered. |
| 147 PP_DCHECK(false); | 160 PP_DCHECK(false); |
| 148 return; | 161 return; |
| 149 } | 162 } |
| 150 | 163 |
| 151 // Validate that we're removing the object we thing we are. | 164 // Validate that we're removing the object we thing we are. |
| 152 PP_DCHECK(found->second == object); | 165 PP_DCHECK(found->second == object); |
| 153 (void)object; // Prevent warning in release mode. | 166 (void)object; // Prevent warning in release mode. |
| 154 | 167 |
| 155 interface_name_to_objects_.erase(found); | 168 interface_name_to_objects_.erase(found); |
| 156 } | 169 } |
| 157 | 170 |
| 158 // static | 171 // static |
| 172 void Instance::RemovePerInstanceObject(const InstanceHandle& instance, |
| 173 const std::string& interface_name, |
| 174 void* object) { |
| 175 // TODO(brettw) assert we're on the main thread. |
| 176 Instance* that = Module::Get()->InstanceForPPInstance(instance.pp_instance()); |
| 177 if (!that) |
| 178 return; |
| 179 that->RemovePerInstanceObject(interface_name, object); |
| 180 } |
| 181 |
| 182 // static |
| 159 void* Instance::GetPerInstanceObject(PP_Instance instance, | 183 void* Instance::GetPerInstanceObject(PP_Instance instance, |
| 160 const std::string& interface_name) { | 184 const std::string& interface_name) { |
| 161 Instance* that = Module::Get()->InstanceForPPInstance(instance); | 185 Instance* that = Module::Get()->InstanceForPPInstance(instance); |
| 162 if (!that) | 186 if (!that) |
| 163 return NULL; | 187 return NULL; |
| 164 InterfaceNameToObjectMap::iterator found = | 188 InterfaceNameToObjectMap::iterator found = |
| 165 that->interface_name_to_objects_.find(interface_name); | 189 that->interface_name_to_objects_.find(interface_name); |
| 166 if (found == that->interface_name_to_objects_.end()) | 190 if (found == that->interface_name_to_objects_.end()) |
| 167 return NULL; | 191 return NULL; |
| 168 return found->second; | 192 return found->second; |
| 169 } | 193 } |
| 170 | 194 |
| 171 } // namespace pp | 195 } // namespace pp |
| OLD | NEW |