diff options
124 files changed, 1105 insertions, 1172 deletions
diff --git a/chrome/renderer/chrome_ppb_pdf_impl.cc b/chrome/renderer/chrome_ppb_pdf_impl.cc index bd8b4c0..8f4f31a 100644 --- a/chrome/renderer/chrome_ppb_pdf_impl.cc +++ b/chrome/renderer/chrome_ppb_pdf_impl.cc @@ -13,6 +13,9 @@ #include "grit/webkit_strings.h" #include "ppapi/c/pp_resource.h" #include "ppapi/c/private/ppb_pdf.h" +#include "ppapi/shared_impl/resource.h" +#include "ppapi/shared_impl/resource_tracker.h" +#include "ppapi/shared_impl/tracker_base.h" #include "ppapi/shared_impl/var.h" #include "skia/ext/platform_canvas.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -208,14 +211,12 @@ bool GetFontTableForPrivateFontFile(PP_Resource font_file, void* output, uint32_t* output_length) { #if defined(OS_LINUX) - scoped_refptr<webkit::ppapi::Resource> - resource(webkit::ppapi::ResourceTracker::Get()->GetResource(font_file)); - if (!resource.get()) + ppapi::Resource* resource = + ppapi::TrackerBase::Get()->GetResourceTracker()->GetResource(font_file); + if (!resource) return false; - PrivateFontFile* font = static_cast<PrivateFontFile*>(resource.get()); - if (!font) - return false; + PrivateFontFile* font = static_cast<PrivateFontFile*>(resource); return font->GetFontTable(table, output, output_length); #else return false; diff --git a/ppapi/ppapi_proxy.gypi b/ppapi/ppapi_proxy.gypi index 774132a..65b4039 100644 --- a/ppapi/ppapi_proxy.gypi +++ b/ppapi/ppapi_proxy.gypi @@ -41,8 +41,6 @@ 'proxy/plugin_dispatcher.h', 'proxy/plugin_message_filter.cc', 'proxy/plugin_message_filter.h', - 'proxy/plugin_resource.cc', - 'proxy/plugin_resource.h', 'proxy/plugin_resource_tracker.cc', 'proxy/plugin_resource_tracker.h', 'proxy/plugin_var_serialization_rules.cc', diff --git a/ppapi/ppapi_shared.gypi b/ppapi/ppapi_shared.gypi index 8e782fc..6e4f777 100644 --- a/ppapi/ppapi_shared.gypi +++ b/ppapi/ppapi_shared.gypi @@ -53,8 +53,10 @@ 'shared_impl/ppapi_preferences.h', 'shared_impl/ppp_instance_combined.cc', 'shared_impl/ppp_instance_combined.h', - 'shared_impl/resource_object_base.cc', - 'shared_impl/resource_object_base.h', + 'shared_impl/resource.cc', + 'shared_impl/resource.h', + 'shared_impl/resource_tracker.cc', + 'shared_impl/resource_tracker.h', 'shared_impl/time_conversion.cc', 'shared_impl/time_conversion.h', 'shared_impl/tracker_base.cc', diff --git a/ppapi/ppapi_tests.gypi b/ppapi/ppapi_tests.gypi index a15748f..34420b5 100644 --- a/ppapi/ppapi_tests.gypi +++ b/ppapi/ppapi_tests.gypi @@ -195,6 +195,7 @@ 'proxy/ppp_instance_proxy_test.cc', 'proxy/ppp_messaging_proxy_test.cc', 'proxy/serialized_var_unittest.cc', + 'shared_impl/resource_tracker_unittest.cc', ], }, ], diff --git a/ppapi/proxy/mock_resource.cc b/ppapi/proxy/mock_resource.cc index 2f1a0b7..2173eea 100644 --- a/ppapi/proxy/mock_resource.cc +++ b/ppapi/proxy/mock_resource.cc @@ -5,12 +5,12 @@ #include "ppapi/proxy/mock_resource.h" using ppapi::HostResource; +using ppapi::Resource; namespace pp { namespace proxy { -MockResource::MockResource(const HostResource& resource) - : PluginResource(resource) { +MockResource::MockResource(const HostResource& resource) : Resource(resource) { } MockResource::~MockResource() { diff --git a/ppapi/proxy/mock_resource.h b/ppapi/proxy/mock_resource.h index dbad2f6..a886c20 100644 --- a/ppapi/proxy/mock_resource.h +++ b/ppapi/proxy/mock_resource.h @@ -6,12 +6,12 @@ #define PPAPI_PROXY_MOCK_RESOURCE_H_ #include "ppapi/c/pp_instance.h" -#include "ppapi/proxy/plugin_resource.h" +#include "ppapi/shared_impl/resource.h" namespace pp { namespace proxy { -class MockResource : public PluginResource { +class MockResource : public ppapi::Resource { public: MockResource(const ppapi::HostResource& resource); virtual ~MockResource(); diff --git a/ppapi/proxy/plugin_dispatcher.cc b/ppapi/proxy/plugin_dispatcher.cc index 53dab26..fea4de6 100644 --- a/ppapi/proxy/plugin_dispatcher.cc +++ b/ppapi/proxy/plugin_dispatcher.cc @@ -24,6 +24,7 @@ #include "ppapi/proxy/ppb_instance_proxy.h" #include "ppapi/proxy/ppp_class_proxy.h" #include "ppapi/proxy/resource_creation_proxy.h" +#include "ppapi/shared_impl/resource.h" #include "ppapi/shared_impl/tracker_base.h" #if defined(OS_POSIX) @@ -31,6 +32,8 @@ #include "ipc/ipc_channel_posix.h" #endif +using ppapi::Resource; + namespace pp { namespace proxy { @@ -74,6 +77,11 @@ PluginDispatcher* PluginDispatcher::GetForInstance(PP_Instance instance) { } // static +PluginDispatcher* PluginDispatcher::GetForResource(const Resource* resource) { + return GetForInstance(resource->pp_instance()); +} + +// static const void* PluginDispatcher::GetInterfaceFromDispatcher( const char* interface) { // All interfaces the plugin requests of the browser are "PPB". diff --git a/ppapi/proxy/plugin_dispatcher.h b/ppapi/proxy/plugin_dispatcher.h index ae6da60..b2fbeec 100644 --- a/ppapi/proxy/plugin_dispatcher.h +++ b/ppapi/proxy/plugin_dispatcher.h @@ -26,6 +26,7 @@ class WaitableEvent; namespace ppapi { struct Preferences; +class Resource; } namespace pp { @@ -84,6 +85,10 @@ class PluginDispatcher : public Dispatcher { // DidCreateInstance/DidDestroyInstance. static PluginDispatcher* GetForInstance(PP_Instance instance); + // Same as GetForInstance but retrieves the instance from the given resource + // object as a convenience. Returns NULL on failure. + static PluginDispatcher* GetForResource(const ppapi::Resource* resource); + static const void* GetInterfaceFromDispatcher(const char* interface); // You must call this function before anything else. Returns true on success. diff --git a/ppapi/proxy/plugin_resource.cc b/ppapi/proxy/plugin_resource.cc deleted file mode 100644 index e9f3b75..0000000 --- a/ppapi/proxy/plugin_resource.cc +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ppapi/proxy/plugin_resource.h" - -using ppapi::HostResource; - -namespace pp { -namespace proxy { - -PluginResource::PluginResource(const HostResource& resource) - : ResourceObjectBase(resource.instance()), - host_resource_(resource) { -} - -PluginResource::~PluginResource() { -} - -PluginDispatcher* PluginResource::GetDispatcher() { - PluginDispatcher* disp = PluginDispatcher::GetForInstance(instance()); - CHECK(disp); - return disp; -} - -} // namespace proxy -} // namespace pp diff --git a/ppapi/proxy/plugin_resource.h b/ppapi/proxy/plugin_resource.h deleted file mode 100644 index 298b4cd..0000000 --- a/ppapi/proxy/plugin_resource.h +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef PPAPI_PROXY_PLUGIN_RESOURCE_H_ -#define PPAPI_PROXY_PLUGIN_RESOURCE_H_ - -#include "base/basictypes.h" -#include "ppapi/c/pp_instance.h" -#include "ppapi/proxy/plugin_dispatcher.h" -#include "ppapi/proxy/plugin_resource_tracker.h" -#include "ppapi/shared_impl/host_resource.h" -#include "ppapi/shared_impl/resource_object_base.h" - -namespace pp { -namespace proxy { - -class PluginResource : public ::ppapi::ResourceObjectBase { - public: - PluginResource(const ppapi::HostResource& resource); - virtual ~PluginResource(); - - PP_Instance instance() const { return host_resource_.instance(); } - - // Returns the host resource ID for sending to the host process. - const ppapi::HostResource& host_resource() const { - return host_resource_; - } - - PluginDispatcher* GetDispatcher(); - - private: - // The resource ID in the host that this object corresponds to. Inside the - // plugin we'll remap the resource IDs so we can have many host processes - // each independently generating resources (which may conflict) but the IDs - // in the plugin will all be unique. - ppapi::HostResource host_resource_; - - DISALLOW_COPY_AND_ASSIGN(PluginResource); -}; - -} // namespace proxy -} // namespace pp - -#endif // PPAPI_PROXY_PLUGIN_RESOURCE_H_ diff --git a/ppapi/proxy/plugin_resource_tracker.cc b/ppapi/proxy/plugin_resource_tracker.cc index a511fd9..ac4621e 100644 --- a/ppapi/proxy/plugin_resource_tracker.cc +++ b/ppapi/proxy/plugin_resource_tracker.cc @@ -8,12 +8,13 @@ #include "base/memory/singleton.h" #include "ppapi/proxy/plugin_dispatcher.h" #include "ppapi/proxy/ppapi_messages.h" -#include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/serialized_var.h" +#include "ppapi/shared_impl/resource.h" #include "ppapi/shared_impl/tracker_base.h" #include "ppapi/shared_impl/var.h" using ppapi::HostResource; +using ppapi::Resource; namespace pp { namespace proxy { @@ -29,37 +30,8 @@ PluginResourceTracker* g_resource_tracker_override = NULL; } // namespace -PluginResourceTracker::ResourceInfo::ResourceInfo() : ref_count(0) { -} - -PluginResourceTracker::ResourceInfo::ResourceInfo(int rc, PluginResource* r) - : ref_count(rc), - resource(r) { -} - -PluginResourceTracker::ResourceInfo::ResourceInfo(const ResourceInfo& other) - : ref_count(other.ref_count), - resource(other.resource) { - // Wire up the new shared resource tracker base to use our implementation. - ::ppapi::TrackerBase::Init(&GetTrackerBase); -} - -PluginResourceTracker::ResourceInfo::~ResourceInfo() { -} - -PluginResourceTracker::ResourceInfo& -PluginResourceTracker::ResourceInfo::operator=( - const ResourceInfo& other) { - ref_count = other.ref_count; - resource = other.resource; - return *this; -} - -// Start counting resources at a high number to avoid collisions with vars (to -// help debugging). PluginResourceTracker::PluginResourceTracker() - : var_tracker_test_override_(NULL), - last_resource_id_(0x00100000) { + : var_tracker_test_override_(NULL) { } PluginResourceTracker::~PluginResourceTracker() { @@ -83,39 +55,6 @@ PluginResourceTracker::GetTrackerBaseInstance() { return GetInstance(); } -PluginResource* PluginResourceTracker::GetResourceObject( - PP_Resource pp_resource) { - ResourceMap::iterator found = resource_map_.find(pp_resource); - if (found == resource_map_.end()) - return NULL; - return found->second.resource.get(); -} - -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); - if (!object->host_resource().is_null()) { - // The host resource ID will be 0 for resources that only exist in the - // plugin process. Don't add those to the list. - host_resource_map_[object->host_resource()] = plugin_resource; - } - return plugin_resource; -} - -void PluginResourceTracker::AddRefResource(PP_Resource resource) { - ResourceMap::iterator found = resource_map_.find(resource); - if (found == resource_map_.end()) { - NOTREACHED(); - return; - } - found->second.ref_count++; -} - -void PluginResourceTracker::ReleaseResource(PP_Resource resource) { - ReleasePluginResourceRef(resource, true); -} - PP_Resource PluginResourceTracker::PluginResourceForHostResource( const HostResource& resource) const { HostResourceMap::const_iterator found = host_resource_map_.find(resource); @@ -124,14 +63,6 @@ PP_Resource PluginResourceTracker::PluginResourceForHostResource( return found->second; } -::ppapi::ResourceObjectBase* PluginResourceTracker::GetResourceAPI( - PP_Resource res) { - ResourceMap::iterator found = resource_map_.find(res); - if (found == resource_map_.end()) - return NULL; - return found->second.resource.get(); -} - ::ppapi::FunctionGroupBase* PluginResourceTracker::GetFunctionAPI( PP_Instance inst, pp::proxy::InterfaceID id) { @@ -141,46 +72,41 @@ PP_Resource PluginResourceTracker::PluginResourceForHostResource( return NULL; } -PP_Instance PluginResourceTracker::GetInstanceForResource( - PP_Resource resource) { - ResourceMap::iterator found = resource_map_.find(resource); - if (found == resource_map_.end()) - return 0; - return found->second.resource->instance(); -} - ppapi::VarTracker* PluginResourceTracker::GetVarTracker() { return &var_tracker(); } -void PluginResourceTracker::ReleasePluginResourceRef( - const PP_Resource& resource, - bool notify_browser_on_release) { - ResourceMap::iterator found = resource_map_.find(resource); - if (found == resource_map_.end()) - return; - found->second.ref_count--; - if (found->second.ref_count == 0) { - // 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. - scoped_refptr<PluginResource> plugin_resource = found->second.resource; +ppapi::ResourceTracker* PluginResourceTracker::GetResourceTracker() { + return this; +} + +PP_Resource PluginResourceTracker::AddResource(Resource* object) { + PP_Resource ret = ResourceTracker::AddResource(object); + + // Some resources are plugin-only, so they don't have a host resource. + if (object->host_resource().host_resource()) + host_resource_map_.insert(std::make_pair(object->host_resource(), ret)); + return ret; +} + +void PluginResourceTracker::RemoveResource(Resource* object) { + ResourceTracker::RemoveResource(object); + + if (!object->host_resource().is_null()) { + // The host_resource will be NULL for proxy-only resources, which we + // obviously don't need to tell the host about. + DCHECK(host_resource_map_.find(object->host_resource()) != + host_resource_map_.end()); + host_resource_map_.erase(object->host_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 = 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 - // already been freed correctly on the browser side. The host_resource - // will be NULL for proxy-only resources, which we obviously don't need to - // tell the host about. - if (notify_browser_on_release && dispatcher && !host_resource.is_null()) { + PluginDispatcher::GetForInstance(object->pp_instance()); + if (dispatcher) { + // The 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 + // already been freed correctly on the browser side. dispatcher->Send(new PpapiHostMsg_PPBCore_ReleaseResource( - INTERFACE_ID_PPB_CORE, host_resource)); + INTERFACE_ID_PPB_CORE, object->host_resource())); } } } diff --git a/ppapi/proxy/plugin_resource_tracker.h b/ppapi/proxy/plugin_resource_tracker.h index f788c6c..ccc6d70 100644 --- a/ppapi/proxy/plugin_resource_tracker.h +++ b/ppapi/proxy/plugin_resource_tracker.h @@ -16,6 +16,7 @@ #include "ppapi/c/pp_var.h" #include "ppapi/proxy/plugin_var_tracker.h" #include "ppapi/shared_impl/host_resource.h" +#include "ppapi/shared_impl/resource_tracker.h" #include "ppapi/shared_impl/tracker_base.h" template<typename T> struct DefaultSingletonTraits; @@ -28,9 +29,9 @@ namespace pp { namespace proxy { class PluginDispatcher; -class PluginResource; -class PluginResourceTracker : public ::ppapi::TrackerBase { +class PluginResourceTracker : public ppapi::TrackerBase, + public ppapi::ResourceTracker { public: // Called by tests that want to specify a specific ResourceTracker. This // allows them to use a unique one each time and avoids singletons sticking @@ -41,21 +42,6 @@ class PluginResourceTracker : public ::ppapi::TrackerBase { static PluginResourceTracker* GetInstance(); static ::ppapi::TrackerBase* GetTrackerBaseInstance(); - // Returns the object associated with the given resource ID, or NULL if - // there isn't one. - PluginResource* GetResourceObject(PP_Resource pp_resource); - - // Adds the given resource object to the tracked list, and returns the - // 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. - // - // 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); - // Given a host resource, maps it to an existing plugin resource ID if it // exists, or returns 0 on failure. PP_Resource PluginResourceForHostResource( @@ -71,13 +57,16 @@ class PluginResourceTracker : public ::ppapi::TrackerBase { } // TrackerBase. - virtual ppapi::ResourceObjectBase* GetResourceAPI( - PP_Resource res) OVERRIDE; virtual ppapi::FunctionGroupBase* GetFunctionAPI( PP_Instance inst, pp::proxy::InterfaceID id) OVERRIDE; - virtual PP_Instance GetInstanceForResource(PP_Resource resource) OVERRIDE; virtual ppapi::VarTracker* GetVarTracker() OVERRIDE; + virtual ppapi::ResourceTracker* GetResourceTracker() OVERRIDE; + + protected: + // ResourceTracker overrides. + virtual PP_Resource AddResource(ppapi::Resource* object) OVERRIDE; + virtual void RemoveResource(ppapi::Resource* object) OVERRIDE; private: friend struct DefaultSingletonTraits<PluginResourceTracker>; @@ -87,21 +76,6 @@ class PluginResourceTracker : public ::ppapi::TrackerBase { PluginResourceTracker(); virtual ~PluginResourceTracker(); - struct ResourceInfo { - ResourceInfo(); - ResourceInfo(int ref_count, PluginResource* r); - ResourceInfo(const ResourceInfo& other); - ~ResourceInfo(); - - ResourceInfo& operator=(const ResourceInfo& other); - - int ref_count; - scoped_refptr<PluginResource> resource; // May be NULL. - }; - - void ReleasePluginResourceRef(const PP_Resource& var, - bool notify_browser_on_release); - // Use the var_tracker_test_override_ instead if it's non-NULL. // // TODO(brettw) this should be somehow separated out from here. I'm thinking @@ -113,18 +87,10 @@ class PluginResourceTracker : public ::ppapi::TrackerBase { // test implementation is provided. PluginVarTracker* var_tracker_test_override_; - // Map of plugin resource IDs to the information tracking that resource. - typedef std::map<PP_Resource, ResourceInfo> ResourceMap; - ResourceMap resource_map_; - // Map of host instance/resource pairs to a plugin resource ID. typedef std::map<ppapi::HostResource, PP_Resource> HostResourceMap; HostResourceMap host_resource_map_; - // Tracks the last ID we've sent out as a plugin resource so we don't send - // duplicates. - PP_Resource last_resource_id_; - DISALLOW_COPY_AND_ASSIGN(PluginResourceTracker); }; diff --git a/ppapi/proxy/plugin_resource_tracker_unittest.cc b/ppapi/proxy/plugin_resource_tracker_unittest.cc index 8295302..cb26638 100644 --- a/ppapi/proxy/plugin_resource_tracker_unittest.cc +++ b/ppapi/proxy/plugin_resource_tracker_unittest.cc @@ -39,11 +39,6 @@ class PluginResourceTrackerTest : public PluginProxyTest { public: PluginResourceTrackerTest() {} ~PluginResourceTrackerTest() {} - - PluginResourceTracker& tracker() { return tracker_; } - - private: - PluginResourceTracker tracker_; }; TEST_F(PluginResourceTrackerTest, PluginResourceForHostResource) { @@ -53,22 +48,22 @@ TEST_F(PluginResourceTrackerTest, PluginResourceForHostResource) { serialized.SetHostResource(pp_instance(), host_resource); // When we haven't added an object, the return value should be 0. - EXPECT_EQ(0, tracker().PluginResourceForHostResource(serialized)); + EXPECT_EQ(0, resource_tracker().PluginResourceForHostResource(serialized)); 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(object); + PP_Resource plugin_resource = object->GetReference(); // Now that the object has been added, the return value should be the plugin // resource ID we already got. EXPECT_EQ(plugin_resource, - tracker().PluginResourceForHostResource(serialized)); + resource_tracker().PluginResourceForHostResource(serialized)); // Releasing the resource should have freed it. - tracker().ReleaseResource(plugin_resource); + resource_tracker().ReleaseResource(plugin_resource); EXPECT_EQ(0, TrackedMockResource::tracked_alive_count); - EXPECT_EQ(0, tracker().PluginResourceForHostResource(serialized)); + EXPECT_EQ(0, resource_tracker().PluginResourceForHostResource(serialized)); } } // namespace proxy diff --git a/ppapi/proxy/ppapi_param_traits.cc b/ppapi/proxy/ppapi_param_traits.cc index bca08ee..d8f6b70 100644 --- a/ppapi/proxy/ppapi_param_traits.cc +++ b/ppapi/proxy/ppapi_param_traits.cc @@ -375,15 +375,15 @@ void ParamTraits<pp::proxy::SerializedFontDescription>::Log( // static void ParamTraits<ppapi::HostResource>::Write(Message* m, - const param_type& p) { + const param_type& p) { ParamTraits<PP_Instance>::Write(m, p.instance()); ParamTraits<PP_Resource>::Write(m, p.host_resource()); } // static bool ParamTraits<ppapi::HostResource>::Read(const Message* m, - void** iter, - param_type* r) { + void** iter, + param_type* r) { PP_Instance instance; PP_Resource resource; if (!ParamTraits<PP_Instance>::Read(m, iter, &instance) || diff --git a/ppapi/proxy/ppapi_proxy_test.cc b/ppapi/proxy/ppapi_proxy_test.cc index eb7b440..8049330 100644 --- a/ppapi/proxy/ppapi_proxy_test.cc +++ b/ppapi/proxy/ppapi_proxy_test.cc @@ -147,6 +147,7 @@ Dispatcher* PluginProxyTestHarness::GetDispatcher() { void PluginProxyTestHarness::SetUpHarness() { // These must be first since the dispatcher set-up uses them. + resource_tracker_.DidCreateInstance(pp_instance()); PluginResourceTracker::SetInstanceForTest(&resource_tracker_); resource_tracker_.set_var_tracker_test_override(&var_tracker_); @@ -163,6 +164,7 @@ void PluginProxyTestHarness::SetUpHarnessWithChannel( base::WaitableEvent* shutdown_event, bool is_client) { // These must be first since the dispatcher set-up uses them. + resource_tracker_.DidCreateInstance(pp_instance()); PluginResourceTracker::SetInstanceForTest(&resource_tracker_); resource_tracker_.set_var_tracker_test_override(&var_tracker_); plugin_delegate_mock_.Init(ipc_message_loop, shutdown_event); @@ -180,6 +182,7 @@ void PluginProxyTestHarness::TearDownHarness() { plugin_dispatcher_->DidDestroyInstance(pp_instance()); plugin_dispatcher_.reset(); + resource_tracker_.DidDeleteInstance(pp_instance()); PluginResourceTracker::SetInstanceForTest(NULL); } diff --git a/ppapi/proxy/ppb_audio_config_proxy.cc b/ppapi/proxy/ppb_audio_config_proxy.cc index f2eb9d8..eeb4907 100644 --- a/ppapi/proxy/ppb_audio_config_proxy.cc +++ b/ppapi/proxy/ppb_audio_config_proxy.cc @@ -6,33 +6,31 @@ #include "ppapi/c/ppb_audio_config.h" #include "ppapi/proxy/plugin_dispatcher.h" -#include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/shared_impl/audio_config_impl.h" #include "ppapi/thunk/thunk.h" using ppapi::HostResource; +using ppapi::Resource; namespace pp { namespace proxy { // The implementation is actually in AudioConfigImpl. -class AudioConfig : public PluginResource, - public ppapi::AudioConfigImpl { +class AudioConfig : public Resource, public ppapi::AudioConfigImpl { public: // Note that you must call Init (on AudioConfigImpl) before using this class. AudioConfig(const HostResource& resource); virtual ~AudioConfig(); - // ResourceObjectBase overrides. + // Resource overrides. virtual ::ppapi::thunk::PPB_AudioConfig_API* AsPPB_AudioConfig_API() OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(AudioConfig); }; -AudioConfig::AudioConfig(const HostResource& resource) - : PluginResource(resource) { +AudioConfig::AudioConfig(const HostResource& resource) : Resource(resource) { } AudioConfig::~AudioConfig() { @@ -80,7 +78,7 @@ PP_Resource PPB_AudioConfig_Proxy::CreateProxyResource( HostResource::MakeInstanceOnly(instance))); if (!object->Init(sample_rate, sample_frame_count)) return 0; - return PluginResourceTracker::GetInstance()->AddResource(object); + return object->GetReference(); } bool PPB_AudioConfig_Proxy::OnMessageReceived(const IPC::Message& msg) { diff --git a/ppapi/proxy/ppb_audio_proxy.cc b/ppapi/proxy/ppb_audio_proxy.cc index c6562ec..d9f5d60 100644 --- a/ppapi/proxy/ppb_audio_proxy.cc +++ b/ppapi/proxy/ppb_audio_proxy.cc @@ -14,15 +14,16 @@ #include "ppapi/proxy/enter_proxy.h" #include "ppapi/proxy/interface_id.h" #include "ppapi/proxy/plugin_dispatcher.h" -#include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/shared_impl/audio_impl.h" +#include "ppapi/shared_impl/resource.h" #include "ppapi/thunk/ppb_audio_config_api.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/resource_creation_api.h" #include "ppapi/thunk/thunk.h" using ppapi::HostResource; +using ppapi::Resource; using ppapi::thunk::EnterResourceNoLock; using ppapi::thunk::PPB_Audio_API; using ppapi::thunk::PPB_AudioConfig_API; @@ -30,7 +31,7 @@ using ppapi::thunk::PPB_AudioConfig_API; namespace pp { namespace proxy { -class Audio : public PluginResource, public ppapi::AudioImpl { +class Audio : public Resource, public ppapi::AudioImpl { public: Audio(const HostResource& audio_id, PP_Resource config_id, @@ -38,7 +39,7 @@ class Audio : public PluginResource, public ppapi::AudioImpl { void* user_data); virtual ~Audio(); - // ResourceObjectBase overrides. + // Resource overrides. virtual PPB_Audio_API* AsPPB_Audio_API(); // PPB_Audio_API implementation. @@ -62,7 +63,7 @@ Audio::Audio(const HostResource& audio_id, PP_Resource config_id, PPB_Audio_Callback callback, void* user_data) - : PluginResource(audio_id), + : Resource(audio_id), config_(config_id) { SetCallback(callback, user_data); PluginResourceTracker::GetInstance()->AddRefResource(config_); @@ -86,7 +87,7 @@ PP_Bool Audio::StartPlayback() { if (playing()) return PP_TRUE; SetStartPlaybackState(); - PluginDispatcher::GetForInstance(instance())->Send( + PluginDispatcher::GetForResource(this)->Send( new PpapiHostMsg_PPBAudio_StartOrStop( INTERFACE_ID_PPB_AUDIO, host_resource(), true)); return PP_TRUE; @@ -95,7 +96,7 @@ PP_Bool Audio::StartPlayback() { PP_Bool Audio::StopPlayback() { if (!playing()) return PP_TRUE; - PluginDispatcher::GetForInstance(instance())->Send( + PluginDispatcher::GetForResource(this)->Send( new PpapiHostMsg_PPBAudio_StartOrStop( INTERFACE_ID_PPB_AUDIO, host_resource(), false)); SetStopPlaybackState(); @@ -179,8 +180,8 @@ PP_Resource PPB_Audio_Proxy::CreateProxyResource( if (result.is_null()) return 0; - return PluginResourceTracker::GetInstance()->AddResource( - new Audio(result, config_id, audio_callback, user_data)); + return (new Audio(result, config_id, + audio_callback, user_data))->GetReference(); } bool PPB_Audio_Proxy::OnMessageReceived(const IPC::Message& msg) { diff --git a/ppapi/proxy/ppb_broker_proxy.cc b/ppapi/proxy/ppb_broker_proxy.cc index ac99699..b0ebcb5 100644 --- a/ppapi/proxy/ppb_broker_proxy.cc +++ b/ppapi/proxy/ppb_broker_proxy.cc @@ -8,13 +8,13 @@ #include "ppapi/c/trusted/ppb_broker_trusted.h" #include "ppapi/proxy/enter_proxy.h" #include "ppapi/proxy/plugin_dispatcher.h" -#include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/thunk/ppb_broker_api.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/thunk.h" using ppapi::HostResource; +using ppapi::Resource; using ppapi::thunk::PPB_Broker_API; namespace pp { @@ -49,12 +49,12 @@ InterfaceProxy* CreateBrokerProxy(Dispatcher* dispatcher, } // namespace -class Broker : public PPB_Broker_API, public PluginResource { +class Broker : public PPB_Broker_API, public Resource { public: explicit Broker(const HostResource& resource); virtual ~Broker(); - // ResourceObjectBase overries. + // Resource overries. virtual PPB_Broker_API* AsPPB_Broker_API() OVERRIDE; // PPB_Broker_API implementation. @@ -78,8 +78,7 @@ class Broker : public PPB_Broker_API, public PluginResource { DISALLOW_COPY_AND_ASSIGN(Broker); }; -Broker::Broker(const HostResource& resource) - : PluginResource(resource), +Broker::Broker(const HostResource& resource) : Resource(resource), called_connect_(false), current_connect_callback_(PP_MakeCompletionCallback(NULL, NULL)), socket_handle_(base::kInvalidPlatformFileValue) { @@ -116,8 +115,9 @@ int32_t Broker::Connect(PP_CompletionCallback connect_callback) { current_connect_callback_ = connect_callback; called_connect_ = true; - bool success = GetDispatcher()->Send(new PpapiHostMsg_PPBBroker_Connect( - INTERFACE_ID_PPB_BROKER, host_resource())); + bool success = PluginDispatcher::GetForResource(this)->Send( + new PpapiHostMsg_PPBBroker_Connect( + INTERFACE_ID_PPB_BROKER, host_resource())); return success ? PP_OK_COMPLETIONPENDING : PP_ERROR_FAILED; } @@ -181,8 +181,7 @@ PP_Resource PPB_Broker_Proxy::CreateProxyResource(PP_Instance instance) { INTERFACE_ID_PPB_BROKER, instance, &result)); if (result.is_null()) return 0; - - return PluginResourceTracker::GetInstance()->AddResource(new Broker(result)); + return (new Broker(result))->GetReference(); } bool PPB_Broker_Proxy::OnMessageReceived(const IPC::Message& msg) { diff --git a/ppapi/proxy/ppb_buffer_proxy.cc b/ppapi/proxy/ppb_buffer_proxy.cc index 558b531..9598a4f 100644 --- a/ppapi/proxy/ppb_buffer_proxy.cc +++ b/ppapi/proxy/ppb_buffer_proxy.cc @@ -20,6 +20,7 @@ #include "ppapi/thunk/thunk.h" using ppapi::HostResource; +using ppapi::Resource; namespace pp { namespace proxy { @@ -36,7 +37,7 @@ InterfaceProxy* CreateBufferProxy(Dispatcher* dispatcher, Buffer::Buffer(const HostResource& resource, const base::SharedMemoryHandle& shm_handle, uint32_t size) - : PluginResource(resource), + : Resource(resource), shm_(shm_handle, false), size_(size), mapped_data_(NULL), @@ -114,8 +115,7 @@ PP_Resource PPB_Buffer_Proxy::AddProxyResource( const HostResource& resource, base::SharedMemoryHandle shm_handle, uint32_t size) { - return PluginResourceTracker::GetInstance()->AddResource( - new Buffer(resource, shm_handle, size)); + return (new Buffer(resource, shm_handle, size))->GetReference(); } bool PPB_Buffer_Proxy::OnMessageReceived(const IPC::Message& msg) { diff --git a/ppapi/proxy/ppb_buffer_proxy.h b/ppapi/proxy/ppb_buffer_proxy.h index 02e47f8..9d6cfbe 100644 --- a/ppapi/proxy/ppb_buffer_proxy.h +++ b/ppapi/proxy/ppb_buffer_proxy.h @@ -8,7 +8,7 @@ #include "base/shared_memory.h" #include "ppapi/c/pp_instance.h" #include "ppapi/proxy/interface_proxy.h" -#include "ppapi/proxy/plugin_resource.h" +#include "ppapi/shared_impl/resource.h" #include "ppapi/thunk/ppb_buffer_api.h" struct PPB_Buffer_Dev; @@ -21,14 +21,14 @@ namespace pp { namespace proxy { class Buffer : public ppapi::thunk::PPB_Buffer_API, - public PluginResource { + public ppapi::Resource { public: Buffer(const ppapi::HostResource& resource, const base::SharedMemoryHandle& shm_handle, uint32_t size); virtual ~Buffer(); - // ResourceObjectBase overrides. + // Resource overrides. virtual ppapi::thunk::PPB_Buffer_API* AsPPB_Buffer_API() OVERRIDE; // PPB_Buffer_API implementation. diff --git a/ppapi/proxy/ppb_context_3d_proxy.cc b/ppapi/proxy/ppb_context_3d_proxy.cc index b7e5066..a213635 100644 --- a/ppapi/proxy/ppb_context_3d_proxy.cc +++ b/ppapi/proxy/ppb_context_3d_proxy.cc @@ -13,7 +13,6 @@ #include "ppapi/c/dev/ppb_context_3d_trusted_dev.h" #include "ppapi/proxy/enter_proxy.h" #include "ppapi/proxy/plugin_dispatcher.h" -#include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/ppb_surface_3d_proxy.h" #include "ppapi/thunk/enter.h" @@ -21,6 +20,7 @@ #include "ppapi/thunk/thunk.h" using ppapi::HostResource; +using ppapi::Resource; using ppapi::thunk::EnterFunctionNoLock; using ppapi::thunk::EnterResourceNoLock; using ppapi::thunk::PPB_Context3D_API; @@ -340,7 +340,7 @@ void PepperCommandBuffer::UpdateState(const gpu::CommandBuffer::State& state) { // Context3D ------------------------------------------------------------------- Context3D::Context3D(const HostResource& resource) - : PluginResource(resource), + : Resource(resource), draw_(NULL), read_(NULL), transfer_buffer_id_(0) { @@ -356,7 +356,7 @@ PPB_Context3D_API* Context3D::AsPPB_Context3D_API() { } bool Context3D::CreateImplementation() { - PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance()); + PluginDispatcher* dispatcher = PluginDispatcher::GetForResource(this); if (!dispatcher) return false; @@ -418,9 +418,10 @@ int32_t Context3D::BindSurfaces(PP_Resource pp_draw, PP_Resource pp_read) { read_surface ? read_surface->host_resource() : HostResource(); int32_t result; - GetDispatcher()->Send(new PpapiHostMsg_PPBContext3D_BindSurfaces( - INTERFACE_ID_PPB_CONTEXT_3D, - host_resource(), host_draw, host_read, &result)); + PluginDispatcher::GetForResource(this)->Send( + new PpapiHostMsg_PPBContext3D_BindSurfaces( + INTERFACE_ID_PPB_CONTEXT_3D, + host_resource(), host_draw, host_read, &result)); if (result != PP_OK) return result; @@ -432,7 +433,9 @@ int32_t Context3D::BindSurfaces(PP_Resource pp_draw, PP_Resource pp_read) { // Resize the backing texture to the size of the instance when it is // bound. // TODO(alokp): This should be the responsibility of plugins. - InstanceData* data = GetDispatcher()->GetInstanceData(instance()); + InstanceData* data = + PluginDispatcher::GetForResource(this)->GetInstanceData( + pp_instance()); gles2_impl()->ResizeCHROMIUM(data->position.size.width, data->position.size.height); } @@ -443,8 +446,8 @@ int32_t Context3D::BindSurfaces(PP_Resource pp_draw, PP_Resource pp_read) { } int32_t Context3D::GetBoundSurfaces(PP_Resource* draw, PP_Resource* read) { - *draw = draw_ ? draw_->resource() : 0; - *read = read_ ? read_->resource() : 0; + *draw = draw_ ? draw_->pp_resource() : 0; + *read = read_ ? read_->pp_resource() : 0; return PP_OK; } @@ -583,7 +586,7 @@ PP_Resource PPB_Context3D_Proxy::Create(PP_Instance instance, scoped_refptr<Context3D> context_3d(new Context3D(result)); if (!context_3d->CreateImplementation()) return 0; - return PluginResourceTracker::GetInstance()->AddResource(context_3d); + return context_3d->GetReference(); } bool PPB_Context3D_Proxy::OnMessageReceived(const IPC::Message& msg) { diff --git a/ppapi/proxy/ppb_context_3d_proxy.h b/ppapi/proxy/ppb_context_3d_proxy.h index 017c2a1..cdbdd70 100644 --- a/ppapi/proxy/ppb_context_3d_proxy.h +++ b/ppapi/proxy/ppb_context_3d_proxy.h @@ -7,13 +7,14 @@ #include <vector> +#include "base/memory/scoped_ptr.h" #include "base/shared_memory.h" #include "gpu/command_buffer/common/command_buffer.h" #include "ppapi/c/dev/pp_graphics_3d_dev.h" #include "ppapi/c/pp_instance.h" #include "ppapi/proxy/interface_proxy.h" -#include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/proxy_non_thread_safe_ref_count.h" +#include "ppapi/shared_impl/resource.h" #include "ppapi/thunk/ppb_context_3d_api.h" struct PPB_Context3D_Dev; @@ -34,13 +35,13 @@ namespace proxy { class Surface3D; -class Context3D : public PluginResource, +class Context3D : public ppapi::Resource, public ppapi::thunk::PPB_Context3D_API { public: explicit Context3D(const ppapi::HostResource& resource); virtual ~Context3D(); - // ResourceObjectBase overrides. + // Resource overrides. virtual ::ppapi::thunk::PPB_Context3D_API* AsPPB_Context3D_API() OVERRIDE; gpu::gles2::GLES2Implementation* gles2_impl() const { diff --git a/ppapi/proxy/ppb_cursor_control_proxy.cc b/ppapi/proxy/ppb_cursor_control_proxy.cc index 19ea104..cef77f2 100644 --- a/ppapi/proxy/ppb_cursor_control_proxy.cc +++ b/ppapi/proxy/ppb_cursor_control_proxy.cc @@ -7,13 +7,13 @@ #include "ppapi/c/dev/pp_cursor_type_dev.h" #include "ppapi/c/dev/ppb_cursor_control_dev.h" #include "ppapi/proxy/plugin_dispatcher.h" -#include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/plugin_resource_tracker.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/thunk.h" using ppapi::HostResource; +using ppapi::Resource; using ppapi::thunk::EnterFunctionNoLock; using ppapi::thunk::PPB_CursorControl_FunctionAPI; @@ -61,9 +61,9 @@ PP_Bool PPB_CursorControl_Proxy::SetCursor(PP_Instance instance, // It's legal for the image ID to be null if the type is not custom. HostResource cursor_image_resource; if (type == PP_CURSORTYPE_CUSTOM) { - PluginResource* cursor_image = PluginResourceTracker::GetInstance()-> - GetResourceObject(custom_image_id); - if (!cursor_image || cursor_image->instance() != instance) + Resource* cursor_image = PluginResourceTracker::GetInstance()-> + GetResource(custom_image_id); + if (!cursor_image || cursor_image->pp_instance() != instance) return PP_FALSE; cursor_image_resource = cursor_image->host_resource(); } else { diff --git a/ppapi/proxy/ppb_file_chooser_proxy.cc b/ppapi/proxy/ppb_file_chooser_proxy.cc index 4999e18..ae0eac7 100644 --- a/ppapi/proxy/ppb_file_chooser_proxy.cc +++ b/ppapi/proxy/ppb_file_chooser_proxy.cc @@ -12,25 +12,25 @@ #include "ppapi/proxy/enter_proxy.h" #include "ppapi/proxy/host_dispatcher.h" #include "ppapi/proxy/plugin_dispatcher.h" -#include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/ppb_file_ref_proxy.h" #include "ppapi/proxy/serialized_var.h" #include "ppapi/thunk/thunk.h" using ppapi::HostResource; +using ppapi::Resource; using ppapi::thunk::PPB_FileChooser_API; namespace pp { namespace proxy { -class FileChooser : public PluginResource, +class FileChooser : public Resource, public PPB_FileChooser_API { public: FileChooser(const HostResource& resource); virtual ~FileChooser(); - // ResourceObjectBase overrides. + // Resource overrides. virtual PPB_FileChooser_API* AsPPB_FileChooser_API() OVERRIDE; // PPB_FileChooser_API implementation. @@ -55,7 +55,7 @@ class FileChooser : public PluginResource, }; FileChooser::FileChooser(const HostResource& resource) - : PluginResource(resource), + : Resource(resource), current_show_callback_(PP_MakeCompletionCallback(NULL, NULL)) { } @@ -87,8 +87,9 @@ int32_t FileChooser::Show(PP_CompletionCallback callback) { return PP_ERROR_INPROGRESS; // Can't show more than once. current_show_callback_ = callback; - GetDispatcher()->Send(new PpapiHostMsg_PPBFileChooser_Show( - INTERFACE_ID_PPB_FILE_CHOOSER, host_resource())); + PluginDispatcher::GetForResource(this)->Send( + new PpapiHostMsg_PPBFileChooser_Show( + INTERFACE_ID_PPB_FILE_CHOOSER, host_resource())); return PP_OK_COMPLETIONPENDING; } @@ -164,8 +165,7 @@ PP_Resource PPB_FileChooser_Proxy::CreateProxyResource( if (result.is_null()) return 0; - return PluginResourceTracker::GetInstance()->AddResource( - new FileChooser(result)); + return (new FileChooser(result))->GetReference(); } bool PPB_FileChooser_Proxy::OnMessageReceived(const IPC::Message& msg) { diff --git a/ppapi/proxy/ppb_file_ref_proxy.cc b/ppapi/proxy/ppb_file_ref_proxy.cc index a72519d..d831bfc 100644 --- a/ppapi/proxy/ppb_file_ref_proxy.cc +++ b/ppapi/proxy/ppb_file_ref_proxy.cc @@ -10,7 +10,6 @@ #include "ppapi/proxy/enter_proxy.h" #include "ppapi/proxy/host_dispatcher.h" #include "ppapi/proxy/plugin_dispatcher.h" -#include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/serialized_var.h" #include "ppapi/thunk/ppb_file_ref_api.h" @@ -18,6 +17,7 @@ #include "ppapi/thunk/thunk.h" using ppapi::HostResource; +using ppapi::Resource; using ppapi::thunk::EnterFunctionNoLock; using ppapi::thunk::EnterResourceNoLock; using ppapi::thunk::PPB_FileRef_API; @@ -35,12 +35,12 @@ InterfaceProxy* CreateFileRefProxy(Dispatcher* dispatcher, } // namespace -class FileRef : public PluginResource, public PPB_FileRef_API { +class FileRef : public Resource, public PPB_FileRef_API { public: explicit FileRef(const PPBFileRef_CreateInfo& info); virtual ~FileRef(); - // ResourceObjectBase overrides. + // Resource overrides. virtual PPB_FileRef_API* AsPPB_FileRef_API() OVERRIDE; // PPB_FileRef_API implementation. @@ -58,6 +58,10 @@ class FileRef : public PluginResource, public PPB_FileRef_API { PP_CompletionCallback callback) OVERRIDE; private: + PluginDispatcher* GetDispatcher() const { + return PluginDispatcher::GetForResource(this); + } + PP_FileSystemType file_system_type_; PP_Var path_; PP_Var name_; @@ -66,8 +70,8 @@ class FileRef : public PluginResource, public PPB_FileRef_API { }; FileRef::FileRef(const PPBFileRef_CreateInfo& info) - : PluginResource(info.resource) { - Dispatcher* dispatcher = PluginDispatcher::GetForInstance(instance()); + : Resource(info.resource) { + Dispatcher* dispatcher = PluginDispatcher::GetForResource(this); file_system_type_ = static_cast<PP_FileSystemType>(info.file_system_type); @@ -134,10 +138,10 @@ int32_t FileRef::Delete(PP_CompletionCallback callback) { int32_t FileRef::Rename(PP_Resource new_file_ref, PP_CompletionCallback callback) { - PluginResource* new_file_ref_object = - PluginResourceTracker::GetInstance()->GetResourceObject(new_file_ref); + Resource* new_file_ref_object = + PluginResourceTracker::GetInstance()->GetResource(new_file_ref); if (!new_file_ref_object || - new_file_ref_object->host_resource().instance() != instance()) + new_file_ref_object->host_resource().instance() != pp_instance()) return PP_ERROR_BADRESOURCE; GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_Rename( @@ -169,15 +173,16 @@ const InterfaceProxy::Info* PPB_FileRef_Proxy::GetInfo() { // static PP_Resource PPB_FileRef_Proxy::CreateProxyResource(PP_Resource file_system, const char* path) { - PluginResource* file_system_object = - PluginResourceTracker::GetInstance()->GetResourceObject(file_system); + Resource* file_system_object = + PluginResourceTracker::GetInstance()->GetResource(file_system); if (!file_system_object) return 0; PPBFileRef_CreateInfo create_info; - file_system_object->GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_Create( - INTERFACE_ID_PPB_FILE_REF, file_system_object->host_resource(), - path, &create_info)); + PluginDispatcher::GetForResource(file_system_object)->Send( + new PpapiHostMsg_PPBFileRef_Create( + INTERFACE_ID_PPB_FILE_REF, file_system_object->host_resource(), + path, &create_info)); return PPB_FileRef_Proxy::DeserializeFileRef(create_info); } @@ -228,9 +233,7 @@ PP_Resource PPB_FileRef_Proxy::DeserializeFileRef( const PPBFileRef_CreateInfo& serialized) { if (serialized.resource.is_null()) return 0; // Resource invalid. - - return PluginResourceTracker::GetInstance()->AddResource( - new FileRef(serialized)); + return (new FileRef(serialized))->GetReference(); } void PPB_FileRef_Proxy::OnMsgCreate(const HostResource& file_system, diff --git a/ppapi/proxy/ppb_file_system_proxy.cc b/ppapi/proxy/ppb_file_system_proxy.cc index 98a1a7f..b3035b9 100644 --- a/ppapi/proxy/ppb_file_system_proxy.cc +++ b/ppapi/proxy/ppb_file_system_proxy.cc @@ -11,7 +11,6 @@ #include "ppapi/proxy/enter_proxy.h" #include "ppapi/proxy/host_dispatcher.h" #include "ppapi/proxy/plugin_dispatcher.h" -#include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/serialized_var.h" #include "ppapi/thunk/enter.h" @@ -20,6 +19,7 @@ #include "ppapi/thunk/thunk.h" using ppapi::HostResource; +using ppapi::Resource; using ppapi::thunk::EnterFunctionNoLock; using ppapi::thunk::PPB_FileSystem_API; using ppapi::thunk::ResourceCreationAPI; @@ -39,12 +39,12 @@ InterfaceProxy* CreateFileSystemProxy(Dispatcher* dispatcher, // This object maintains most of the state of the ref in the plugin for fast // querying. It's all set in the constructor from the "create info" sent from // the host. -class FileSystem : public PluginResource, public PPB_FileSystem_API { +class FileSystem : public Resource, public PPB_FileSystem_API { public: FileSystem(const HostResource& host_resource, PP_FileSystemType type); virtual ~FileSystem(); - // ResourceObjectBase override. + // Resource override. virtual PPB_FileSystem_API* AsPPB_FileSystem_API() OVERRIDE; // PPB_FileSystem_APi implementation. @@ -65,7 +65,7 @@ class FileSystem : public PluginResource, public PPB_FileSystem_API { FileSystem::FileSystem(const HostResource& host_resource, PP_FileSystemType type) - : PluginResource(host_resource), + : Resource(host_resource), type_(type), called_open_(false), current_open_callback_(PP_MakeCompletionCallback(NULL, NULL)) { @@ -98,8 +98,9 @@ int32_t FileSystem::Open(int64_t expected_size, current_open_callback_ = callback; called_open_ = true; - GetDispatcher()->Send(new PpapiHostMsg_PPBFileSystem_Open( - INTERFACE_ID_PPB_FILE_SYSTEM, host_resource(), expected_size)); + PluginDispatcher::GetForResource(this)->Send( + new PpapiHostMsg_PPBFileSystem_Open( + INTERFACE_ID_PPB_FILE_SYSTEM, host_resource(), expected_size)); return PP_OK_COMPLETIONPENDING; } @@ -144,9 +145,7 @@ PP_Resource PPB_FileSystem_Proxy::CreateProxyResource( INTERFACE_ID_PPB_FILE_SYSTEM, instance, type, &result)); if (result.is_null()) return 0; - - return PluginResourceTracker::GetInstance()->AddResource( - new FileSystem(result, type)); + return (new FileSystem(result, type))->GetReference(); } bool PPB_FileSystem_Proxy::OnMessageReceived(const IPC::Message& msg) { diff --git a/ppapi/proxy/ppb_flash_file_proxy.cc b/ppapi/proxy/ppb_flash_file_proxy.cc index 73e8a2d8..9400728 100644 --- a/ppapi/proxy/ppb_flash_file_proxy.cc +++ b/ppapi/proxy/ppb_flash_file_proxy.cc @@ -20,10 +20,12 @@ #include "ppapi/c/pp_file_info.h" #include "ppapi/c/private/ppb_flash_file.h" #include "ppapi/proxy/plugin_dispatcher.h" -#include "ppapi/proxy/plugin_resource.h" +#include "ppapi/proxy/plugin_resource_tracker.h" #include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/shared_impl/resource.h" using ppapi::HostResource; +using ppapi::Resource; namespace pp { namespace proxy { @@ -625,13 +627,12 @@ namespace { int32_t OpenFileRefFile(PP_Resource file_ref_id, int32_t mode, PP_FileHandle* file) { - PluginResource* file_ref = - PluginResourceTracker::GetInstance()->GetResourceObject(file_ref_id); + Resource* file_ref = + PluginResourceTracker::GetInstance()->GetResource(file_ref_id); if (!file_ref) return PP_ERROR_BADRESOURCE; - PluginDispatcher* dispatcher = - PluginDispatcher::GetForInstance(file_ref->instance()); + PluginDispatcher* dispatcher = PluginDispatcher::GetForResource(file_ref); if (!dispatcher) return PP_ERROR_BADARGUMENT; @@ -646,13 +647,12 @@ int32_t OpenFileRefFile(PP_Resource file_ref_id, int32_t QueryFileRefFile(PP_Resource file_ref_id, PP_FileInfo* info) { - PluginResource* file_ref = - PluginResourceTracker::GetInstance()->GetResourceObject(file_ref_id); + Resource* file_ref = + PluginResourceTracker::GetInstance()->GetResource(file_ref_id); if (!file_ref) return PP_ERROR_BADRESOURCE; - PluginDispatcher* dispatcher = - PluginDispatcher::GetForInstance(file_ref->instance()); + PluginDispatcher* dispatcher = PluginDispatcher::GetForResource(file_ref); if (!dispatcher) return PP_ERROR_BADARGUMENT; diff --git a/ppapi/proxy/ppb_flash_menu_proxy.cc b/ppapi/proxy/ppb_flash_menu_proxy.cc index c2b74a2..98ee3b6 100644 --- a/ppapi/proxy/ppb_flash_menu_proxy.cc +++ b/ppapi/proxy/ppb_flash_menu_proxy.cc @@ -14,6 +14,7 @@ #include "ppapi/thunk/thunk.h" using ppapi::HostResource; +using ppapi::Resource; using ppapi::thunk::EnterFunctionNoLock; using ppapi::thunk::PPB_Flash_Menu_API; using ppapi::thunk::ResourceCreationAPI; @@ -21,12 +22,12 @@ using ppapi::thunk::ResourceCreationAPI; namespace pp { namespace proxy { -class FlashMenu : public PPB_Flash_Menu_API, public PluginResource { +class FlashMenu : public PPB_Flash_Menu_API, public Resource { public: explicit FlashMenu(const HostResource& resource); virtual ~FlashMenu(); - // ResourceObjectBase overrides. + // Resource overrides. virtual PPB_Flash_Menu_API* AsPPB_Flash_Menu_API() OVERRIDE; // PPB_Flash_Menu_API implementation. @@ -44,7 +45,7 @@ class FlashMenu : public PPB_Flash_Menu_API, public PluginResource { }; FlashMenu::FlashMenu(const HostResource& resource) - : PluginResource(resource), + : Resource(resource), callback_(PP_BlockUntilComplete()), selected_id_ptr_(NULL) { } @@ -65,8 +66,9 @@ int32_t FlashMenu::Show(const struct PP_Point* location, selected_id_ptr_ = selected_id; callback_ = callback; - GetDispatcher()->Send(new PpapiHostMsg_PPBFlashMenu_Show( - INTERFACE_ID_PPB_FLASH_MENU, host_resource(), *location)); + PluginDispatcher::GetForResource(this)->Send( + new PpapiHostMsg_PPBFlashMenu_Show( + INTERFACE_ID_PPB_FLASH_MENU, host_resource(), *location)); return PP_OK_COMPLETIONPENDING; } @@ -122,9 +124,7 @@ PP_Resource PPB_Flash_Menu_Proxy::CreateProxyResource( INTERFACE_ID_PPB_FLASH_MENU, instance_id, serialized_menu, &result)); if (result.is_null()) return 0; - - return PluginResourceTracker::GetInstance()->AddResource( - new FlashMenu(result)); + return (new FlashMenu(result))->GetReference(); } bool PPB_Flash_Menu_Proxy::OnMessageReceived(const IPC::Message& msg) { diff --git a/ppapi/proxy/ppb_flash_menu_proxy.h b/ppapi/proxy/ppb_flash_menu_proxy.h index 979abee..adce7ec 100644 --- a/ppapi/proxy/ppb_flash_menu_proxy.h +++ b/ppapi/proxy/ppb_flash_menu_proxy.h @@ -6,13 +6,16 @@ #define PPAPI_PPB_FLASH_MENU_PROXY_H_ #include "ppapi/proxy/interface_proxy.h" -#include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/proxy_non_thread_safe_ref_count.h" struct PP_Flash_Menu; struct PP_Point; struct PPB_Flash_Menu; +namespace ppapi { +class HostResource; +} + namespace pp { namespace proxy { diff --git a/ppapi/proxy/ppb_flash_net_connector_proxy.cc b/ppapi/proxy/ppb_flash_net_connector_proxy.cc index 0d93428..c222720 100644 --- a/ppapi/proxy/ppb_flash_net_connector_proxy.cc +++ b/ppapi/proxy/ppb_flash_net_connector_proxy.cc @@ -10,7 +10,6 @@ #include "ppapi/c/private/ppb_flash_net_connector.h" #include "ppapi/proxy/enter_proxy.h" #include "ppapi/proxy/plugin_dispatcher.h" -#include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/serialized_var.h" #include "ppapi/thunk/enter.h" @@ -19,6 +18,7 @@ #include "ppapi/thunk/thunk.h" using ppapi::HostResource; +using ppapi::Resource; using ppapi::thunk::EnterFunctionNoLock; using ppapi::thunk::PPB_Flash_NetConnector_API; using ppapi::thunk::ResourceCreationAPI; @@ -50,12 +50,12 @@ class AbortCallbackTask : public Task { }; class FlashNetConnector : public PPB_Flash_NetConnector_API, - public PluginResource { + public Resource { public: explicit FlashNetConnector(const HostResource& resource); virtual ~FlashNetConnector(); - // ResourceObjectBase overrides. + // Resource overrides. virtual PPB_Flash_NetConnector_API* AsPPB_Flash_NetConnector_API() OVERRIDE; // PPB_Flash_NetConnector_API implementation. @@ -92,7 +92,7 @@ class FlashNetConnector : public PPB_Flash_NetConnector_API, }; FlashNetConnector::FlashNetConnector(const HostResource& resource) - : PluginResource(resource), + : Resource(resource), callback_(PP_BlockUntilComplete()), local_addr_out_(NULL), remote_addr_out_(NULL) { @@ -163,7 +163,7 @@ int32_t FlashNetConnector::ConnectWithMessage( return PP_ERROR_INPROGRESS; // Can only have one pending request. // Send the request, it will call us back via ConnectACK. - GetDispatcher()->Send(msg_deletor.release()); + PluginDispatcher::GetForResource(this)->Send(msg_deletor.release()); callback_ = callback; socket_out_ = socket_out; @@ -230,9 +230,7 @@ PP_Resource PPB_Flash_NetConnector_Proxy::CreateProxyResource( INTERFACE_ID_PPB_FLASH_NETCONNECTOR, instance, &result)); if (result.is_null()) return 0; - - return PluginResourceTracker::GetInstance()->AddResource( - new FlashNetConnector(result)); + return (new FlashNetConnector(result))->GetReference(); } bool PPB_Flash_NetConnector_Proxy::OnMessageReceived(const IPC::Message& msg) { diff --git a/ppapi/proxy/ppb_flash_proxy.cc b/ppapi/proxy/ppb_flash_proxy.cc index 289a864..bbe7018 100644 --- a/ppapi/proxy/ppb_flash_proxy.cc +++ b/ppapi/proxy/ppb_flash_proxy.cc @@ -14,12 +14,14 @@ #include "ppapi/c/private/ppb_flash.h" #include "ppapi/proxy/host_dispatcher.h" #include "ppapi/proxy/plugin_dispatcher.h" -#include "ppapi/proxy/plugin_resource.h" +#include "ppapi/proxy/plugin_resource_tracker.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/proxy_module.h" #include "ppapi/proxy/serialized_var.h" +#include "ppapi/shared_impl/resource.h" using ppapi::HostResource; +using ppapi::Resource; namespace pp { namespace proxy { @@ -44,17 +46,17 @@ PP_Bool DrawGlyphs(PP_Instance instance, uint32_t glyph_count, const uint16_t glyph_indices[], const PP_Point glyph_advances[]) { - PluginResource* image_data = PluginResourceTracker::GetInstance()-> - GetResourceObject(pp_image_data); + Resource* image_data = PluginResourceTracker::GetInstance()->GetResource( + pp_image_data); if (!image_data) return PP_FALSE; // The instance parameter isn't strictly necessary but we check that it // matches anyway. - if (image_data->instance() != instance) + if (image_data->pp_instance() != instance) return PP_FALSE; PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance( - image_data->instance()); + image_data->pp_instance()); if (!dispatcher) return PP_FALSE; @@ -96,13 +98,13 @@ PP_Var GetProxyForURL(PP_Instance instance, const char* url) { int32_t Navigate(PP_Resource request_id, const char* target, bool from_user_action) { - PluginResource* request_object = - PluginResourceTracker::GetInstance()->GetResourceObject(request_id); + Resource* request_object = + PluginResourceTracker::GetInstance()->GetResource(request_id); if (!request_object) return PP_ERROR_BADRESOURCE; PluginDispatcher* dispatcher = - PluginDispatcher::GetForInstance(request_object->instance()); + PluginDispatcher::GetForInstance(request_object->pp_instance()); if (!dispatcher) return PP_ERROR_FAILED; diff --git a/ppapi/proxy/ppb_flash_tcp_socket_proxy.cc b/ppapi/proxy/ppb_flash_tcp_socket_proxy.cc index 1be870c..52dca5d 100644 --- a/ppapi/proxy/ppb_flash_tcp_socket_proxy.cc +++ b/ppapi/proxy/ppb_flash_tcp_socket_proxy.cc @@ -14,13 +14,14 @@ #include "base/task.h" #include "ppapi/c/pp_errors.h" #include "ppapi/proxy/plugin_dispatcher.h" -#include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/plugin_resource_tracker.h" #include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/shared_impl/resource.h" #include "ppapi/thunk/ppb_flash_tcp_socket_api.h" #include "ppapi/thunk/thunk.h" using ppapi::HostResource; +using ppapi::Resource; using ppapi::thunk::PPB_Flash_TCPSocket_API; namespace pp { @@ -58,12 +59,12 @@ InterfaceProxy* CreateFlashTCPSocketProxy(Dispatcher* dispatcher, } // namespace class FlashTCPSocket : public PPB_Flash_TCPSocket_API, - public PluginResource { + public Resource { public: FlashTCPSocket(const HostResource& resource, uint32 socket_id); virtual ~FlashTCPSocket(); - // ResourceObjectBase overrides. + // Resource overrides. virtual PPB_Flash_TCPSocket_API* AsPPB_Flash_TCPSocket_API() OVERRIDE; // PPB_Flash_TCPSocket_API implementation. @@ -110,6 +111,10 @@ class FlashTCPSocket : public PPB_Flash_TCPSocket_API, bool IsConnected() const; + PluginDispatcher* GetDispatcher() const { + return PluginDispatcher::GetForResource(this); + } + // Backend for both Connect() and ConnectWithNetAddress(). To keep things // generic, the message is passed in (on error, it's deleted). int32_t ConnectWithMessage(IPC::Message* msg, @@ -135,7 +140,7 @@ class FlashTCPSocket : public PPB_Flash_TCPSocket_API, }; FlashTCPSocket::FlashTCPSocket(const HostResource& resource, uint32 socket_id) - : PluginResource(resource), + : Resource(resource), socket_id_(socket_id), connection_state_(BEFORE_CONNECT), connect_callback_(PP_BlockUntilComplete()), @@ -420,9 +425,8 @@ PP_Resource PPB_Flash_TCPSocket_Proxy::CreateProxyResource( &socket_id)); if (socket_id == 0) return 0; - - return PluginResourceTracker::GetInstance()->AddResource( - new FlashTCPSocket(HostResource::MakeInstanceOnly(instance), socket_id)); + return (new FlashTCPSocket(HostResource::MakeInstanceOnly(instance), + socket_id))->GetReference(); } bool PPB_Flash_TCPSocket_Proxy::OnMessageReceived(const IPC::Message& msg) { diff --git a/ppapi/proxy/ppb_font_proxy.cc b/ppapi/proxy/ppb_font_proxy.cc index 392481b..2760c0b 100644 --- a/ppapi/proxy/ppb_font_proxy.cc +++ b/ppapi/proxy/ppb_font_proxy.cc @@ -12,13 +12,14 @@ #include "ppapi/proxy/ppb_image_data_proxy.h" #include "ppapi/proxy/serialized_var.h" #include "ppapi/shared_impl/ppapi_preferences.h" -#include "ppapi/shared_impl/resource_object_base.h" +#include "ppapi/shared_impl/resource.h" #include "ppapi/shared_impl/var.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/ppb_image_data_api.h" #include "ppapi/thunk/thunk.h" using ppapi::HostResource; +using ppapi::Resource; using ppapi::StringVar; using ppapi::thunk::EnterResourceNoLock; using ppapi::thunk::PPB_ImageData_API; @@ -95,19 +96,20 @@ bool PPB_Font_Proxy::OnMessageReceived(const IPC::Message& msg) { Font::Font(const HostResource& resource, const PP_FontDescription_Dev& desc) - : PluginResource(resource), + : Resource(resource), webkit_event_(false, false) { TRACE_EVENT0("ppapi proxy", "Font::Font"); scoped_refptr<StringVar> face(StringVar::FromPPVar(desc.face)); - WebKitForwarding* forwarding = GetDispatcher()->GetWebKitForwarding(); + PluginDispatcher* dispatcher = PluginDispatcher::GetForResource(this); + WebKitForwarding* forwarding = dispatcher->GetWebKitForwarding(); RunOnWebKitThread(true, base::Bind(&WebKitForwarding::CreateFontForwarding, base::Unretained(forwarding), &webkit_event_, desc, face.get() ? face->value() : std::string(), - GetDispatcher()->preferences(), + dispatcher->preferences(), &font_forwarding_)); } @@ -221,7 +223,7 @@ int32_t Font::PixelOffsetForCharacter(const PP_TextRun_Dev* text, } void Font::RunOnWebKitThread(bool blocking, const base::Closure& task) { - GetDispatcher()->PostToWebKitThread(FROM_HERE, task); + PluginDispatcher::GetForResource(this)->PostToWebKitThread(FROM_HERE, task); if (blocking) webkit_event_.Wait(); } diff --git a/ppapi/proxy/ppb_font_proxy.h b/ppapi/proxy/ppb_font_proxy.h index 8058fdf..8ea0e51 100644 --- a/ppapi/proxy/ppb_font_proxy.h +++ b/ppapi/proxy/ppb_font_proxy.h @@ -5,11 +5,12 @@ #ifndef PPAPI_PROXY_PPB_FONT_PROXY_H_ #define PPAPI_PROXY_PPB_FONT_PROXY_H_ -#include "base/basictypes.h" +#include "base/callback.h" #include "base/synchronization/waitable_event.h" #include "ppapi/proxy/interface_proxy.h" -#include "ppapi/proxy/plugin_resource.h" +#include "ppapi/shared_impl/function_group_base.h" #include "ppapi/shared_impl/host_resource.h" +#include "ppapi/shared_impl/resource.h" #include "ppapi/shared_impl/webkit_forwarding.h" #include "ppapi/thunk/ppb_font_api.h" @@ -42,7 +43,7 @@ class PPB_Font_Proxy : public ppapi::FunctionGroupBase, DISALLOW_COPY_AND_ASSIGN(PPB_Font_Proxy); }; -class Font : public PluginResource, +class Font : public ppapi::Resource, public ppapi::thunk::PPB_Font_API { public: // Note that there isn't a "real" resource in the renderer backing a font, @@ -53,7 +54,7 @@ class Font : public PluginResource, Font(const ppapi::HostResource& resource, const PP_FontDescription_Dev& desc); virtual ~Font(); - // ResourceObjectBase. + // Resource. virtual ppapi::thunk::PPB_Font_API* AsPPB_Font_API() OVERRIDE; // PPB_Font_API implementation. diff --git a/ppapi/proxy/ppb_graphics_2d_proxy.cc b/ppapi/proxy/ppb_graphics_2d_proxy.cc index eaa1032..f752949 100644 --- a/ppapi/proxy/ppb_graphics_2d_proxy.cc +++ b/ppapi/proxy/ppb_graphics_2d_proxy.cc @@ -14,13 +14,13 @@ #include "ppapi/c/ppb_graphics_2d.h" #include "ppapi/proxy/enter_proxy.h" #include "ppapi/proxy/plugin_dispatcher.h" -#include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/ppb_graphics_2d_api.h" #include "ppapi/thunk/thunk.h" using ppapi::HostResource; +using ppapi::Resource; using ppapi::thunk::PPB_Graphics2D_API; namespace pp { @@ -35,15 +35,15 @@ InterfaceProxy* CreateGraphics2DProxy(Dispatcher* dispatcher, } // namespace -class Graphics2D : public PluginResource, - public ::ppapi::thunk::PPB_Graphics2D_API { +class Graphics2D : public ppapi::Resource, + public ppapi::thunk::PPB_Graphics2D_API { public: Graphics2D(const HostResource& host_resource, const PP_Size& size, PP_Bool is_always_opaque); virtual ~Graphics2D(); - // ResourceObjectBase. + // Resource. virtual PPB_Graphics2D_API* AsPPB_Graphics2D_API(); // PPB_Graphics_2D_API. @@ -60,6 +60,10 @@ class Graphics2D : public PluginResource, void FlushACK(int32_t result_code); private: + PluginDispatcher* GetDispatcher() const { + return PluginDispatcher::GetForResource(this); + } + PP_Size size_; PP_Bool is_always_opaque_; @@ -73,7 +77,7 @@ class Graphics2D : public PluginResource, Graphics2D::Graphics2D(const HostResource& host_resource, const PP_Size& size, PP_Bool is_always_opaque) - : PluginResource(host_resource), + : Resource(host_resource), size_(size), is_always_opaque_(is_always_opaque), current_flush_callback_(PP_BlockUntilComplete()) { @@ -95,10 +99,10 @@ PP_Bool Graphics2D::Describe(PP_Size* size, PP_Bool* is_always_opaque) { void Graphics2D::PaintImageData(PP_Resource image_data, const PP_Point* top_left, const PP_Rect* src_rect) { - PluginResource* image_object = PluginResourceTracker::GetInstance()-> - GetResourceObject(image_data); - //if (!image_object || instance() != image_object->instance()) - // return; + Resource* image_object = PluginResourceTracker::GetInstance()-> + GetResource(image_data); + if (!image_object || pp_instance() != image_object->pp_instance()) + return; PP_Rect dummy; memset(&dummy, 0, sizeof(PP_Rect)); @@ -118,9 +122,9 @@ void Graphics2D::Scroll(const PP_Rect* clip_rect, } void Graphics2D::ReplaceContents(PP_Resource image_data) { - PluginResource* image_object = PluginResourceTracker::GetInstance()-> - GetResourceObject(image_data); - if (!image_object || instance() != image_object->instance()) + Resource* image_object = PluginResourceTracker::GetInstance()-> + GetResource(image_data); + if (!image_object || pp_instance() != image_object->pp_instance()) return; GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_ReplaceContents( @@ -183,8 +187,7 @@ PP_Resource PPB_Graphics2D_Proxy::CreateProxyResource( &result)); if (result.is_null()) return 0; - return PluginResourceTracker::GetInstance()->AddResource( - new Graphics2D(result, size, is_always_opaque)); + return (new Graphics2D(result, size, is_always_opaque))->GetReference(); } bool PPB_Graphics2D_Proxy::OnMessageReceived(const IPC::Message& msg) { diff --git a/ppapi/proxy/ppb_graphics_2d_proxy.h b/ppapi/proxy/ppb_graphics_2d_proxy.h index 77f0dd6..7834acc 100644 --- a/ppapi/proxy/ppb_graphics_2d_proxy.h +++ b/ppapi/proxy/ppb_graphics_2d_proxy.h @@ -14,7 +14,6 @@ #include "ppapi/c/pp_var.h" #include "ppapi/cpp/completion_callback.h" #include "ppapi/proxy/interface_proxy.h" -#include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/proxy_non_thread_safe_ref_count.h" #include "ppapi/shared_impl/host_resource.h" diff --git a/ppapi/proxy/ppb_graphics_3d_proxy.cc b/ppapi/proxy/ppb_graphics_3d_proxy.cc index 51b567e..a8cea51 100644 --- a/ppapi/proxy/ppb_graphics_3d_proxy.cc +++ b/ppapi/proxy/ppb_graphics_3d_proxy.cc @@ -14,6 +14,7 @@ #include "ppapi/thunk/thunk.h" using ppapi::HostResource; +using ppapi::Resource; using ppapi::thunk::EnterFunctionNoLock; using ppapi::thunk::EnterResourceNoLock; using ppapi::thunk::PPB_Graphics3D_API; @@ -324,7 +325,7 @@ InterfaceProxy* CreateGraphics3DProxy(Dispatcher* dispatcher, } // namespace Graphics3D::Graphics3D(const HostResource& resource) - : PluginResource(resource) { + : Resource(resource) { } Graphics3D::~Graphics3D() { @@ -332,7 +333,7 @@ Graphics3D::~Graphics3D() { } bool Graphics3D::Init() { - PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance()); + PluginDispatcher* dispatcher = PluginDispatcher::GetForResource(this); if (!dispatcher) return false; @@ -390,7 +391,7 @@ int32 Graphics3D::DoSwapBuffers() { IPC::Message* msg = new PpapiHostMsg_PPBGraphics3D_SwapBuffers( INTERFACE_ID_PPB_GRAPHICS_3D, host_resource()); msg->set_unblock(true); - GetDispatcher()->Send(msg); + PluginDispatcher::GetForResource(this)->Send(msg); gles2_impl()->SwapBuffers(); return PP_OK_COMPLETIONPENDING; @@ -451,8 +452,7 @@ PP_Resource PPB_Graphics3D_Proxy::CreateProxyResource( scoped_refptr<Graphics3D> graphics_3d(new Graphics3D(result)); if (!graphics_3d->Init()) return 0; - - return PluginResourceTracker::GetInstance()->AddResource(graphics_3d); + return graphics_3d->GetReference(); } bool PPB_Graphics3D_Proxy::OnMessageReceived(const IPC::Message& msg) { diff --git a/ppapi/proxy/ppb_graphics_3d_proxy.h b/ppapi/proxy/ppb_graphics_3d_proxy.h index a304de3..bb6df67 100644 --- a/ppapi/proxy/ppb_graphics_3d_proxy.h +++ b/ppapi/proxy/ppb_graphics_3d_proxy.h @@ -13,9 +13,9 @@ #include "ppapi/c/pp_instance.h" #include "ppapi/cpp/completion_callback.h" #include "ppapi/proxy/interface_proxy.h" -#include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/proxy_non_thread_safe_ref_count.h" #include "ppapi/shared_impl/graphics_3d_impl.h" +#include "ppapi/shared_impl/resource.h" namespace ppapi { class HostResource; @@ -24,7 +24,7 @@ class HostResource; namespace pp { namespace proxy { -class Graphics3D : public PluginResource, +class Graphics3D : public ppapi::Resource, public ppapi::Graphics3DImpl { public: explicit Graphics3D(const ppapi::HostResource& resource); @@ -32,7 +32,7 @@ class Graphics3D : public PluginResource, bool Init(); - // PluginResource overrides. + // Resource overrides. virtual ::ppapi::thunk::PPB_Graphics3D_API* AsPPB_Graphics3D_API() OVERRIDE { return this; } diff --git a/ppapi/proxy/ppb_image_data_proxy.cc b/ppapi/proxy/ppb_image_data_proxy.cc index dec6efc..9e090c8 100644 --- a/ppapi/proxy/ppb_image_data_proxy.cc +++ b/ppapi/proxy/ppb_image_data_proxy.cc @@ -17,11 +17,13 @@ #include "ppapi/proxy/plugin_resource_tracker.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/shared_impl/host_resource.h" +#include "ppapi/shared_impl/resource.h" #include "ppapi/thunk/thunk.h" #include "skia/ext/platform_canvas.h" #include "ui/gfx/surface/transport_dib.h" using ppapi::HostResource; +using ppapi::Resource; namespace pp { namespace proxy { @@ -66,7 +68,7 @@ bool PPB_ImageData_Proxy::OnMessageReceived(const IPC::Message& msg) { ImageData::ImageData(const HostResource& resource, const PP_ImageDataDesc& desc, ImageHandle handle) - : PluginResource(resource), + : Resource(resource), desc_(desc) { #if defined(OS_WIN) transport_dib_.reset(TransportDIB::CreateWithHandle(handle)); diff --git a/ppapi/proxy/ppb_image_data_proxy.h b/ppapi/proxy/ppb_image_data_proxy.h index 75d3faf..c861963 100644 --- a/ppapi/proxy/ppb_image_data_proxy.h +++ b/ppapi/proxy/ppb_image_data_proxy.h @@ -5,6 +5,7 @@ #ifndef PPAPI_PPB_IMAGE_DATA_PROXY_H_ #define PPAPI_PPB_IMAGE_DATA_PROXY_H_ +#include "base/scoped_ptr.h" #include "ppapi/c/pp_bool.h" #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_instance.h" @@ -13,9 +14,9 @@ #include "ppapi/c/pp_size.h" #include "ppapi/c/pp_var.h" #include "ppapi/proxy/interface_proxy.h" -#include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/serialized_structs.h" #include "ppapi/shared_impl/image_data_impl.h" +#include "ppapi/shared_impl/resource.h" #include "ppapi/thunk/ppb_image_data_api.h" struct PPB_ImageData; @@ -47,8 +48,8 @@ class PPB_ImageData_Proxy : public InterfaceProxy { virtual bool OnMessageReceived(const IPC::Message& msg); }; -class ImageData : public PluginResource, - public ::ppapi::thunk::PPB_ImageData_API, +class ImageData : public ppapi::Resource, + public ppapi::thunk::PPB_ImageData_API, public ppapi::ImageDataImpl { public: ImageData(const ppapi::HostResource& resource, @@ -56,8 +57,8 @@ class ImageData : public PluginResource, ImageHandle handle); virtual ~ImageData(); - // ResourceObjectBase overrides. - virtual ::ppapi::thunk::PPB_ImageData_API* AsPPB_ImageData_API() OVERRIDE; + // Resource overrides. + virtual ppapi::thunk::PPB_ImageData_API* AsPPB_ImageData_API() OVERRIDE; // PPB_ImageData API. virtual PP_Bool Describe(PP_ImageDataDesc* desc) OVERRIDE; diff --git a/ppapi/proxy/ppb_input_event_proxy.cc b/ppapi/proxy/ppb_input_event_proxy.cc index 593bf1e..a9b1a4f 100644 --- a/ppapi/proxy/ppb_input_event_proxy.cc +++ b/ppapi/proxy/ppb_input_event_proxy.cc @@ -6,28 +6,29 @@ #include "ppapi/c/ppb_audio_config.h" #include "ppapi/proxy/plugin_dispatcher.h" -#include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/plugin_var_tracker.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/shared_impl/input_event_impl.h" +#include "ppapi/shared_impl/resource.h" #include "ppapi/shared_impl/var.h" #include "ppapi/thunk/thunk.h" using ppapi::HostResource; using ppapi::InputEventData; using ppapi::InputEventImpl; +using ppapi::Resource; using ppapi::thunk::PPB_InputEvent_API; namespace pp { namespace proxy { // The implementation is actually in InputEventImpl. -class InputEvent : public PluginResource, public InputEventImpl { +class InputEvent : public Resource, public InputEventImpl { public: InputEvent(const HostResource& resource, const InputEventData& data); virtual ~InputEvent(); - // ResourceObjectBase overrides. + // Resource overrides. virtual PPB_InputEvent_API* AsPPB_InputEvent_API() OVERRIDE; // InputEventImpl overrides. @@ -38,7 +39,7 @@ class InputEvent : public PluginResource, public InputEventImpl { }; InputEvent::InputEvent(const HostResource& resource, const InputEventData& data) - : PluginResource(resource), + : Resource(resource), InputEventImpl(data) { } @@ -122,8 +123,8 @@ const InterfaceProxy::Info* PPB_InputEvent_Proxy::GetWheelInputEventInfo() { PP_Resource PPB_InputEvent_Proxy::CreateProxyResource( PP_Instance instance, const InputEventData& data) { - return PluginResourceTracker::GetInstance()->AddResource( - new InputEvent(HostResource::MakeInstanceOnly(instance), data)); + return (new InputEvent(HostResource::MakeInstanceOnly(instance), data))-> + GetReference(); } bool PPB_InputEvent_Proxy::OnMessageReceived(const IPC::Message& msg) { diff --git a/ppapi/proxy/ppb_instance_proxy.cc b/ppapi/proxy/ppb_instance_proxy.cc index 08da58c..ffa4f66 100644 --- a/ppapi/proxy/ppb_instance_proxy.cc +++ b/ppapi/proxy/ppb_instance_proxy.cc @@ -10,7 +10,6 @@ #include "ppapi/c/ppb_messaging.h" #include "ppapi/proxy/host_dispatcher.h" #include "ppapi/proxy/plugin_dispatcher.h" -#include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/plugin_resource_tracker.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/serialized_var.h" @@ -23,6 +22,7 @@ #endif using ppapi::HostResource; +using ppapi::Resource; using ppapi::thunk::EnterFunctionNoLock; using ppapi::thunk::EnterResourceNoLock; using ppapi::thunk::PPB_Instance_FunctionAPI; @@ -147,9 +147,8 @@ PPB_Instance_FunctionAPI* PPB_Instance_Proxy::AsPPB_Instance_FunctionAPI() { PP_Bool PPB_Instance_Proxy::BindGraphics(PP_Instance instance, PP_Resource device) { - PluginResource* object = - PluginResourceTracker::GetInstance()->GetResourceObject(device); - if (!object || object->instance() != instance) + Resource* object = PluginResourceTracker::GetInstance()->GetResource(device); + if (!object || object->pp_instance() != instance) return PP_FALSE; PP_Bool result = PP_FALSE; diff --git a/ppapi/proxy/ppb_pdf_proxy.cc b/ppapi/proxy/ppb_pdf_proxy.cc index 5711030..b7b3704 100644 --- a/ppapi/proxy/ppb_pdf_proxy.cc +++ b/ppapi/proxy/ppb_pdf_proxy.cc @@ -13,23 +13,23 @@ #include "build/build_config.h" #include "ppapi/c/private/ppb_pdf.h" #include "ppapi/proxy/plugin_dispatcher.h" -#include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/plugin_resource_tracker.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/ppb_pdf_api.h" using ppapi::HostResource; +using ppapi::Resource; using ppapi::thunk::PPB_PDFFont_API; using ppapi::thunk::EnterResource; namespace pp { namespace proxy { -class PrivateFontFile : public PluginResource, +class PrivateFontFile : public Resource, public PPB_PDFFont_API { public: - PrivateFontFile(const HostResource& resource) : PluginResource(resource) { + PrivateFontFile(const HostResource& resource) : Resource(resource) { } virtual ~PrivateFontFile() {} @@ -80,9 +80,7 @@ PP_Resource GetFontFileWithFallback( INTERFACE_ID_PPB_PDF, instance, desc, charset, &result)); if (result.is_null()) return 0; - - return PluginResourceTracker::GetInstance()->AddResource( - new PrivateFontFile(result)); + return (new PrivateFontFile(result))->GetReference(); } bool GetFontTableForPrivateFontFile(PP_Resource font_file, @@ -95,7 +93,7 @@ bool GetFontTableForPrivateFontFile(PP_Resource font_file, PrivateFontFile* object = static_cast<PrivateFontFile*>(enter.object()); PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance( - object->instance()); + object->pp_instance()); if (!dispatcher) return false; diff --git a/ppapi/proxy/ppb_surface_3d_proxy.cc b/ppapi/proxy/ppb_surface_3d_proxy.cc index 28577d7..1ddcc42 100644 --- a/ppapi/proxy/ppb_surface_3d_proxy.cc +++ b/ppapi/proxy/ppb_surface_3d_proxy.cc @@ -10,7 +10,6 @@ #include "ppapi/c/dev/ppb_surface_3d_dev.h" #include "ppapi/proxy/enter_proxy.h" #include "ppapi/proxy/plugin_dispatcher.h" -#include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/ppb_context_3d_proxy.h" #include "ppapi/thunk/enter.h" @@ -18,6 +17,7 @@ #include "ppapi/thunk/thunk.h" using ppapi::HostResource; +using ppapi::Resource; using ppapi::thunk::EnterFunctionNoLock; using ppapi::thunk::PPB_Surface3D_API; using ppapi::thunk::ResourceCreationAPI; @@ -37,8 +37,7 @@ InterfaceProxy* CreateSurface3DProxy(Dispatcher* dispatcher, // Surface3D ------------------------------------------------------------------- Surface3D::Surface3D(const HostResource& host_resource) - : PluginResource(host_resource), - resource_(0), + : Resource(host_resource), context_(NULL), current_flush_callback_(PP_BlockUntilComplete()) { } @@ -79,7 +78,7 @@ int32_t Surface3D::SwapBuffers(PP_CompletionCallback callback) { IPC::Message* msg = new PpapiHostMsg_PPBSurface3D_SwapBuffers( INTERFACE_ID_PPB_SURFACE_3D, host_resource()); msg->set_unblock(true); - GetDispatcher()->Send(msg); + PluginDispatcher::GetForResource(this)->Send(msg); context_->gles2_impl()->SwapBuffers(); return PP_OK_COMPLETIONPENDING; @@ -137,11 +136,7 @@ PP_Resource PPB_Surface3D_Proxy::CreateProxyResource( if (result.is_null()) return 0; - scoped_refptr<Surface3D> surface_3d(new Surface3D(result)); - PP_Resource resource = - PluginResourceTracker::GetInstance()->AddResource(surface_3d); - surface_3d->set_resource(resource); - return resource; + return (new Surface3D(result))->GetReference(); } bool PPB_Surface3D_Proxy::OnMessageReceived(const IPC::Message& msg) { diff --git a/ppapi/proxy/ppb_surface_3d_proxy.h b/ppapi/proxy/ppb_surface_3d_proxy.h index 0fa0d4c..ae2ec8f 100644 --- a/ppapi/proxy/ppb_surface_3d_proxy.h +++ b/ppapi/proxy/ppb_surface_3d_proxy.h @@ -12,8 +12,8 @@ #include "ppapi/c/pp_instance.h" #include "ppapi/cpp/completion_callback.h" #include "ppapi/proxy/interface_proxy.h" -#include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/proxy_non_thread_safe_ref_count.h" +#include "ppapi/shared_impl/resource.h" #include "ppapi/thunk/ppb_surface_3d_api.h" struct PPB_Surface3D_Dev; @@ -23,13 +23,13 @@ namespace proxy { class Context3D; -class Surface3D : public PluginResource, +class Surface3D : public ppapi::Resource, public ppapi::thunk::PPB_Surface3D_API { public: explicit Surface3D(const ppapi::HostResource& host_resource); virtual ~Surface3D(); - // ResourceObjectBase overrides. + // Resource overrides. virtual PPB_Surface3D_API* AsPPB_Surface3D_API() OVERRIDE; // PPB_Surface3D_API implementation. @@ -51,11 +51,7 @@ class Surface3D : public PluginResource, Context3D* context() const { return context_; } - void set_resource(PP_Resource resource) { resource_ = resource; } - PP_Resource resource() const { return resource_; } - private: - PP_Resource resource_; Context3D* context_; // In the plugin, this is the current callback set for Flushes. When the diff --git a/ppapi/proxy/ppb_testing_proxy.cc b/ppapi/proxy/ppb_testing_proxy.cc index 7a1f7fd..0e6ed6d 100644 --- a/ppapi/proxy/ppb_testing_proxy.cc +++ b/ppapi/proxy/ppb_testing_proxy.cc @@ -7,11 +7,12 @@ #include "base/message_loop.h" #include "ppapi/c/dev/ppb_testing_dev.h" #include "ppapi/proxy/plugin_dispatcher.h" -#include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/plugin_resource_tracker.h" #include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/shared_impl/resource.h" using ppapi::HostResource; +using ppapi::Resource; namespace pp { namespace proxy { @@ -21,18 +22,18 @@ namespace { PP_Bool ReadImageData(PP_Resource graphics_2d, PP_Resource image, const PP_Point* top_left) { - PluginResource* image_object = PluginResourceTracker::GetInstance()-> - GetResourceObject(image); + Resource* image_object = PluginResourceTracker::GetInstance()-> + GetResource(image); if (!image_object) return PP_FALSE; - PluginResource* graphics_2d_object = - PluginResourceTracker::GetInstance()->GetResourceObject(graphics_2d); + Resource* graphics_2d_object = + PluginResourceTracker::GetInstance()->GetResource(graphics_2d); if (!graphics_2d_object || - image_object->instance() != graphics_2d_object->instance()) + image_object->pp_instance() != graphics_2d_object->pp_instance()) return PP_FALSE; PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance( - image_object->instance()); + image_object->pp_instance()); if (!dispatcher) return PP_FALSE; diff --git a/ppapi/proxy/ppb_url_loader_proxy.cc b/ppapi/proxy/ppb_url_loader_proxy.cc index 43997ea..5528a52 100644 --- a/ppapi/proxy/ppb_url_loader_proxy.cc +++ b/ppapi/proxy/ppb_url_loader_proxy.cc @@ -19,7 +19,6 @@ #include "ppapi/proxy/enter_proxy.h" #include "ppapi/proxy/host_dispatcher.h" #include "ppapi/proxy/plugin_dispatcher.h" -#include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/plugin_resource_tracker.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/ppb_url_response_info_proxy.h" @@ -33,6 +32,7 @@ #endif using ppapi::HostResource; +using ppapi::Resource; using ppapi::thunk::EnterFunctionNoLock; using ppapi::thunk::EnterResourceNoLock; using ppapi::thunk::PPB_URLLoader_API; @@ -80,12 +80,12 @@ InterfaceProxy* CreateURLLoaderProxy(Dispatcher* dispatcher, // URLLoader ------------------------------------------------------------------- -class URLLoader : public PluginResource, public PPB_URLLoader_API { +class URLLoader : public Resource, public PPB_URLLoader_API { public: URLLoader(const HostResource& resource); virtual ~URLLoader(); - // ResourceObjectBase overrides. + // Resource overrides. virtual PPB_URLLoader_API* AsPPB_URLLoader_API() OVERRIDE; // PPB_URLLoader_API implementation. @@ -121,6 +121,10 @@ class URLLoader : public PluginResource, public PPB_URLLoader_API { // The size must be not more than the current size of the buffer. void PopBuffer(void* output_buffer, int32_t output_size); + PluginDispatcher* GetDispatcher() const { + return PluginDispatcher::GetForResource(this); + } + // Initialized to -1. Will be set to nonnegative values by the UpdateProgress // message when the values are known. int64_t bytes_sent_; @@ -147,7 +151,7 @@ class URLLoader : public PluginResource, public PPB_URLLoader_API { }; URLLoader::URLLoader(const HostResource& resource) - : PluginResource(resource), + : Resource(resource), bytes_sent_(-1), total_bytes_to_be_sent_(-1), bytes_received_(-1), @@ -178,8 +182,8 @@ PPB_URLLoader_API* URLLoader::AsPPB_URLLoader_API() { int32_t URLLoader::Open(PP_Resource request_id, PP_CompletionCallback callback) { - PluginResource* request_object = - PluginResourceTracker::GetInstance()->GetResourceObject(request_id); + Resource* request_object = + PluginResourceTracker::GetInstance()->GetResource(request_id); if (!request_object) return PP_ERROR_BADARGUMENT; @@ -358,8 +362,7 @@ PPB_URLLoader_Proxy::~PPB_URLLoader_Proxy() { // static PP_Resource PPB_URLLoader_Proxy::TrackPluginResource( const HostResource& url_loader_resource) { - return PluginResourceTracker::GetInstance()->AddResource( - new URLLoader(url_loader_resource)); + return (new URLLoader(url_loader_resource))->GetReference(); } // static diff --git a/ppapi/proxy/ppb_url_request_info_proxy.cc b/ppapi/proxy/ppb_url_request_info_proxy.cc index 63a0b87..7b4152a 100644 --- a/ppapi/proxy/ppb_url_request_info_proxy.cc +++ b/ppapi/proxy/ppb_url_request_info_proxy.cc @@ -7,13 +7,13 @@ #include "ppapi/c/ppb_url_request_info.h" #include "ppapi/proxy/enter_proxy.h" #include "ppapi/proxy/plugin_dispatcher.h" -#include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/thunk/ppb_url_request_info_api.h" #include "ppapi/thunk/resource_creation_api.h" #include "ppapi/thunk/thunk.h" using ppapi::HostResource; +using ppapi::Resource; using ppapi::thunk::EnterFunctionNoLock; using ppapi::thunk::PPB_URLRequestInfo_API; using ppapi::thunk::ResourceCreationAPI; @@ -30,7 +30,7 @@ InterfaceProxy* CreateURLRequestInfoProxy(Dispatcher* dispatcher, } // namespace -class URLRequestInfo : public PluginResource, +class URLRequestInfo : public Resource, public PPB_URLRequestInfo_API { public: URLRequestInfo(const HostResource& resource); @@ -49,11 +49,15 @@ class URLRequestInfo : public PluginResource, PP_Time expected_last_modified_time) OVERRIDE; private: + PluginDispatcher* GetDispatcher() const { + return PluginDispatcher::GetForResource(this); + } + DISALLOW_COPY_AND_ASSIGN(URLRequestInfo); }; URLRequestInfo::URLRequestInfo(const HostResource& resource) - : PluginResource(resource) { + : Resource(resource) { } URLRequestInfo::~URLRequestInfo() { @@ -89,8 +93,8 @@ PP_Bool URLRequestInfo::AppendFileToBody(PP_Resource file_ref, int64_t start_offset, int64_t number_of_bytes, PP_Time expected_last_modified_time) { - PluginResource* file_ref_object = - PluginResourceTracker::GetInstance()->GetResourceObject(file_ref); + Resource* file_ref_object = + PluginResourceTracker::GetInstance()->GetResource(file_ref); if (!file_ref_object) return PP_FALSE; @@ -139,9 +143,7 @@ PP_Resource PPB_URLRequestInfo_Proxy::CreateProxyResource( INTERFACE_ID_PPB_URL_REQUEST_INFO, instance, &result)); if (result.is_null()) return 0; - - return PluginResourceTracker::GetInstance()->AddResource( - new URLRequestInfo(result)); + return (new URLRequestInfo(result))->GetReference(); } bool PPB_URLRequestInfo_Proxy::OnMessageReceived(const IPC::Message& msg) { diff --git a/ppapi/proxy/ppb_url_response_info_proxy.cc b/ppapi/proxy/ppb_url_response_info_proxy.cc index f0bfaf2..710f6b0 100644 --- a/ppapi/proxy/ppb_url_response_info_proxy.cc +++ b/ppapi/proxy/ppb_url_response_info_proxy.cc @@ -8,14 +8,15 @@ #include "ppapi/proxy/enter_proxy.h" #include "ppapi/proxy/host_dispatcher.h" #include "ppapi/proxy/plugin_dispatcher.h" -#include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/ppb_file_ref_proxy.h" #include "ppapi/proxy/serialized_var.h" +#include "ppapi/shared_impl/resource.h" #include "ppapi/thunk/ppb_url_response_info_api.h" #include "ppapi/thunk/thunk.h" using ppapi::HostResource; +using ppapi::Resource; using ppapi::thunk::PPB_URLResponseInfo_API; namespace pp { @@ -32,13 +33,12 @@ InterfaceProxy* CreateURLResponseInfoProxy(Dispatcher* dispatcher, // URLResponseInfo ------------------------------------------------------------- -class URLResponseInfo : public PluginResource, - public PPB_URLResponseInfo_API { +class URLResponseInfo : public Resource, public PPB_URLResponseInfo_API { public: URLResponseInfo(const HostResource& resource); virtual ~URLResponseInfo(); - // ResourceObjectBase override. + // Resource override. virtual PPB_URLResponseInfo_API* AsPPB_URLResponseInfo_API() OVERRIDE; // PPB_URLResponseInfo_API implementation. @@ -50,7 +50,7 @@ class URLResponseInfo : public PluginResource, }; URLResponseInfo::URLResponseInfo(const HostResource& resource) - : PluginResource(resource) { + : Resource(resource) { } URLResponseInfo::~URLResponseInfo() { @@ -61,10 +61,11 @@ PPB_URLResponseInfo_API* URLResponseInfo::AsPPB_URLResponseInfo_API() { } PP_Var URLResponseInfo::GetProperty(PP_URLResponseProperty property) { + PluginDispatcher* dispatcher = PluginDispatcher::GetForResource(this); ReceiveSerializedVarReturnValue result; - GetDispatcher()->Send(new PpapiHostMsg_PPBURLResponseInfo_GetProperty( + dispatcher->Send(new PpapiHostMsg_PPBURLResponseInfo_GetProperty( INTERFACE_ID_PPB_URL_RESPONSE_INFO, host_resource(), property, &result)); - return result.Return(GetDispatcher()); + return result.Return(dispatcher); } PP_Resource URLResponseInfo::GetBodyAsFileRef() { @@ -73,8 +74,9 @@ PP_Resource URLResponseInfo::GetBodyAsFileRef() { // where the file is ready. This will prevent us from having to do this sync // IPC here. PPBFileRef_CreateInfo create_info; - GetDispatcher()->Send(new PpapiHostMsg_PPBURLResponseInfo_GetBodyAsFileRef( - INTERFACE_ID_PPB_URL_RESPONSE_INFO, host_resource(), &create_info)); + PluginDispatcher::GetForResource(this)->Send( + new PpapiHostMsg_PPBURLResponseInfo_GetBodyAsFileRef( + INTERFACE_ID_PPB_URL_RESPONSE_INFO, host_resource(), &create_info)); return PPB_FileRef_Proxy::DeserializeFileRef(create_info); } @@ -104,8 +106,7 @@ const InterfaceProxy::Info* PPB_URLResponseInfo_Proxy::GetInfo() { // static PP_Resource PPB_URLResponseInfo_Proxy::CreateResponseForResource( const HostResource& resource) { - return PluginResourceTracker::GetInstance()->AddResource( - new URLResponseInfo(resource)); + return (new URLResponseInfo(resource))->GetReference(); } bool PPB_URLResponseInfo_Proxy::OnMessageReceived(const IPC::Message& msg) { diff --git a/ppapi/proxy/ppb_url_response_info_proxy.h b/ppapi/proxy/ppb_url_response_info_proxy.h index f181dfd..9ef469b 100644 --- a/ppapi/proxy/ppb_url_response_info_proxy.h +++ b/ppapi/proxy/ppb_url_response_info_proxy.h @@ -31,7 +31,7 @@ class PPB_URLResponseInfo_Proxy : public InterfaceProxy { // URLResponseInfo objects are actually created and returned by the // URLLoader. This function allows the URLLoader to convert a new // HostResource representing a response info to a properly tracked - // URLReponseInfo PluginResource. Returns the plugin resource ID for the + // URLReponseInfo Resource. Returns the plugin resource ID for the // new resource. static PP_Resource CreateResponseForResource( const ppapi::HostResource& resource); diff --git a/ppapi/proxy/ppb_video_capture_proxy.cc b/ppapi/proxy/ppb_video_capture_proxy.cc index 56a99e5..a49b6e8 100644 --- a/ppapi/proxy/ppb_video_capture_proxy.cc +++ b/ppapi/proxy/ppb_video_capture_proxy.cc @@ -16,7 +16,6 @@ #include "ppapi/proxy/enter_proxy.h" #include "ppapi/proxy/host_dispatcher.h" #include "ppapi/proxy/plugin_dispatcher.h" -#include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/ppb_buffer_proxy.h" #include "ppapi/thunk/ppb_buffer_api.h" @@ -25,6 +24,7 @@ #include "ppapi/thunk/thunk.h" using ppapi::HostResource; +using ppapi::Resource; using ppapi::thunk::EnterResourceNoLock; using ppapi::thunk::PPB_Buffer_API; using ppapi::thunk::PPB_BufferTrusted_API; @@ -145,12 +145,12 @@ PPP_VideoCapture_Dev ppp_video_capture = { } // namespace class VideoCapture : public ppapi::thunk::PPB_VideoCapture_API, - public PluginResource { + public Resource { public: VideoCapture(const HostResource& resource); virtual ~VideoCapture(); - // ResourceObjectBase overrides. + // Resource overrides. virtual ppapi::thunk::PPB_VideoCapture_API* AsPPB_VideoCapture_API() OVERRIDE; // PPB_VideoCapture_API implementation. @@ -246,13 +246,17 @@ class VideoCapture : public ppapi::thunk::PPB_VideoCapture_API, } private: + PluginDispatcher* GetDispatcher() const { + return PluginDispatcher::GetForResource(this); + } + uint32_t status_; std::vector<bool> buffer_in_use_; DISALLOW_COPY_AND_ASSIGN(VideoCapture); }; VideoCapture::VideoCapture(const HostResource& resource) - : PluginResource(resource), + : Resource(resource), status_(PP_VIDEO_CAPTURE_STATUS_STOPPED) { } @@ -294,9 +298,7 @@ PP_Resource PPB_VideoCapture_Proxy::CreateProxyResource(PP_Instance instance) { INTERFACE_ID_PPB_VIDEO_CAPTURE_DEV, instance, &result)); if (result.is_null()) return 0; - - return PluginResourceTracker::GetInstance()->AddResource( - new VideoCapture(result)); + return (new VideoCapture(result))->GetReference(); } bool PPB_VideoCapture_Proxy::OnMessageReceived(const IPC::Message& msg) { diff --git a/ppapi/proxy/ppb_video_decoder_proxy.cc b/ppapi/proxy/ppb_video_decoder_proxy.cc index 85f6bff..bcc0fc94 100644 --- a/ppapi/proxy/ppb_video_decoder_proxy.cc +++ b/ppapi/proxy/ppb_video_decoder_proxy.cc @@ -16,6 +16,7 @@ #include "ppapi/thunk/thunk.h" using ppapi::HostResource; +using ppapi::Resource; using ppapi::thunk::EnterResourceNoLock; using ppapi::thunk::PPB_Buffer_API; using ppapi::thunk::PPB_Context3D_API; @@ -24,16 +25,18 @@ using ppapi::thunk::PPB_VideoDecoder_API; namespace pp { namespace proxy { -class VideoDecoder : public PluginResource, +class VideoDecoder : public Resource, public ::ppapi::VideoDecoderImpl { public: + // You must call Init() before using this class. + explicit VideoDecoder(const HostResource& resource); virtual ~VideoDecoder(); static VideoDecoder* Create(const HostResource& 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. @@ -46,13 +49,10 @@ class VideoDecoder : public PluginResource, virtual int32_t Reset(PP_CompletionCallback callback) OVERRIDE; virtual void Destroy() OVERRIDE; - protected: - virtual void AddRefResource(PP_Resource resource) OVERRIDE; - virtual void UnrefResource(PP_Resource resource) OVERRIDE; - private: friend class PPB_VideoDecoder_Proxy; - explicit VideoDecoder(const HostResource& resource); + + PluginDispatcher* GetDispatcher() const; // Run the callbacks that were passed into the plugin interface. void FlushACK(int32_t result); @@ -62,24 +62,7 @@ class VideoDecoder : public PluginResource, DISALLOW_COPY_AND_ASSIGN(VideoDecoder); }; -VideoDecoder::VideoDecoder(const HostResource& decoder) - : PluginResource(decoder) { -} - -VideoDecoder* VideoDecoder::Create(const HostResource& resource, - PP_Resource context3d_id, - const PP_VideoConfigElement* config) { - if (!context3d_id) - return NULL; - - EnterResourceNoLock<PPB_Context3D_API> enter_context(context3d_id, true); - if (enter_context.failed()) - return NULL; - - scoped_refptr<VideoDecoder> decoder(new VideoDecoder(resource)); - if (decoder->Init(context3d_id, enter_context.object(), config)) - return decoder.release(); - return NULL; +VideoDecoder::VideoDecoder(const HostResource& decoder) : Resource(decoder) { } VideoDecoder::~VideoDecoder() { @@ -155,12 +138,8 @@ void VideoDecoder::Destroy() { ::ppapi::VideoDecoderImpl::Destroy(); } -void VideoDecoder::AddRefResource(PP_Resource resource) { - PluginResourceTracker::GetInstance()->AddRefResource(resource); -} - -void VideoDecoder::UnrefResource(PP_Resource resource) { - PluginResourceTracker::GetInstance()->ReleaseResource(resource); +PluginDispatcher* VideoDecoder::GetDispatcher() const { + return PluginDispatcher::GetForResource(this); } void VideoDecoder::ResetACK(int32_t result) { @@ -257,8 +236,11 @@ PP_Resource PPB_VideoDecoder_Proxy::CreateProxyResource( if (result.is_null()) return 0; - return PluginResourceTracker::GetInstance()->AddResource( - VideoDecoder::Create(result, context3d_id, config)); + // Need a scoped_refptr to keep the object alive during the Init call. + scoped_refptr<VideoDecoder> decoder(new VideoDecoder(result)); + if (!decoder->Init(context3d_id, enter_context.object(), config)) + return 0; + return decoder->GetReference(); } void PPB_VideoDecoder_Proxy::OnMsgCreate( diff --git a/ppapi/proxy/ppb_video_decoder_proxy.h b/ppapi/proxy/ppb_video_decoder_proxy.h index e7c0457..d915d22 100644 --- a/ppapi/proxy/ppb_video_decoder_proxy.h +++ b/ppapi/proxy/ppb_video_decoder_proxy.h @@ -8,7 +8,6 @@ #include "ppapi/c/pp_instance.h" #include "ppapi/cpp/completion_callback.h" #include "ppapi/proxy/interface_proxy.h" -#include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/proxy_non_thread_safe_ref_count.h" #include "ppapi/shared_impl/video_decoder_impl.h" #include "ppapi/thunk/ppb_video_decoder_api.h" diff --git a/ppapi/proxy/ppp_graphics_3d_proxy.h b/ppapi/proxy/ppp_graphics_3d_proxy.h index b52a500..4f1af56 100644 --- a/ppapi/proxy/ppp_graphics_3d_proxy.h +++ b/ppapi/proxy/ppp_graphics_3d_proxy.h @@ -7,6 +7,7 @@ #include "ppapi/c/pp_instance.h" #include "ppapi/proxy/interface_proxy.h" +#include "ppapi/shared_impl/host_resource.h" struct PPP_Graphics3D_Dev; diff --git a/ppapi/proxy/ppp_instance_private_proxy.h b/ppapi/proxy/ppp_instance_private_proxy.h index 166ee7d..f981167 100644 --- a/ppapi/proxy/ppp_instance_private_proxy.h +++ b/ppapi/proxy/ppp_instance_private_proxy.h @@ -9,6 +9,7 @@ #include "ppapi/c/pp_resource.h" #include "ppapi/c/pp_var.h" #include "ppapi/proxy/interface_proxy.h" +#include "ppapi/shared_impl/host_resource.h" struct PPP_Instance_Private; diff --git a/ppapi/proxy/ppp_instance_proxy.cc b/ppapi/proxy/ppp_instance_proxy.cc index 05c061b..612fb77 100644 --- a/ppapi/proxy/ppp_instance_proxy.cc +++ b/ppapi/proxy/ppp_instance_proxy.cc @@ -165,6 +165,7 @@ void PPP_Instance_Proxy::OnMsgDidCreate( PluginDispatcher* plugin_dispatcher = static_cast<PluginDispatcher*>(dispatcher()); plugin_dispatcher->DidCreateInstance(instance); + ppapi::TrackerBase::Get()->GetResourceTracker()->DidCreateInstance(instance); // Make sure the arrays always have at least one element so we can take the // address below. @@ -185,6 +186,7 @@ void PPP_Instance_Proxy::OnMsgDidCreate( void PPP_Instance_Proxy::OnMsgDidDestroy(PP_Instance instance) { combined_interface_->DidDestroy(instance); + ppapi::TrackerBase::Get()->GetResourceTracker()->DidDeleteInstance(instance); static_cast<PluginDispatcher*>(dispatcher())->DidDestroyInstance(instance); } diff --git a/ppapi/proxy/ppp_video_decoder_proxy.cc b/ppapi/proxy/ppp_video_decoder_proxy.cc index d4eaed1..ddfc0c3 100644 --- a/ppapi/proxy/ppp_video_decoder_proxy.cc +++ b/ppapi/proxy/ppp_video_decoder_proxy.cc @@ -5,6 +5,7 @@ #include "ppapi/proxy/ppp_video_decoder_proxy.h" #include "ppapi/proxy/host_dispatcher.h" +#include "ppapi/proxy/plugin_resource_tracker.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/ppb_video_decoder_proxy.h" #include "ppapi/thunk/enter.h" @@ -153,7 +154,8 @@ void PPP_VideoDecoder_Proxy::OnMsgNotifyEndOfStream( const HostResource& decoder) { PP_Resource plugin_decoder = PluginResourceTracker::GetInstance()-> PluginResourceForHostResource(decoder); - ppp_video_decoder_target()->EndOfStream(decoder.instance(), plugin_decoder); + ppp_video_decoder_target()->EndOfStream(decoder.instance(), + plugin_decoder); } void PPP_VideoDecoder_Proxy::OnMsgNotifyError( diff --git a/ppapi/proxy/proxy_module.h b/ppapi/proxy/proxy_module.h index 304f24f..5b2e540 100644 --- a/ppapi/proxy/proxy_module.h +++ b/ppapi/proxy/proxy_module.h @@ -15,7 +15,6 @@ namespace pp { namespace proxy { class PluginDispatcher; -class PluginResource; class ProxyModule { public: diff --git a/ppapi/proxy/resource_creation_proxy.cc b/ppapi/proxy/resource_creation_proxy.cc index 201eef1..4ba7cd1 100644 --- a/ppapi/proxy/resource_creation_proxy.cc +++ b/ppapi/proxy/resource_creation_proxy.cc @@ -158,9 +158,8 @@ PP_Resource ResourceCreationProxy::CreateFontObject( const PP_FontDescription_Dev* description) { if (!ppapi::FontImpl::IsPPFontDescriptionValid(*description)) return 0; - - return PluginResourceTracker::GetInstance()->AddResource( - new Font(HostResource::MakeInstanceOnly(instance), *description)); + return (new Font(HostResource::MakeInstanceOnly(instance), *description))-> + GetReference(); } PP_Resource ResourceCreationProxy::CreateGraphics2D(PP_Instance instance, @@ -192,8 +191,7 @@ PP_Resource ResourceCreationProxy::CreateImageData(PP_Instance instance, PP_ImageDataDesc desc; memcpy(&desc, image_data_desc.data(), sizeof(PP_ImageDataDesc)); - return PluginResourceTracker::GetInstance()->AddResource( - new ImageData(result, desc, image_handle)); + return (new ImageData(result, desc, image_handle))->GetReference(); } PP_Resource ResourceCreationProxy::CreateKeyboardInputEvent( diff --git a/ppapi/shared_impl/audio_config_impl.h b/ppapi/shared_impl/audio_config_impl.h index 230856f..079df76 100644 --- a/ppapi/shared_impl/audio_config_impl.h +++ b/ppapi/shared_impl/audio_config_impl.h @@ -7,7 +7,7 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" -#include "ppapi/shared_impl/resource_object_base.h" +#include "ppapi/shared_impl/resource.h" #include "ppapi/thunk/ppb_audio_config_api.h" namespace ppapi { diff --git a/ppapi/shared_impl/audio_impl.h b/ppapi/shared_impl/audio_impl.h index a640d37..220962bb 100644 --- a/ppapi/shared_impl/audio_impl.h +++ b/ppapi/shared_impl/audio_impl.h @@ -10,7 +10,7 @@ #include "base/sync_socket.h" #include "base/threading/simple_thread.h" #include "ppapi/c/ppb_audio.h" -#include "ppapi/shared_impl/resource_object_base.h" +#include "ppapi/shared_impl/resource.h" #include "ppapi/thunk/ppb_audio_api.h" namespace ppapi { diff --git a/ppapi/shared_impl/resource.cc b/ppapi/shared_impl/resource.cc new file mode 100644 index 0000000..11ac86a --- /dev/null +++ b/ppapi/shared_impl/resource.cc @@ -0,0 +1,54 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/shared_impl/resource.h" + +#include "base/logging.h" +#include "ppapi/shared_impl/resource_tracker.h" +#include "ppapi/shared_impl/tracker_base.h" + +namespace ppapi { + +Resource::Resource(PP_Instance instance) { + // The instance should always be valid (nonzero). + DCHECK(instance); + + // For the in-process case, the host resource and resource are the same. + // + // AddResource needs our instance() getter to work, and that goes through + // the host resource, so we need to fill that first even though we don't + // have a resource ID yet, then fill the resource in later. + host_resource_ = HostResource::MakeInstanceOnly(instance); + pp_resource_ = TrackerBase::Get()->GetResourceTracker()->AddResource(this); + host_resource_.SetHostResource(instance, pp_resource_); +} + +Resource::Resource(const HostResource& host_resource) + : host_resource_(host_resource) { + pp_resource_ = TrackerBase::Get()->GetResourceTracker()->AddResource(this); +} + +Resource::~Resource() { + TrackerBase::Get()->GetResourceTracker()->RemoveResource(this); +} + +PP_Resource Resource::GetReference() { + TrackerBase::Get()->GetResourceTracker()->AddRefResource(pp_resource()); + return pp_resource(); +} + +void Resource::LastPluginRefWasDeleted() { +} + +void Resource::InstanceWasDeleted() { + host_resource_ = HostResource(); +} + +#define DEFINE_TYPE_GETTER(RESOURCE) \ + thunk::RESOURCE* Resource::As##RESOURCE() { return NULL; } +FOR_ALL_PPAPI_RESOURCE_APIS(DEFINE_TYPE_GETTER) +#undef DEFINE_TYPE_GETTER + +} // namespace ppapi + diff --git a/ppapi/shared_impl/resource.h b/ppapi/shared_impl/resource.h new file mode 100644 index 0000000..6bb4099 --- /dev/null +++ b/ppapi/shared_impl/resource.h @@ -0,0 +1,141 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_SHARED_IMPL_RESOURCE_H_ +#define PPAPI_SHARED_IMPL_RESOURCE_H_ + +#include <stddef.h> // For NULL. + +#include "base/basictypes.h" +#include "base/memory/ref_counted.h" +#include "ppapi/c/pp_instance.h" +#include "ppapi/c/pp_resource.h" +#include "ppapi/shared_impl/host_resource.h" + +// All resource types should be added here. This implements our hand-rolled +// RTTI system since we don't compile with "real" RTTI. +#define FOR_ALL_PPAPI_RESOURCE_APIS(F) \ + F(PPB_AudioConfig_API) \ + F(PPB_AudioTrusted_API) \ + F(PPB_Audio_API) \ + F(PPB_Broker_API) \ + F(PPB_Buffer_API) \ + F(PPB_BufferTrusted_API) \ + F(PPB_Context3D_API) \ + F(PPB_DirectoryReader_API) \ + F(PPB_FileChooser_API) \ + F(PPB_FileIO_API) \ + F(PPB_FileRef_API) \ + F(PPB_FileSystem_API) \ + F(PPB_Find_API) \ + F(PPB_Flash_Menu_API) \ + F(PPB_Flash_NetConnector_API) \ + F(PPB_Flash_TCPSocket_API) \ + F(PPB_Font_API) \ + F(PPB_Graphics2D_API) \ + F(PPB_Graphics3D_API) \ + F(PPB_ImageData_API) \ + F(PPB_InputEvent_API) \ + F(PPB_LayerCompositor_API) \ + F(PPB_PDFFont_API) \ + F(PPB_Scrollbar_API) \ + F(PPB_Surface3D_API) \ + F(PPB_Transport_API) \ + F(PPB_URLLoader_API) \ + F(PPB_URLRequestInfo_API) \ + F(PPB_URLResponseInfo_API) \ + F(PPB_VideoCapture_API) \ + F(PPB_VideoDecoder_API) \ + F(PPB_VideoLayer_API) \ + F(PPB_Widget_API) + +namespace ppapi { + +// Forward declare all the resource APIs. +namespace thunk { +#define DECLARE_RESOURCE_CLASS(RESOURCE) class RESOURCE; +FOR_ALL_PPAPI_RESOURCE_APIS(DECLARE_RESOURCE_CLASS) +#undef DECLARE_RESOURCE_CLASS +} // namespace thunk + +class Resource : public base::RefCounted<Resource> { + public: + // For constructing non-proxied objects. This just takes the associated + // instance, and generates a new resource ID. The host resource will be the + // same as the newly-generated resource ID. + explicit Resource(PP_Instance instance); + + // For constructing proxied objects. This takes the resource generated in + // the host side, stores it, and allocates a "local" resource ID for use in + // the current process. + explicit Resource(const HostResource& host_resource); + + virtual ~Resource(); + + PP_Instance pp_instance() const { return host_resource_.instance(); } + + // Returns the resource ID for this object in the current process without + // adjusting the refcount. See also GetReference(). + PP_Resource pp_resource() const { return pp_resource_; } + + // Returns the host resource which identifies the resource in the host side + // of the process in the case of proxied objects. For in-process objects, + // this just identifies the in-process resource ID & instance. + const HostResource& host_resource() { return host_resource_; } + + // Adds a ref on behalf of the plugin and returns the resource ID. This is + // normally used when returning a resource to the plugin, where it's + // expecting the returned resource to have ownership of a ref passed. + // See also pp_resource() to avoid the AddRef. + PP_Resource GetReference(); + + // 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). + virtual void LastPluginRefWasDeleted(); + + // Called by the resource tracker when the instance is going away but the + // object is still alive (this is not the common case, since it requires + // something in the implementation to be keeping a ref that keeps the + // resource alive. + // + // You will want to override this if your resource does some kind of + // background processing (like maybe network loads) on behalf of the plugin + // and you want to stop that when the plugin is deleted. + // + // Be sure to call this version which clears the instance ID. + virtual void InstanceWasDeleted(); + + // Dynamic casting for this object. Returns the pointer to the given type if + // it's supported. Derived classes override the functions they support to + // return the interface. + #define DEFINE_TYPE_GETTER(RESOURCE) \ + virtual thunk::RESOURCE* As##RESOURCE(); + FOR_ALL_PPAPI_RESOURCE_APIS(DEFINE_TYPE_GETTER) + #undef DEFINE_TYPE_GETTER + + // Template-based dynamic casting. See specializations below. + template <typename T> T* GetAs() { return NULL; } + + private: + // See the getters above. + PP_Resource pp_resource_; + HostResource host_resource_; + + DISALLOW_IMPLICIT_CONSTRUCTORS(Resource); +}; + +// Template-based dynamic casting. These specializations forward to the +// AsXXX virtual functions to return whether the given type is supported. +#define DEFINE_RESOURCE_CAST(RESOURCE) \ + template<> inline thunk::RESOURCE* Resource::GetAs() { \ + return As##RESOURCE(); \ + } +FOR_ALL_PPAPI_RESOURCE_APIS(DEFINE_RESOURCE_CAST) +#undef DEFINE_RESOURCE_CAST + +} // namespace ppapi + +#endif // PPAPI_SHARED_IMPL_RESOURCE_H_ diff --git a/ppapi/shared_impl/resource_object_base.cc b/ppapi/shared_impl/resource_object_base.cc deleted file mode 100644 index 27ef9e9..0000000 --- a/ppapi/shared_impl/resource_object_base.cc +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ppapi/shared_impl/resource_object_base.h" - -#include "base/logging.h" - -namespace ppapi { - -ResourceObjectBase::ResourceObjectBase(PP_Instance instance) - : pp_instance_(instance) { - // Instance should be valid (nonzero). - DCHECK(instance); -} - -ResourceObjectBase::~ResourceObjectBase() { -} - -#define DEFINE_TYPE_GETTER(RESOURCE) \ - thunk::RESOURCE* ResourceObjectBase::As##RESOURCE() { return NULL; } -FOR_ALL_PPAPI_RESOURCE_APIS(DEFINE_TYPE_GETTER) -#undef DEFINE_TYPE_GETTER - -} // namespace ppapi - diff --git a/ppapi/shared_impl/resource_object_base.h b/ppapi/shared_impl/resource_object_base.h deleted file mode 100644 index 3408525..0000000 --- a/ppapi/shared_impl/resource_object_base.h +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef PPAPI_SHARED_IMPL_RESOURCE_OBJECT_BASE_H_ -#define PPAPI_SHARED_IMPL_RESOURCE_OBJECT_BASE_H_ - -#include <stddef.h> // For NULL. - -#include "base/memory/ref_counted.h" -#include "ppapi/c/pp_instance.h" - -#define FOR_ALL_PPAPI_RESOURCE_APIS(F) \ - F(PPB_AudioConfig_API) \ - F(PPB_AudioTrusted_API) \ - F(PPB_Audio_API) \ - F(PPB_Broker_API) \ - F(PPB_Buffer_API) \ - F(PPB_BufferTrusted_API) \ - F(PPB_Context3D_API) \ - F(PPB_DirectoryReader_API) \ - F(PPB_FileChooser_API) \ - F(PPB_FileIO_API) \ - F(PPB_FileRef_API) \ - F(PPB_FileSystem_API) \ - F(PPB_Find_API) \ - F(PPB_Flash_Menu_API) \ - F(PPB_Flash_NetConnector_API) \ - F(PPB_Flash_TCPSocket_API) \ - F(PPB_Font_API) \ - F(PPB_Graphics2D_API) \ - F(PPB_Graphics3D_API) \ - F(PPB_ImageData_API) \ - F(PPB_InputEvent_API) \ - F(PPB_LayerCompositor_API) \ - F(PPB_PDFFont_API) \ - F(PPB_Scrollbar_API) \ - F(PPB_Surface3D_API) \ - F(PPB_Transport_API) \ - F(PPB_URLLoader_API) \ - F(PPB_URLRequestInfo_API) \ - F(PPB_URLResponseInfo_API) \ - F(PPB_VideoCapture_API) \ - F(PPB_VideoDecoder_API) \ - F(PPB_VideoLayer_API) \ - F(PPB_Widget_API) - -namespace ppapi { - -// Forward declare all the resource APIs. -namespace thunk { -#define DECLARE_RESOURCE_CLASS(RESOURCE) class RESOURCE; -FOR_ALL_PPAPI_RESOURCE_APIS(DECLARE_RESOURCE_CLASS) -#undef DECLARE_RESOURCE_CLASS -} // namespace thunk - -class ResourceObjectBase : public base::RefCounted<ResourceObjectBase> { - public: - ResourceObjectBase(PP_Instance instance); - virtual ~ResourceObjectBase(); - - PP_Instance pp_instance() const { return pp_instance_; } - - // Dynamic casting for this object. Returns the pointer to the given type if - // Inheritance-based dynamic casting for this object. Returns the pointer to - // the given type if it's supported. Derived classes override the functions - // they support to return the interface. - #define DEFINE_TYPE_GETTER(RESOURCE) \ - virtual thunk::RESOURCE* As##RESOURCE(); - FOR_ALL_PPAPI_RESOURCE_APIS(DEFINE_TYPE_GETTER) - #undef DEFINE_TYPE_GETTER - - // Template-based dynamic casting. See specializations below. - template <typename T> T* GetAs() { return NULL; } - - private: - PP_Instance pp_instance_; - - DISALLOW_IMPLICIT_CONSTRUCTORS(ResourceObjectBase); -}; - -// Template-based dynamic casting. These specializations forward to the -// AsXXX virtual functions to return whether the given type is supported. -#define DEFINE_RESOURCE_CAST(RESOURCE) \ - template<> inline thunk::RESOURCE* ResourceObjectBase::GetAs() { \ - return As##RESOURCE(); \ - } -FOR_ALL_PPAPI_RESOURCE_APIS(DEFINE_RESOURCE_CAST) -#undef DEFINE_RESOURCE_CAST - -} // namespace ppapi - -#endif // PPAPI_SHARED_IMPL_RESOURCE_OBJECT_BASE_H_ diff --git a/ppapi/shared_impl/resource_tracker.cc b/ppapi/shared_impl/resource_tracker.cc new file mode 100644 index 0000000..ecaa38d --- /dev/null +++ b/ppapi/shared_impl/resource_tracker.cc @@ -0,0 +1,162 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/shared_impl/resource_tracker.h" + +#include "ppapi/shared_impl/id_assignment.h" +#include "ppapi/shared_impl/resource.h" + +namespace ppapi { + +ResourceTracker::ResourceTracker() : last_resource_value_(0) { +} + +ResourceTracker::~ResourceTracker() { +} + +Resource* ResourceTracker::GetResource(PP_Resource res) const { + ResourceMap::const_iterator i = live_resources_.find(res); + if (i == live_resources_.end()) + return NULL; + return i->second.first; +} + +void ResourceTracker::AddRefResource(PP_Resource res) { + DLOG_IF(ERROR, !CheckIdType(res, PP_ID_TYPE_RESOURCE)) + << res << " is not a PP_Resource."; + ResourceMap::iterator i = live_resources_.find(res); + if (i == live_resources_.end()) + return; + + // Prevent overflow of refcount. + if (i->second.second == + std::numeric_limits<ResourceAndRefCount::second_type>::max()) + return; + + // When we go from 0 to 1 plugin ref count, keep an additional "real" ref + // on its behalf. + if (i->second.second == 0) + i->second.first->AddRef(); + + i->second.second++; + return; +} + +void ResourceTracker::ReleaseResource(PP_Resource res) { + DLOG_IF(ERROR, !CheckIdType(res, PP_ID_TYPE_RESOURCE)) + << res << " is not a PP_Resource."; + ResourceMap::iterator i = live_resources_.find(res); + if (i == live_resources_.end()) + return; + + // Prevent underflow of refcount. + if (i->second.second == 0) + return; + + i->second.second--; + if (i->second.second == 0) { + i->second.first->LastPluginRefWasDeleted(); + + // When we go from 1 to 0 plugin ref count, free the additional "real" ref + // on its behalf. THIS WILL MOST LIKELY RELEASE THE OBJECT AND REMOVE IT + // FROM OUR LIST. + i->second.first->Release(); + } +} + +void ResourceTracker::DidCreateInstance(PP_Instance instance) { + // Due to the infrastructure of some tests, the instance is registered + // twice in a few cases. It would be nice not to do that and assert here + // instead. + if (instance_map_.find(instance) != instance_map_.end()) + return; + instance_map_[instance] = linked_ptr<InstanceData>(new InstanceData); +} + +void ResourceTracker::DidDeleteInstance(PP_Instance instance) { + InstanceMap::iterator found_instance = instance_map_.find(instance); + + // Due to the infrastructure of some tests, the instance is uyregistered + // twice in a few cases. It would be nice not to do that and assert here + // instead. + if (found_instance == instance_map_.end()) + return; + + InstanceData& data = *found_instance->second; + + // Force release all plugin references to resources associated with the + // deleted instance. Make a copy since as we iterate through them, each one + // will remove itself from the tracking info individually. + ResourceSet to_delete = data.resources; + ResourceSet::iterator cur = to_delete.begin(); + while (cur != to_delete.end()) { + // Note that it's remotely possible for the object to already be deleted + // from the live resources. One case is if a resource object is holding + // the last ref to another. When we release the first one, it will release + // the second one. So the second one will be gone when we eventually get + // to it. + ResourceMap::iterator found_resource = live_resources_.find(*cur); + if (found_resource != live_resources_.end()) { + Resource* resource = found_resource->second.first; + if (found_resource->second.second > 0) { + resource->LastPluginRefWasDeleted(); + found_resource->second.second = 0; + + // This will most likely delete the resource object and remove it + // from the live_resources_ list. + resource->Release(); + } + } + + cur++; + } + + // In general the above pass will delete all the resources and there won't + // be any left in the map. However, if parts of the implementation are still + // holding on to internal refs, we need to tell them that the instance is + // gone. + to_delete = data.resources; + cur = to_delete.begin(); + while (cur != to_delete.end()) { + ResourceMap::iterator found_resource = live_resources_.find(*cur); + if (found_resource != live_resources_.end()) + found_resource->second.first->InstanceWasDeleted(); + cur++; + } + + instance_map_.erase(instance); +} + +int ResourceTracker::GetLiveObjectsForInstance(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->resources.size()); +} + +PP_Resource ResourceTracker::AddResource(Resource* object) { + // If the plugin manages to create too many resources, don't do crazy stuff. + if (last_resource_value_ == kMaxPPId) + return 0; + + // If you hit this somebody forgot to call DidCreateInstance or the resource + // was created with an invalid PP_Instance. + DCHECK(instance_map_.find(object->pp_instance()) != instance_map_.end()); + + PP_Resource new_id = MakeTypedId(++last_resource_value_, PP_ID_TYPE_RESOURCE); + instance_map_[object->pp_instance()]->resources.insert(new_id); + + live_resources_[new_id] = ResourceAndRefCount(object, 0); + return new_id; +} + +void ResourceTracker::RemoveResource(Resource* object) { + PP_Resource pp_resource = object->pp_resource(); + if (object->pp_instance()) + instance_map_[object->pp_instance()]->resources.erase(pp_resource); + live_resources_.erase(pp_resource); +} + + +} // namespace ppapi diff --git a/ppapi/shared_impl/resource_tracker.h b/ppapi/shared_impl/resource_tracker.h new file mode 100644 index 0000000..04230d9 --- /dev/null +++ b/ppapi/shared_impl/resource_tracker.h @@ -0,0 +1,93 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_SHARED_IMPL_RESOURCE_TRACKER_H_ +#define PPAPI_SHARED_IMPL_RESOURCE_TRACKER_H_ + +#include <set> + +#include "base/basictypes.h" +#include "base/hash_tables.h" +#include "base/memory/linked_ptr.h" +#include "ppapi/c/pp_instance.h" +#include "ppapi/c/pp_resource.h" + +namespace ppapi { + +class Resource; + +class ResourceTracker { + public: + ResourceTracker(); + virtual ~ResourceTracker(); + + // The returned pointer will be NULL if there is no resource. The reference + // count of the resource is unaffected. + Resource* GetResource(PP_Resource res) const; + + void AddRefResource(PP_Resource res); + void ReleaseResource(PP_Resource res); + + // Notifies the tracker that a new instance has been created. This must be + // called before creating any resources associated with the instance. + void DidCreateInstance(PP_Instance instance); + + // Called when an instance is being deleted. All plugin refs for the + // associated resources will be force freed, and the resources (if they still + // exist) will be disassociated from the instance. + void DidDeleteInstance(PP_Instance instance); + + // Returns the number of resources associated with the given instance. + // Returns 0 if the instance isn't known. + int GetLiveObjectsForInstance(PP_Instance instance) const; + + protected: + // This calls AddResource and RemoveResource. + friend class Resource; + + // Adds the given resource to the tracker, associating it with the instance + // stored in the resource object. The new resource ID is returned, and the + // resource will have 0 plugin refcount. This is called by the resource + // constructor. + // + // Returns 0 if the resource could not be added. + virtual PP_Resource AddResource(Resource* object); + + // The opposite of AddResource, this removes the tracking information for + // the given resource. It's called from the resource destructor. + virtual void RemoveResource(Resource* object); + + private: + typedef std::set<PP_Resource> ResourceSet; + + struct InstanceData { + // Lists all resources associated with the given instance as non-owning + // pointers. This allows us to notify those resources that the instance is + // going away (otherwise, they may crash if they outlive the instance). + ResourceSet resources; + }; + typedef base::hash_map<PP_Instance, linked_ptr<InstanceData> > InstanceMap; + + InstanceMap instance_map_; + + // For each PP_Resource, keep the object pointer and a plugin use count. + // This use count is different then Resource object's RefCount, and is + // manipulated using this AddRefResource/UnrefResource. When the plugin use + // count is positive, we keep an extra ref on the Resource on + // behalf of the plugin. When it drops to 0, we free that ref, keeping + // the resource in the list. + // + // A resource will be in this list as long as the object is alive. + typedef std::pair<Resource*, int> ResourceAndRefCount; + typedef base::hash_map<PP_Resource, ResourceAndRefCount> ResourceMap; + ResourceMap live_resources_; + + int32 last_resource_value_; + + DISALLOW_COPY_AND_ASSIGN(ResourceTracker); +}; + +} // namespace ppapi + +#endif // PPAPI_SHARED_IMPL_RESOURCE_TRACKER_H_ diff --git a/ppapi/shared_impl/resource_tracker_unittest.cc b/ppapi/shared_impl/resource_tracker_unittest.cc new file mode 100644 index 0000000..186b162 --- /dev/null +++ b/ppapi/shared_impl/resource_tracker_unittest.cc @@ -0,0 +1,148 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "testing/gtest/include/gtest/gtest.h" + +#include "base/compiler_specific.h" +#include "ppapi/shared_impl/resource.h" +#include "ppapi/shared_impl/resource_tracker.h" +#include "ppapi/shared_impl/tracker_base.h" + +namespace ppapi { + +namespace { + +int mock_resource_alive_count = 0; +int last_plugin_ref_was_deleted_count = 0; +int instance_was_deleted_count = 0; + +class MyMockResource : public Resource { + public: + MyMockResource(PP_Instance instance) : Resource(instance) { + mock_resource_alive_count++; + } + virtual ~MyMockResource() { + mock_resource_alive_count--; + } + + virtual void LastPluginRefWasDeleted() OVERRIDE { + Resource::LastPluginRefWasDeleted(); + last_plugin_ref_was_deleted_count++; + } + virtual void InstanceWasDeleted() OVERRIDE { + Resource::InstanceWasDeleted(); + instance_was_deleted_count++; + } +}; + +// Global singleton used by the TrackerBase. +TrackerBase* my_tracker_base = NULL; +TrackerBase* GetMyTrackerBase() { + return my_tracker_base; +} + +} // namespace + +class ResourceTrackerTest : public testing::Test, public TrackerBase { + public: + ResourceTrackerTest() {} + + // Test implementation. + virtual void SetUp() OVERRIDE { + my_tracker_base = this; + TrackerBase::Init(&GetMyTrackerBase); + + ASSERT_EQ(0, mock_resource_alive_count); + last_plugin_ref_was_deleted_count = 0; + instance_was_deleted_count = 0; + } + virtual void TearDown() OVERRIDE { + my_tracker_base = NULL; + TrackerBase::Init(NULL); + } + + // TrackerBase implementation. + virtual FunctionGroupBase* GetFunctionAPI( + PP_Instance inst, + pp::proxy::InterfaceID id) OVERRIDE { + return NULL; + } + virtual VarTracker* GetVarTracker() OVERRIDE { + return NULL; + } + virtual ResourceTracker* GetResourceTracker() OVERRIDE { + return &resource_tracker_; + } + + ResourceTracker& resource_tracker() { return resource_tracker_; } + + private: + ResourceTracker resource_tracker_; +}; + +// Test that LastPluginRefWasDeleted is called when the last plugin ref was +// deleted but the object lives on. +TEST_F(ResourceTrackerTest, LastPluginRef) { + PP_Instance instance = 0x1234567; + resource_tracker().DidCreateInstance(instance); + + scoped_refptr<MyMockResource> resource(new MyMockResource(instance)); + PP_Resource pp_resource = resource->GetReference(); + EXPECT_TRUE(resource_tracker().GetResource(pp_resource)); + + // Releasing it should keep the object (because we have a ref) but fire the + // "last plugin ref" message. + resource_tracker().ReleaseResource(pp_resource); + EXPECT_EQ(1, last_plugin_ref_was_deleted_count); + EXPECT_EQ(1, mock_resource_alive_count); + + resource_tracker().DidDeleteInstance(instance); + resource = NULL; + EXPECT_FALSE(resource_tracker().GetResource(pp_resource)); +} + +// Tests when the plugin is holding a ref to a resource when the instance is +// deleted. +TEST_F(ResourceTrackerTest, InstanceDeletedWithPluginRef) { + // Make a resource with one ref held by the plugin, and delete the instance. + PP_Instance instance = 0x2345678; + resource_tracker().DidCreateInstance(instance); + MyMockResource* resource = new MyMockResource(instance); + resource->GetReference(); + EXPECT_EQ(1, mock_resource_alive_count); + resource_tracker().DidDeleteInstance(instance); + + // The resource should have been deleted, and before it was, it should have + // received a "last plugin ref was deleted" notification. + EXPECT_EQ(0, mock_resource_alive_count); + EXPECT_EQ(1, last_plugin_ref_was_deleted_count); + EXPECT_EQ(0, instance_was_deleted_count); +} + +// Test when the plugin and the internal implementation (via scoped_refptr) is +// holding a ref to a resource when the instance is deleted. +TEST_F(ResourceTrackerTest, InstanceDeletedWithBothRefed) { + // Create a new instance. + PP_Instance instance = 0x3456789; + + // Make a resource with one ref held by the plugin and one ref held by us + // (outlives the plugin), and delete the instance. + resource_tracker().DidCreateInstance(instance); + scoped_refptr<MyMockResource> resource = new MyMockResource(instance); + resource->GetReference(); + EXPECT_EQ(1, mock_resource_alive_count); + resource_tracker().DidDeleteInstance(instance); + + // The resource should NOT have been deleted, and it should have received both + // a "last plugin ref was deleted" and a "instance was deleted" notification. + EXPECT_EQ(1, mock_resource_alive_count); + EXPECT_EQ(1, last_plugin_ref_was_deleted_count); + EXPECT_EQ(1, instance_was_deleted_count); + EXPECT_EQ(0, resource->pp_instance()); + + resource = NULL; + EXPECT_EQ(0, mock_resource_alive_count); +} + +} // namespace ppapi diff --git a/ppapi/shared_impl/tracker_base.h b/ppapi/shared_impl/tracker_base.h index 4b45a79..63585ea 100644 --- a/ppapi/shared_impl/tracker_base.h +++ b/ppapi/shared_impl/tracker_base.h @@ -14,7 +14,7 @@ namespace ppapi { class FunctionGroupBase; -class ResourceObjectBase; +class ResourceTracker; class VarTracker; // Tracks resource and function APIs, providing a mapping between ID and @@ -37,20 +37,13 @@ class TrackerBase { // Init() first (it should be unnecessary to NULL-check this). static TrackerBase* Get(); - // Returns the resource object corresponding to the given ID, or NULL if - // there isn't one. - virtual ResourceObjectBase* GetResourceAPI(PP_Resource res) = 0; - // Returns the function object corresponding to the given ID, or NULL if // there isn't one. virtual FunctionGroupBase* GetFunctionAPI(PP_Instance inst, pp::proxy::InterfaceID id) = 0; - // Returns the instance corresponding to the given resource, or 0 if the - // resource is invalid. - virtual PP_Instance GetInstanceForResource(PP_Resource resource) = 0; - virtual VarTracker* GetVarTracker() = 0; + virtual ResourceTracker* GetResourceTracker() = 0; }; } // namespace ppapi diff --git a/ppapi/shared_impl/video_decoder_impl.cc b/ppapi/shared_impl/video_decoder_impl.cc index ef20f8b..ecdde86 100644 --- a/ppapi/shared_impl/video_decoder_impl.cc +++ b/ppapi/shared_impl/video_decoder_impl.cc @@ -8,6 +8,7 @@ #include "gpu/command_buffer/client/gles2_implementation.h" #include "ppapi/c/pp_errors.h" #include "ppapi/proxy/plugin_resource_tracker.h" +#include "ppapi/shared_impl/resource_tracker.h" #include "ppapi/thunk/ppb_context_3d_api.h" #include "ppapi/thunk/enter.h" @@ -33,7 +34,7 @@ bool VideoDecoderImpl::Init(PP_Resource context3d_id, DCHECK(!gles2_impl_ && !context3d_id_); gles2_impl_ = context3d->GetGLES2Impl(); - AddRefResource(context3d_id); + TrackerBase::Get()->GetResourceTracker()->AddRefResource(context3d_id); context3d_id_ = context3d_id; return true; } @@ -41,7 +42,7 @@ bool VideoDecoderImpl::Init(PP_Resource context3d_id, void VideoDecoderImpl::Destroy() { context3d_id_ = 0; gles2_impl_ = NULL; - UnrefResource(context3d_id_); + TrackerBase::Get()->GetResourceTracker()->ReleaseResource(context3d_id_); } bool VideoDecoderImpl::SetFlushCallback(PP_CompletionCallback callback) { diff --git a/ppapi/shared_impl/video_decoder_impl.h b/ppapi/shared_impl/video_decoder_impl.h index 6cd8044..191efa9 100644 --- a/ppapi/shared_impl/video_decoder_impl.h +++ b/ppapi/shared_impl/video_decoder_impl.h @@ -11,7 +11,7 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" #include "ppapi/c/dev/ppb_video_decoder_dev.h" -#include "ppapi/shared_impl/resource_object_base.h" +#include "ppapi/shared_impl/resource.h" #include "ppapi/thunk/ppb_video_decoder_api.h" namespace gpu { @@ -61,11 +61,6 @@ class VideoDecoderImpl : public thunk::PPB_VideoDecoder_API { thunk::PPB_Context3D_API* context, const PP_VideoConfigElement* dec_config); - // TODO(fischman/vrk): Remove accordingly when brettw has merged resource - // trackers. - virtual void AddRefResource(PP_Resource resource) = 0; - virtual void UnrefResource(PP_Resource resource) = 0; - private: // Key: bitstream_buffer_id, value: callback to run when bitstream decode is // done. diff --git a/ppapi/thunk/enter.h b/ppapi/thunk/enter.h index ea2fc82..e7f0d0f 100644 --- a/ppapi/thunk/enter.h +++ b/ppapi/thunk/enter.h @@ -9,8 +9,9 @@ #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_object_base.h" +#include "ppapi/shared_impl/resource.h" #include "ppapi/shared_impl/tracker_base.h" +#include "ppapi/shared_impl/resource_tracker.h" namespace ppapi { namespace thunk { @@ -77,9 +78,15 @@ template<typename FunctionsT> class EnterFunctionGivenResource : public EnterFunction<FunctionsT> { public: EnterFunctionGivenResource(PP_Resource resource, bool report_error) - : EnterFunction<FunctionsT>( - TrackerBase::Get()->GetInstanceForResource(resource), - report_error) { + : EnterFunction<FunctionsT>(GetInstanceForResource(resource), + report_error) { + } + + private: + static PP_Instance GetInstanceForResource(PP_Resource resource) { + Resource* object = + TrackerBase::Get()->GetResourceTracker()->GetResource(resource); + return object ? object->pp_instance() : 0; } }; @@ -90,7 +97,8 @@ class EnterResource { public: EnterResource(PP_Resource resource, bool report_error) : object_(NULL) { - ResourceObjectBase* base = TrackerBase::Get()->GetResourceAPI(resource); + Resource* base = + TrackerBase::Get()->GetResourceTracker()->GetResource(resource); if (base) object_ = base->GetAs<ResourceT>(); // TODO(brettw) check error and if report_error is set, do something. 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 |