diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-20 19:09:20 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-20 19:09:20 +0000 |
commit | 794d83cda5183b25665e99296ab6f5e6c1dbf2dc (patch) | |
tree | 5b69cd2fa55d7eb0ac3c9a98f1012358e2f349b2 /ppapi | |
parent | 83c23571249a13c68d07122070bf73c2a9cd435e (diff) | |
download | chromium_src-794d83cda5183b25665e99296ab6f5e6c1dbf2dc.zip chromium_src-794d83cda5183b25665e99296ab6f5e6c1dbf2dc.tar.gz chromium_src-794d83cda5183b25665e99296ab6f5e6c1dbf2dc.tar.bz2 |
Add a new globals object for PPAPI tracking information.
[ Reland of 106142: http://codereview.chromium.org/8316008 ]
This adds a specialization on the host and plugin side of the proxy. This
replaces the ad-hoc singleton tracking done by the resource and var trackers
with just being getters on this global object.
Most code can use the single PpapiGlobals class. I also allow code to get the
host and plugin specializations since some code needs access to some specific
features of each side.
In a later pass I'll move the other stuff out of TrackerBase and delete it.
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/8344025
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106537 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
41 files changed, 336 insertions, 174 deletions
diff --git a/ppapi/ppapi_proxy.gypi b/ppapi/ppapi_proxy.gypi index 8630cf9..257d336 100644 --- a/ppapi/ppapi_proxy.gypi +++ b/ppapi/ppapi_proxy.gypi @@ -44,6 +44,8 @@ 'proxy/interface_proxy.h', 'proxy/plugin_dispatcher.cc', 'proxy/plugin_dispatcher.h', + 'proxy/plugin_globals.cc', + 'proxy/plugin_globals.h', 'proxy/plugin_message_filter.cc', 'proxy/plugin_message_filter.h', 'proxy/plugin_resource_tracker.cc', diff --git a/ppapi/ppapi_shared.gypi b/ppapi/ppapi_shared.gypi index b6399eb..80055ae 100644 --- a/ppapi/ppapi_shared.gypi +++ b/ppapi/ppapi_shared.gypi @@ -56,6 +56,8 @@ 'shared_impl/memory_impl.cc', 'shared_impl/opengles2_impl.cc', 'shared_impl/opengles2_impl.h', + 'shared_impl/ppapi_globals.cc', + 'shared_impl/ppapi_globals.h', 'shared_impl/ppapi_preferences.cc', 'shared_impl/ppapi_preferences.h', 'shared_impl/ppp_instance_combined.cc', diff --git a/ppapi/ppapi_tests.gypi b/ppapi/ppapi_tests.gypi index b7999b3..625a06d 100644 --- a/ppapi/ppapi_tests.gypi +++ b/ppapi/ppapi_tests.gypi @@ -137,7 +137,8 @@ 'tests/test_var_deprecated.h', ], 'dependencies': [ - 'ppapi.gyp:ppapi_cpp' + 'ppapi.gyp:ppapi_cpp', + 'ppapi_internal.gyp:ppapi_shared', ], 'run_as': { 'action': [ @@ -218,6 +219,8 @@ 'proxy/ppp_messaging_proxy_unittest.cc', 'proxy/serialized_var_unittest.cc', 'shared_impl/resource_tracker_unittest.cc', + 'shared_impl/test_globals.cc', + 'shared_impl/test_globals.h', ], }, { diff --git a/ppapi/proxy/enter_proxy.h b/ppapi/proxy/enter_proxy.h index d7bf7c2..96ac0c18 100644 --- a/ppapi/proxy/enter_proxy.h +++ b/ppapi/proxy/enter_proxy.h @@ -9,6 +9,7 @@ #include "ppapi/cpp/completion_callback.h" #include "ppapi/proxy/host_dispatcher.h" #include "ppapi/proxy/plugin_dispatcher.h" +#include "ppapi/proxy/plugin_globals.h" #include "ppapi/proxy/plugin_resource_tracker.h" #include "ppapi/thunk/enter.h" @@ -32,8 +33,8 @@ class EnterPluginFromHostResource public: EnterPluginFromHostResource(const HostResource& host_resource) : thunk::EnterResourceNoLock<ResourceT>( - PluginResourceTracker::GetInstance()->PluginResourceForHostResource( - host_resource), + PluginGlobals::Get()->plugin_resource_tracker()-> + PluginResourceForHostResource(host_resource), false) { // Validate that we're in the plugin rather than the host. Otherwise this // object will do the wrong thing. In the plugin, the instance should have diff --git a/ppapi/proxy/plugin_globals.cc b/ppapi/proxy/plugin_globals.cc new file mode 100644 index 0000000..888c3bd --- /dev/null +++ b/ppapi/proxy/plugin_globals.cc @@ -0,0 +1,31 @@ +// 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_globals.h" + +namespace ppapi { +namespace proxy { + +PluginGlobals* PluginGlobals::plugin_globals_ = NULL; + +PluginGlobals::PluginGlobals() : ppapi::PpapiGlobals() { + DCHECK(!plugin_globals_); + plugin_globals_ = this; +} + +PluginGlobals::~PluginGlobals() { + DCHECK(plugin_globals_ == this); + plugin_globals_ = NULL; +} + +ResourceTracker* PluginGlobals::GetResourceTracker() { + return &plugin_resource_tracker_; +} + +VarTracker* PluginGlobals::GetVarTracker() { + return &plugin_var_tracker_; +} + +} // namespace proxy +} // namespace ppapi diff --git a/ppapi/proxy/plugin_globals.h b/ppapi/proxy/plugin_globals.h new file mode 100644 index 0000000..70dea89 --- /dev/null +++ b/ppapi/proxy/plugin_globals.h @@ -0,0 +1,51 @@ +// 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_GLOBALS_H_ +#define PPAPI_PROXY_PLUGIN_GLOBALS_H_ + +#include "base/compiler_specific.h" +#include "ppapi/proxy/plugin_resource_tracker.h" +#include "ppapi/proxy/plugin_var_tracker.h" +#include "ppapi/proxy/ppapi_proxy_export.h" +#include "ppapi/shared_impl/ppapi_globals.h" + +namespace ppapi { +namespace proxy { + +class PPAPI_PROXY_EXPORT PluginGlobals : public PpapiGlobals { + public: + PluginGlobals(); + virtual ~PluginGlobals(); + + // Getter for the global singleton. Generally, you should use + // PpapiGlobals::Get() when possible. Use this only when you need some + // plugin-specific functionality. + inline static PluginGlobals* Get() { return plugin_globals_; } + + // PpapiGlobals implementation. + virtual ResourceTracker* GetResourceTracker() OVERRIDE; + virtual VarTracker* GetVarTracker() OVERRIDE; + + // Getters for the plugin-specific versions. + PluginResourceTracker* plugin_resource_tracker() { + return &plugin_resource_tracker_; + } + PluginVarTracker* plugin_var_tracker() { + return &plugin_var_tracker_; + } + + private: + static PluginGlobals* plugin_globals_; + + PluginResourceTracker plugin_resource_tracker_; + PluginVarTracker plugin_var_tracker_; + + DISALLOW_COPY_AND_ASSIGN(PluginGlobals); +}; + +} // namespace proxy +} // namespace ppapi + +#endif // PPAPI_PROXY_PLUGIN_GLOBALS_H_ diff --git a/ppapi/proxy/plugin_resource_tracker.cc b/ppapi/proxy/plugin_resource_tracker.cc index 4abd8f7..67e2d69 100644 --- a/ppapi/proxy/plugin_resource_tracker.cc +++ b/ppapi/proxy/plugin_resource_tracker.cc @@ -7,6 +7,7 @@ #include "base/logging.h" #include "base/memory/singleton.h" #include "ppapi/proxy/plugin_dispatcher.h" +#include "ppapi/proxy/plugin_globals.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/serialized_var.h" #include "ppapi/shared_impl/proxy_lock.h" @@ -19,17 +20,13 @@ namespace proxy { namespace { -// When non-NULL, this object overrides the ResourceTrackerSingleton. -PluginResourceTracker* g_resource_tracker_override = NULL; - TrackerBase* GetTrackerBase() { - return PluginResourceTracker::GetInstance(); + return PluginGlobals::Get()->plugin_resource_tracker(); } } // namespace -PluginResourceTracker::PluginResourceTracker() - : var_tracker_test_override_(NULL) { +PluginResourceTracker::PluginResourceTracker() { #ifdef ENABLE_PEPPER_THREADING // Set the global proxy lock, since the plugin-side of the proxy needs to be // synchronized. @@ -44,20 +41,8 @@ PluginResourceTracker::~PluginResourceTracker() { } // static -void PluginResourceTracker::SetInstanceForTest(PluginResourceTracker* tracker) { - g_resource_tracker_override = tracker; -} - -// static -PluginResourceTracker* PluginResourceTracker::GetInstance() { - if (g_resource_tracker_override) - return g_resource_tracker_override; - return Singleton<PluginResourceTracker>::get(); -} - -// static TrackerBase* PluginResourceTracker::GetTrackerBaseInstance() { - return GetInstance(); + return GetTrackerBase(); } PP_Resource PluginResourceTracker::PluginResourceForHostResource( @@ -76,14 +61,6 @@ FunctionGroupBase* PluginResourceTracker::GetFunctionAPI(PP_Instance inst, return NULL; } -VarTracker* PluginResourceTracker::GetVarTracker() { - return &var_tracker(); -} - -ResourceTracker* PluginResourceTracker::GetResourceTracker() { - return this; -} - PP_Module PluginResourceTracker::GetModuleForInstance(PP_Instance instance) { // Currently proxied plugins don't use the PP_Module for anything useful. return 0; diff --git a/ppapi/proxy/plugin_resource_tracker.h b/ppapi/proxy/plugin_resource_tracker.h index 30fafb2..cf87787 100644 --- a/ppapi/proxy/plugin_resource_tracker.h +++ b/ppapi/proxy/plugin_resource_tracker.h @@ -15,7 +15,6 @@ #include "ppapi/c/pp_stdint.h" #include "ppapi/c/pp_resource.h" #include "ppapi/c/pp_var.h" -#include "ppapi/proxy/plugin_var_tracker.h" #include "ppapi/proxy/ppapi_proxy_export.h" #include "ppapi/shared_impl/host_resource.h" #include "ppapi/shared_impl/resource_tracker.h" @@ -34,13 +33,9 @@ class PluginDispatcher; class PPAPI_PROXY_EXPORT PluginResourceTracker : public TrackerBase, public 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 - // around across tests. - static void SetInstanceForTest(PluginResourceTracker* tracker); + PluginResourceTracker(); + virtual ~PluginResourceTracker(); - // Returns the global singleton resource tracker for the plugin. - static PluginResourceTracker* GetInstance(); static TrackerBase* GetTrackerBaseInstance(); // Given a host resource, maps it to an existing plugin resource ID if it @@ -48,20 +43,9 @@ class PPAPI_PROXY_EXPORT PluginResourceTracker : public TrackerBase, PP_Resource PluginResourceForHostResource( const HostResource& resource) const; - PluginVarTracker& var_tracker() { - return var_tracker_test_override_ ? *var_tracker_test_override_ - : var_tracker_; - } - - void set_var_tracker_test_override(PluginVarTracker* t) { - var_tracker_test_override_ = t; - } - // TrackerBase. virtual FunctionGroupBase* GetFunctionAPI(PP_Instance inst, InterfaceID id) OVERRIDE; - virtual VarTracker* GetVarTracker() OVERRIDE; - virtual ResourceTracker* GetResourceTracker() OVERRIDE; virtual PP_Module GetModuleForInstance(PP_Instance instance) OVERRIDE; protected: @@ -70,24 +54,6 @@ class PPAPI_PROXY_EXPORT PluginResourceTracker : public TrackerBase, virtual void RemoveResource(Resource* object) OVERRIDE; private: - friend struct DefaultSingletonTraits<PluginResourceTracker>; - friend class PluginResourceTrackerTest; - friend class PluginProxyTestHarness; - - PluginResourceTracker(); - virtual ~PluginResourceTracker(); - - // 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 - // of some global object that manages PPAPI globals, including separate var - // and resource trackers. - PluginVarTracker var_tracker_; - - // Non-owning pointer to a var tracker mock used by tests. NULL when no - // test implementation is provided. - PluginVarTracker* var_tracker_test_override_; - // Map of host instance/resource pairs to a plugin resource ID. typedef std::map<HostResource, PP_Resource> HostResourceMap; HostResourceMap host_resource_map_; diff --git a/ppapi/proxy/plugin_var_serialization_rules.cc b/ppapi/proxy/plugin_var_serialization_rules.cc index 49e1fc3..3d9975a 100644 --- a/ppapi/proxy/plugin_var_serialization_rules.cc +++ b/ppapi/proxy/plugin_var_serialization_rules.cc @@ -6,15 +6,17 @@ #include "base/logging.h" #include "ppapi/proxy/plugin_dispatcher.h" +#include "ppapi/proxy/plugin_globals.h" #include "ppapi/proxy/plugin_resource_tracker.h" #include "ppapi/proxy/plugin_var_tracker.h" +#include "ppapi/shared_impl/ppapi_globals.h" #include "ppapi/shared_impl/var.h" namespace ppapi { namespace proxy { PluginVarSerializationRules::PluginVarSerializationRules() - : var_tracker_(&PluginResourceTracker::GetInstance()->var_tracker()) { + : var_tracker_(PluginGlobals::Get()->plugin_var_tracker()) { } PluginVarSerializationRules::~PluginVarSerializationRules() { diff --git a/ppapi/proxy/ppapi_proxy_test.cc b/ppapi/proxy/ppapi_proxy_test.cc index 1c7233c..484253b 100644 --- a/ppapi/proxy/ppapi_proxy_test.cc +++ b/ppapi/proxy/ppapi_proxy_test.cc @@ -151,9 +151,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_); + resource_tracker().DidCreateInstance(pp_instance()); plugin_dispatcher_.reset(new PluginDispatcher( base::Process::Current().handle(), @@ -168,9 +166,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_); + resource_tracker().DidCreateInstance(pp_instance()); plugin_delegate_mock_.Init(ipc_message_loop, shutdown_event); plugin_dispatcher_.reset(new PluginDispatcher( @@ -186,8 +182,7 @@ void PluginProxyTestHarness::TearDownHarness() { plugin_dispatcher_->DidDestroyInstance(pp_instance()); plugin_dispatcher_.reset(); - resource_tracker_.DidDeleteInstance(pp_instance()); - PluginResourceTracker::SetInstanceForTest(NULL); + resource_tracker().DidDeleteInstance(pp_instance()); } base::MessageLoopProxy* diff --git a/ppapi/proxy/ppapi_proxy_test.h b/ppapi/proxy/ppapi_proxy_test.h index 03ec57d..cf71a5e 100644 --- a/ppapi/proxy/ppapi_proxy_test.h +++ b/ppapi/proxy/ppapi_proxy_test.h @@ -13,6 +13,7 @@ #include "ppapi/c/pp_instance.h" #include "ppapi/proxy/host_dispatcher.h" #include "ppapi/proxy/plugin_dispatcher.h" +#include "ppapi/proxy/plugin_globals.h" #include "ppapi/proxy/plugin_resource_tracker.h" #include "ppapi/proxy/plugin_var_tracker.h" #include "testing/gtest/include/gtest/gtest.h" @@ -78,8 +79,12 @@ class PluginProxyTestHarness : public ProxyTestHarnessBase { virtual ~PluginProxyTestHarness(); PluginDispatcher* plugin_dispatcher() { return plugin_dispatcher_.get(); } - PluginResourceTracker& resource_tracker() { return resource_tracker_; } - PluginVarTracker& var_tracker() { return var_tracker_; } + PluginResourceTracker& resource_tracker() { + return *plugin_globals_.plugin_resource_tracker(); + } + PluginVarTracker& var_tracker() { + return *plugin_globals_.plugin_var_tracker(); + } // ProxyTestHarnessBase implementation. virtual Dispatcher* GetDispatcher(); @@ -123,8 +128,8 @@ class PluginProxyTestHarness : public ProxyTestHarnessBase { }; private: - PluginResourceTracker resource_tracker_; - PluginVarTracker var_tracker_; + PluginGlobals plugin_globals_; + scoped_ptr<PluginDispatcher> plugin_dispatcher_; PluginDelegateMock plugin_delegate_mock_; }; diff --git a/ppapi/proxy/ppb_audio_proxy.cc b/ppapi/proxy/ppb_audio_proxy.cc index 453d7b0..f1aedf7 100644 --- a/ppapi/proxy/ppb_audio_proxy.cc +++ b/ppapi/proxy/ppb_audio_proxy.cc @@ -16,6 +16,7 @@ #include "ppapi/proxy/plugin_dispatcher.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/shared_impl/audio_impl.h" +#include "ppapi/shared_impl/ppapi_globals.h" #include "ppapi/shared_impl/resource.h" #include "ppapi/thunk/ppb_audio_config_api.h" #include "ppapi/thunk/enter.h" @@ -64,11 +65,11 @@ Audio::Audio(const HostResource& audio_id, : Resource(audio_id), config_(config_id) { SetCallback(callback, user_data); - PluginResourceTracker::GetInstance()->AddRefResource(config_); + PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(config_); } Audio::~Audio() { - PluginResourceTracker::GetInstance()->ReleaseResource(config_); + PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(config_); } PPB_Audio_API* Audio::AsPPB_Audio_API() { @@ -77,7 +78,7 @@ PPB_Audio_API* Audio::AsPPB_Audio_API() { PP_Resource Audio::GetCurrentConfig() { // AddRef for the caller. - PluginResourceTracker::GetInstance()->AddRefResource(config_); + PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(config_); return config_; } diff --git a/ppapi/proxy/ppb_core_proxy.cc b/ppapi/proxy/ppb_core_proxy.cc index 9173df6..c01eb45 100644 --- a/ppapi/proxy/ppb_core_proxy.cc +++ b/ppapi/proxy/ppb_core_proxy.cc @@ -18,6 +18,7 @@ #include "ppapi/proxy/plugin_dispatcher.h" #include "ppapi/proxy/plugin_resource_tracker.h" #include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/shared_impl/ppapi_globals.h" #include "ppapi/shared_impl/proxy_lock.h" #include "ppapi/shared_impl/time_conversion.h" @@ -34,12 +35,12 @@ base::MessageLoopProxy* GetMainThreadMessageLoop() { void AddRefResource(PP_Resource resource) { ppapi::ProxyAutoLock lock; - PluginResourceTracker::GetInstance()->AddRefResource(resource); + PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(resource); } void ReleaseResource(PP_Resource resource) { ppapi::ProxyAutoLock lock; - PluginResourceTracker::GetInstance()->ReleaseResource(resource); + PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(resource); } double GetTime() { diff --git a/ppapi/proxy/ppb_cursor_control_proxy.cc b/ppapi/proxy/ppb_cursor_control_proxy.cc index a0b0ee8..960c010 100644 --- a/ppapi/proxy/ppb_cursor_control_proxy.cc +++ b/ppapi/proxy/ppb_cursor_control_proxy.cc @@ -9,6 +9,7 @@ #include "ppapi/proxy/plugin_dispatcher.h" #include "ppapi/proxy/plugin_resource_tracker.h" #include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/shared_impl/ppapi_globals.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/thunk.h" @@ -37,8 +38,8 @@ 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) { - Resource* cursor_image = PluginResourceTracker::GetInstance()-> - GetResource(custom_image_id); + Resource* cursor_image = + PpapiGlobals::Get()->GetResourceTracker()->GetResource(custom_image_id); if (!cursor_image || cursor_image->pp_instance() != instance) return PP_FALSE; cursor_image_resource = cursor_image->host_resource(); diff --git a/ppapi/proxy/ppb_file_chooser_proxy.cc b/ppapi/proxy/ppb_file_chooser_proxy.cc index 1c7907c..1e55af6 100644 --- a/ppapi/proxy/ppb_file_chooser_proxy.cc +++ b/ppapi/proxy/ppb_file_chooser_proxy.cc @@ -17,6 +17,8 @@ #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/ppb_file_ref_proxy.h" #include "ppapi/proxy/serialized_var.h" +#include "ppapi/shared_impl/ppapi_globals.h" +#include "ppapi/shared_impl/resource_tracker.h" #include "ppapi/shared_impl/var.h" #include "ppapi/thunk/resource_creation_api.h" #include "ppapi/thunk/thunk.h" @@ -87,7 +89,7 @@ FileChooser::~FileChooser() { // Any existing files we haven't transferred ownership to the plugin need // to be freed. - PluginResourceTracker* tracker = PluginResourceTracker::GetInstance(); + ResourceTracker* tracker = PpapiGlobals::Get()->GetResourceTracker(); while (!file_queue_.empty()) { tracker->ReleaseResource(file_queue_.front()); file_queue_.pop(); diff --git a/ppapi/proxy/ppb_file_ref_proxy.cc b/ppapi/proxy/ppb_file_ref_proxy.cc index 49a1131..c9824a4 100644 --- a/ppapi/proxy/ppb_file_ref_proxy.cc +++ b/ppapi/proxy/ppb_file_ref_proxy.cc @@ -90,7 +90,7 @@ int32_t FileRef::Delete(PP_CompletionCallback callback) { int32_t FileRef::Rename(PP_Resource new_file_ref, PP_CompletionCallback callback) { Resource* new_file_ref_object = - PluginResourceTracker::GetInstance()->GetResource(new_file_ref); + PpapiGlobals::Get()->GetResourceTracker()->GetResource(new_file_ref); if (!new_file_ref_object || new_file_ref_object->host_resource().instance() != pp_instance()) return PP_ERROR_BADRESOURCE; @@ -113,7 +113,7 @@ PPB_FileRef_Proxy::~PPB_FileRef_Proxy() { PP_Resource PPB_FileRef_Proxy::CreateProxyResource(PP_Resource file_system, const char* path) { Resource* file_system_object = - PluginResourceTracker::GetInstance()->GetResource(file_system); + PpapiGlobals::Get()->GetResourceTracker()->GetResource(file_system); if (!file_system_object) return 0; diff --git a/ppapi/proxy/ppb_flash_file_proxy.cc b/ppapi/proxy/ppb_flash_file_proxy.cc index fa636aa..de5a40c 100644 --- a/ppapi/proxy/ppb_flash_file_proxy.cc +++ b/ppapi/proxy/ppb_flash_file_proxy.cc @@ -21,9 +21,10 @@ #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_tracker.h" #include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/shared_impl/ppapi_globals.h" #include "ppapi/shared_impl/resource.h" +#include "ppapi/shared_impl/resource_tracker.h" namespace ppapi { namespace proxy { @@ -631,7 +632,7 @@ int32_t OpenFileRefFile(PP_Resource file_ref_id, int32_t mode, PP_FileHandle* file) { Resource* file_ref = - PluginResourceTracker::GetInstance()->GetResource(file_ref_id); + PpapiGlobals::Get()->GetResourceTracker()->GetResource(file_ref_id); if (!file_ref) return PP_ERROR_BADRESOURCE; @@ -651,7 +652,7 @@ int32_t OpenFileRefFile(PP_Resource file_ref_id, int32_t QueryFileRefFile(PP_Resource file_ref_id, PP_FileInfo* info) { Resource* file_ref = - PluginResourceTracker::GetInstance()->GetResource(file_ref_id); + PpapiGlobals::Get()->GetResourceTracker()->GetResource(file_ref_id); if (!file_ref) return PP_ERROR_BADRESOURCE; diff --git a/ppapi/proxy/ppb_flash_proxy.cc b/ppapi/proxy/ppb_flash_proxy.cc index 1faae86..b1d0d22 100644 --- a/ppapi/proxy/ppb_flash_proxy.cc +++ b/ppapi/proxy/ppb_flash_proxy.cc @@ -14,11 +14,12 @@ #include "ppapi/c/private/ppb_flash.h" #include "ppapi/proxy/host_dispatcher.h" #include "ppapi/proxy/plugin_dispatcher.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/ppapi_globals.h" #include "ppapi/shared_impl/resource.h" +#include "ppapi/shared_impl/resource_tracker.h" #include "ppapi/shared_impl/scoped_pp_resource.h" #include "ppapi/shared_impl/var.h" #include "ppapi/thunk/enter.h" @@ -48,8 +49,8 @@ PP_Bool DrawGlyphs(PP_Instance instance, uint32_t glyph_count, const uint16_t glyph_indices[], const PP_Point glyph_advances[]) { - Resource* image_data = PluginResourceTracker::GetInstance()->GetResource( - pp_image_data); + Resource* image_data = + PpapiGlobals::Get()->GetResourceTracker()->GetResource(pp_image_data); if (!image_data) return PP_FALSE; // The instance parameter isn't strictly necessary but we check that it diff --git a/ppapi/proxy/ppb_graphics_2d_proxy.cc b/ppapi/proxy/ppb_graphics_2d_proxy.cc index dcf8d26..7bed679 100644 --- a/ppapi/proxy/ppb_graphics_2d_proxy.cc +++ b/ppapi/proxy/ppb_graphics_2d_proxy.cc @@ -87,8 +87,8 @@ 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) { - Resource* image_object = PluginResourceTracker::GetInstance()-> - GetResource(image_data); + Resource* image_object = + PpapiGlobals::Get()->GetResourceTracker()->GetResource(image_data); if (!image_object || pp_instance() != image_object->pp_instance()) return; @@ -110,8 +110,8 @@ void Graphics2D::Scroll(const PP_Rect* clip_rect, } void Graphics2D::ReplaceContents(PP_Resource image_data) { - Resource* image_object = PluginResourceTracker::GetInstance()-> - GetResource(image_data); + Resource* image_object = + PpapiGlobals::Get()->GetResourceTracker()->GetResource(image_data); if (!image_object || pp_instance() != image_object->pp_instance()) return; diff --git a/ppapi/proxy/ppb_instance_proxy.cc b/ppapi/proxy/ppb_instance_proxy.cc index 0d79df43..f11f396 100644 --- a/ppapi/proxy/ppb_instance_proxy.cc +++ b/ppapi/proxy/ppb_instance_proxy.cc @@ -11,9 +11,9 @@ #include "ppapi/c/ppb_mouse_lock.h" #include "ppapi/proxy/host_dispatcher.h" #include "ppapi/proxy/plugin_dispatcher.h" -#include "ppapi/proxy/plugin_resource_tracker.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/serialized_var.h" +#include "ppapi/shared_impl/ppapi_globals.h" #include "ppapi/shared_impl/url_util_impl.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/thunk.h" @@ -123,7 +123,8 @@ PPB_Instance_FunctionAPI* PPB_Instance_Proxy::AsPPB_Instance_FunctionAPI() { PP_Bool PPB_Instance_Proxy::BindGraphics(PP_Instance instance, PP_Resource device) { - Resource* object = PluginResourceTracker::GetInstance()->GetResource(device); + Resource* object = + PpapiGlobals::Get()->GetResourceTracker()->GetResource(device); if (!object || object->pp_instance() != instance) return PP_FALSE; diff --git a/ppapi/proxy/ppb_testing_proxy.cc b/ppapi/proxy/ppb_testing_proxy.cc index 836e1cf..470d3da 100644 --- a/ppapi/proxy/ppb_testing_proxy.cc +++ b/ppapi/proxy/ppb_testing_proxy.cc @@ -7,9 +7,10 @@ #include "base/message_loop.h" #include "ppapi/c/dev/ppb_testing_dev.h" #include "ppapi/proxy/plugin_dispatcher.h" -#include "ppapi/proxy/plugin_resource_tracker.h" #include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/shared_impl/ppapi_globals.h" #include "ppapi/shared_impl/resource.h" +#include "ppapi/shared_impl/resource_tracker.h" namespace ppapi { namespace proxy { @@ -19,12 +20,12 @@ namespace { PP_Bool ReadImageData(PP_Resource graphics_2d, PP_Resource image, const PP_Point* top_left) { - Resource* image_object = PluginResourceTracker::GetInstance()-> - GetResource(image); + Resource* image_object = + PpapiGlobals::Get()->GetResourceTracker()->GetResource(image); if (!image_object) return PP_FALSE; Resource* graphics_2d_object = - PluginResourceTracker::GetInstance()->GetResource(graphics_2d); + PpapiGlobals::Get()->GetResourceTracker()->GetResource(graphics_2d); if (!graphics_2d_object || image_object->pp_instance() != graphics_2d_object->pp_instance()) return PP_FALSE; diff --git a/ppapi/proxy/ppb_url_loader_proxy.cc b/ppapi/proxy/ppb_url_loader_proxy.cc index 70c01e8..2ad3025 100644 --- a/ppapi/proxy/ppb_url_loader_proxy.cc +++ b/ppapi/proxy/ppb_url_loader_proxy.cc @@ -172,7 +172,7 @@ URLLoader::~URLLoader() { } if (response_info_) - PluginResourceTracker::GetInstance()->ReleaseResource(response_info_); + PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(response_info_); } PPB_URLLoader_API* URLLoader::AsPPB_URLLoader_API() { @@ -240,7 +240,7 @@ PP_Resource URLLoader::GetResponseInfo() { } // The caller expects to get a ref, and we want to keep holding ours. - PluginResourceTracker::GetInstance()->AddRefResource(response_info_); + PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(response_info_); return response_info_; } diff --git a/ppapi/proxy/ppb_var_deprecated_proxy.cc b/ppapi/proxy/ppb_var_deprecated_proxy.cc index 6475580..892fba1 100644 --- a/ppapi/proxy/ppb_var_deprecated_proxy.cc +++ b/ppapi/proxy/ppb_var_deprecated_proxy.cc @@ -15,6 +15,7 @@ #include "ppapi/c/ppb_core.h" #include "ppapi/proxy/host_dispatcher.h" #include "ppapi/proxy/plugin_dispatcher.h" +#include "ppapi/proxy/plugin_globals.h" #include "ppapi/proxy/plugin_resource_tracker.h" #include "ppapi/proxy/plugin_var_tracker.h" #include "ppapi/proxy/ppapi_messages.h" @@ -41,8 +42,9 @@ PluginDispatcher* CheckExceptionAndGetDispatcher(const PP_Var& object, if (object.type == PP_VARTYPE_OBJECT) { // Get the dispatcher for the object. - PluginDispatcher* dispatcher = PluginResourceTracker::GetInstance()-> - var_tracker().DispatcherForPluginObject(object); + PluginDispatcher* dispatcher = + PluginGlobals::Get()->plugin_var_tracker()-> + DispatcherForPluginObject(object); if (dispatcher) return dispatcher; } @@ -59,11 +61,11 @@ PluginDispatcher* CheckExceptionAndGetDispatcher(const PP_Var& object, // PPB_Var_Deprecated plugin --------------------------------------------------- void AddRefVar(PP_Var var) { - PluginResourceTracker::GetInstance()->var_tracker().AddRefVar(var); + PpapiGlobals::Get()->GetVarTracker()->AddRefVar(var); } void ReleaseVar(PP_Var var) { - PluginResourceTracker::GetInstance()->var_tracker().ReleaseVar(var); + PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(var); } PP_Var VarFromUtf8(PP_Module module, const char* data, uint32_t len) { diff --git a/ppapi/proxy/ppb_var_proxy.cc b/ppapi/proxy/ppb_var_proxy.cc index 0c7cf5b..4301234 100644 --- a/ppapi/proxy/ppb_var_proxy.cc +++ b/ppapi/proxy/ppb_var_proxy.cc @@ -6,10 +6,10 @@ #include "ppapi/c/pp_var.h" #include "ppapi/c/ppb_var.h" -#include "ppapi/proxy/plugin_resource_tracker.h" -#include "ppapi/proxy/plugin_var_tracker.h" +#include "ppapi/shared_impl/ppapi_globals.h" #include "ppapi/shared_impl/proxy_lock.h" #include "ppapi/shared_impl/var.h" +#include "ppapi/shared_impl/var_tracker.h" namespace ppapi { namespace proxy { @@ -20,12 +20,12 @@ namespace { void AddRefVar(PP_Var var) { ppapi::ProxyAutoLock lock; - PluginResourceTracker::GetInstance()->var_tracker().AddRefVar(var); + PpapiGlobals::Get()->GetVarTracker()->AddRefVar(var); } void ReleaseVar(PP_Var var) { ppapi::ProxyAutoLock lock; - PluginResourceTracker::GetInstance()->var_tracker().ReleaseVar(var); + PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(var); } PP_Var VarFromUtf8(PP_Module module, const char* data, uint32_t len) { diff --git a/ppapi/proxy/ppb_video_capture_proxy.cc b/ppapi/proxy/ppb_video_capture_proxy.cc index 9f40c1f..c771bf5 100644 --- a/ppapi/proxy/ppb_video_capture_proxy.cc +++ b/ppapi/proxy/ppb_video_capture_proxy.cc @@ -373,11 +373,11 @@ void PPP_VideoCapture_Proxy::OnMsgOnDeviceInfo( const PP_VideoCaptureDeviceInfo_Dev& info, const std::vector<PPPVideoCapture_Buffer>& buffers) { EnterPluginFromHostResource<PPB_VideoCapture_API> enter(host_resource); - PluginResourceTracker* tracker = PluginResourceTracker::GetInstance(); - PP_Resource resource = tracker->PluginResourceForHostResource(host_resource); - if (!resource || !ppp_video_capture_impl_ || enter.failed()) + if (enter.failed() || !ppp_video_capture_impl_) return; + PluginResourceTracker* tracker = + PluginGlobals::Get()->plugin_resource_tracker(); scoped_array<PP_Resource> resources(new PP_Resource[buffers.size()]); for (size_t i = 0; i < buffers.size(); ++i) { // We assume that the browser created a new set of resources. @@ -386,10 +386,12 @@ void PPP_VideoCapture_Proxy::OnMsgOnDeviceInfo( buffers[i].handle, buffers[i].size); } - static_cast<VideoCapture*>(enter.object())->SetBufferCount(buffers.size()); + + VideoCapture* capture = static_cast<VideoCapture*>(enter.object()); + capture->SetBufferCount(buffers.size()); ppp_video_capture_impl_->OnDeviceInfo( host_resource.instance(), - resource, + capture->pp_resource(), &info, buffers.size(), resources.get()); @@ -400,40 +402,38 @@ void PPP_VideoCapture_Proxy::OnMsgOnDeviceInfo( void PPP_VideoCapture_Proxy::OnMsgOnStatus(const HostResource& host_resource, uint32_t status) { EnterPluginFromHostResource<PPB_VideoCapture_API> enter(host_resource); - PluginResourceTracker* tracker = PluginResourceTracker::GetInstance(); - PP_Resource resource = tracker->PluginResourceForHostResource(host_resource); - if (!resource || !ppp_video_capture_impl_ || enter.failed()) + if (enter.failed() || !ppp_video_capture_impl_) return; - if (!static_cast<VideoCapture*>(enter.object())->OnStatus(status)) + VideoCapture* capture = static_cast<VideoCapture*>(enter.object()); + if (!capture->OnStatus(status)) return; ppp_video_capture_impl_->OnStatus( - host_resource.instance(), resource, status); + host_resource.instance(), capture->pp_resource(), status); } void PPP_VideoCapture_Proxy::OnMsgOnError(const HostResource& host_resource, uint32_t error_code) { EnterPluginFromHostResource<PPB_VideoCapture_API> enter(host_resource); - PluginResourceTracker* tracker = PluginResourceTracker::GetInstance(); - PP_Resource resource = tracker->PluginResourceForHostResource(host_resource); - if (!resource || !ppp_video_capture_impl_ || enter.failed()) + if (enter.failed() || !ppp_video_capture_impl_) return; - static_cast<VideoCapture*>(enter.object())->set_status( - PP_VIDEO_CAPTURE_STATUS_STOPPED); + + VideoCapture* capture = static_cast<VideoCapture*>(enter.object()); + capture->set_status(PP_VIDEO_CAPTURE_STATUS_STOPPED); ppp_video_capture_impl_->OnError( - host_resource.instance(), resource, error_code); + host_resource.instance(), capture->pp_resource(), error_code); } void PPP_VideoCapture_Proxy::OnMsgOnBufferReady( const HostResource& host_resource, uint32_t buffer) { EnterPluginFromHostResource<PPB_VideoCapture_API> enter(host_resource); - PluginResourceTracker* tracker = PluginResourceTracker::GetInstance(); - PP_Resource resource = tracker->PluginResourceForHostResource(host_resource); - if (!resource || !ppp_video_capture_impl_ || enter.failed()) + if (enter.failed() || !ppp_video_capture_impl_) return; - static_cast<VideoCapture*>(enter.object())->SetBufferInUse(buffer); + + VideoCapture* capture = static_cast<VideoCapture*>(enter.object()); + capture->SetBufferInUse(buffer); ppp_video_capture_impl_->OnBufferReady( - host_resource.instance(), resource, buffer); + host_resource.instance(), capture->pp_resource(), buffer); } } // namespace proxy diff --git a/ppapi/proxy/ppp_instance_private_proxy_unittest.cc b/ppapi/proxy/ppp_instance_private_proxy_unittest.cc index a192154..ea57ec1 100644 --- a/ppapi/proxy/ppp_instance_private_proxy_unittest.cc +++ b/ppapi/proxy/ppp_instance_private_proxy_unittest.cc @@ -156,7 +156,7 @@ TEST_F(PPP_Instance_Private_ProxyTest, PPPInstancePrivate) { // Now instance_obj is valid and should have a ref-count of 1. PluginVarTracker& plugin_var_tracker = - PluginResourceTracker::GetInstance()->var_tracker(); + *PluginGlobals::Get()->plugin_var_tracker(); // Check the plugin-side reference count. EXPECT_EQ(1, plugin_var_tracker.GetRefCountForObject(instance_obj)); // Check the host-side var and reference count. diff --git a/ppapi/proxy/ppp_instance_proxy.cc b/ppapi/proxy/ppp_instance_proxy.cc index c3e7395..9463f28 100644 --- a/ppapi/proxy/ppp_instance_proxy.cc +++ b/ppapi/proxy/ppp_instance_proxy.cc @@ -15,6 +15,7 @@ #include "ppapi/proxy/plugin_resource_tracker.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/ppb_url_loader_proxy.h" +#include "ppapi/shared_impl/ppapi_globals.h" namespace ppapi { namespace proxy { @@ -175,7 +176,7 @@ void PPP_Instance_Proxy::OnMsgDidCreate( PluginDispatcher* plugin_dispatcher = static_cast<PluginDispatcher*>(dispatcher()); plugin_dispatcher->DidCreateInstance(instance); - ppapi::TrackerBase::Get()->GetResourceTracker()->DidCreateInstance(instance); + PpapiGlobals::Get()->GetResourceTracker()->DidCreateInstance(instance); // Make sure the arrays always have at least one element so we can take the // address below. @@ -196,7 +197,7 @@ void PPP_Instance_Proxy::OnMsgDidCreate( void PPP_Instance_Proxy::OnMsgDidDestroy(PP_Instance instance) { combined_interface_->DidDestroy(instance); - ppapi::TrackerBase::Get()->GetResourceTracker()->DidDeleteInstance(instance); + PpapiGlobals::Get()->GetResourceTracker()->DidDeleteInstance(instance); static_cast<PluginDispatcher*>(dispatcher())->DidDestroyInstance(instance); } @@ -235,7 +236,7 @@ void PPP_Instance_Proxy::OnMsgHandleDocumentLoad(PP_Instance instance, // representing all plugin references). // Once all references at the plugin side are released, the renderer side will // be notified and release the reference added in HandleDocumentLoad() above. - PluginResourceTracker::GetInstance()->ReleaseResource(plugin_loader); + PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(plugin_loader); } } // namespace proxy diff --git a/ppapi/proxy/ppp_messaging_proxy.cc b/ppapi/proxy/ppp_messaging_proxy.cc index 390794a..60cd8c4 100644 --- a/ppapi/proxy/ppp_messaging_proxy.cc +++ b/ppapi/proxy/ppp_messaging_proxy.cc @@ -12,6 +12,8 @@ #include "ppapi/proxy/plugin_var_tracker.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/serialized_var.h" +#include "ppapi/shared_impl/ppapi_globals.h" +#include "ppapi/shared_impl/var_tracker.h" namespace ppapi { namespace proxy { @@ -82,7 +84,7 @@ void PPP_Messaging_Proxy::OnMsgHandleMessage( PP_Var received_var(message_data.Get(dispatcher())); // SerializedVarReceiveInput will decrement the reference count, but we want // to give the recipient a reference. - PluginResourceTracker::GetInstance()->var_tracker().AddRefVar(received_var); + PpapiGlobals::Get()->GetVarTracker()->AddRefVar(received_var); ppp_messaging_impl_->HandleMessage(instance, received_var); } diff --git a/ppapi/proxy/ppp_video_decoder_proxy.cc b/ppapi/proxy/ppp_video_decoder_proxy.cc index c115278..3852806 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_globals.h" #include "ppapi/proxy/plugin_resource_tracker.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/ppb_video_decoder_proxy.h" @@ -131,7 +132,7 @@ bool PPP_VideoDecoder_Proxy::OnMessageReceived(const IPC::Message& msg) { void PPP_VideoDecoder_Proxy::OnMsgProvidePictureBuffers( const HostResource& decoder, uint32_t req_num_of_bufs, const PP_Size& dimensions) { - PP_Resource plugin_decoder = PluginResourceTracker::GetInstance()-> + PP_Resource plugin_decoder = PluginGlobals::Get()->plugin_resource_tracker()-> PluginResourceForHostResource(decoder); ppp_video_decoder_impl_->ProvidePictureBuffers( decoder.instance(), plugin_decoder, req_num_of_bufs, &dimensions); @@ -139,7 +140,7 @@ void PPP_VideoDecoder_Proxy::OnMsgProvidePictureBuffers( void PPP_VideoDecoder_Proxy::OnMsgDismissPictureBuffer( const HostResource& decoder, int32_t picture_id) { - PP_Resource plugin_decoder = PluginResourceTracker::GetInstance()-> + PP_Resource plugin_decoder = PluginGlobals::Get()->plugin_resource_tracker()-> PluginResourceForHostResource(decoder); ppp_video_decoder_impl_->DismissPictureBuffer( decoder.instance(), plugin_decoder, picture_id); @@ -147,7 +148,7 @@ void PPP_VideoDecoder_Proxy::OnMsgDismissPictureBuffer( void PPP_VideoDecoder_Proxy::OnMsgPictureReady( const HostResource& decoder, const PP_Picture_Dev& picture) { - PP_Resource plugin_decoder = PluginResourceTracker::GetInstance()-> + PP_Resource plugin_decoder = PluginGlobals::Get()->plugin_resource_tracker()-> PluginResourceForHostResource(decoder); ppp_video_decoder_impl_->PictureReady( decoder.instance(), plugin_decoder, &picture); @@ -155,7 +156,7 @@ void PPP_VideoDecoder_Proxy::OnMsgPictureReady( void PPP_VideoDecoder_Proxy::OnMsgNotifyEndOfStream( const HostResource& decoder) { - PP_Resource plugin_decoder = PluginResourceTracker::GetInstance()-> + PP_Resource plugin_decoder = PluginGlobals::Get()->plugin_resource_tracker()-> PluginResourceForHostResource(decoder); ppp_video_decoder_impl_->EndOfStream(decoder.instance(), plugin_decoder); @@ -163,7 +164,7 @@ void PPP_VideoDecoder_Proxy::OnMsgNotifyEndOfStream( void PPP_VideoDecoder_Proxy::OnMsgNotifyError( const HostResource& decoder, PP_VideoDecodeError_Dev error) { - PP_Resource plugin_decoder = PluginResourceTracker::GetInstance()-> + PP_Resource plugin_decoder = PluginGlobals::Get()->plugin_resource_tracker()-> PluginResourceForHostResource(decoder); ppp_video_decoder_impl_->NotifyError( decoder.instance(), plugin_decoder, error); diff --git a/ppapi/shared_impl/ppapi_globals.cc b/ppapi/shared_impl/ppapi_globals.cc new file mode 100644 index 0000000..9b5e9a8 --- /dev/null +++ b/ppapi/shared_impl/ppapi_globals.cc @@ -0,0 +1,23 @@ +// 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/ppapi_globals.h" + +#include "base/logging.h" + +namespace ppapi { + +PpapiGlobals* PpapiGlobals::ppapi_globals_ = NULL; + +PpapiGlobals::PpapiGlobals() { + DCHECK(!ppapi_globals_); + ppapi_globals_ = this; +} + +PpapiGlobals::~PpapiGlobals() { + DCHECK(ppapi_globals_ == this); + ppapi_globals_ = NULL; +} + +} // namespace ppapi diff --git a/ppapi/shared_impl/ppapi_globals.h b/ppapi/shared_impl/ppapi_globals.h new file mode 100644 index 0000000..d0936ee --- /dev/null +++ b/ppapi/shared_impl/ppapi_globals.h @@ -0,0 +1,36 @@ +// 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_PPAPI_GLOBALS_H_ +#define PPAPI_SHARED_IMPL_PPAPI_GLOBALS_H_ + +#include "base/basictypes.h" +#include "ppapi/shared_impl/ppapi_shared_export.h" + +namespace ppapi { + +class ResourceTracker; +class VarTracker; + +// Abstract base class +class PPAPI_SHARED_EXPORT PpapiGlobals { + public: + PpapiGlobals(); + virtual ~PpapiGlobals(); + + // Getter for the global singleton. + inline static PpapiGlobals* Get() { return ppapi_globals_; } + + virtual ResourceTracker* GetResourceTracker() = 0; + virtual VarTracker* GetVarTracker() = 0; + + private: + static PpapiGlobals* ppapi_globals_; + + DISALLOW_COPY_AND_ASSIGN(PpapiGlobals); +}; + +} // namespace ppapi + +#endif // PPAPI_SHARED_IMPL_PPAPI_GLOBALS_H_ diff --git a/ppapi/shared_impl/resource.cc b/ppapi/shared_impl/resource.cc index 11ac86a..4e1f2a8 100644 --- a/ppapi/shared_impl/resource.cc +++ b/ppapi/shared_impl/resource.cc @@ -6,7 +6,7 @@ #include "base/logging.h" #include "ppapi/shared_impl/resource_tracker.h" -#include "ppapi/shared_impl/tracker_base.h" +#include "ppapi/shared_impl/ppapi_globals.h" namespace ppapi { @@ -20,21 +20,21 @@ Resource::Resource(PP_Instance instance) { // 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); + pp_resource_ = PpapiGlobals::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); + pp_resource_ = PpapiGlobals::Get()->GetResourceTracker()->AddResource(this); } Resource::~Resource() { - TrackerBase::Get()->GetResourceTracker()->RemoveResource(this); + PpapiGlobals::Get()->GetResourceTracker()->RemoveResource(this); } PP_Resource Resource::GetReference() { - TrackerBase::Get()->GetResourceTracker()->AddRefResource(pp_resource()); + PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(pp_resource()); return pp_resource(); } diff --git a/ppapi/shared_impl/resource_tracker_unittest.cc b/ppapi/shared_impl/resource_tracker_unittest.cc index 371f6e77..2e22d6a 100644 --- a/ppapi/shared_impl/resource_tracker_unittest.cc +++ b/ppapi/shared_impl/resource_tracker_unittest.cc @@ -7,6 +7,7 @@ #include "base/compiler_specific.h" #include "ppapi/shared_impl/resource.h" #include "ppapi/shared_impl/resource_tracker.h" +#include "ppapi/shared_impl/test_globals.h" #include "ppapi/shared_impl/tracker_base.h" namespace ppapi { @@ -68,20 +69,14 @@ class ResourceTrackerTest : public testing::Test, public TrackerBase { ppapi::proxy::InterfaceID id) OVERRIDE { return NULL; } - virtual VarTracker* GetVarTracker() OVERRIDE { - return NULL; - } - virtual ResourceTracker* GetResourceTracker() OVERRIDE { - return &resource_tracker_; - } virtual PP_Module GetModuleForInstance(PP_Instance /* instance */) OVERRIDE { return 0; } - ResourceTracker& resource_tracker() { return resource_tracker_; } + ResourceTracker& resource_tracker() { return *globals_.GetResourceTracker(); } private: - ResourceTracker resource_tracker_; + TestGlobals globals_; }; // Test that LastPluginRefWasDeleted is called when the last plugin ref was diff --git a/ppapi/shared_impl/scoped_pp_resource.cc b/ppapi/shared_impl/scoped_pp_resource.cc index d5a9748..8399208 100644 --- a/ppapi/shared_impl/scoped_pp_resource.cc +++ b/ppapi/shared_impl/scoped_pp_resource.cc @@ -4,9 +4,9 @@ #include "ppapi/shared_impl/scoped_pp_resource.h" +#include "ppapi/shared_impl/ppapi_globals.h" #include "ppapi/shared_impl/resource.h" #include "ppapi/shared_impl/resource_tracker.h" -#include "ppapi/shared_impl/tracker_base.h" namespace ppapi { @@ -64,12 +64,12 @@ PP_Resource ScopedPPResource::Release() { void ScopedPPResource::CallAddRef() { if (id_) - TrackerBase::Get()->GetResourceTracker()->AddRefResource(id_); + PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(id_); } void ScopedPPResource::CallRelease() { if (id_) - TrackerBase::Get()->GetResourceTracker()->ReleaseResource(id_); + PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(id_); } } // namespace ppapi diff --git a/ppapi/shared_impl/test_globals.cc b/ppapi/shared_impl/test_globals.cc new file mode 100644 index 0000000..17ac224 --- /dev/null +++ b/ppapi/shared_impl/test_globals.cc @@ -0,0 +1,23 @@ +// 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/test_globals.h" + +namespace ppapi { + +TestGlobals::TestGlobals() : ppapi::PpapiGlobals() { +} + +TestGlobals::~TestGlobals() { +} + +ResourceTracker* TestGlobals::GetResourceTracker() { + return &resource_tracker_; +} + +VarTracker* TestGlobals::GetVarTracker() { + return &var_tracker_; +} + +} // namespace ppapi diff --git a/ppapi/shared_impl/test_globals.h b/ppapi/shared_impl/test_globals.h new file mode 100644 index 0000000..c2062b7 --- /dev/null +++ b/ppapi/shared_impl/test_globals.h @@ -0,0 +1,35 @@ +// 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_TEST_GLOBALS_H_ +#define PPAPI_SHARED_IMPL_TEST_GLOBALS_H_ + +#include "base/compiler_specific.h" +#include "ppapi/shared_impl/ppapi_globals.h" +#include "ppapi/shared_impl/resource_tracker.h" +#include "ppapi/shared_impl/var_tracker.h" + +namespace ppapi { + +// Implementation of PpapiGlobals for tests that don't need either the host- or +// plugin-specific implementations. +class TestGlobals : public PpapiGlobals { + public: + TestGlobals(); + virtual ~TestGlobals(); + + // PpapiGlobals implementation. + virtual ResourceTracker* GetResourceTracker() OVERRIDE; + virtual VarTracker* GetVarTracker() OVERRIDE; + + private: + ResourceTracker resource_tracker_; + VarTracker var_tracker_; + + DISALLOW_COPY_AND_ASSIGN(TestGlobals); +}; + +} // namespace ppapi + +#endif // PPAPI_SHARED_IMPL_TEST_GLOBALS_H_ diff --git a/ppapi/shared_impl/tracker_base.h b/ppapi/shared_impl/tracker_base.h index 9ff19d4..940cef4 100644 --- a/ppapi/shared_impl/tracker_base.h +++ b/ppapi/shared_impl/tracker_base.h @@ -44,9 +44,6 @@ class PPAPI_SHARED_EXPORT TrackerBase { virtual FunctionGroupBase* GetFunctionAPI(PP_Instance inst, proxy::InterfaceID id) = 0; - virtual VarTracker* GetVarTracker() = 0; - virtual ResourceTracker* GetResourceTracker() = 0; - // Returns the PP_Module associated with the given PP_Instance, or 0 on // failure. virtual PP_Module GetModuleForInstance(PP_Instance instance) = 0; diff --git a/ppapi/shared_impl/url_util_impl.cc b/ppapi/shared_impl/url_util_impl.cc index 5bced6c..d295fd7 100644 --- a/ppapi/shared_impl/url_util_impl.cc +++ b/ppapi/shared_impl/url_util_impl.cc @@ -5,6 +5,7 @@ #include "ppapi/shared_impl/url_util_impl.h" #include "googleurl/src/gurl.h" +#include "ppapi/shared_impl/ppapi_globals.h" #include "ppapi/shared_impl/tracker_base.h" #include "ppapi/shared_impl/var.h" #include "ppapi/shared_impl/var_tracker.h" @@ -106,7 +107,7 @@ PP_Var URLUtilImpl::ConvertComponentsAndReturnURL( return url; PP_Var result = Canonicalize(url, components); - TrackerBase::Get()->GetVarTracker()->ReleaseVar(url); + PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(url); return result; } diff --git a/ppapi/shared_impl/var.cc b/ppapi/shared_impl/var.cc index 165b8ff..edf339a 100644 --- a/ppapi/shared_impl/var.cc +++ b/ppapi/shared_impl/var.cc @@ -10,7 +10,7 @@ #include "base/string_number_conversions.h" #include "base/string_util.h" #include "ppapi/c/pp_var.h" -#include "ppapi/shared_impl/tracker_base.h" +#include "ppapi/shared_impl/ppapi_globals.h" #include "ppapi/shared_impl/var_tracker.h" namespace ppapi { @@ -78,7 +78,7 @@ int32 Var::GetExistingVarID() const { } int32 Var::GetOrCreateVarID() { - VarTracker* tracker = TrackerBase::Get()->GetVarTracker(); + VarTracker* tracker = PpapiGlobals::Get()->GetVarTracker(); if (var_id_) { if (!tracker->AddRefVar(var_id_)) return 0; @@ -148,7 +148,7 @@ StringVar* StringVar::FromPPVar(PP_Var var) { if (var.type != PP_VARTYPE_STRING) return NULL; scoped_refptr<Var> var_object( - TrackerBase::Get()->GetVarTracker()->GetVar(var)); + PpapiGlobals::Get()->GetVarTracker()->GetVar(var)); if (!var_object) return NULL; return var_object->AsStringVar(); diff --git a/ppapi/shared_impl/video_decoder_impl.cc b/ppapi/shared_impl/video_decoder_impl.cc index 71921f92..0b6d4e5 100644 --- a/ppapi/shared_impl/video_decoder_impl.cc +++ b/ppapi/shared_impl/video_decoder_impl.cc @@ -32,14 +32,14 @@ void VideoDecoderImpl::InitCommon( DCHECK(graphics_context); DCHECK(!gles2_impl_ && !graphics_context_); gles2_impl_ = gles2_impl; - TrackerBase::Get()->GetResourceTracker()->AddRefResource(graphics_context); + PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(graphics_context); graphics_context_ = graphics_context; } void VideoDecoderImpl::Destroy() { graphics_context_ = 0; gles2_impl_ = NULL; - TrackerBase::Get()->GetResourceTracker()->ReleaseResource(graphics_context_); + PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(graphics_context_); } bool VideoDecoderImpl::SetFlushCallback(PP_CompletionCallback callback) { diff --git a/ppapi/thunk/enter.h b/ppapi/thunk/enter.h index 34fb706..faa556d 100644 --- a/ppapi/thunk/enter.h +++ b/ppapi/thunk/enter.h @@ -9,10 +9,11 @@ #include "ppapi/c/pp_resource.h" #include "ppapi/proxy/interface_id.h" #include "ppapi/shared_impl/function_group_base.h" +#include "ppapi/shared_impl/ppapi_globals.h" #include "ppapi/shared_impl/proxy_lock.h" #include "ppapi/shared_impl/resource.h" -#include "ppapi/shared_impl/tracker_base.h" #include "ppapi/shared_impl/resource_tracker.h" +#include "ppapi/shared_impl/tracker_base.h" #include "ppapi/thunk/ppapi_thunk_export.h" #include "ppapi/thunk/ppb_instance_api.h" #include "ppapi/thunk/resource_creation_api.h" @@ -116,7 +117,7 @@ class EnterFunctionGivenResource : public EnterFunction<FunctionsT> { private: static PP_Instance GetInstanceForResource(PP_Resource resource) { Resource* object = - TrackerBase::Get()->GetResourceTracker()->GetResource(resource); + PpapiGlobals::Get()->GetResourceTracker()->GetResource(resource); return object ? object->pp_instance() : 0; } }; @@ -128,7 +129,8 @@ class EnterResource : subtle::LockOnEntry<lock_on_entry> { public: EnterResource(PP_Resource resource, bool report_error) : object_(NULL) { - resource_ = TrackerBase::Get()->GetResourceTracker()->GetResource(resource); + resource_ = + PpapiGlobals::Get()->GetResourceTracker()->GetResource(resource); if (resource_) object_ = resource_->GetAs<ResourceT>(); // TODO(brettw) check error and if report_error is set, do something. |