Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Side by Side Diff: ppapi/proxy/plugin_resource_tracker.cc

Issue 7608030: Convert the PluginResource to be refcounted. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 12 matching lines...) Expand all
23 23
24 ::ppapi::TrackerBase* GetTrackerBase() { 24 ::ppapi::TrackerBase* GetTrackerBase() {
25 return PluginResourceTracker::GetInstance(); 25 return PluginResourceTracker::GetInstance();
26 } 26 }
27 27
28 } // namespace 28 } // namespace
29 29
30 PluginResourceTracker::ResourceInfo::ResourceInfo() : ref_count(0) { 30 PluginResourceTracker::ResourceInfo::ResourceInfo() : ref_count(0) {
31 } 31 }
32 32
33 PluginResourceTracker::ResourceInfo::ResourceInfo(int rc, 33 PluginResourceTracker::ResourceInfo::ResourceInfo(int rc, PluginResource* r)
34 linked_ptr<PluginResource> r)
35 : ref_count(rc), 34 : ref_count(rc),
36 resource(r) { 35 resource(r) {
37 } 36 }
38 37
39 PluginResourceTracker::ResourceInfo::ResourceInfo(const ResourceInfo& other) 38 PluginResourceTracker::ResourceInfo::ResourceInfo(const ResourceInfo& other)
40 : ref_count(other.ref_count), 39 : ref_count(other.ref_count),
41 resource(other.resource) { 40 resource(other.resource) {
42 // Wire up the new shared resource tracker base to use our implementation. 41 // Wire up the new shared resource tracker base to use our implementation.
43 ::ppapi::TrackerBase::Init(&GetTrackerBase); 42 ::ppapi::TrackerBase::Init(&GetTrackerBase);
44 } 43 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 } 82 }
84 83
85 PluginResource* PluginResourceTracker::GetResourceObject( 84 PluginResource* PluginResourceTracker::GetResourceObject(
86 PP_Resource pp_resource) { 85 PP_Resource pp_resource) {
87 ResourceMap::iterator found = resource_map_.find(pp_resource); 86 ResourceMap::iterator found = resource_map_.find(pp_resource);
88 if (found == resource_map_.end()) 87 if (found == resource_map_.end())
89 return NULL; 88 return NULL;
90 return found->second.resource.get(); 89 return found->second.resource.get();
91 } 90 }
92 91
93 PP_Resource PluginResourceTracker::AddResource( 92 PP_Resource PluginResourceTracker::AddResource(PluginResource* object) {
94 linked_ptr<PluginResource> object) {
95 PP_Resource plugin_resource = ++last_resource_id_; 93 PP_Resource plugin_resource = ++last_resource_id_;
96 DCHECK(resource_map_.find(plugin_resource) == resource_map_.end()); 94 DCHECK(resource_map_.find(plugin_resource) == resource_map_.end());
97 resource_map_[plugin_resource] = ResourceInfo(1, object); 95 resource_map_[plugin_resource] = ResourceInfo(1, object);
98 if (!object->host_resource().is_null()) { 96 if (!object->host_resource().is_null()) {
99 // The host resource ID will be 0 for resources that only exist in the 97 // The host resource ID will be 0 for resources that only exist in the
100 // plugin process. Don't add those to the list. 98 // plugin process. Don't add those to the list.
101 host_resource_map_[object->host_resource()] = plugin_resource; 99 host_resource_map_[object->host_resource()] = plugin_resource;
102 } 100 }
103 return plugin_resource; 101 return plugin_resource;
104 } 102 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 const PP_Resource& resource, 155 const PP_Resource& resource,
158 bool notify_browser_on_release) { 156 bool notify_browser_on_release) {
159 ResourceMap::iterator found = resource_map_.find(resource); 157 ResourceMap::iterator found = resource_map_.find(resource);
160 if (found == resource_map_.end()) 158 if (found == resource_map_.end())
161 return; 159 return;
162 found->second.ref_count--; 160 found->second.ref_count--;
163 if (found->second.ref_count == 0) { 161 if (found->second.ref_count == 0) {
164 // Keep a reference while removing in case the destructor ends up 162 // Keep a reference while removing in case the destructor ends up
165 // re-entering. That way, when the destructor is called, it's out of the 163 // re-entering. That way, when the destructor is called, it's out of the
166 // maps. 164 // maps.
167 linked_ptr<PluginResource> plugin_resource = found->second.resource; 165 scoped_refptr<PluginResource> plugin_resource = found->second.resource;
168 PluginDispatcher* dispatcher = 166 PluginDispatcher* dispatcher =
169 PluginDispatcher::GetForInstance(plugin_resource->instance()); 167 PluginDispatcher::GetForInstance(plugin_resource->instance());
170 HostResource host_resource = plugin_resource->host_resource(); 168 HostResource host_resource = plugin_resource->host_resource();
171 if (!host_resource.is_null()) 169 if (!host_resource.is_null())
172 host_resource_map_.erase(host_resource); 170 host_resource_map_.erase(host_resource);
173 resource_map_.erase(found); 171 resource_map_.erase(found);
174 plugin_resource.reset(); 172 plugin_resource = NULL;
175 173
176 // dispatcher can be NULL if the plugin held on to a resource after the 174 // dispatcher can be NULL if the plugin held on to a resource after the
177 // instance was destroyed. In that case the browser-side resource has 175 // instance was destroyed. In that case the browser-side resource has
178 // already been freed correctly on the browser side. The host_resource 176 // already been freed correctly on the browser side. The host_resource
179 // will be NULL for proxy-only resources, which we obviously don't need to 177 // will be NULL for proxy-only resources, which we obviously don't need to
180 // tell the host about. 178 // tell the host about.
181 if (notify_browser_on_release && dispatcher && !host_resource.is_null()) { 179 if (notify_browser_on_release && dispatcher && !host_resource.is_null()) {
182 dispatcher->Send(new PpapiHostMsg_PPBCore_ReleaseResource( 180 dispatcher->Send(new PpapiHostMsg_PPBCore_ReleaseResource(
183 INTERFACE_ID_PPB_CORE, host_resource)); 181 INTERFACE_ID_PPB_CORE, host_resource));
184 } 182 }
185 } 183 }
186 } 184 }
187 185
188 } // namespace proxy 186 } // namespace proxy
189 } // namespace pp 187 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698