diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-18 15:41:01 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-18 15:41:01 +0000 |
commit | 7f8b26b5f223689de7af4803bc07e1e953ff5953 (patch) | |
tree | d6f3e574d97c6253b8b202264fe23dea1b489dc2 /webkit | |
parent | d8886526085a42874663be638be1421e78f6172c (diff) | |
download | chromium_src-7f8b26b5f223689de7af4803bc07e1e953ff5953.zip chromium_src-7f8b26b5f223689de7af4803bc07e1e953ff5953.tar.gz chromium_src-7f8b26b5f223689de7af4803bc07e1e953ff5953.tar.bz2 |
Add a unified resource tracker shared between the proxy and the impl.
This renames the old ResourceObjectBase to Resource and removes the old
PluginResource. It moves the resource tracker from the impl to the
shared_impl, and makes the proxy use it.
Some things become a little less neat because there's no proxy resource base
class. In particular GetDispatcher() is now gone. I considered whether to
add a helper base class that provides this function, but decided against it
and had individual resource classes implement this when their implementation
would find it useful. This is because ultimately I want more of this
functionality to move into the shared_impl, and it's easier to do that if
there are fewer proxy-specific things in the resources.
This changes the way that plugins are added to the tracker. Previously they
would only be in the tracker if the plugin had a reference to them, although
they could be alive if the impl had a scoped_ptr referencing an object. This
actually has the bug that if we then give the resource back to the plugin,
it wouldn't be refcounted properly and everything would get confused.
Now the tracker tracks all live resource objects whether or not the plugin
has a ref. This works basically like the var tracker (it would be nice if
the var and resource trackers shared more code, but that would further
complicate this already overcomplicated patch). The resource tracker takes an
extra ref whenever the plugin has one or more, and otherwise just tracks live
resources.
Review URL: http://codereview.chromium.org/7629017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97314 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
52 files changed, 129 insertions, 506 deletions
diff --git a/webkit/plugins/ppapi/callbacks_unittest.cc b/webkit/plugins/ppapi/callbacks_unittest.cc index 9d561a2..4cd8084 100644 --- a/webkit/plugins/ppapi/callbacks_unittest.cc +++ b/webkit/plugins/ppapi/callbacks_unittest.cc @@ -202,13 +202,13 @@ TEST_F(CallbackResourceTest, AbortOnNoRef) { // Kill resource #1, spin the message loop to run posted calls, and check that // things are in the expected states. - resource_tracker->UnrefResource(resource_1_id); + resource_tracker->ReleaseResource(resource_1_id); MessageLoop::current()->RunAllPending(); resource_1->CheckFinalState(); resource_2->CheckIntermediateState(); // Kill resource #2. - resource_tracker->UnrefResource(resource_2_id); + resource_tracker->ReleaseResource(resource_2_id); MessageLoop::current()->RunAllPending(); resource_1->CheckFinalState(); resource_2->CheckFinalState(); @@ -228,7 +228,7 @@ TEST_F(CallbackResourceTest, Resurrection) { // Unref it, spin the message loop to run posted calls, and check that things // are in the expected states. - resource_tracker->UnrefResource(resource_id); + resource_tracker->ReleaseResource(resource_id); MessageLoop::current()->RunAllPending(); resource->CheckFinalState(); @@ -238,7 +238,7 @@ TEST_F(CallbackResourceTest, Resurrection) { resource->CheckFinalState(); // Unref it again and do the same. - resource_tracker->UnrefResource(new_resource_id); + resource_tracker->ReleaseResource(new_resource_id); MessageLoop::current()->RunAllPending(); resource->CheckFinalState(); diff --git a/webkit/plugins/ppapi/plugin_module.cc b/webkit/plugins/ppapi/plugin_module.cc index f891e9b..927528d 100644 --- a/webkit/plugins/ppapi/plugin_module.cc +++ b/webkit/plugins/ppapi/plugin_module.cc @@ -138,15 +138,11 @@ base::MessageLoopProxy* GetMainThreadMessageLoop() { // PPB_Core -------------------------------------------------------------------- void AddRefResource(PP_Resource resource) { - if (!ResourceTracker::Get()->AddRefResource(resource)) { - DLOG(WARNING) << "AddRefResource()ing a nonexistent resource " << resource; - } + ResourceTracker::Get()->AddRefResource(resource); } void ReleaseResource(PP_Resource resource) { - if (!ResourceTracker::Get()->UnrefResource(resource)) { - DLOG(WARNING) << "ReleaseResource()ing a nonexistent resource " << resource; - } + ResourceTracker::Get()->ReleaseResource(resource); } PP_Time GetTime() { diff --git a/webkit/plugins/ppapi/ppb_audio_impl.cc b/webkit/plugins/ppapi/ppb_audio_impl.cc index 4c74181..f13dda9 100644 --- a/webkit/plugins/ppapi/ppb_audio_impl.cc +++ b/webkit/plugins/ppapi/ppb_audio_impl.cc @@ -58,7 +58,7 @@ PPB_Audio_Impl::PPB_Audio_Impl(PluginInstance* instance) PPB_Audio_Impl::~PPB_Audio_Impl() { if (config_id_) - ResourceTracker::Get()->UnrefResource(config_id_); + ResourceTracker::Get()->ReleaseResource(config_id_); // Calling ShutDown() makes sure StreamCreated cannot be called anymore and // releases the audio data associated with the pointer. Note however, that diff --git a/webkit/plugins/ppapi/ppb_audio_impl.h b/webkit/plugins/ppapi/ppb_audio_impl.h index 2a3ae8a..4570a87 100644 --- a/webkit/plugins/ppapi/ppb_audio_impl.h +++ b/webkit/plugins/ppapi/ppb_audio_impl.h @@ -35,7 +35,7 @@ class PPB_AudioConfig_Impl : public Resource, PP_AudioSampleRate sample_rate, uint32_t sample_frame_count); - // ResourceObjectBase overrides. + // Resource overrides. virtual ::ppapi::thunk::PPB_AudioConfig_API* AsPPB_AudioConfig_API() OVERRIDE; private: @@ -69,7 +69,7 @@ class PPB_Audio_Impl : public Resource, bool Init(PP_Resource config_id, PPB_Audio_Callback user_callback, void* user_data); - // ResourceObjectBase overrides. + // Resource overrides. virtual ::ppapi::thunk::PPB_Audio_API* AsPPB_Audio_API(); // PPB_Audio_API implementation. diff --git a/webkit/plugins/ppapi/ppb_broker_impl.cc b/webkit/plugins/ppapi/ppb_broker_impl.cc index 8b41c28..46ff79f 100644 --- a/webkit/plugins/ppapi/ppb_broker_impl.cc +++ b/webkit/plugins/ppapi/ppb_broker_impl.cc @@ -69,10 +69,8 @@ int32_t PPB_Broker_Impl::Connect(PP_CompletionCallback connect_callback) { // and BrokerConnected is called before ConnectToPpapiBroker returns. // Because it must be created now, it must be aborted and cleared if // ConnectToPpapiBroker fails. - PP_Resource resource_id = GetReferenceNoAddRef(); - CHECK(resource_id); connect_callback_ = new TrackedCompletionCallback( - instance()->module()->GetCallbackTracker(), resource_id, + instance()->module()->GetCallbackTracker(), pp_resource(), connect_callback); broker_ = instance()->delegate()->ConnectToPpapiBroker(this); diff --git a/webkit/plugins/ppapi/ppb_broker_impl.h b/webkit/plugins/ppapi/ppb_broker_impl.h index 8e51321..c3a7434 100644 --- a/webkit/plugins/ppapi/ppb_broker_impl.h +++ b/webkit/plugins/ppapi/ppb_broker_impl.h @@ -27,7 +27,7 @@ class PPB_Broker_Impl : public Resource, explicit PPB_Broker_Impl(PluginInstance* instance); virtual ~PPB_Broker_Impl(); - // ResourceObjectBase override. + // Resource override. virtual ::ppapi::thunk::PPB_Broker_API* AsPPB_Broker_API() OVERRIDE; // PPB_BrokerTrusted implementation. diff --git a/webkit/plugins/ppapi/ppb_buffer_impl.h b/webkit/plugins/ppapi/ppb_buffer_impl.h index 41bc67a..47a7095 100644 --- a/webkit/plugins/ppapi/ppb_buffer_impl.h +++ b/webkit/plugins/ppapi/ppb_buffer_impl.h @@ -32,7 +32,7 @@ class PPB_Buffer_Impl : public Resource, base::SharedMemory* shared_memory() const { return shared_memory_.get(); } uint32_t size() const { return size_; } - // ResourceObjectBase overrides. + // Resource overrides. virtual ::ppapi::thunk::PPB_Buffer_API* AsPPB_Buffer_API() OVERRIDE; virtual ::ppapi::thunk::PPB_BufferTrusted_API* AsPPB_BufferTrusted_API(); diff --git a/webkit/plugins/ppapi/ppb_context_3d_impl.h b/webkit/plugins/ppapi/ppb_context_3d_impl.h index 4bdbe21..f1340e2 100644 --- a/webkit/plugins/ppapi/ppb_context_3d_impl.h +++ b/webkit/plugins/ppapi/ppb_context_3d_impl.h @@ -40,7 +40,7 @@ class PPB_Context3D_Impl : public Resource, PP_Resource share_context, const int32_t* attrib_list); - // ResourceObjectBase override. + // Resource override. virtual ::ppapi::thunk::PPB_Context3D_API* AsPPB_Context3D_API(); // PPB_Context3D_API implementation. diff --git a/webkit/plugins/ppapi/ppb_directory_reader_impl.cc b/webkit/plugins/ppapi/ppb_directory_reader_impl.cc index cb95b11..f758873 100644 --- a/webkit/plugins/ppapi/ppb_directory_reader_impl.cc +++ b/webkit/plugins/ppapi/ppb_directory_reader_impl.cc @@ -67,10 +67,8 @@ PP_Resource PPB_DirectoryReader_Impl::Create(PP_Resource directory_ref) { EnterResourceNoLock<PPB_FileRef_API> enter(directory_ref, true); if (enter.failed()) return 0; - - PPB_DirectoryReader_Impl* reader = new PPB_DirectoryReader_Impl( - static_cast<PPB_FileRef_Impl*>(enter.object())); - return reader->GetReference(); + return (new PPB_DirectoryReader_Impl( + static_cast<PPB_FileRef_Impl*>(enter.object())))->GetReference(); } PPB_DirectoryReader_API* PPB_DirectoryReader_Impl::AsPPB_DirectoryReader_API() { @@ -90,13 +88,10 @@ int32_t PPB_DirectoryReader_Impl::GetNextEntry( } PluginInstance* instance = directory_ref_->instance(); - PP_Resource resource_id = GetReferenceNoAddRef(); - DCHECK(resource_id != 0); if (!instance->delegate()->ReadDirectory( directory_ref_->GetFileSystemURL(), new FileCallbacks(instance->module()->AsWeakPtr(), - resource_id, - callback, NULL, NULL, this))) + pp_resource(), callback, NULL, NULL, this))) return PP_ERROR_FAILED; return PP_OK_COMPLETIONPENDING; @@ -128,7 +123,7 @@ bool PPB_DirectoryReader_Impl::FillUpEntry() { base::FileUtilProxy::Entry dir_entry = entries_.front(); entries_.pop(); if (entry_->file_ref) - ResourceTracker::Get()->UnrefResource(entry_->file_ref); + ResourceTracker::Get()->ReleaseResource(entry_->file_ref); PPB_FileRef_Impl* file_ref = new PPB_FileRef_Impl(instance(), directory_ref_->file_system(), FilePathStringToUTF8String(dir_entry.name)); diff --git a/webkit/plugins/ppapi/ppb_directory_reader_impl.h b/webkit/plugins/ppapi/ppb_directory_reader_impl.h index 4c58f47..cda9800 100644 --- a/webkit/plugins/ppapi/ppb_directory_reader_impl.h +++ b/webkit/plugins/ppapi/ppb_directory_reader_impl.h @@ -29,7 +29,7 @@ class PPB_DirectoryReader_Impl static PP_Resource Create(PP_Resource directory_ref); - // ResourceObjectBase overrides. + // Resource overrides. virtual ::ppapi::thunk::PPB_DirectoryReader_API* AsPPB_DirectoryReader_API() OVERRIDE; diff --git a/webkit/plugins/ppapi/ppb_file_chooser_impl.cc b/webkit/plugins/ppapi/ppb_file_chooser_impl.cc index 5fd777e..88ef8c4 100644 --- a/webkit/plugins/ppapi/ppb_file_chooser_impl.cc +++ b/webkit/plugins/ppapi/ppb_file_chooser_impl.cc @@ -80,9 +80,7 @@ PP_Resource PPB_FileChooser_Impl::Create( if ((options->mode != PP_FILECHOOSERMODE_OPEN) && (options->mode != PP_FILECHOOSERMODE_OPENMULTIPLE)) return 0; - - PPB_FileChooser_Impl* chooser = new PPB_FileChooser_Impl(instance, options); - return chooser->GetReference(); + return (new PPB_FileChooser_Impl(instance, options))->GetReference(); } PPB_FileChooser_Impl* PPB_FileChooser_Impl::AsPPB_FileChooser_Impl() { @@ -129,10 +127,8 @@ void PPB_FileChooser_Impl::RegisterCallback( DCHECK(callback.func); DCHECK(!callback_.get() || callback_->completed()); - PP_Resource resource_id = GetReferenceNoAddRef(); - CHECK(resource_id); callback_ = new TrackedCompletionCallback( - instance()->module()->GetCallbackTracker(), resource_id, callback); + instance()->module()->GetCallbackTracker(), pp_resource(), callback); } void PPB_FileChooser_Impl::RunCallback(int32_t result) { diff --git a/webkit/plugins/ppapi/ppb_file_chooser_impl.h b/webkit/plugins/ppapi/ppb_file_chooser_impl.h index 0f0f7bf..796ddd1 100644 --- a/webkit/plugins/ppapi/ppb_file_chooser_impl.h +++ b/webkit/plugins/ppapi/ppb_file_chooser_impl.h @@ -35,7 +35,7 @@ class PPB_FileChooser_Impl : public Resource, // Resource overrides. virtual PPB_FileChooser_Impl* AsPPB_FileChooser_Impl(); - // ResourceObjectBase overrides. + // Resource overrides. virtual ::ppapi::thunk::PPB_FileChooser_API* AsPPB_FileChooser_API() OVERRIDE; // Stores the list of selected files. diff --git a/webkit/plugins/ppapi/ppb_file_io_impl.cc b/webkit/plugins/ppapi/ppb_file_io_impl.cc index 5ac35b2..63021fa 100644 --- a/webkit/plugins/ppapi/ppb_file_io_impl.cc +++ b/webkit/plugins/ppapi/ppb_file_io_impl.cc @@ -314,10 +314,8 @@ void PPB_FileIO_Impl::RegisterCallback(OperationType op, (pending_op_ != OPERATION_EXCLUSIVE && pending_op_ == op)); CallbackEntry entry; - PP_Resource resource_id = GetReferenceNoAddRef(); - CHECK(resource_id); entry.callback = new TrackedCompletionCallback( - instance()->module()->GetCallbackTracker(), resource_id, callback); + instance()->module()->GetCallbackTracker(), pp_resource(), callback); entry.read_buffer = read_buffer; callbacks_.push(entry); diff --git a/webkit/plugins/ppapi/ppb_file_io_impl.h b/webkit/plugins/ppapi/ppb_file_io_impl.h index 4b90451..2426387 100644 --- a/webkit/plugins/ppapi/ppb_file_io_impl.h +++ b/webkit/plugins/ppapi/ppb_file_io_impl.h @@ -37,7 +37,7 @@ class PPB_FileIO_Impl : public Resource, explicit PPB_FileIO_Impl(PluginInstance* instance); virtual ~PPB_FileIO_Impl(); - // ResourceObjectBase overrides. + // Resource overrides. virtual ::ppapi::thunk::PPB_FileIO_API* AsPPB_FileIO_API() OVERRIDE; // PPB_FileIO_API implementation. diff --git a/webkit/plugins/ppapi/ppb_file_ref_impl.cc b/webkit/plugins/ppapi/ppb_file_ref_impl.cc index 00d5db4..1a1e397 100644 --- a/webkit/plugins/ppapi/ppb_file_ref_impl.cc +++ b/webkit/plugins/ppapi/ppb_file_ref_impl.cc @@ -97,10 +97,8 @@ PP_Resource PPB_FileRef_Impl::Create(PP_Resource pp_file_system, return 0; TrimTrailingSlash(&validated_path); - PPB_FileRef_Impl* file_ref = - new PPB_FileRef_Impl(file_system->instance(), - file_system, validated_path); - return file_ref->GetReference(); + return (new PPB_FileRef_Impl(file_system->instance(), + file_system, validated_path))->GetReference(); } PPB_FileRef_API* PPB_FileRef_Impl::AsPPB_FileRef_API() { @@ -176,8 +174,7 @@ int32_t PPB_FileRef_Impl::MakeDirectory(PP_Bool make_ancestors, if (!instance()->delegate()->MakeDirectory( GetFileSystemURL(), PP_ToBool(make_ancestors), new FileCallbacks(instance()->module()->AsWeakPtr(), - GetReferenceNoAddRef(), callback, - NULL, NULL, NULL))) + pp_resource(), callback, NULL, NULL, NULL))) return PP_ERROR_FAILED; return PP_OK_COMPLETIONPENDING; } @@ -192,8 +189,7 @@ int32_t PPB_FileRef_Impl::Touch(PP_Time last_access_time, PPTimeToTime(last_access_time), PPTimeToTime(last_modified_time), new FileCallbacks(instance()->module()->AsWeakPtr(), - GetReferenceNoAddRef(), callback, - NULL, NULL, NULL))) + pp_resource(), callback, NULL, NULL, NULL))) return PP_ERROR_FAILED; return PP_OK_COMPLETIONPENDING; } @@ -204,8 +200,7 @@ int32_t PPB_FileRef_Impl::Delete(PP_CompletionCallback callback) { if (!instance()->delegate()->Delete( GetFileSystemURL(), new FileCallbacks(instance()->module()->AsWeakPtr(), - GetReferenceNoAddRef(), callback, - NULL, NULL, NULL))) + pp_resource(), callback, NULL, NULL, NULL))) return PP_ERROR_FAILED; return PP_OK_COMPLETIONPENDING; } @@ -227,8 +222,7 @@ int32_t PPB_FileRef_Impl::Rename(PP_Resource new_pp_file_ref, if (!instance()->delegate()->Rename( GetFileSystemURL(), new_file_ref->GetFileSystemURL(), new FileCallbacks(instance()->module()->AsWeakPtr(), - GetReferenceNoAddRef(), callback, - NULL, NULL, NULL))) + pp_resource(), callback, NULL, NULL, NULL))) return PP_ERROR_FAILED; return PP_OK_COMPLETIONPENDING; } diff --git a/webkit/plugins/ppapi/ppb_file_ref_impl.h b/webkit/plugins/ppapi/ppb_file_ref_impl.h index fa3bfbd..7823c50 100644 --- a/webkit/plugins/ppapi/ppb_file_ref_impl.h +++ b/webkit/plugins/ppapi/ppb_file_ref_impl.h @@ -36,7 +36,7 @@ class PPB_FileRef_Impl : public Resource, // Resource overrides. virtual PPB_FileRef_Impl* AsPPB_FileRef_Impl(); - // ResourceObjectBase overrides. + // Resource overrides. virtual ::ppapi::thunk::PPB_FileRef_API* AsPPB_FileRef_API() OVERRIDE; // PPB_FileRef_API implementation. diff --git a/webkit/plugins/ppapi/ppb_file_system_impl.cc b/webkit/plugins/ppapi/ppb_file_system_impl.cc index 9ba9b3f..2a4bb05 100644 --- a/webkit/plugins/ppapi/ppb_file_system_impl.cc +++ b/webkit/plugins/ppapi/ppb_file_system_impl.cc @@ -46,9 +46,7 @@ PP_Resource PPB_FileSystem_Impl::Create(PluginInstance* instance, type != PP_FILESYSTEMTYPE_LOCALPERSISTENT && type != PP_FILESYSTEMTYPE_LOCALTEMPORARY) return 0; - - PPB_FileSystem_Impl* file_system = new PPB_FileSystem_Impl(instance, type); - return file_system->GetReference(); + return (new PPB_FileSystem_Impl(instance, type))->GetReference(); } PPB_FileSystem_API* PPB_FileSystem_Impl::AsPPB_FileSystem_API() { @@ -74,8 +72,7 @@ int32_t PPB_FileSystem_Impl::Open(int64_t expected_size, instance()->container()->element().document().url(), file_system_type, expected_size, new FileCallbacks(instance()->module()->AsWeakPtr(), - GetReferenceNoAddRef(), - callback, NULL, + pp_resource(), callback, NULL, scoped_refptr<PPB_FileSystem_Impl>(this), NULL))) return PP_ERROR_FAILED; return PP_OK_COMPLETIONPENDING; diff --git a/webkit/plugins/ppapi/ppb_file_system_impl.h b/webkit/plugins/ppapi/ppb_file_system_impl.h index b14685d..66b5ff2 100644 --- a/webkit/plugins/ppapi/ppb_file_system_impl.h +++ b/webkit/plugins/ppapi/ppb_file_system_impl.h @@ -28,7 +28,7 @@ class PPB_FileSystem_Impl : public Resource, static PP_Resource Create(PluginInstance* instance, PP_FileSystemType type); - // ResourceObjectBase overrides. + // Resource overrides. virtual ::ppapi::thunk::PPB_FileSystem_API* AsPPB_FileSystem_API() OVERRIDE; PluginInstance* instance() { return instance_; } diff --git a/webkit/plugins/ppapi/ppb_flash_menu_impl.cc b/webkit/plugins/ppapi/ppb_flash_menu_impl.cc index 959d9e2..80faa25 100644 --- a/webkit/plugins/ppapi/ppb_flash_menu_impl.cc +++ b/webkit/plugins/ppapi/ppb_flash_menu_impl.cc @@ -141,18 +141,12 @@ int32_t PPB_Flash_Menu_Impl::Show(const PP_Point* location, if (callback_.get() && !callback_->completed()) return PP_ERROR_INPROGRESS; - PP_Resource resource_id = GetReferenceNoAddRef(); - if (!resource_id) { - NOTREACHED(); - return PP_ERROR_FAILED; - } - int32_t rv = instance()->delegate()->ShowContextMenu( instance(), this, gfx::Point(location->x, location->y)); if (rv == PP_OK_COMPLETIONPENDING) { // Record callback and output buffers. callback_ = new TrackedCompletionCallback( - instance()->module()->GetCallbackTracker(), resource_id, callback); + instance()->module()->GetCallbackTracker(), pp_resource(), callback); selected_id_out_ = selected_id_out; } else { // This should never be completed synchronously successfully. diff --git a/webkit/plugins/ppapi/ppb_flash_menu_impl.h b/webkit/plugins/ppapi/ppb_flash_menu_impl.h index dcb56e4..9c6c6fb 100644 --- a/webkit/plugins/ppapi/ppb_flash_menu_impl.h +++ b/webkit/plugins/ppapi/ppb_flash_menu_impl.h @@ -29,7 +29,7 @@ class PPB_Flash_Menu_Impl : public Resource, static PP_Resource Create(PluginInstance* instance, const PP_Flash_Menu* menu_data); - // ResourceObjectBase. + // Resource. virtual ::ppapi::thunk::PPB_Flash_Menu_API* AsPPB_Flash_Menu_API() OVERRIDE; // PPB_Flash_Menu implementation. diff --git a/webkit/plugins/ppapi/ppb_flash_net_connector_impl.cc b/webkit/plugins/ppapi/ppb_flash_net_connector_impl.cc index ef8bc9c..820c3db 100644 --- a/webkit/plugins/ppapi/ppb_flash_net_connector_impl.cc +++ b/webkit/plugins/ppapi/ppb_flash_net_connector_impl.cc @@ -48,17 +48,11 @@ int32_t PPB_Flash_NetConnector_Impl::ConnectTcp( if (callback_.get() && !callback_->completed()) return PP_ERROR_INPROGRESS; - PP_Resource resource_id = GetReferenceNoAddRef(); - if (!resource_id) { - NOTREACHED(); - return PP_ERROR_FAILED; - } - int32_t rv = instance()->delegate()->ConnectTcp(this, host, port); if (rv == PP_OK_COMPLETIONPENDING) { // Record callback and output buffers. callback_ = new TrackedCompletionCallback( - instance()->module()->GetCallbackTracker(), resource_id, callback); + instance()->module()->GetCallbackTracker(), pp_resource(), callback); socket_out_ = socket_out; local_addr_out_ = local_addr_out; remote_addr_out_ = remote_addr_out; @@ -87,17 +81,11 @@ int32_t PPB_Flash_NetConnector_Impl::ConnectTcpAddress( if (callback_.get() && !callback_->completed()) return PP_ERROR_INPROGRESS; - PP_Resource resource_id = GetReferenceNoAddRef(); - if (!resource_id) { - NOTREACHED(); - return PP_ERROR_FAILED; - } - int32_t rv = instance()->delegate()->ConnectTcpAddress(this, addr); if (rv == PP_OK_COMPLETIONPENDING) { // Record callback and output buffers. callback_ = new TrackedCompletionCallback( - instance()->module()->GetCallbackTracker(), resource_id, callback); + instance()->module()->GetCallbackTracker(), pp_resource(), callback); socket_out_ = socket_out; local_addr_out_ = local_addr_out; remote_addr_out_ = remote_addr_out; diff --git a/webkit/plugins/ppapi/ppb_flash_net_connector_impl.h b/webkit/plugins/ppapi/ppb_flash_net_connector_impl.h index 8bd6013..3e90347 100644 --- a/webkit/plugins/ppapi/ppb_flash_net_connector_impl.h +++ b/webkit/plugins/ppapi/ppb_flash_net_connector_impl.h @@ -22,7 +22,7 @@ class PPB_Flash_NetConnector_Impl explicit PPB_Flash_NetConnector_Impl(PluginInstance* instance); virtual ~PPB_Flash_NetConnector_Impl(); - // ResourceObjectBase override. + // Resource override. virtual ::ppapi::thunk::PPB_Flash_NetConnector_API* AsPPB_Flash_NetConnector_API() OVERRIDE; diff --git a/webkit/plugins/ppapi/ppb_font_impl.cc b/webkit/plugins/ppapi/ppb_font_impl.cc index 0173dea..fbbddea 100644 --- a/webkit/plugins/ppapi/ppb_font_impl.cc +++ b/webkit/plugins/ppapi/ppb_font_impl.cc @@ -62,8 +62,7 @@ PP_Resource PPB_Font_Impl::Create(PluginInstance* instance, const PP_FontDescription_Dev& description) { if (!::ppapi::FontImpl::IsPPFontDescriptionValid(description)) return 0; - scoped_refptr<PPB_Font_Impl> font(new PPB_Font_Impl(instance, description)); - return font->GetReference(); + return (new PPB_Font_Impl(instance, description))->GetReference(); } ::ppapi::thunk::PPB_Font_API* PPB_Font_Impl::AsPPB_Font_API() { diff --git a/webkit/plugins/ppapi/ppb_font_impl.h b/webkit/plugins/ppapi/ppb_font_impl.h index 0096675..fce96be 100644 --- a/webkit/plugins/ppapi/ppb_font_impl.h +++ b/webkit/plugins/ppapi/ppb_font_impl.h @@ -29,7 +29,7 @@ class PPB_Font_Impl : public Resource, static PP_Resource Create(PluginInstance* instance, const PP_FontDescription_Dev& description); - // ResourceObjectBase. + // Resource. virtual ::ppapi::thunk::PPB_Font_API* AsPPB_Font_API() OVERRIDE; // PPB_Font implementation. diff --git a/webkit/plugins/ppapi/ppb_graphics_3d_impl.cc b/webkit/plugins/ppapi/ppb_graphics_3d_impl.cc index 766be45..470fbf5 100644 --- a/webkit/plugins/ppapi/ppb_graphics_3d_impl.cc +++ b/webkit/plugins/ppapi/ppb_graphics_3d_impl.cc @@ -66,10 +66,8 @@ PP_Resource PPB_Graphics3D_Impl::Create(PluginInstance* instance, const int32_t* attrib_list) { scoped_refptr<PPB_Graphics3D_Impl> graphics_3d( new PPB_Graphics3D_Impl(instance)); - if (!graphics_3d->Init(share_context, attrib_list)) return 0; - return graphics_3d->GetReference(); } @@ -78,10 +76,8 @@ PP_Resource PPB_Graphics3D_Impl::CreateRaw(PluginInstance* instance, const int32_t* attrib_list) { scoped_refptr<PPB_Graphics3D_Impl> graphics_3d( new PPB_Graphics3D_Impl(instance)); - if (!graphics_3d->InitRaw(share_context, attrib_list)) return 0; - return graphics_3d->GetReference(); } diff --git a/webkit/plugins/ppapi/ppb_graphics_3d_impl.h b/webkit/plugins/ppapi/ppb_graphics_3d_impl.h index 461ce06..9bcc1c7 100644 --- a/webkit/plugins/ppapi/ppb_graphics_3d_impl.h +++ b/webkit/plugins/ppapi/ppb_graphics_3d_impl.h @@ -25,7 +25,7 @@ class PPB_Graphics3D_Impl : public Resource, PP_Resource share_context, const int32_t* attrib_list); - // ResourceObjectBase override. + // Resource override. virtual ::ppapi::thunk::PPB_Graphics3D_API* AsPPB_Graphics3D_API() OVERRIDE; // PPB_Graphics3D_API trusted implementation. diff --git a/webkit/plugins/ppapi/ppb_input_event_impl.cc b/webkit/plugins/ppapi/ppb_input_event_impl.cc index ffb6cba..f2383b0 100644 --- a/webkit/plugins/ppapi/ppb_input_event_impl.cc +++ b/webkit/plugins/ppapi/ppb_input_event_impl.cc @@ -25,9 +25,7 @@ PPB_InputEvent_Impl::PPB_InputEvent_Impl(PluginInstance* instance, // static PP_Resource PPB_InputEvent_Impl::Create(PluginInstance* instance, const InputEventData& data) { - scoped_refptr<PPB_InputEvent_Impl> event( - new PPB_InputEvent_Impl(instance, data)); - return event->GetReference(); + return (new PPB_InputEvent_Impl(instance, data))->GetReference(); } PPB_InputEvent_API* PPB_InputEvent_Impl::AsPPB_InputEvent_API() { diff --git a/webkit/plugins/ppapi/ppb_input_event_impl.h b/webkit/plugins/ppapi/ppb_input_event_impl.h index f2bd982..48bc3fb 100644 --- a/webkit/plugins/ppapi/ppb_input_event_impl.h +++ b/webkit/plugins/ppapi/ppb_input_event_impl.h @@ -21,7 +21,7 @@ class PPB_InputEvent_Impl : public Resource, static PP_Resource Create(PluginInstance* instance, const ::ppapi::InputEventData& data); - // ResourceObjectBase overrides. + // Resource overrides. virtual ::ppapi::thunk::PPB_InputEvent_API* AsPPB_InputEvent_API() OVERRIDE; protected: diff --git a/webkit/plugins/ppapi/ppb_layer_compositor_impl.h b/webkit/plugins/ppapi/ppb_layer_compositor_impl.h index 601cfa0..b35264f 100644 --- a/webkit/plugins/ppapi/ppb_layer_compositor_impl.h +++ b/webkit/plugins/ppapi/ppb_layer_compositor_impl.h @@ -25,7 +25,7 @@ class PPB_LayerCompositor_Impl static const PPB_LayerCompositor_Dev* GetInterface(); - // ResourceObjectBase override. + // Resource override. virtual PPB_LayerCompositor_API* AsPPB_LayerCompositor_API(); // PPB_LayerCompositor_API implementation. diff --git a/webkit/plugins/ppapi/ppb_proxy_impl.cc b/webkit/plugins/ppapi/ppb_proxy_impl.cc index 1660b71..630e1e0 100644 --- a/webkit/plugins/ppapi/ppb_proxy_impl.cc +++ b/webkit/plugins/ppapi/ppb_proxy_impl.cc @@ -28,10 +28,10 @@ void PluginCrashed(PP_Module module) { } PP_Instance GetInstanceForResource(PP_Resource resource) { - scoped_refptr<Resource> obj(ResourceTracker::Get()->GetResource(resource)); + ::ppapi::Resource* obj = ResourceTracker::Get()->GetResource(resource); if (!obj) return 0; - return obj->instance()->pp_instance(); + return obj->pp_instance(); } void SetReserveInstanceIDCallback(PP_Module module, diff --git a/webkit/plugins/ppapi/ppb_scrollbar_impl.h b/webkit/plugins/ppapi/ppb_scrollbar_impl.h index 7ffbbcf..a10e694 100644 --- a/webkit/plugins/ppapi/ppb_scrollbar_impl.h +++ b/webkit/plugins/ppapi/ppb_scrollbar_impl.h @@ -28,7 +28,7 @@ class PPB_Scrollbar_Impl : public PPB_Widget_Impl, virtual ~PPB_Scrollbar_Impl(); - // ResourceObjectBase override. + // Resource override. virtual PPB_Scrollbar_API* AsPPB_Scrollbar_API() OVERRIDE; // Returns a pointer to the interface implementing PPB_Scrollbar_0_3 that is diff --git a/webkit/plugins/ppapi/ppb_surface_3d_impl.cc b/webkit/plugins/ppapi/ppb_surface_3d_impl.cc index 81d761f..fe26514 100644 --- a/webkit/plugins/ppapi/ppb_surface_3d_impl.cc +++ b/webkit/plugins/ppapi/ppb_surface_3d_impl.cc @@ -71,10 +71,8 @@ int32_t PPB_Surface3D_Impl::SwapBuffers(PP_CompletionCallback callback) { if (!context_) return PP_ERROR_FAILED; - PP_Resource resource_id = GetReferenceNoAddRef(); - CHECK(resource_id); swap_callback_ = new TrackedCompletionCallback( - instance()->module()->GetCallbackTracker(), resource_id, callback); + instance()->module()->GetCallbackTracker(), pp_resource(), callback); gpu::gles2::GLES2Implementation* impl = context_->gles2_impl(); if (impl) context_->gles2_impl()->SwapBuffers(); diff --git a/webkit/plugins/ppapi/ppb_surface_3d_impl.h b/webkit/plugins/ppapi/ppb_surface_3d_impl.h index 24a66e5..11703af 100644 --- a/webkit/plugins/ppapi/ppb_surface_3d_impl.h +++ b/webkit/plugins/ppapi/ppb_surface_3d_impl.h @@ -29,7 +29,7 @@ class PPB_Surface3D_Impl : public Resource, PP_Config3D_Dev config, const int32_t* attrib_list); - // ResourceObjectBase override. + // Resource override. virtual ::ppapi::thunk::PPB_Surface3D_API* AsPPB_Surface3D_API() OVERRIDE; // PPB_Surface3D_API implementation. diff --git a/webkit/plugins/ppapi/ppb_transport_impl.cc b/webkit/plugins/ppapi/ppb_transport_impl.cc index 0e68931..55a46e8 100644 --- a/webkit/plugins/ppapi/ppb_transport_impl.cc +++ b/webkit/plugins/ppapi/ppb_transport_impl.cc @@ -113,10 +113,8 @@ int32_t PPB_Transport_Impl::Connect(PP_CompletionCallback callback) { started_ = true; - PP_Resource resource_id = GetReferenceNoAddRef(); - CHECK(resource_id); connect_callback_ = new TrackedCompletionCallback( - instance()->module()->GetCallbackTracker(), resource_id, callback); + instance()->module()->GetCallbackTracker(), pp_resource(), callback); return PP_OK_COMPLETIONPENDING; } @@ -135,10 +133,8 @@ int32_t PPB_Transport_Impl::GetNextAddress(PP_Var* address, return PP_OK; } - PP_Resource resource_id = GetReferenceNoAddRef(); - CHECK(resource_id); next_address_callback_ = new TrackedCompletionCallback( - instance()->module()->GetCallbackTracker(), resource_id, callback); + instance()->module()->GetCallbackTracker(), pp_resource(), callback); return PP_OK_COMPLETIONPENDING; } @@ -170,10 +166,8 @@ int32_t PPB_Transport_Impl::Recv(void* data, uint32_t len, new net::WrappedIOBuffer(static_cast<const char*>(data)); int result = MapNetError(channel->Read(buffer, len, &channel_read_callback_)); if (result == PP_OK_COMPLETIONPENDING) { - PP_Resource resource_id = GetReferenceNoAddRef(); - CHECK(resource_id); recv_callback_ = new TrackedCompletionCallback( - instance()->module()->GetCallbackTracker(), resource_id, callback); + instance()->module()->GetCallbackTracker(), pp_resource(), callback); } return result; @@ -196,10 +190,8 @@ int32_t PPB_Transport_Impl::Send(const void* data, uint32_t len, int result = MapNetError(channel->Write(buffer, len, &channel_write_callback_)); if (result == PP_OK_COMPLETIONPENDING) { - PP_Resource resource_id = GetReferenceNoAddRef(); - CHECK(resource_id); send_callback_ = new TrackedCompletionCallback( - instance()->module()->GetCallbackTracker(), resource_id, callback); + instance()->module()->GetCallbackTracker(), pp_resource(), callback); } return result; diff --git a/webkit/plugins/ppapi/ppb_transport_impl.h b/webkit/plugins/ppapi/ppb_transport_impl.h index e7d9760..f1219cb 100644 --- a/webkit/plugins/ppapi/ppb_transport_impl.h +++ b/webkit/plugins/ppapi/ppb_transport_impl.h @@ -29,7 +29,7 @@ class PPB_Transport_Impl : public Resource, const char* name, const char* proto); - // ResourceObjectBase override. + // Resource override. virtual ::ppapi::thunk::PPB_Transport_API* AsPPB_Transport_API() OVERRIDE; // PPB_Transport_API implementation. diff --git a/webkit/plugins/ppapi/ppb_url_loader_impl.cc b/webkit/plugins/ppapi/ppb_url_loader_impl.cc index 6fb46ef..95349b7 100644 --- a/webkit/plugins/ppapi/ppb_url_loader_impl.cc +++ b/webkit/plugins/ppapi/ppb_url_loader_impl.cc @@ -76,8 +76,8 @@ PPB_URLLoader_API* PPB_URLLoader_Impl::AsPPB_URLLoader_API() { return this; } -void PPB_URLLoader_Impl::ClearInstance() { - Resource::ClearInstance(); +void PPB_URLLoader_Impl::InstanceWasDeleted() { + Resource::InstanceWasDeleted(); loader_.reset(); } @@ -362,10 +362,8 @@ void PPB_URLLoader_Impl::RegisterCallback(PP_CompletionCallback callback) { DCHECK(callback.func); DCHECK(!pending_callback_.get() || pending_callback_->completed()); - PP_Resource resource_id = GetReferenceNoAddRef(); - CHECK(resource_id); pending_callback_ = new TrackedCompletionCallback( - instance()->module()->GetCallbackTracker(), resource_id, callback); + instance()->module()->GetCallbackTracker(), pp_resource(), callback); } void PPB_URLLoader_Impl::RunCallback(int32_t result) { @@ -414,24 +412,17 @@ void PPB_URLLoader_Impl::SaveResponse(const WebURLResponse& response) { void PPB_URLLoader_Impl::UpdateStatus() { if (status_callback_ && (RecordDownloadProgress() || RecordUploadProgress())) { - PP_Resource pp_resource = GetReferenceNoAddRef(); - if (pp_resource) { - // The PP_Resource on the plugin will be NULL if the plugin has no - // reference to this object. That's fine, because then we don't need to - // call UpdateStatus. - // - // Here we go through some effort to only send the exact information that - // the requestor wanted in the request flags. It would be just as - // efficient to send all of it, but we don't want people to rely on - // getting download progress when they happen to set the upload progress - // flag. - status_callback_( - instance()->pp_instance(), pp_resource, - RecordUploadProgress() ? bytes_sent_ : -1, - RecordUploadProgress() ? total_bytes_to_be_sent_ : -1, - RecordDownloadProgress() ? bytes_received_ : -1, - RecordDownloadProgress() ? total_bytes_to_be_received_ : -1); - } + // Here we go through some effort to only send the exact information that + // the requestor wanted in the request flags. It would be just as + // efficient to send all of it, but we don't want people to rely on + // getting download progress when they happen to set the upload progress + // flag. + status_callback_( + instance()->pp_instance(), pp_resource(), + RecordUploadProgress() ? bytes_sent_ : -1, + RecordUploadProgress() ? total_bytes_to_be_sent_ : -1, + RecordDownloadProgress() ? bytes_received_ : -1, + RecordDownloadProgress() ? total_bytes_to_be_received_ : -1); } } diff --git a/webkit/plugins/ppapi/ppb_url_loader_impl.h b/webkit/plugins/ppapi/ppb_url_loader_impl.h index 585411c..d067ebf 100644 --- a/webkit/plugins/ppapi/ppb_url_loader_impl.h +++ b/webkit/plugins/ppapi/ppb_url_loader_impl.h @@ -36,11 +36,9 @@ class PPB_URLLoader_Impl : public Resource, PPB_URLLoader_Impl(PluginInstance* instance, bool main_document_loader); virtual ~PPB_URLLoader_Impl(); - // ResourceObjectBase overrides. - virtual ::ppapi::thunk::PPB_URLLoader_API* AsPPB_URLLoader_API() OVERRIDE; - // Resource overrides. - virtual void ClearInstance() OVERRIDE; + virtual ::ppapi::thunk::PPB_URLLoader_API* AsPPB_URLLoader_API() OVERRIDE; + virtual void InstanceWasDeleted() OVERRIDE; // PPB_URLLoader_API implementation. virtual int32_t Open(PP_Resource request_id, diff --git a/webkit/plugins/ppapi/ppb_url_request_info_impl.h b/webkit/plugins/ppapi/ppb_url_request_info_impl.h index e937b88..c0ec99b 100644 --- a/webkit/plugins/ppapi/ppb_url_request_info_impl.h +++ b/webkit/plugins/ppapi/ppb_url_request_info_impl.h @@ -29,7 +29,7 @@ class PPB_URLRequestInfo_Impl : public Resource, explicit PPB_URLRequestInfo_Impl(PluginInstance* instance); virtual ~PPB_URLRequestInfo_Impl(); - // ResourceObjectBase overrides. + // Resource overrides. virtual PPB_URLRequestInfo_API* AsPPB_URLRequestInfo_API() OVERRIDE; // PPB_URLRequestInfo implementation. diff --git a/webkit/plugins/ppapi/ppb_url_response_info_impl.h b/webkit/plugins/ppapi/ppb_url_response_info_impl.h index 10f44ea..5c50746 100644 --- a/webkit/plugins/ppapi/ppb_url_response_info_impl.h +++ b/webkit/plugins/ppapi/ppb_url_response_info_impl.h @@ -30,7 +30,7 @@ class PPB_URLResponseInfo_Impl bool Initialize(const WebKit::WebURLResponse& response); - // ResourceObjectBase overrides. + // Resource overrides. virtual PPB_URLResponseInfo_API* AsPPB_URLResponseInfo_API() OVERRIDE; // PPB_URLResponseInfo_API implementation. diff --git a/webkit/plugins/ppapi/ppb_video_capture_impl.cc b/webkit/plugins/ppapi/ppb_video_capture_impl.cc index c112fce..3663853 100644 --- a/webkit/plugins/ppapi/ppb_video_capture_impl.cc +++ b/webkit/plugins/ppapi/ppb_video_capture_impl.cc @@ -219,7 +219,7 @@ void PPB_VideoCapture_Impl::OnDeviceInfoReceived( info.buffer = static_cast<PPB_Buffer_Impl*>(enter.object()); info.data = info.buffer->Map(); if (!info.data) { - ResourceTracker::Get()->UnrefResource(resources[i]); + ResourceTracker::Get()->ReleaseResource(resources[i]); break; } buffers_.push_back(info); @@ -247,7 +247,7 @@ void PPB_VideoCapture_Impl::ReleaseBuffers() { ResourceTracker *tracker = ResourceTracker::Get(); for (size_t i = 0; i < buffers_.size(); ++i) { buffers_[i].buffer->Unmap(); - tracker->UnrefResource(buffers_[i].buffer->GetReferenceNoAddRef()); + tracker->ReleaseResource(buffers_[i].buffer->pp_resource()); } buffers_.clear(); } diff --git a/webkit/plugins/ppapi/ppb_video_capture_impl.h b/webkit/plugins/ppapi/ppb_video_capture_impl.h index be24f23..d05747d 100644 --- a/webkit/plugins/ppapi/ppb_video_capture_impl.h +++ b/webkit/plugins/ppapi/ppb_video_capture_impl.h @@ -35,7 +35,7 @@ class PPB_VideoCapture_Impl : public Resource, bool Init(); - // ResourceObjectBase overrides. + // Resource overrides. virtual PPB_VideoCapture_API* AsPPB_VideoCapture_API() OVERRIDE; // PPB_VideoCapture implementation. diff --git a/webkit/plugins/ppapi/ppb_video_decoder_impl.cc b/webkit/plugins/ppapi/ppb_video_decoder_impl.cc index 9c8b37e..919a1c8 100644 --- a/webkit/plugins/ppapi/ppb_video_decoder_impl.cc +++ b/webkit/plugins/ppapi/ppb_video_decoder_impl.cc @@ -246,13 +246,6 @@ void PPB_VideoDecoder_Impl::NotifyFlushDone() { void PPB_VideoDecoder_Impl::NotifyInitializeDone() { NOTREACHED() << "PlatformVideoDecoder::Initialize() is synchronous!"; } -void PPB_VideoDecoder_Impl::AddRefResource(PP_Resource resource) { - ResourceTracker::Get()->AddRefResource(resource); -} - -void PPB_VideoDecoder_Impl::UnrefResource(PP_Resource resource) { - ResourceTracker::Get()->UnrefResource(resource); -} } // namespace ppapi } // namespace webkit diff --git a/webkit/plugins/ppapi/ppb_video_decoder_impl.h b/webkit/plugins/ppapi/ppb_video_decoder_impl.h index 09f638e..7f0848d 100644 --- a/webkit/plugins/ppapi/ppb_video_decoder_impl.h +++ b/webkit/plugins/ppapi/ppb_video_decoder_impl.h @@ -53,7 +53,7 @@ class PPB_VideoDecoder_Impl : public Resource, PP_Resource context3d_id, const PP_VideoConfigElement* config); - // ResourceObjectBase overrides. + // Resource overrides. virtual PPB_VideoDecoder_API* AsPPB_VideoDecoder_API() OVERRIDE; // PPB_VideoDecoder_API implementation. @@ -84,8 +84,6 @@ class PPB_VideoDecoder_Impl : public Resource, virtual bool Init(PP_Resource context3d_id, ::ppapi::thunk::PPB_Context3D_API* context, const PP_VideoConfigElement* dec_config) OVERRIDE; - virtual void AddRefResource(PP_Resource resource) OVERRIDE; - virtual void UnrefResource(PP_Resource resource) OVERRIDE; private: explicit PPB_VideoDecoder_Impl(PluginInstance* instance); diff --git a/webkit/plugins/ppapi/ppb_video_layer_impl.cc b/webkit/plugins/ppapi/ppb_video_layer_impl.cc index 1782109..e7cad6f 100644 --- a/webkit/plugins/ppapi/ppb_video_layer_impl.cc +++ b/webkit/plugins/ppapi/ppb_video_layer_impl.cc @@ -25,10 +25,7 @@ PP_Resource PPB_VideoLayer_Impl::Create(PluginInstance* instance, PP_VideoLayerMode_Dev mode) { if (mode != PP_VIDEOLAYERMODE_SOFTWARE) return 0; - - scoped_refptr<PPB_VideoLayer_Impl> layer( - new PPB_VideoLayer_Software(instance)); - return layer->GetReference(); + return (new PPB_VideoLayer_Software(instance))->GetReference(); } PPB_VideoLayer_API* PPB_VideoLayer_Impl::AsPPB_VideoLayer_API() { diff --git a/webkit/plugins/ppapi/ppb_video_layer_impl.h b/webkit/plugins/ppapi/ppb_video_layer_impl.h index 091608f..7449b57 100644 --- a/webkit/plugins/ppapi/ppb_video_layer_impl.h +++ b/webkit/plugins/ppapi/ppb_video_layer_impl.h @@ -24,7 +24,7 @@ class PPB_VideoLayer_Impl : public Resource, static PP_Resource Create(PluginInstance* instance, PP_VideoLayerMode_Dev mode); - // ResourceObjectBase override. + // Resource override. virtual PPB_VideoLayer_API* AsPPB_VideoLayer_API() OVERRIDE; // Derived classes must implement PPB_VideoLayer_API. diff --git a/webkit/plugins/ppapi/ppb_widget_impl.h b/webkit/plugins/ppapi/ppb_widget_impl.h index dda41d0..b8ebc71 100644 --- a/webkit/plugins/ppapi/ppb_widget_impl.h +++ b/webkit/plugins/ppapi/ppb_widget_impl.h @@ -32,7 +32,7 @@ class PPB_Widget_Impl : public Resource, explicit PPB_Widget_Impl(PluginInstance* instance); virtual ~PPB_Widget_Impl(); - // ResourceObjectBase overrides. + // Resource overrides. virtual ::ppapi::thunk::PPB_Widget_API* AsPPB_Widget_API() OVERRIDE; // PPB_WidgetAPI implementation. diff --git a/webkit/plugins/ppapi/resource.cc b/webkit/plugins/ppapi/resource.cc index cb4ae37..a84e1d3 100644 --- a/webkit/plugins/ppapi/resource.cc +++ b/webkit/plugins/ppapi/resource.cc @@ -14,40 +14,29 @@ namespace webkit { namespace ppapi { Resource::Resource(PluginInstance* instance) - : ResourceObjectBase(instance->pp_instance()), - resource_id_(0), + : ::ppapi::Resource(instance->pp_instance()), instance_(instance) { - ResourceTracker::Get()->ResourceCreated(this, instance_); } Resource::~Resource() { - ResourceTracker::Get()->ResourceDestroyed(this); } PP_Resource Resource::GetReference() { - ResourceTracker *tracker = ResourceTracker::Get(); - if (resource_id_) - tracker->AddRefResource(resource_id_); - else - resource_id_ = tracker->AddResource(this); - return resource_id_; + ResourceTracker* tracker = ResourceTracker::Get(); + tracker->AddRefResource(pp_resource()); + return pp_resource(); } -PP_Resource Resource::GetReferenceNoAddRef() const { - return resource_id_; +void Resource::LastPluginRefWasDeleted() { + instance()->module()->GetCallbackTracker()->PostAbortForResource( + pp_resource()); } -void Resource::ClearInstance() { +void Resource::InstanceWasDeleted() { + ::ppapi::Resource::InstanceWasDeleted(); instance_ = NULL; } -void Resource::LastPluginRefWasDeleted() { - DCHECK(resource_id_ != 0); - instance()->module()->GetCallbackTracker()->PostAbortForResource( - resource_id_); - resource_id_ = 0; -} - } // namespace ppapi } // namespace webkit diff --git a/webkit/plugins/ppapi/resource.h b/webkit/plugins/ppapi/resource.h index 445fd58..2514177 100644 --- a/webkit/plugins/ppapi/resource.h +++ b/webkit/plugins/ppapi/resource.h @@ -6,14 +6,15 @@ #define WEBKIT_PLUGINS_PPAPI_RESOURCE_H_ #include "base/basictypes.h" +#include "base/compiler_specific.h" #include "ppapi/c/pp_resource.h" -#include "ppapi/shared_impl/resource_object_base.h" +#include "ppapi/shared_impl/resource.h" #include "webkit/plugins/ppapi/resource_tracker.h" namespace webkit { namespace ppapi { -class Resource : public ::ppapi::ResourceObjectBase { +class Resource : public ::ppapi::Resource { public: explicit Resource(PluginInstance* instance); virtual ~Resource(); @@ -23,30 +24,12 @@ class Resource : public ::ppapi::ResourceObjectBase { // PPAPI implementation is keeping a reference for some reason. PluginInstance* instance() const { return instance_; } - // Clears the instance pointer when the associated PluginInstance will be - // destroyed. - // - // If you override this, be sure to call the base class' implementation. - virtual void ClearInstance(); - // Returns an resource id of this object. If the object doesn't have a // resource id, new one is created with plugin refcount of 1. If it does, // the refcount is incremented. Use this when you need to return a new // reference to the plugin. PP_Resource GetReference(); - // Returns the resource ID of this object OR NULL IF THERE IS NONE ASSIGNED. - // This will happen if the plugin doesn't have a reference to the given - // resource. The resource will not be addref'ed. - // - // This should only be used as an input parameter to the plugin for status - // updates in the proxy layer, where if the plugin has no reference, it will - // just give up since nothing needs to be updated. - // - // Generally you should use GetReference instead. This is why it has this - // obscure name rather than pp_resource(). - PP_Resource GetReferenceNoAddRef() const; - // When you need to ensure that a resource has a reference, but you do not // want to increase the refcount (for example, if you need to call a plugin // callback function with a reference), you can use this class. For example: @@ -57,28 +40,16 @@ class Resource : public ::ppapi::ResourceObjectBase { explicit ScopedResourceId(Resource* resource) : id(resource->GetReference()) {} ~ScopedResourceId() { - ResourceTracker::Get()->UnrefResource(id); + ResourceTracker::Get()->ReleaseResource(id); } const PP_Resource id; }; - // Called by the resource tracker when the last reference from the plugin - // was released. For a few types of resources, the resource could still - // stay alive if there are other references held by the PPAPI implementation - // (possibly for callbacks and things). - // - // If you override this, be sure to call the base class' implementation. - virtual void LastPluginRefWasDeleted(); + // Resource implementation. + virtual void LastPluginRefWasDeleted() OVERRIDE; + virtual void InstanceWasDeleted() OVERRIDE; private: - // If referenced by a plugin, holds the id of this resource object. Do not - // access this member directly, because it is possible that the plugin holds - // no references to the object, and therefore the resource_id_ is zero. Use - // either GetReference() to obtain a new resource_id and increase the - // refcount, or TemporaryReference when you do not want to increase the - // refcount. - PP_Resource resource_id_; - // Non-owning pointer to our instance. See getter above. PluginInstance* instance_; diff --git a/webkit/plugins/ppapi/resource_creation_impl.cc b/webkit/plugins/ppapi/resource_creation_impl.cc index 97e1988..720f8a4 100644 --- a/webkit/plugins/ppapi/resource_creation_impl.cc +++ b/webkit/plugins/ppapi/resource_creation_impl.cc @@ -39,30 +39,6 @@ using ppapi::StringVar; namespace webkit { namespace ppapi { -namespace { - -// We use two methods for creating resources. When the resource initialization -// is simple and can't fail, just do -// return ReturnResource(new PPB_Foo_Impl(instance_, ...)); -// This will set up everything necessary. -// -// If the resource is more complex, generally the best thing is to write a -// static "Create" function on the resource class that returns a PP_Resource -// or 0 on failure. That helps keep the resource-specific stuff localized and -// this class very simple. -PP_Resource ReturnResource(Resource* resource) { - // We actually have to keep a ref here since the argument will not be ref'ed - // at all if it was just passed in with new (the expected usage). The - // returned PP_Resource created by GetReference will hold onto a ref on - // behalf of the plugin which will outlive this function. So the end result - // will be a Resource with one ref. - scoped_refptr<Resource> ref(resource); - return resource->GetReference(); -} - -} // namespace - - ResourceCreationImpl::ResourceCreationImpl(PluginInstance* instance) : instance_(instance) { } @@ -94,11 +70,11 @@ PP_Resource ResourceCreationImpl::CreateAudioConfig( PP_Resource ResourceCreationImpl::CreateAudioTrusted( PP_Instance instance_id) { - return ReturnResource(new PPB_Audio_Impl(instance_)); + return (new PPB_Audio_Impl(instance_))->GetReference(); } PP_Resource ResourceCreationImpl::CreateBroker(PP_Instance instance) { - return ReturnResource(new PPB_Broker_Impl(instance_)); + return (new PPB_Broker_Impl(instance_))->GetReference(); } PP_Resource ResourceCreationImpl::CreateBuffer(PP_Instance instance, @@ -136,7 +112,7 @@ PP_Resource ResourceCreationImpl::CreateFileChooser( } PP_Resource ResourceCreationImpl::CreateFileIO(PP_Instance instance) { - return ReturnResource(new PPB_FileIO_Impl(instance_)); + return (new PPB_FileIO_Impl(instance_))->GetReference(); } PP_Resource ResourceCreationImpl::CreateFileRef(PP_Resource file_system, @@ -158,7 +134,7 @@ PP_Resource ResourceCreationImpl::CreateFlashMenu( PP_Resource ResourceCreationImpl::CreateFlashNetConnector( PP_Instance instance) { - return ReturnResource(new PPB_Flash_NetConnector_Impl(instance_)); + return (new PPB_Flash_NetConnector_Impl(instance_))->GetReference(); } PP_Resource ResourceCreationImpl::CreateFlashTCPSocket( @@ -274,11 +250,11 @@ PP_Resource ResourceCreationImpl::CreateTransport(PP_Instance instance, } PP_Resource ResourceCreationImpl::CreateURLLoader(PP_Instance instance) { - return ReturnResource(new PPB_URLLoader_Impl(instance_, false)); + return (new PPB_URLLoader_Impl(instance_, false))->GetReference(); } PP_Resource ResourceCreationImpl::CreateURLRequestInfo(PP_Instance instance) { - return ReturnResource(new PPB_URLRequestInfo_Impl(instance_)); + return (new PPB_URLRequestInfo_Impl(instance_))->GetReference(); } PP_Resource ResourceCreationImpl::CreateVideoCapture(PP_Instance instance) { @@ -286,7 +262,7 @@ PP_Resource ResourceCreationImpl::CreateVideoCapture(PP_Instance instance) { new PPB_VideoCapture_Impl(instance_); if (!video_capture->Init()) return 0; - return ReturnResource(video_capture); + return video_capture->GetReference(); } PP_Resource ResourceCreationImpl::CreateVideoDecoder( diff --git a/webkit/plugins/ppapi/resource_tracker.cc b/webkit/plugins/ppapi/resource_tracker.cc index 5e15103..1405a30 100644 --- a/webkit/plugins/ppapi/resource_tracker.cc +++ b/webkit/plugins/ppapi/resource_tracker.cc @@ -50,10 +50,6 @@ struct ResourceTracker::InstanceData { // destroyed, it will notify us and we'll delete all associated data. PluginInstance* instance; - // Resources associated with the instance. - ResourceSet ref_resources; - std::set<Resource*> assoc_resources; - // Tracks all live NPObjectVars used by this module so we can map NPObjects // to the corresponding object, and also release these properly if the // instance goes away when there are still refs. These are non-owning @@ -65,16 +61,6 @@ struct ResourceTracker::InstanceData { function_proxies[::pp::proxy::INTERFACE_ID_COUNT]; }; -scoped_refptr<Resource> ResourceTracker::GetResource(PP_Resource res) const { - DLOG_IF(ERROR, !CheckIdType(res, ::ppapi::PP_ID_TYPE_RESOURCE)) - << res << " is not a PP_Resource."; - ResourceMap::const_iterator result = live_resources_.find(res); - if (result == live_resources_.end()) { - return scoped_refptr<Resource>(); - } - return result->second.first; -} - // static ResourceTracker* ResourceTracker::global_tracker_ = NULL; ResourceTracker* ResourceTracker::singleton_override_ = NULL; @@ -97,81 +83,6 @@ ResourceTracker* ResourceTracker::Get() { return global_tracker_; } -void ResourceTracker::ResourceCreated(Resource* resource, - PluginInstance* instance) { - if (!instance) - return; - PP_Instance pp_instance = instance->pp_instance(); - DCHECK(pp_instance); - DCHECK(instance_map_.find(pp_instance) != instance_map_.end()); - instance_map_[pp_instance]->assoc_resources.insert(resource); -} - -void ResourceTracker::ResourceDestroyed(Resource* resource) { - if (!resource->instance()) - return; - - PP_Instance pp_instance = resource->instance()->pp_instance(); - DCHECK(pp_instance); - DCHECK(instance_map_.find(pp_instance) != instance_map_.end()); - - instance_map_[pp_instance]->assoc_resources.erase(resource); -} - -PP_Resource ResourceTracker::AddResource(Resource* resource) { - // If the plugin manages to create 1 billion resources, don't do crazy stuff. - if (last_resource_id_ == - (std::numeric_limits<PP_Resource>::max() >> ::ppapi::kPPIdTypeBits)) - return 0; - - // Add the resource with plugin use-count 1. - PP_Resource new_id = MakeTypedId(++last_resource_id_, - ::ppapi::PP_ID_TYPE_RESOURCE); - live_resources_.insert(std::make_pair(new_id, std::make_pair(resource, 1))); - - // Track associated with the instance. - PP_Instance pp_instance = resource->instance()->pp_instance(); - DCHECK(instance_map_.find(pp_instance) != instance_map_.end()); - instance_map_[pp_instance]->ref_resources.insert(new_id); - return new_id; -} - -bool ResourceTracker::AddRefResource(PP_Resource res) { - DLOG_IF(ERROR, !CheckIdType(res, ::ppapi::PP_ID_TYPE_RESOURCE)) - << res << " is not a PP_Resource."; - ResourceMap::iterator i = live_resources_.find(res); - if (i != live_resources_.end()) { - // We don't protect against overflow, since a plugin as malicious as to ref - // once per every byte in the address space could have just as well unrefed - // one time too many. - ++i->second.second; - return true; - } else { - return false; - } -} - -bool ResourceTracker::UnrefResource(PP_Resource res) { - DLOG_IF(ERROR, !CheckIdType(res, ::ppapi::PP_ID_TYPE_RESOURCE)) - << res << " is not a PP_Resource."; - ResourceMap::iterator i = live_resources_.find(res); - if (i != live_resources_.end()) { - if (!--i->second.second) { - Resource* to_release = i->second.first; - // LastPluginRefWasDeleted will clear the instance pointer, so save it - // first. - PP_Instance instance = to_release->instance()->pp_instance(); - to_release->LastPluginRefWasDeleted(); - - instance_map_[instance]->ref_resources.erase(res); - live_resources_.erase(i); - } - return true; - } else { - return false; - } -} - void ResourceTracker::CleanupInstanceData(PP_Instance instance, bool delete_instance) { DLOG_IF(ERROR, !CheckIdType(instance, ::ppapi::PP_ID_TYPE_INSTANCE)) @@ -183,30 +94,6 @@ void ResourceTracker::CleanupInstanceData(PP_Instance instance, } InstanceData& data = *found->second; - // Force release all plugin references to resources associated with the - // deleted instance. - ResourceSet::iterator cur_res = data.ref_resources.begin(); - while (cur_res != data.ref_resources.end()) { - ResourceMap::iterator found_resource = live_resources_.find(*cur_res); - if (found_resource == live_resources_.end()) { - NOTREACHED(); - } else { - Resource* resource = found_resource->second.first; - - // Must delete from the resource set first since the resource's instance - // pointer will get zeroed out in LastPluginRefWasDeleted. - resource->LastPluginRefWasDeleted(); - live_resources_.erase(*cur_res); - } - - // Iterators to a set are stable so we can iterate the set while the items - // are being deleted as long as we're careful not to delete the item we're - // holding an iterator to. - ResourceSet::iterator current = cur_res++; - data.ref_resources.erase(current); - } - DCHECK(data.ref_resources.empty()); - // Force delete all var references. Need to make a copy so we can iterate over // the map while deleting stuff from it. NPObjectToNPObjectVarMap np_object_map_copy = data.np_object_to_object_var; @@ -225,36 +112,10 @@ void ResourceTracker::CleanupInstanceData(PP_Instance instance, } DCHECK(data.np_object_to_object_var.empty()); - // Clear any resources that still reference this instance. - for (std::set<Resource*>::iterator res = data.assoc_resources.begin(); - res != data.assoc_resources.end(); - ++res) - (*res)->ClearInstance(); - data.assoc_resources.clear(); - if (delete_instance) instance_map_.erase(found); } -uint32 ResourceTracker::GetLiveObjectsForInstance( - PP_Instance instance) const { - InstanceMap::const_iterator found = instance_map_.find(instance); - if (found == instance_map_.end()) - return 0; - return static_cast<uint32>(found->second->ref_resources.size() + - found->second->np_object_to_object_var.size()); -} - -::ppapi::ResourceObjectBase* ResourceTracker::GetResourceAPI( - PP_Resource res) { - DLOG_IF(ERROR, !CheckIdType(res, ::ppapi::PP_ID_TYPE_RESOURCE)) - << res << " is not a PP_Resource."; - ResourceMap::const_iterator result = live_resources_.find(res); - if (result == live_resources_.end()) - return NULL; - return result->second.first.get(); -} - ::ppapi::FunctionGroupBase* ResourceTracker::GetFunctionAPI( PP_Instance pp_instance, pp::proxy::InterfaceID id) { @@ -297,17 +158,14 @@ uint32 ResourceTracker::GetLiveObjectsForInstance( return proxy.get(); } -PP_Instance ResourceTracker::GetInstanceForResource(PP_Resource pp_resource) { - scoped_refptr<Resource> resource(GetResource(pp_resource)); - if (!resource.get()) - return 0; - return resource->instance()->pp_instance(); -} - ::ppapi::VarTracker* ResourceTracker::GetVarTracker() { return &var_tracker_; } +::ppapi::ResourceTracker* ResourceTracker::GetResourceTracker() { + return this; +} + void ResourceTracker::AddNPObjectVar(NPObjectVar* object_var) { DCHECK(instance_map_.find(object_var->pp_instance()) != instance_map_.end()); InstanceData& data = *instance_map_[object_var->pp_instance()].get(); @@ -346,6 +204,14 @@ NPObjectVar* ResourceTracker::NPObjectVarForNPObject(PP_Instance instance, return found->second; } +int ResourceTracker::GetLiveNPObjectVarsForInstance( + PP_Instance instance) const { + InstanceMap::const_iterator found = instance_map_.find(instance); + if (found == instance_map_.end()) + return 0; + return static_cast<int>(found->second->np_object_to_object_var.size()); +} + PP_Instance ResourceTracker::AddInstance(PluginInstance* instance) { DCHECK(instance_map_.find(instance->pp_instance()) == instance_map_.end()); @@ -363,14 +229,18 @@ PP_Instance ResourceTracker::AddInstance(PluginInstance* instance) { instance_map_[new_instance] = linked_ptr<InstanceData>(new InstanceData); instance_map_[new_instance]->instance = instance; + + DidCreateInstance(new_instance); return new_instance; } void ResourceTracker::InstanceDeleted(PP_Instance instance) { + DidDeleteInstance(instance); CleanupInstanceData(instance, true); } void ResourceTracker::InstanceCrashed(PP_Instance instance) { + DidDeleteInstance(instance); CleanupInstanceData(instance, false); } diff --git a/webkit/plugins/ppapi/resource_tracker.h b/webkit/plugins/ppapi/resource_tracker.h index 7fd445b..3a33b4f 100644 --- a/webkit/plugins/ppapi/resource_tracker.h +++ b/webkit/plugins/ppapi/resource_tracker.h @@ -20,6 +20,7 @@ #include "ppapi/c/pp_resource.h" #include "ppapi/proxy/interface_id.h" #include "ppapi/shared_impl/function_group_base.h" +#include "ppapi/shared_impl/resource_tracker.h" #include "ppapi/shared_impl/tracker_base.h" #include "ppapi/shared_impl/var_tracker.h" @@ -42,36 +43,20 @@ class ResourceTrackerTest; // us to check resource ID validity and to map them to a specific module. // // This object is NOT threadsafe. -class ResourceTracker : public ::ppapi::TrackerBase { +class ResourceTracker : public ::ppapi::TrackerBase, + public ::ppapi::ResourceTracker { public: // Returns the pointer to the singleton object. static ResourceTracker* Get(); // PP_Resources -------------------------------------------------------------- - // The returned pointer will be NULL if there is no resource. Note that this - // return value is a scoped_refptr so that we ensure the resource is valid - // from the point of the lookup to the point that the calling code needs it. - // Otherwise, the plugin could Release() the resource on another thread and - // the object will get deleted out from under us. - scoped_refptr<Resource> GetResource(PP_Resource res) const; - - // Increment resource's plugin refcount. See ResourceAndRefCount comments - // below. - bool AddRefResource(PP_Resource res); - bool UnrefResource(PP_Resource res); - - // Returns the number of resources associated with this module. - uint32 GetLiveObjectsForInstance(PP_Instance instance) const; - // TrackerBase. - virtual ::ppapi::ResourceObjectBase* GetResourceAPI( - PP_Resource res) OVERRIDE; virtual ::ppapi::FunctionGroupBase* GetFunctionAPI( PP_Instance pp_instance, pp::proxy::InterfaceID id) OVERRIDE; - virtual PP_Instance GetInstanceForResource(PP_Resource resource) OVERRIDE; virtual ::ppapi::VarTracker* GetVarTracker() OVERRIDE; + virtual ::ppapi::ResourceTracker* GetResourceTracker() OVERRIDE; // PP_Vars ------------------------------------------------------------------- @@ -88,6 +73,10 @@ class ResourceTracker : public ::ppapi::TrackerBase { ::ppapi::NPObjectVar* NPObjectVarForNPObject(PP_Instance instance, NPObject* np_object); + // Returns the number of NPObjectVar's associated with the given instance. + // Returns 0 if the instance isn't known. + int GetLiveNPObjectVarsForInstance(PP_Instance instance) const; + // PP_Modules ---------------------------------------------------------------- // Adds a new plugin module to the list of tracked module, and returns a new @@ -130,19 +119,7 @@ class ResourceTracker : public ::ppapi::TrackerBase { // Prohibit creation other then by the Singleton class. ResourceTracker(); - ~ResourceTracker(); - - // Called when a new resource is created and associates it with its - // PluginInstance. - void ResourceCreated(Resource* resource, PluginInstance* instance); - - // Removes a resource from the resource map. - void ResourceDestroyed(Resource* resource); - - // Adds the given resource to the tracker and assigns it a resource ID and - // refcount of 1. The assigned resource ID will be returned. Used only by the - // Resource class. - PP_Resource AddResource(Resource* resource); + virtual ~ResourceTracker(); // Force frees all vars and resources associated with the given instance. // If delete_instance is true, the instance tracking information will also diff --git a/webkit/plugins/ppapi/resource_tracker_unittest.cc b/webkit/plugins/ppapi/resource_tracker_unittest.cc index eb7ec80..c43b1d2 100644 --- a/webkit/plugins/ppapi/resource_tracker_unittest.cc +++ b/webkit/plugins/ppapi/resource_tracker_unittest.cc @@ -113,82 +113,6 @@ class ResourceTrackerTest : public PpapiUnittest { ResourceTracker tracker_; }; -TEST_F(ResourceTrackerTest, Ref) { - ASSERT_EQ(0, TrackedMockResource::tracked_objects_alive); - EXPECT_EQ(0u, - tracker().GetLiveObjectsForInstance(instance()->pp_instance())); - { - scoped_refptr<TrackedMockResource> new_resource( - new TrackedMockResource(instance())); - ASSERT_EQ(1, TrackedMockResource::tracked_objects_alive); - - // Since we haven't gotten a PP_Resource, it's not associated with the - // module. - EXPECT_EQ(0u, - tracker().GetLiveObjectsForInstance(instance()->pp_instance())); - } - ASSERT_EQ(0, TrackedMockResource::tracked_objects_alive); - - // Make a new resource and get it as a PP_Resource. - PP_Resource resource_id = 0; - { - scoped_refptr<TrackedMockResource> new_resource( - new TrackedMockResource(instance())); - ASSERT_EQ(1, TrackedMockResource::tracked_objects_alive); - resource_id = new_resource->GetReference(); - EXPECT_EQ(1u, - tracker().GetLiveObjectsForInstance(instance()->pp_instance())); - - // Resource IDs should be consistent. - PP_Resource resource_id_2 = new_resource->GetReference(); - ASSERT_EQ(resource_id, resource_id_2); - } - - // This time it should not have been deleted since the PP_Resource carries - // a ref. - ASSERT_EQ(1, TrackedMockResource::tracked_objects_alive); - - // Now we have two refs, derefing twice should delete the object. - tracker().UnrefResource(resource_id); - ASSERT_EQ(1, TrackedMockResource::tracked_objects_alive); - tracker().UnrefResource(resource_id); - ASSERT_EQ(0, TrackedMockResource::tracked_objects_alive); -} - -TEST_F(ResourceTrackerTest, DeleteResourceWithInstance) { - // Make a second instance (the test harness already creates & manages one). - scoped_refptr<PluginInstance> instance2( - PluginInstance::Create1_0(delegate(), module(), - GetMockInterface(PPP_INSTANCE_INTERFACE_1_0))); - PP_Instance pp_instance2 = instance2->pp_instance(); - - // Make two resources and take refs on behalf of the "plugin" for each. - scoped_refptr<TrackedMockResource> resource1( - new TrackedMockResource(instance2)); - resource1->GetReference(); - scoped_refptr<TrackedMockResource> resource2( - new TrackedMockResource(instance2)); - resource2->GetReference(); - - // Keep an "internal" ref to only the first (the PP_Resource also holds a - // ref to each resource on behalf of the plugin). - resource2 = NULL; - - ASSERT_EQ(2, TrackedMockResource::tracked_objects_alive); - EXPECT_EQ(2u, tracker().GetLiveObjectsForInstance(pp_instance2)); - - // Free the instance, this should release both plugin refs. - instance2 = NULL; - EXPECT_EQ(0u, tracker().GetLiveObjectsForInstance(pp_instance2)); - - // The resource we have a scoped_refptr to should still be alive, but it - // should have a NULL instance. - ASSERT_FALSE(resource1->instance()); - ASSERT_EQ(1, TrackedMockResource::tracked_objects_alive); - resource1 = NULL; - ASSERT_EQ(0, TrackedMockResource::tracked_objects_alive); -} - TEST_F(ResourceTrackerTest, DeleteObjectVarWithInstance) { // Make a second instance (the test harness already creates & manages one). scoped_refptr<PluginInstance> instance2( @@ -201,11 +125,11 @@ TEST_F(ResourceTrackerTest, DeleteObjectVarWithInstance) { NPObjectToPPVar(instance2.get(), npobject.get()); EXPECT_EQ(1, g_npobjects_alive); - EXPECT_EQ(1u, tracker().GetLiveObjectsForInstance(pp_instance2)); + EXPECT_EQ(1, tracker().GetLiveNPObjectVarsForInstance(pp_instance2)); // Free the instance, this should release the ObjectVar. instance2 = NULL; - EXPECT_EQ(0u, tracker().GetLiveObjectsForInstance(pp_instance2)); + EXPECT_EQ(0, tracker().GetLiveNPObjectVarsForInstance(pp_instance2)); } // Make sure that using the same NPObject should give the same PP_Var |