From 51e1aec0a2197056f0e26e05a88819b611d65cdb Mon Sep 17 00:00:00 2001 From: "brettw@chromium.org" Date: Thu, 11 Aug 2011 04:48:30 +0000 Subject: Convert the PluginResource to be refcounted. This is to make the future transition to a shared resource tracker (which will use refcounted resources) easier. There should be no behavior change. Review URL: http://codereview.chromium.org/7608030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@96324 0039d316-1c4b-4281-b951-d872f2087c98 --- ppapi/proxy/plugin_resource.h | 4 +++- ppapi/proxy/plugin_resource_tracker.cc | 10 ++++------ ppapi/proxy/plugin_resource_tracker.h | 9 +++++---- ppapi/proxy/plugin_resource_tracker_unittest.cc | 3 +-- ppapi/proxy/ppb_audio_config_proxy.cc | 2 +- ppapi/proxy/ppb_audio_proxy.cc | 5 ++--- ppapi/proxy/ppb_broker_proxy.cc | 3 +-- ppapi/proxy/ppb_buffer_proxy.cc | 4 ++-- ppapi/proxy/ppb_context_3d_proxy.cc | 2 +- ppapi/proxy/ppb_file_chooser_proxy.cc | 4 ++-- ppapi/proxy/ppb_file_ref_proxy.cc | 4 ++-- ppapi/proxy/ppb_file_system_proxy.cc | 4 ++-- ppapi/proxy/ppb_flash_menu_proxy.cc | 4 ++-- ppapi/proxy/ppb_flash_net_connector_proxy.cc | 4 ++-- ppapi/proxy/ppb_flash_tcp_socket_proxy.cc | 6 ++---- ppapi/proxy/ppb_graphics_2d_proxy.cc | 5 ++--- ppapi/proxy/ppb_graphics_3d_proxy.cc | 2 +- ppapi/proxy/ppb_input_event_proxy.cc | 5 ++--- ppapi/proxy/ppb_pdf_proxy.cc | 4 ++-- ppapi/proxy/ppb_surface_3d_proxy.cc | 2 +- ppapi/proxy/ppb_url_loader_proxy.cc | 4 ++-- ppapi/proxy/ppb_url_request_info_proxy.cc | 4 ++-- ppapi/proxy/ppb_url_response_info_proxy.cc | 4 ++-- ppapi/proxy/ppb_video_capture_proxy.cc | 4 ++-- ppapi/proxy/ppb_video_decoder_proxy.cc | 6 ++---- ppapi/proxy/resource_creation_proxy.cc | 9 ++++----- 26 files changed, 54 insertions(+), 63 deletions(-) diff --git a/ppapi/proxy/plugin_resource.h b/ppapi/proxy/plugin_resource.h index 3abe9cb..703a529 100644 --- a/ppapi/proxy/plugin_resource.h +++ b/ppapi/proxy/plugin_resource.h @@ -6,6 +6,7 @@ #define PPAPI_PROXY_PLUGIN_RESOURCE_H_ #include "base/basictypes.h" +#include "base/memory/ref_counted.h" #include "ppapi/c/pp_instance.h" #include "ppapi/proxy/host_resource.h" #include "ppapi/proxy/plugin_dispatcher.h" @@ -45,7 +46,8 @@ namespace proxy { FOR_ALL_PLUGIN_RESOURCES(DECLARE_RESOURCE_CLASS) #undef DECLARE_RESOURCE_CLASS -class PluginResource : public ::ppapi::ResourceObjectBase { +class PluginResource : public ::ppapi::ResourceObjectBase, + public base::RefCounted { public: PluginResource(const HostResource& resource); virtual ~PluginResource(); diff --git a/ppapi/proxy/plugin_resource_tracker.cc b/ppapi/proxy/plugin_resource_tracker.cc index cabf9cb..a82ccef 100644 --- a/ppapi/proxy/plugin_resource_tracker.cc +++ b/ppapi/proxy/plugin_resource_tracker.cc @@ -30,8 +30,7 @@ PluginResourceTracker* g_resource_tracker_override = NULL; PluginResourceTracker::ResourceInfo::ResourceInfo() : ref_count(0) { } -PluginResourceTracker::ResourceInfo::ResourceInfo(int rc, - linked_ptr r) +PluginResourceTracker::ResourceInfo::ResourceInfo(int rc, PluginResource* r) : ref_count(rc), resource(r) { } @@ -90,8 +89,7 @@ PluginResource* PluginResourceTracker::GetResourceObject( return found->second.resource.get(); } -PP_Resource PluginResourceTracker::AddResource( - linked_ptr object) { +PP_Resource PluginResourceTracker::AddResource(PluginResource* object) { PP_Resource plugin_resource = ++last_resource_id_; DCHECK(resource_map_.find(plugin_resource) == resource_map_.end()); resource_map_[plugin_resource] = ResourceInfo(1, object); @@ -164,14 +162,14 @@ void PluginResourceTracker::ReleasePluginResourceRef( // Keep a reference while removing in case the destructor ends up // re-entering. That way, when the destructor is called, it's out of the // maps. - linked_ptr plugin_resource = found->second.resource; + scoped_refptr plugin_resource = found->second.resource; PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(plugin_resource->instance()); HostResource host_resource = plugin_resource->host_resource(); if (!host_resource.is_null()) host_resource_map_.erase(host_resource); resource_map_.erase(found); - plugin_resource.reset(); + plugin_resource = NULL; // dispatcher can be NULL if the plugin held on to a resource after the // instance was destroyed. In that case the browser-side resource has diff --git a/ppapi/proxy/plugin_resource_tracker.h b/ppapi/proxy/plugin_resource_tracker.h index b96831c..d313a9f 100644 --- a/ppapi/proxy/plugin_resource_tracker.h +++ b/ppapi/proxy/plugin_resource_tracker.h @@ -9,7 +9,6 @@ #include #include "base/compiler_specific.h" -#include "base/memory/linked_ptr.h" #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_instance.h" #include "ppapi/c/pp_stdint.h" @@ -50,7 +49,9 @@ class PluginResourceTracker : public ::ppapi::TrackerBase { // plugin-local PP_Resource ID that identifies the resource. Note that this // PP_Resource is not valid to send to the host, use // PluginResource.host_resource() to get that. - PP_Resource AddResource(linked_ptr object); + // + // The resource tracker will take a reference to the given object. + PP_Resource AddResource(PluginResource* object); void AddRefResource(PP_Resource resource); void ReleaseResource(PP_Resource resource); @@ -88,14 +89,14 @@ class PluginResourceTracker : public ::ppapi::TrackerBase { struct ResourceInfo { ResourceInfo(); - ResourceInfo(int ref_count, linked_ptr r); + ResourceInfo(int ref_count, PluginResource* r); ResourceInfo(const ResourceInfo& other); ~ResourceInfo(); ResourceInfo& operator=(const ResourceInfo& other); int ref_count; - linked_ptr resource; // May be NULL. + scoped_refptr resource; // May be NULL. }; void ReleasePluginResourceRef(const PP_Resource& var, diff --git a/ppapi/proxy/plugin_resource_tracker_unittest.cc b/ppapi/proxy/plugin_resource_tracker_unittest.cc index 5a317128..5d673f5 100644 --- a/ppapi/proxy/plugin_resource_tracker_unittest.cc +++ b/ppapi/proxy/plugin_resource_tracker_unittest.cc @@ -56,8 +56,7 @@ TEST_F(PluginResourceTrackerTest, PluginResourceForHostResource) { EXPECT_EQ(0, TrackedMockResource::tracked_alive_count); TrackedMockResource* object = new TrackedMockResource(serialized); EXPECT_EQ(1, TrackedMockResource::tracked_alive_count); - PP_Resource plugin_resource = - tracker().AddResource(linked_ptr(object)); + PP_Resource plugin_resource = tracker().AddResource(object); // Now that the object has been added, the return value should be the plugin // resource ID we already got. diff --git a/ppapi/proxy/ppb_audio_config_proxy.cc b/ppapi/proxy/ppb_audio_config_proxy.cc index e8eb056..f202b63 100644 --- a/ppapi/proxy/ppb_audio_config_proxy.cc +++ b/ppapi/proxy/ppb_audio_config_proxy.cc @@ -74,7 +74,7 @@ PP_Resource PPB_AudioConfig_Proxy::CreateProxyResource( PP_Instance instance, PP_AudioSampleRate sample_rate, uint32_t sample_frame_count) { - linked_ptr object(new AudioConfig( + scoped_refptr object(new AudioConfig( HostResource::MakeInstanceOnly(instance))); if (!object->Init(sample_rate, sample_frame_count)) return 0; diff --git a/ppapi/proxy/ppb_audio_proxy.cc b/ppapi/proxy/ppb_audio_proxy.cc index f0db204..9ec3b30 100644 --- a/ppapi/proxy/ppb_audio_proxy.cc +++ b/ppapi/proxy/ppb_audio_proxy.cc @@ -178,9 +178,8 @@ PP_Resource PPB_Audio_Proxy::CreateProxyResource( if (result.is_null()) return 0; - linked_ptr