| 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 "ppapi/host/ppapi_host.h" | 5 #include "ppapi/host/ppapi_host.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "ppapi/c/pp_errors.h" | 8 #include "ppapi/c/pp_errors.h" |
| 9 #include "ppapi/host/host_factory.h" | 9 #include "ppapi/host/host_factory.h" |
| 10 #include "ppapi/host/host_message_context.h" | 10 #include "ppapi/host/host_message_context.h" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 resource_host = host_factory_filters_[i]->CreateResourceHost( | 129 resource_host = host_factory_filters_[i]->CreateResourceHost( |
| 130 this, params, instance, nested_msg).Pass(); | 130 this, params, instance, nested_msg).Pass(); |
| 131 if (resource_host.get()) | 131 if (resource_host.get()) |
| 132 break; | 132 break; |
| 133 } | 133 } |
| 134 if (!resource_host.get()) { | 134 if (!resource_host.get()) { |
| 135 NOTREACHED(); | 135 NOTREACHED(); |
| 136 return; | 136 return; |
| 137 } | 137 } |
| 138 | 138 |
| 139 if (nested_msg.type() == PpapiHostMsg_Graphics2D_Create::ID) |
| 140 graphics_2d_set_.insert(params.pp_resource()); |
| 141 |
| 139 resources_[params.pp_resource()] = | 142 resources_[params.pp_resource()] = |
| 140 linked_ptr<ResourceHost>(resource_host.release()); | 143 linked_ptr<ResourceHost>(resource_host.release()); |
| 141 } | 144 } |
| 142 | 145 |
| 143 void PpapiHost::OnHostMsgResourceDestroyed(PP_Resource resource) { | 146 // static |
| 144 ResourceMap::iterator found = resources_.find(resource); | 147 template <typename Container, typename Element> |
| 145 if (found == resources_.end()) { | 148 void PpapiHost::ReleaseResource(Container container, Element element) { |
| 149 typename Container::iterator found = container.find(element); |
| 150 if (found == container.end()) { |
| 146 NOTREACHED(); | 151 NOTREACHED(); |
| 147 return; | 152 return; |
| 148 } | 153 } |
| 149 resources_.erase(found); | 154 container.erase(found); |
| 150 } | 155 } |
| 151 | 156 |
| 152 ResourceHost* PpapiHost::GetResourceHost(PP_Resource resource) { | 157 void PpapiHost::OnHostMsgResourceDestroyed(PP_Resource resource) { |
| 153 ResourceMap::iterator found = resources_.find(resource); | 158 ReleaseResource(resources_, resource); |
| 159 ReleaseResource(graphics_2d_set_, resource); |
| 160 } |
| 161 |
| 162 ResourceHost* PpapiHost::GetResourceHost(PP_Resource resource) const { |
| 163 ResourceMap::const_iterator found = resources_.find(resource); |
| 154 return found == resources_.end() ? NULL : found->second.get(); | 164 return found == resources_.end() ? NULL : found->second.get(); |
| 155 } | 165 } |
| 156 | 166 |
| 167 bool PpapiHost::IsGraphics2DResource(PP_Resource resource) const { |
| 168 return graphics_2d_set_.find(resource) != graphics_2d_set_.end(); |
| 169 } |
| 170 |
| 157 } // namespace host | 171 } // namespace host |
| 158 } // namespace ppapi | 172 } // namespace ppapi |
| OLD | NEW |