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/proxy/plugin_resource_tracker.h" | 5 #include "ppapi/proxy/plugin_resource_tracker.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.h" |
9 #include "ppapi/proxy/plugin_dispatcher.h" | 9 #include "ppapi/proxy/plugin_dispatcher.h" |
10 #include "ppapi/proxy/ppapi_messages.h" | 10 #include "ppapi/proxy/ppapi_messages.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 PluginResource* PluginResourceTracker::GetResourceObject( | 83 PluginResource* PluginResourceTracker::GetResourceObject( |
84 PP_Resource pp_resource) { | 84 PP_Resource pp_resource) { |
85 ResourceMap::iterator found = resource_map_.find(pp_resource); | 85 ResourceMap::iterator found = resource_map_.find(pp_resource); |
86 if (found == resource_map_.end()) | 86 if (found == resource_map_.end()) |
87 return NULL; | 87 return NULL; |
88 return found->second.resource.get(); | 88 return found->second.resource.get(); |
89 } | 89 } |
90 | 90 |
91 PP_Resource PluginResourceTracker::AddResource( | 91 PP_Resource PluginResourceTracker::AddResource( |
92 linked_ptr<PluginResource> object) { | 92 linked_ptr<PluginResource> object) { |
93 if (object->host_resource().is_null()) { | |
94 // Prevent adding null resources or GetResourceObject(0) will return a | |
95 // valid pointer! | |
96 NOTREACHED(); | |
97 return 0; | |
98 } | |
99 | |
100 PP_Resource plugin_resource = ++last_resource_id_; | 93 PP_Resource plugin_resource = ++last_resource_id_; |
101 DCHECK(resource_map_.find(plugin_resource) == resource_map_.end()); | 94 DCHECK(resource_map_.find(plugin_resource) == resource_map_.end()); |
102 resource_map_[plugin_resource] = ResourceInfo(1, object); | 95 resource_map_[plugin_resource] = ResourceInfo(1, object); |
103 host_resource_map_[object->host_resource()] = plugin_resource; | 96 if (!object->host_resource().is_null()) { |
| 97 // The host resource ID will be 0 for resources that only exist in the |
| 98 // plugin process. Don't add those to the list. |
| 99 host_resource_map_[object->host_resource()] = plugin_resource; |
| 100 } |
104 return plugin_resource; | 101 return plugin_resource; |
105 } | 102 } |
106 | 103 |
107 void PluginResourceTracker::AddRefResource(PP_Resource resource) { | 104 void PluginResourceTracker::AddRefResource(PP_Resource resource) { |
108 ResourceMap::iterator found = resource_map_.find(resource); | 105 ResourceMap::iterator found = resource_map_.find(resource); |
109 if (found == resource_map_.end()) { | 106 if (found == resource_map_.end()) { |
110 NOTREACHED(); | 107 NOTREACHED(); |
111 return; | 108 return; |
112 } | 109 } |
113 found->second.ref_count++; | 110 found->second.ref_count++; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 return; | 147 return; |
151 found->second.ref_count--; | 148 found->second.ref_count--; |
152 if (found->second.ref_count == 0) { | 149 if (found->second.ref_count == 0) { |
153 // Keep a reference while removing in case the destructor ends up | 150 // Keep a reference while removing in case the destructor ends up |
154 // re-entering. That way, when the destructor is called, it's out of the | 151 // re-entering. That way, when the destructor is called, it's out of the |
155 // maps. | 152 // maps. |
156 linked_ptr<PluginResource> plugin_resource = found->second.resource; | 153 linked_ptr<PluginResource> plugin_resource = found->second.resource; |
157 PluginDispatcher* dispatcher = | 154 PluginDispatcher* dispatcher = |
158 PluginDispatcher::GetForInstance(plugin_resource->instance()); | 155 PluginDispatcher::GetForInstance(plugin_resource->instance()); |
159 HostResource host_resource = plugin_resource->host_resource(); | 156 HostResource host_resource = plugin_resource->host_resource(); |
160 host_resource_map_.erase(host_resource); | 157 if (!host_resource.is_null()) |
| 158 host_resource_map_.erase(host_resource); |
161 resource_map_.erase(found); | 159 resource_map_.erase(found); |
162 plugin_resource.reset(); | 160 plugin_resource.reset(); |
163 | 161 |
164 if (notify_browser_on_release) { | 162 if (notify_browser_on_release) { |
165 if (dispatcher) { | 163 if (dispatcher) { |
166 dispatcher->Send(new PpapiHostMsg_PPBCore_ReleaseResource( | 164 dispatcher->Send(new PpapiHostMsg_PPBCore_ReleaseResource( |
167 INTERFACE_ID_PPB_CORE, host_resource)); | 165 INTERFACE_ID_PPB_CORE, host_resource)); |
168 } else { | 166 } else { |
169 NOTREACHED(); | 167 NOTREACHED(); |
170 } | 168 } |
171 } | 169 } |
172 } | 170 } |
173 } | 171 } |
174 | 172 |
175 } // namespace proxy | 173 } // namespace proxy |
176 } // namespace pp | 174 } // namespace pp |
OLD | NEW |