diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-18 15:41:01 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-18 15:41:01 +0000 |
commit | 7f8b26b5f223689de7af4803bc07e1e953ff5953 (patch) | |
tree | d6f3e574d97c6253b8b202264fe23dea1b489dc2 /ppapi | |
parent | d8886526085a42874663be638be1421e78f6172c (diff) | |
download | chromium_src-7f8b26b5f223689de7af4803bc07e1e953ff5953.zip chromium_src-7f8b26b5f223689de7af4803bc07e1e953ff5953.tar.gz chromium_src-7f8b26b5f223689de7af4803bc07e1e953ff5953.tar.bz2 |
Add a unified resource tracker shared between the proxy and the impl.
This renames the old ResourceObjectBase to Resource and removes the old
PluginResource. It moves the resource tracker from the impl to the
shared_impl, and makes the proxy use it.
Some things become a little less neat because there's no proxy resource base
class. In particular GetDispatcher() is now gone. I considered whether to
add a helper base class that provides this function, but decided against it
and had individual resource classes implement this when their implementation
would find it useful. This is because ultimately I want more of this
functionality to move into the shared_impl, and it's easier to do that if
there are fewer proxy-specific things in the resources.
This changes the way that plugins are added to the tracker. Previously they
would only be in the tracker if the plugin had a reference to them, although
they could be alive if the impl had a scoped_ptr referencing an object. This
actually has the bug that if we then give the resource back to the plugin,
it wouldn't be refcounted properly and everything would get confused.
Now the tracker tracks all live resource objects whether or not the plugin
has a ref. This works basically like the var tracker (it would be nice if
the var and resource trackers shared more code, but that would further
complicate this already overcomplicated patch). The resource tracker takes an
extra ref whenever the plugin has one or more, and otherwise just tracks live
resources.
Review URL: http://codereview.chromium.org/7629017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97314 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
71 files changed, 969 insertions, 660 deletions
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. |