diff options
author | sail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-18 22:16:26 +0000 |
---|---|---|
committer | sail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-18 22:16:26 +0000 |
commit | faa2a45bf31af9e1131bb0cfa17ab1e2400ec0e4 (patch) | |
tree | f3f7c49fa06c0b32a78723f77bc3581559abb0f3 | |
parent | de3c5ea947350a310bcdaabe7a8cb2dbef3fc9a8 (diff) | |
download | chromium_src-faa2a45bf31af9e1131bb0cfa17ab1e2400ec0e4.zip chromium_src-faa2a45bf31af9e1131bb0cfa17ab1e2400ec0e4.tar.gz chromium_src-faa2a45bf31af9e1131bb0cfa17ab1e2400ec0e4.tar.bz2 |
Revert 106142 - Add a new globals object for PPAPI tracking information.
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/8316008
TBR=brettw@chromium.org
Review URL: http://codereview.chromium.org/8342016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106148 0039d316-1c4b-4281-b951-d872f2087c98
65 files changed, 329 insertions, 556 deletions
diff --git a/chrome/renderer/chrome_ppb_pdf_impl.cc b/chrome/renderer/chrome_ppb_pdf_impl.cc index 3a39f25..e9b5174 100644 --- a/chrome/renderer/chrome_ppb_pdf_impl.cc +++ b/chrome/renderer/chrome_ppb_pdf_impl.cc @@ -29,15 +29,12 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" #include "unicode/usearch.h" -#include "webkit/plugins/ppapi/host_globals.h" #include "webkit/plugins/ppapi/plugin_delegate.h" #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/ppb_image_data_impl.h" #include "webkit/plugins/ppapi/resource_tracker.h" -using ppapi::PpapiGlobals; -using webkit::ppapi::HostGlobals; using WebKit::WebView; using content::RenderThread; @@ -126,7 +123,7 @@ static const ResourceImageInfo kResourceImageMap[] = { PP_Var GetLocalizedString(PP_Instance instance_id, PP_ResourceString string_id) { webkit::ppapi::PluginInstance* instance = - HostGlobals::Get()->host_resource_tracker()->GetInstance(instance_id); + webkit::ppapi::ResourceTracker::Get()->GetInstance(instance_id); if (!instance) return PP_MakeUndefined(); @@ -162,7 +159,7 @@ PP_Resource GetResourceImage(PP_Instance instance_id, ResourceBundle::GetSharedInstance().GetBitmapNamed(res_id); // Validate the instance. - if (!HostGlobals::Get()->host_resource_tracker()->GetInstance(instance_id)) + if (!webkit::ppapi::ResourceTracker::Get()->GetInstance(instance_id)) return 0; scoped_refptr<webkit::ppapi::PPB_ImageData_Impl> image_data( new webkit::ppapi::PPB_ImageData_Impl(instance_id)); @@ -190,7 +187,7 @@ PP_Resource GetFontFileWithFallback( PP_PrivateFontCharset charset) { #if defined(OS_LINUX) // Validate the instance before using it below. - if (!HostGlobals::Get()->host_resource_tracker()->GetInstance(instance_id)) + if (!webkit::ppapi::ResourceTracker::Get()->GetInstance(instance_id)) return 0; scoped_refptr<ppapi::StringVar> face_name(ppapi::StringVar::FromPPVar( @@ -222,7 +219,7 @@ bool GetFontTableForPrivateFontFile(PP_Resource font_file, uint32_t* output_length) { #if defined(OS_LINUX) ppapi::Resource* resource = - PpapiGlobals::Get()->GetResourceTracker()->GetResource(font_file); + ppapi::TrackerBase::Get()->GetResourceTracker()->GetResource(font_file); if (!resource) return false; @@ -285,7 +282,7 @@ void SearchString(PP_Instance instance, void DidStartLoading(PP_Instance instance_id) { webkit::ppapi::PluginInstance* instance = - HostGlobals::Get()->host_resource_tracker()->GetInstance(instance_id); + webkit::ppapi::ResourceTracker::Get()->GetInstance(instance_id); if (!instance) return; instance->delegate()->DidStartLoading(); @@ -293,7 +290,7 @@ void DidStartLoading(PP_Instance instance_id) { void DidStopLoading(PP_Instance instance_id) { webkit::ppapi::PluginInstance* instance = - HostGlobals::Get()->host_resource_tracker()->GetInstance(instance_id); + webkit::ppapi::ResourceTracker::Get()->GetInstance(instance_id); if (!instance) return; instance->delegate()->DidStopLoading(); @@ -301,7 +298,7 @@ void DidStopLoading(PP_Instance instance_id) { void SetContentRestriction(PP_Instance instance_id, int restrictions) { webkit::ppapi::PluginInstance* instance = - HostGlobals::Get()->host_resource_tracker()->GetInstance(instance_id); + webkit::ppapi::ResourceTracker::Get()->GetInstance(instance_id); if (!instance) return; instance->delegate()->SetContentRestriction(restrictions); @@ -320,7 +317,7 @@ void UserMetricsRecordAction(PP_Var action) { void HasUnsupportedFeature(PP_Instance instance_id) { webkit::ppapi::PluginInstance* instance = - HostGlobals::Get()->host_resource_tracker()->GetInstance(instance_id); + webkit::ppapi::ResourceTracker::Get()->GetInstance(instance_id); if (!instance) return; @@ -336,7 +333,7 @@ void HasUnsupportedFeature(PP_Instance instance_id) { void SaveAs(PP_Instance instance_id) { webkit::ppapi::PluginInstance* instance = - HostGlobals::Get()->host_resource_tracker()->GetInstance(instance_id); + webkit::ppapi::ResourceTracker::Get()->GetInstance(instance_id); if (!instance) return; instance->delegate()->SaveURLAs(instance->plugin_url()); diff --git a/content/ppapi_plugin/ppapi_thread.h b/content/ppapi_plugin/ppapi_thread.h index 430e168..cc58362 100644 --- a/content/ppapi_plugin/ppapi_thread.h +++ b/content/ppapi_plugin/ppapi_thread.h @@ -18,7 +18,6 @@ #include "ppapi/c/pp_module.h" #include "ppapi/c/trusted/ppp_broker.h" #include "ppapi/proxy/plugin_dispatcher.h" -#include "ppapi/proxy/plugin_globals.h" class FilePath; class PpapiWebKitThread; @@ -67,9 +66,6 @@ class PpapiThread : public ChildThread, base::ScopedNativeLibrary library_; - // Global state tracking for the proxy. - ppapi::proxy::PluginGlobals plugin_globals_; - ppapi::proxy::Dispatcher::GetInterfaceFunc get_plugin_interface_; // Callback to call when a new instance connects to the broker. diff --git a/ppapi/ppapi_proxy.gypi b/ppapi/ppapi_proxy.gypi index 257d336..8630cf9 100644 --- a/ppapi/ppapi_proxy.gypi +++ b/ppapi/ppapi_proxy.gypi @@ -44,8 +44,6 @@ '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 bae1949..06e3e67 100644 --- a/ppapi/ppapi_shared.gypi +++ b/ppapi/ppapi_shared.gypi @@ -56,8 +56,6 @@ '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 72691c2..c7c51cf 100644 --- a/ppapi/ppapi_tests.gypi +++ b/ppapi/ppapi_tests.gypi @@ -220,8 +220,6 @@ '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 96ac0c18..d7bf7c2 100644 --- a/ppapi/proxy/enter_proxy.h +++ b/ppapi/proxy/enter_proxy.h @@ -9,7 +9,6 @@ #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" @@ -33,8 +32,8 @@ class EnterPluginFromHostResource public: EnterPluginFromHostResource(const HostResource& host_resource) : thunk::EnterResourceNoLock<ResourceT>( - PluginGlobals::Get()->plugin_resource_tracker()-> - PluginResourceForHostResource(host_resource), + PluginResourceTracker::GetInstance()->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 deleted file mode 100644 index 888c3bd..0000000 --- a/ppapi/proxy/plugin_globals.cc +++ /dev/null @@ -1,31 +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_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 deleted file mode 100644 index 141b904..0000000 --- a/ppapi/proxy/plugin_globals.h +++ /dev/null @@ -1,50 +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_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/shared_impl/ppapi_globals.h" - -namespace ppapi { -namespace proxy { - -class 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 67e2d69..4abd8f7 100644 --- a/ppapi/proxy/plugin_resource_tracker.cc +++ b/ppapi/proxy/plugin_resource_tracker.cc @@ -7,7 +7,6 @@ #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" @@ -20,13 +19,17 @@ namespace proxy { namespace { +// When non-NULL, this object overrides the ResourceTrackerSingleton. +PluginResourceTracker* g_resource_tracker_override = NULL; + TrackerBase* GetTrackerBase() { - return PluginGlobals::Get()->plugin_resource_tracker(); + return PluginResourceTracker::GetInstance(); } } // namespace -PluginResourceTracker::PluginResourceTracker() { +PluginResourceTracker::PluginResourceTracker() + : var_tracker_test_override_(NULL) { #ifdef ENABLE_PEPPER_THREADING // Set the global proxy lock, since the plugin-side of the proxy needs to be // synchronized. @@ -41,8 +44,20 @@ 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 GetTrackerBase(); + return GetInstance(); } PP_Resource PluginResourceTracker::PluginResourceForHostResource( @@ -61,6 +76,14 @@ 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 cf87787..30fafb2 100644 --- a/ppapi/proxy/plugin_resource_tracker.h +++ b/ppapi/proxy/plugin_resource_tracker.h @@ -15,6 +15,7 @@ #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" @@ -33,9 +34,13 @@ class PluginDispatcher; class PPAPI_PROXY_EXPORT PluginResourceTracker : public TrackerBase, public ResourceTracker { public: - PluginResourceTracker(); - virtual ~PluginResourceTracker(); + // 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); + // 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 @@ -43,9 +48,20 @@ 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: @@ -54,6 +70,24 @@ 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 3d9975a..49e1fc3 100644 --- a/ppapi/proxy/plugin_var_serialization_rules.cc +++ b/ppapi/proxy/plugin_var_serialization_rules.cc @@ -6,17 +6,15 @@ #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_(PluginGlobals::Get()->plugin_var_tracker()) { + : var_tracker_(&PluginResourceTracker::GetInstance()->var_tracker()) { } PluginVarSerializationRules::~PluginVarSerializationRules() { diff --git a/ppapi/proxy/ppapi_proxy_test.cc b/ppapi/proxy/ppapi_proxy_test.cc index 484253b..1c7233c 100644 --- a/ppapi/proxy/ppapi_proxy_test.cc +++ b/ppapi/proxy/ppapi_proxy_test.cc @@ -151,7 +151,9 @@ Dispatcher* PluginProxyTestHarness::GetDispatcher() { void PluginProxyTestHarness::SetUpHarness() { // These must be first since the dispatcher set-up uses them. - resource_tracker().DidCreateInstance(pp_instance()); + resource_tracker_.DidCreateInstance(pp_instance()); + PluginResourceTracker::SetInstanceForTest(&resource_tracker_); + resource_tracker_.set_var_tracker_test_override(&var_tracker_); plugin_dispatcher_.reset(new PluginDispatcher( base::Process::Current().handle(), @@ -166,7 +168,9 @@ 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()); + 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); plugin_dispatcher_.reset(new PluginDispatcher( @@ -182,7 +186,8 @@ void PluginProxyTestHarness::TearDownHarness() { plugin_dispatcher_->DidDestroyInstance(pp_instance()); plugin_dispatcher_.reset(); - resource_tracker().DidDeleteInstance(pp_instance()); + resource_tracker_.DidDeleteInstance(pp_instance()); + PluginResourceTracker::SetInstanceForTest(NULL); } base::MessageLoopProxy* diff --git a/ppapi/proxy/ppapi_proxy_test.h b/ppapi/proxy/ppapi_proxy_test.h index cf71a5e..03ec57d 100644 --- a/ppapi/proxy/ppapi_proxy_test.h +++ b/ppapi/proxy/ppapi_proxy_test.h @@ -13,7 +13,6 @@ #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" @@ -79,12 +78,8 @@ class PluginProxyTestHarness : public ProxyTestHarnessBase { virtual ~PluginProxyTestHarness(); PluginDispatcher* plugin_dispatcher() { return plugin_dispatcher_.get(); } - PluginResourceTracker& resource_tracker() { - return *plugin_globals_.plugin_resource_tracker(); - } - PluginVarTracker& var_tracker() { - return *plugin_globals_.plugin_var_tracker(); - } + PluginResourceTracker& resource_tracker() { return resource_tracker_; } + PluginVarTracker& var_tracker() { return var_tracker_; } // ProxyTestHarnessBase implementation. virtual Dispatcher* GetDispatcher(); @@ -128,8 +123,8 @@ class PluginProxyTestHarness : public ProxyTestHarnessBase { }; private: - PluginGlobals plugin_globals_; - + PluginResourceTracker resource_tracker_; + PluginVarTracker var_tracker_; 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 f1aedf7..453d7b0 100644 --- a/ppapi/proxy/ppb_audio_proxy.cc +++ b/ppapi/proxy/ppb_audio_proxy.cc @@ -16,7 +16,6 @@ #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" @@ -65,11 +64,11 @@ Audio::Audio(const HostResource& audio_id, : Resource(audio_id), config_(config_id) { SetCallback(callback, user_data); - PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(config_); + PluginResourceTracker::GetInstance()->AddRefResource(config_); } Audio::~Audio() { - PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(config_); + PluginResourceTracker::GetInstance()->ReleaseResource(config_); } PPB_Audio_API* Audio::AsPPB_Audio_API() { @@ -78,7 +77,7 @@ PPB_Audio_API* Audio::AsPPB_Audio_API() { PP_Resource Audio::GetCurrentConfig() { // AddRef for the caller. - PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(config_); + PluginResourceTracker::GetInstance()->AddRefResource(config_); return config_; } diff --git a/ppapi/proxy/ppb_core_proxy.cc b/ppapi/proxy/ppb_core_proxy.cc index c01eb45..9173df6 100644 --- a/ppapi/proxy/ppb_core_proxy.cc +++ b/ppapi/proxy/ppb_core_proxy.cc @@ -18,7 +18,6 @@ #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" @@ -35,12 +34,12 @@ base::MessageLoopProxy* GetMainThreadMessageLoop() { void AddRefResource(PP_Resource resource) { ppapi::ProxyAutoLock lock; - PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(resource); + PluginResourceTracker::GetInstance()->AddRefResource(resource); } void ReleaseResource(PP_Resource resource) { ppapi::ProxyAutoLock lock; - PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(resource); + PluginResourceTracker::GetInstance()->ReleaseResource(resource); } double GetTime() { diff --git a/ppapi/proxy/ppb_cursor_control_proxy.cc b/ppapi/proxy/ppb_cursor_control_proxy.cc index 960c010..a0b0ee8 100644 --- a/ppapi/proxy/ppb_cursor_control_proxy.cc +++ b/ppapi/proxy/ppb_cursor_control_proxy.cc @@ -9,7 +9,6 @@ #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" @@ -38,8 +37,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 = - PpapiGlobals::Get()->GetResourceTracker()->GetResource(custom_image_id); + 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(); diff --git a/ppapi/proxy/ppb_file_chooser_proxy.cc b/ppapi/proxy/ppb_file_chooser_proxy.cc index 1e55af6..1c7907c 100644 --- a/ppapi/proxy/ppb_file_chooser_proxy.cc +++ b/ppapi/proxy/ppb_file_chooser_proxy.cc @@ -17,8 +17,6 @@ #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" @@ -89,7 +87,7 @@ FileChooser::~FileChooser() { // Any existing files we haven't transferred ownership to the plugin need // to be freed. - ResourceTracker* tracker = PpapiGlobals::Get()->GetResourceTracker(); + PluginResourceTracker* tracker = PluginResourceTracker::GetInstance(); 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 c9824a4..49a1131 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 = - PpapiGlobals::Get()->GetResourceTracker()->GetResource(new_file_ref); + PluginResourceTracker::GetInstance()->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 = - PpapiGlobals::Get()->GetResourceTracker()->GetResource(file_system); + PluginResourceTracker::GetInstance()->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 de5a40c..fa636aa 100644 --- a/ppapi/proxy/ppb_flash_file_proxy.cc +++ b/ppapi/proxy/ppb_flash_file_proxy.cc @@ -21,10 +21,9 @@ #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 { @@ -632,7 +631,7 @@ int32_t OpenFileRefFile(PP_Resource file_ref_id, int32_t mode, PP_FileHandle* file) { Resource* file_ref = - PpapiGlobals::Get()->GetResourceTracker()->GetResource(file_ref_id); + PluginResourceTracker::GetInstance()->GetResource(file_ref_id); if (!file_ref) return PP_ERROR_BADRESOURCE; @@ -652,7 +651,7 @@ int32_t OpenFileRefFile(PP_Resource file_ref_id, int32_t QueryFileRefFile(PP_Resource file_ref_id, PP_FileInfo* info) { Resource* file_ref = - PpapiGlobals::Get()->GetResourceTracker()->GetResource(file_ref_id); + PluginResourceTracker::GetInstance()->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 b1d0d22..1faae86 100644 --- a/ppapi/proxy/ppb_flash_proxy.cc +++ b/ppapi/proxy/ppb_flash_proxy.cc @@ -14,12 +14,11 @@ #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" @@ -49,8 +48,8 @@ PP_Bool DrawGlyphs(PP_Instance instance, uint32_t glyph_count, const uint16_t glyph_indices[], const PP_Point glyph_advances[]) { - Resource* image_data = - PpapiGlobals::Get()->GetResourceTracker()->GetResource(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 diff --git a/ppapi/proxy/ppb_graphics_2d_proxy.cc b/ppapi/proxy/ppb_graphics_2d_proxy.cc index 7bed679..dcf8d26 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 = - PpapiGlobals::Get()->GetResourceTracker()->GetResource(image_data); + Resource* image_object = PluginResourceTracker::GetInstance()-> + 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 = - PpapiGlobals::Get()->GetResourceTracker()->GetResource(image_data); + Resource* image_object = PluginResourceTracker::GetInstance()-> + 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 7604eed..1a99b47 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,8 +123,7 @@ PPB_Instance_FunctionAPI* PPB_Instance_Proxy::AsPPB_Instance_FunctionAPI() { PP_Bool PPB_Instance_Proxy::BindGraphics(PP_Instance instance, PP_Resource device) { - Resource* object = - PpapiGlobals::Get()->GetResourceTracker()->GetResource(device); + Resource* object = PluginResourceTracker::GetInstance()->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 470d3da..836e1cf 100644 --- a/ppapi/proxy/ppb_testing_proxy.cc +++ b/ppapi/proxy/ppb_testing_proxy.cc @@ -7,10 +7,9 @@ #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 { @@ -20,12 +19,12 @@ namespace { PP_Bool ReadImageData(PP_Resource graphics_2d, PP_Resource image, const PP_Point* top_left) { - Resource* image_object = - PpapiGlobals::Get()->GetResourceTracker()->GetResource(image); + Resource* image_object = PluginResourceTracker::GetInstance()-> + GetResource(image); if (!image_object) return PP_FALSE; Resource* graphics_2d_object = - PpapiGlobals::Get()->GetResourceTracker()->GetResource(graphics_2d); + PluginResourceTracker::GetInstance()->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 2ad3025..70c01e8 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_) - PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(response_info_); + PluginResourceTracker::GetInstance()->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. - PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(response_info_); + PluginResourceTracker::GetInstance()->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 892fba1..6475580 100644 --- a/ppapi/proxy/ppb_var_deprecated_proxy.cc +++ b/ppapi/proxy/ppb_var_deprecated_proxy.cc @@ -15,7 +15,6 @@ #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" @@ -42,9 +41,8 @@ PluginDispatcher* CheckExceptionAndGetDispatcher(const PP_Var& object, if (object.type == PP_VARTYPE_OBJECT) { // Get the dispatcher for the object. - PluginDispatcher* dispatcher = - PluginGlobals::Get()->plugin_var_tracker()-> - DispatcherForPluginObject(object); + PluginDispatcher* dispatcher = PluginResourceTracker::GetInstance()-> + var_tracker().DispatcherForPluginObject(object); if (dispatcher) return dispatcher; } @@ -61,11 +59,11 @@ PluginDispatcher* CheckExceptionAndGetDispatcher(const PP_Var& object, // PPB_Var_Deprecated plugin --------------------------------------------------- void AddRefVar(PP_Var var) { - PpapiGlobals::Get()->GetVarTracker()->AddRefVar(var); + PluginResourceTracker::GetInstance()->var_tracker().AddRefVar(var); } void ReleaseVar(PP_Var var) { - PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(var); + PluginResourceTracker::GetInstance()->var_tracker().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 4301234..0c7cf5b 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/shared_impl/ppapi_globals.h" +#include "ppapi/proxy/plugin_resource_tracker.h" +#include "ppapi/proxy/plugin_var_tracker.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; - PpapiGlobals::Get()->GetVarTracker()->AddRefVar(var); + PluginResourceTracker::GetInstance()->var_tracker().AddRefVar(var); } void ReleaseVar(PP_Var var) { ppapi::ProxyAutoLock lock; - PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(var); + PluginResourceTracker::GetInstance()->var_tracker().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 c771bf5..9f40c1f 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); - if (enter.failed() || !ppp_video_capture_impl_) + PluginResourceTracker* tracker = PluginResourceTracker::GetInstance(); + PP_Resource resource = tracker->PluginResourceForHostResource(host_resource); + if (!resource || !ppp_video_capture_impl_ || enter.failed()) 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,12 +386,10 @@ void PPP_VideoCapture_Proxy::OnMsgOnDeviceInfo( buffers[i].handle, buffers[i].size); } - - VideoCapture* capture = static_cast<VideoCapture*>(enter.object()); - capture->SetBufferCount(buffers.size()); + static_cast<VideoCapture*>(enter.object())->SetBufferCount(buffers.size()); ppp_video_capture_impl_->OnDeviceInfo( host_resource.instance(), - capture->pp_resource(), + resource, &info, buffers.size(), resources.get()); @@ -402,38 +400,40 @@ void PPP_VideoCapture_Proxy::OnMsgOnDeviceInfo( void PPP_VideoCapture_Proxy::OnMsgOnStatus(const HostResource& host_resource, uint32_t status) { EnterPluginFromHostResource<PPB_VideoCapture_API> enter(host_resource); - if (enter.failed() || !ppp_video_capture_impl_) + PluginResourceTracker* tracker = PluginResourceTracker::GetInstance(); + PP_Resource resource = tracker->PluginResourceForHostResource(host_resource); + if (!resource || !ppp_video_capture_impl_ || enter.failed()) return; - VideoCapture* capture = static_cast<VideoCapture*>(enter.object()); - if (!capture->OnStatus(status)) + if (!static_cast<VideoCapture*>(enter.object())->OnStatus(status)) return; ppp_video_capture_impl_->OnStatus( - host_resource.instance(), capture->pp_resource(), status); + host_resource.instance(), resource, status); } void PPP_VideoCapture_Proxy::OnMsgOnError(const HostResource& host_resource, uint32_t error_code) { EnterPluginFromHostResource<PPB_VideoCapture_API> enter(host_resource); - if (enter.failed() || !ppp_video_capture_impl_) + PluginResourceTracker* tracker = PluginResourceTracker::GetInstance(); + PP_Resource resource = tracker->PluginResourceForHostResource(host_resource); + if (!resource || !ppp_video_capture_impl_ || enter.failed()) return; - - VideoCapture* capture = static_cast<VideoCapture*>(enter.object()); - capture->set_status(PP_VIDEO_CAPTURE_STATUS_STOPPED); + static_cast<VideoCapture*>(enter.object())->set_status( + PP_VIDEO_CAPTURE_STATUS_STOPPED); ppp_video_capture_impl_->OnError( - host_resource.instance(), capture->pp_resource(), error_code); + host_resource.instance(), resource, error_code); } void PPP_VideoCapture_Proxy::OnMsgOnBufferReady( const HostResource& host_resource, uint32_t buffer) { EnterPluginFromHostResource<PPB_VideoCapture_API> enter(host_resource); - if (enter.failed() || !ppp_video_capture_impl_) + PluginResourceTracker* tracker = PluginResourceTracker::GetInstance(); + PP_Resource resource = tracker->PluginResourceForHostResource(host_resource); + if (!resource || !ppp_video_capture_impl_ || enter.failed()) return; - - VideoCapture* capture = static_cast<VideoCapture*>(enter.object()); - capture->SetBufferInUse(buffer); + static_cast<VideoCapture*>(enter.object())->SetBufferInUse(buffer); ppp_video_capture_impl_->OnBufferReady( - host_resource.instance(), capture->pp_resource(), buffer); + host_resource.instance(), 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 ea57ec1..a192154 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 = - *PluginGlobals::Get()->plugin_var_tracker(); + PluginResourceTracker::GetInstance()->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 9463f28..c3e7395 100644 --- a/ppapi/proxy/ppp_instance_proxy.cc +++ b/ppapi/proxy/ppp_instance_proxy.cc @@ -15,7 +15,6 @@ #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 { @@ -176,7 +175,7 @@ void PPP_Instance_Proxy::OnMsgDidCreate( PluginDispatcher* plugin_dispatcher = static_cast<PluginDispatcher*>(dispatcher()); plugin_dispatcher->DidCreateInstance(instance); - PpapiGlobals::Get()->GetResourceTracker()->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. @@ -197,7 +196,7 @@ void PPP_Instance_Proxy::OnMsgDidCreate( void PPP_Instance_Proxy::OnMsgDidDestroy(PP_Instance instance) { combined_interface_->DidDestroy(instance); - PpapiGlobals::Get()->GetResourceTracker()->DidDeleteInstance(instance); + ppapi::TrackerBase::Get()->GetResourceTracker()->DidDeleteInstance(instance); static_cast<PluginDispatcher*>(dispatcher())->DidDestroyInstance(instance); } @@ -236,7 +235,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. - PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(plugin_loader); + PluginResourceTracker::GetInstance()->ReleaseResource(plugin_loader); } } // namespace proxy diff --git a/ppapi/proxy/ppp_messaging_proxy.cc b/ppapi/proxy/ppp_messaging_proxy.cc index 60cd8c4..390794a 100644 --- a/ppapi/proxy/ppp_messaging_proxy.cc +++ b/ppapi/proxy/ppp_messaging_proxy.cc @@ -12,8 +12,6 @@ #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 { @@ -84,7 +82,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. - PpapiGlobals::Get()->GetVarTracker()->AddRefVar(received_var); + PluginResourceTracker::GetInstance()->var_tracker().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 3852806..c115278 100644 --- a/ppapi/proxy/ppp_video_decoder_proxy.cc +++ b/ppapi/proxy/ppp_video_decoder_proxy.cc @@ -5,7 +5,6 @@ #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" @@ -132,7 +131,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 = PluginGlobals::Get()->plugin_resource_tracker()-> + PP_Resource plugin_decoder = PluginResourceTracker::GetInstance()-> PluginResourceForHostResource(decoder); ppp_video_decoder_impl_->ProvidePictureBuffers( decoder.instance(), plugin_decoder, req_num_of_bufs, &dimensions); @@ -140,7 +139,7 @@ void PPP_VideoDecoder_Proxy::OnMsgProvidePictureBuffers( void PPP_VideoDecoder_Proxy::OnMsgDismissPictureBuffer( const HostResource& decoder, int32_t picture_id) { - PP_Resource plugin_decoder = PluginGlobals::Get()->plugin_resource_tracker()-> + PP_Resource plugin_decoder = PluginResourceTracker::GetInstance()-> PluginResourceForHostResource(decoder); ppp_video_decoder_impl_->DismissPictureBuffer( decoder.instance(), plugin_decoder, picture_id); @@ -148,7 +147,7 @@ void PPP_VideoDecoder_Proxy::OnMsgDismissPictureBuffer( void PPP_VideoDecoder_Proxy::OnMsgPictureReady( const HostResource& decoder, const PP_Picture_Dev& picture) { - PP_Resource plugin_decoder = PluginGlobals::Get()->plugin_resource_tracker()-> + PP_Resource plugin_decoder = PluginResourceTracker::GetInstance()-> PluginResourceForHostResource(decoder); ppp_video_decoder_impl_->PictureReady( decoder.instance(), plugin_decoder, &picture); @@ -156,7 +155,7 @@ void PPP_VideoDecoder_Proxy::OnMsgPictureReady( void PPP_VideoDecoder_Proxy::OnMsgNotifyEndOfStream( const HostResource& decoder) { - PP_Resource plugin_decoder = PluginGlobals::Get()->plugin_resource_tracker()-> + PP_Resource plugin_decoder = PluginResourceTracker::GetInstance()-> PluginResourceForHostResource(decoder); ppp_video_decoder_impl_->EndOfStream(decoder.instance(), plugin_decoder); @@ -164,7 +163,7 @@ void PPP_VideoDecoder_Proxy::OnMsgNotifyEndOfStream( void PPP_VideoDecoder_Proxy::OnMsgNotifyError( const HostResource& decoder, PP_VideoDecodeError_Dev error) { - PP_Resource plugin_decoder = PluginGlobals::Get()->plugin_resource_tracker()-> + PP_Resource plugin_decoder = PluginResourceTracker::GetInstance()-> 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 deleted file mode 100644 index 9b5e9a8..0000000 --- a/ppapi/shared_impl/ppapi_globals.cc +++ /dev/null @@ -1,23 +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/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 deleted file mode 100644 index 60a50d23..0000000 --- a/ppapi/shared_impl/ppapi_globals.h +++ /dev/null @@ -1,35 +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_PPAPI_GLOBALS_H_ -#define PPAPI_SHARED_IMPL_PPAPI_GLOBALS_H_ - -#include "base/basictypes.h" - -namespace ppapi { - -class ResourceTracker; -class VarTracker; - -// Abstract base class -class 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 4e1f2a8..11ac86a 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/ppapi_globals.h" +#include "ppapi/shared_impl/tracker_base.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_ = PpapiGlobals::Get()->GetResourceTracker()->AddResource(this); + 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_ = PpapiGlobals::Get()->GetResourceTracker()->AddResource(this); + pp_resource_ = TrackerBase::Get()->GetResourceTracker()->AddResource(this); } Resource::~Resource() { - PpapiGlobals::Get()->GetResourceTracker()->RemoveResource(this); + TrackerBase::Get()->GetResourceTracker()->RemoveResource(this); } PP_Resource Resource::GetReference() { - PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(pp_resource()); + TrackerBase::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 2e22d6a..371f6e77 100644 --- a/ppapi/shared_impl/resource_tracker_unittest.cc +++ b/ppapi/shared_impl/resource_tracker_unittest.cc @@ -7,7 +7,6 @@ #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 { @@ -69,14 +68,20 @@ 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 *globals_.GetResourceTracker(); } + ResourceTracker& resource_tracker() { return resource_tracker_; } private: - TestGlobals globals_; + ResourceTracker resource_tracker_; }; // 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 8399208..d5a9748 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_) - PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(id_); + TrackerBase::Get()->GetResourceTracker()->AddRefResource(id_); } void ScopedPPResource::CallRelease() { if (id_) - PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(id_); + TrackerBase::Get()->GetResourceTracker()->ReleaseResource(id_); } } // namespace ppapi diff --git a/ppapi/shared_impl/test_globals.cc b/ppapi/shared_impl/test_globals.cc deleted file mode 100644 index 17ac224..0000000 --- a/ppapi/shared_impl/test_globals.cc +++ /dev/null @@ -1,23 +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/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 deleted file mode 100644 index c2062b7..0000000 --- a/ppapi/shared_impl/test_globals.h +++ /dev/null @@ -1,35 +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_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 940cef4..9ff19d4 100644 --- a/ppapi/shared_impl/tracker_base.h +++ b/ppapi/shared_impl/tracker_base.h @@ -44,6 +44,9 @@ 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 d295fd7..5bced6c 100644 --- a/ppapi/shared_impl/url_util_impl.cc +++ b/ppapi/shared_impl/url_util_impl.cc @@ -5,7 +5,6 @@ #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" @@ -107,7 +106,7 @@ PP_Var URLUtilImpl::ConvertComponentsAndReturnURL( return url; PP_Var result = Canonicalize(url, components); - PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(url); + TrackerBase::Get()->GetVarTracker()->ReleaseVar(url); return result; } diff --git a/ppapi/shared_impl/var.cc b/ppapi/shared_impl/var.cc index edf339a..165b8ff 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/ppapi_globals.h" +#include "ppapi/shared_impl/tracker_base.h" #include "ppapi/shared_impl/var_tracker.h" namespace ppapi { @@ -78,7 +78,7 @@ int32 Var::GetExistingVarID() const { } int32 Var::GetOrCreateVarID() { - VarTracker* tracker = PpapiGlobals::Get()->GetVarTracker(); + VarTracker* tracker = TrackerBase::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( - PpapiGlobals::Get()->GetVarTracker()->GetVar(var)); + TrackerBase::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 0b6d4e5..71921f92 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; - PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(graphics_context); + TrackerBase::Get()->GetResourceTracker()->AddRefResource(graphics_context); graphics_context_ = graphics_context; } void VideoDecoderImpl::Destroy() { graphics_context_ = 0; gles2_impl_ = NULL; - PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(graphics_context_); + TrackerBase::Get()->GetResourceTracker()->ReleaseResource(graphics_context_); } bool VideoDecoderImpl::SetFlushCallback(PP_CompletionCallback callback) { diff --git a/ppapi/thunk/enter.h b/ppapi/thunk/enter.h index faa556d..34fb706 100644 --- a/ppapi/thunk/enter.h +++ b/ppapi/thunk/enter.h @@ -9,11 +9,10 @@ #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/resource_tracker.h" #include "ppapi/shared_impl/tracker_base.h" +#include "ppapi/shared_impl/resource_tracker.h" #include "ppapi/thunk/ppapi_thunk_export.h" #include "ppapi/thunk/ppb_instance_api.h" #include "ppapi/thunk/resource_creation_api.h" @@ -117,7 +116,7 @@ class EnterFunctionGivenResource : public EnterFunction<FunctionsT> { private: static PP_Instance GetInstanceForResource(PP_Resource resource) { Resource* object = - PpapiGlobals::Get()->GetResourceTracker()->GetResource(resource); + TrackerBase::Get()->GetResourceTracker()->GetResource(resource); return object ? object->pp_instance() : 0; } }; @@ -129,8 +128,7 @@ class EnterResource : subtle::LockOnEntry<lock_on_entry> { public: EnterResource(PP_Resource resource, bool report_error) : object_(NULL) { - resource_ = - PpapiGlobals::Get()->GetResourceTracker()->GetResource(resource); + resource_ = TrackerBase::Get()->GetResourceTracker()->GetResource(resource); if (resource_) object_ = resource_->GetAs<ResourceT>(); // TODO(brettw) check error and if report_error is set, do something. diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi index 6f9b624..6ccde32 100644 --- a/webkit/glue/webkit_glue.gypi +++ b/webkit/glue/webkit_glue.gypi @@ -204,8 +204,6 @@ '../plugins/ppapi/file_type_conversions.cc', '../plugins/ppapi/file_type_conversions.h', '../plugins/ppapi/fullscreen_container.h', - '../plugins/ppapi/host_globals.cc', - '../plugins/ppapi/host_globals.h', '../plugins/ppapi/message_channel.cc', '../plugins/ppapi/message_channel.h', '../plugins/ppapi/npapi_glue.cc', diff --git a/webkit/plugins/ppapi/callbacks_unittest.cc b/webkit/plugins/ppapi/callbacks_unittest.cc index b11c725..30e534b 100644 --- a/webkit/plugins/ppapi/callbacks_unittest.cc +++ b/webkit/plugins/ppapi/callbacks_unittest.cc @@ -9,7 +9,6 @@ #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_errors.h" #include "webkit/plugins/ppapi/callbacks.h" -#include "webkit/plugins/ppapi/host_globals.h" #include "webkit/plugins/ppapi/mock_resource.h" #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" @@ -185,8 +184,7 @@ class CallbackResourceTest : public PpapiUnittest { // Test that callbacks get aborted on the last resource unref. TEST_F(CallbackResourceTest, AbortOnNoRef) { - ResourceTracker* resource_tracker = - HostGlobals::Get()->host_resource_tracker(); + ResourceTracker* resource_tracker = ResourceTracker::Get(); // Test several things: Unref-ing a resource (to zero refs) with callbacks // which (1) have been run, (2) have been aborted, (3) haven't been completed. @@ -225,8 +223,7 @@ TEST_F(CallbackResourceTest, AbortOnNoRef) { // Test that "resurrecting" a resource (getting a new ID for a |Resource|) // doesn't resurrect callbacks. TEST_F(CallbackResourceTest, Resurrection) { - ResourceTracker* resource_tracker = - HostGlobals::Get()->host_resource_tracker(); + ResourceTracker* resource_tracker = ResourceTracker::Get(); scoped_refptr<CallbackMockResource> resource( new CallbackMockResource(instance()->pp_instance())); diff --git a/webkit/plugins/ppapi/host_globals.cc b/webkit/plugins/ppapi/host_globals.cc deleted file mode 100644 index 3a3626f..0000000 --- a/webkit/plugins/ppapi/host_globals.cc +++ /dev/null @@ -1,31 +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 "webkit/plugins/ppapi/host_globals.h" - -namespace webkit { -namespace ppapi { - -HostGlobals* HostGlobals::host_globals_ = NULL; - -HostGlobals::HostGlobals() : ::ppapi::PpapiGlobals() { - DCHECK(!host_globals_); - host_globals_ = this; -} - -HostGlobals::~HostGlobals() { - DCHECK(host_globals_ == this); - host_globals_ = NULL; -} - -::ppapi::ResourceTracker* HostGlobals::GetResourceTracker() { - return &host_resource_tracker_; -} - -::ppapi::VarTracker* HostGlobals::GetVarTracker() { - return &host_var_tracker_; -} - -} // namespace ppapi -} // namespace webkit diff --git a/webkit/plugins/ppapi/host_globals.h b/webkit/plugins/ppapi/host_globals.h deleted file mode 100644 index 69b18d0..0000000 --- a/webkit/plugins/ppapi/host_globals.h +++ /dev/null @@ -1,44 +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 WEBKIT_PLUGINS_PPAPI_HOST_GLOBALS_H_ -#define WEBKIT_PLUGINS_PPAPI_HOST_GLOBALS_H_ - -#include "base/compiler_specific.h" -#include "ppapi/shared_impl/ppapi_globals.h" -#include "ppapi/shared_impl/var_tracker.h" -#include "webkit/plugins/ppapi/resource_tracker.h" - -namespace webkit { -namespace ppapi { - -class HostGlobals : public ::ppapi::PpapiGlobals { - public: - HostGlobals(); - virtual ~HostGlobals(); - - // Getter for the global singleton. Generally, you should use - // PpapiGlobals::Get() when possible. Use this only when you need some - // host-specific functionality. - inline static HostGlobals* Get() { return host_globals_; } - - // PpapiGlobals implementation. - virtual ::ppapi::ResourceTracker* GetResourceTracker() OVERRIDE; - virtual ::ppapi::VarTracker* GetVarTracker() OVERRIDE; - - ResourceTracker* host_resource_tracker() { return &host_resource_tracker_; } - - private: - static HostGlobals* host_globals_; - - ResourceTracker host_resource_tracker_; - ::ppapi::VarTracker host_var_tracker_; - - DISALLOW_COPY_AND_ASSIGN(HostGlobals); -}; - -} // namespace ppapi -} // namespace webkit - -#endif // WEBKIT_PLUGINS_PPAPI_HOST_GLOBALS_H_ diff --git a/webkit/plugins/ppapi/npapi_glue.cc b/webkit/plugins/ppapi/npapi_glue.cc index dceb25b..cdb49d5 100644 --- a/webkit/plugins/ppapi/npapi_glue.cc +++ b/webkit/plugins/ppapi/npapi_glue.cc @@ -7,7 +7,6 @@ #include "base/logging.h" #include "base/memory/ref_counted.h" #include "base/string_util.h" -#include "webkit/plugins/ppapi/host_globals.h" #include "webkit/plugins/ppapi/npobject_var.h" #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/plugin_object.h" @@ -18,7 +17,6 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" using ppapi::NPObjectVar; -using ppapi::PpapiGlobals; using ppapi::StringVar; using ppapi::Var; using WebKit::WebBindings; @@ -134,8 +132,8 @@ PP_Var NPIdentifierToPPVar(PP_Module module, NPIdentifier id) { PP_Var NPObjectToPPVar(PluginInstance* instance, NPObject* object) { DCHECK(object); scoped_refptr<NPObjectVar> object_var( - HostGlobals::Get()->host_resource_tracker()->NPObjectVarForNPObject( - instance->pp_instance(), object)); + ResourceTracker::Get()->NPObjectVarForNPObject(instance->pp_instance(), + object)); if (!object_var) { // No object for this module yet, make a new one. object_var = new NPObjectVar(instance->module()->pp_module(), instance->pp_instance(), object); @@ -161,7 +159,7 @@ PPResultAndExceptionToNPResult::~PPResultAndExceptionToNPResult() { // been lost. DCHECK(checked_exception_); - PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(exception_); + ResourceTracker::Get()->GetVarTracker()->ReleaseVar(exception_); } // Call this with the return value of the PPAPI function. It will convert @@ -186,7 +184,7 @@ bool PPResultAndExceptionToNPResult::SetResult(PP_Var result) { // No matter what happened, we need to release the reference to the // value passed in. On success, a reference to this value will be in // the np_result_. - PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(result); + ResourceTracker::Get()->GetVarTracker()->ReleaseVar(result); return success_; } @@ -238,7 +236,7 @@ PPVarArrayFromNPVariantArray::PPVarArrayFromNPVariantArray( } PPVarArrayFromNPVariantArray::~PPVarArrayFromNPVariantArray() { - ::ppapi::VarTracker* var_tracker = PpapiGlobals::Get()->GetVarTracker(); + ::ppapi::VarTracker* var_tracker = ResourceTracker::Get()->GetVarTracker(); for (size_t i = 0; i < size_; i++) var_tracker->ReleaseVar(array_[i]); } @@ -250,7 +248,7 @@ PPVarFromNPObject::PPVarFromNPObject(PluginInstance* instance, NPObject* object) } PPVarFromNPObject::~PPVarFromNPObject() { - PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(var_); + ResourceTracker::Get()->GetVarTracker()->ReleaseVar(var_); } // NPObjectAccessorWithIdentifier ---------------------------------------------- @@ -270,7 +268,7 @@ NPObjectAccessorWithIdentifier::NPObjectAccessorWithIdentifier( } NPObjectAccessorWithIdentifier::~NPObjectAccessorWithIdentifier() { - PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(identifier_); + ResourceTracker::Get()->GetVarTracker()->ReleaseVar(identifier_); } // TryCatch -------------------------------------------------------------------- diff --git a/webkit/plugins/ppapi/npobject_var.cc b/webkit/plugins/ppapi/npobject_var.cc index f87bea4..e430dd2 100644 --- a/webkit/plugins/ppapi/npobject_var.cc +++ b/webkit/plugins/ppapi/npobject_var.cc @@ -7,10 +7,8 @@ #include "base/logging.h" #include "ppapi/c/pp_var.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" -#include "webkit/plugins/ppapi/host_globals.h" #include "webkit/plugins/ppapi/resource_tracker.h" -using webkit::ppapi::HostGlobals; using WebKit::WebBindings; namespace ppapi { @@ -24,12 +22,12 @@ NPObjectVar::NPObjectVar(PP_Module module, pp_instance_(instance), np_object_(np_object) { WebBindings::retainObject(np_object_); - HostGlobals::Get()->host_resource_tracker()->AddNPObjectVar(this); + webkit::ppapi::ResourceTracker::Get()->AddNPObjectVar(this); } NPObjectVar::~NPObjectVar() { if (pp_instance()) - HostGlobals::Get()->host_resource_tracker()->RemoveNPObjectVar(this); + webkit::ppapi::ResourceTracker::Get()->RemoveNPObjectVar(this); WebBindings::releaseObject(np_object_); } @@ -62,7 +60,7 @@ scoped_refptr<NPObjectVar> NPObjectVar::FromPPVar(PP_Var var) { if (var.type != PP_VARTYPE_OBJECT) return scoped_refptr<NPObjectVar>(NULL); scoped_refptr<Var> var_object( - PpapiGlobals::Get()->GetVarTracker()->GetVar(var)); + webkit::ppapi::ResourceTracker::Get()->GetVarTracker()->GetVar(var)); if (!var_object) return scoped_refptr<NPObjectVar>(); return scoped_refptr<NPObjectVar>(var_object->AsNPObjectVar()); diff --git a/webkit/plugins/ppapi/plugin_module.cc b/webkit/plugins/ppapi/plugin_module.cc index ce0cee2..f4db023 100644 --- a/webkit/plugins/ppapi/plugin_module.cc +++ b/webkit/plugins/ppapi/plugin_module.cc @@ -90,7 +90,6 @@ #include "webkit/plugins/plugin_switches.h" #include "webkit/plugins/ppapi/callbacks.h" #include "webkit/plugins/ppapi/common.h" -#include "webkit/plugins/ppapi/host_globals.h" #include "webkit/plugins/ppapi/ppapi_interface_factory.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/ppb_directory_reader_impl.h" @@ -115,7 +114,6 @@ #include "webkit/plugins/ppapi/resource_tracker.h" #include "webkit/plugins/ppapi/webkit_forwarding_impl.h" -using ppapi::PpapiGlobals; using ppapi::TimeTicksToPPTimeTicks; using ppapi::TimeToPPTime; using ppapi::thunk::EnterResource; @@ -126,14 +124,6 @@ namespace ppapi { namespace { -// Global tracking info for PPAPI plugins. This is lazily created before the -// first plugin is allocated, and leaked on shutdown. -// -// Note that we don't want a Singleton here since destroying this object will -// try to free some stuff that requires WebKit, and Singletons are destroyed -// after WebKit. -webkit::ppapi::HostGlobals* host_globals = NULL; - // Maintains all currently loaded plugin libs for validating PP_Module // identifiers. typedef std::set<PluginModule*> PluginModuleSet; @@ -152,11 +142,11 @@ base::MessageLoopProxy* GetMainThreadMessageLoop() { // PPB_Core -------------------------------------------------------------------- void AddRefResource(PP_Resource resource) { - PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(resource); + ResourceTracker::Get()->AddRefResource(resource); } void ReleaseResource(PP_Resource resource) { - PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(resource); + ResourceTracker::Get()->ReleaseResource(resource); } PP_Time GetTime() { @@ -215,8 +205,7 @@ void QuitMessageLoop(PP_Instance instance) { } uint32_t GetLiveObjectsForInstance(PP_Instance instance_id) { - return HostGlobals::Get()->host_resource_tracker()->GetLiveObjectsForInstance( - instance_id); + return ResourceTracker::Get()->GetLiveObjectsForInstance(instance_id); } PP_Bool IsOutOfProcess() { @@ -382,12 +371,8 @@ PluginModule::PluginModule(const std::string& name, name_(name), path_(path), reserve_instance_id_(NULL) { - // Ensure the globals object is created. - if (!host_globals) - host_globals = new HostGlobals; - memset(&entry_points_, 0, sizeof(entry_points_)); - pp_module_ = HostGlobals::Get()->host_resource_tracker()->AddModule(this); + pp_module_ = ResourceTracker::Get()->AddModule(this); GetMainThreadMessageLoop(); // Initialize the main thread message loop. GetLivePluginSet()->insert(this); } @@ -413,7 +398,7 @@ PluginModule::~PluginModule() { base::UnloadNativeLibrary(library_); // Notifications that we've been deleted should be last. - HostGlobals::Get()->host_resource_tracker()->ModuleDeleted(pp_module_); + ResourceTracker::Get()->ModuleDeleted(pp_module_); if (!is_crashed_) { // When the plugin crashes, we immediately tell the lifetime delegate that // we're gone, so we don't want to tell it again. diff --git a/webkit/plugins/ppapi/plugin_object.cc b/webkit/plugins/ppapi/plugin_object.cc index fbbd349..7b58456 100644 --- a/webkit/plugins/ppapi/plugin_object.cc +++ b/webkit/plugins/ppapi/plugin_object.cc @@ -15,7 +15,6 @@ #include "ppapi/c/dev/ppp_class_deprecated.h" #include "ppapi/c/pp_resource.h" #include "ppapi/c/pp_var.h" -#include "ppapi/shared_impl/ppapi_globals.h" #include "ppapi/shared_impl/var.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" #include "webkit/plugins/ppapi/npapi_glue.h" @@ -24,7 +23,6 @@ #include "webkit/plugins/ppapi/resource_tracker.h" #include "webkit/plugins/ppapi/string.h" -using ppapi::PpapiGlobals; using ppapi::StringVar; using ppapi::Var; using WebKit::WebBindings; @@ -152,7 +150,7 @@ bool WrapperClass_SetProperty(NPObject* object, NPIdentifier property_name, accessor.object()->ppp_class()->SetProperty( accessor.object()->ppp_class_data(), accessor.identifier(), value_var, result_converter.exception()); - PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(value_var); + ResourceTracker::Get()->GetVarTracker()->ReleaseVar(value_var); return result_converter.CheckExceptionForNoResult(); } @@ -217,7 +215,7 @@ bool WrapperClass_Enumerate(NPObject* object, NPIdentifier** values, // Release the PP_Var that the plugin allocated. On success, they will all // be converted to NPVariants, and on failure, we want them to just go away. - ::ppapi::VarTracker* var_tracker = PpapiGlobals::Get()->GetVarTracker(); + ::ppapi::VarTracker* var_tracker = ResourceTracker::Get()->GetVarTracker(); for (uint32_t i = 0; i < property_count; ++i) var_tracker->ReleaseVar(properties[i]); free(properties); diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc index 6e3be13..5ec687d 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc @@ -62,7 +62,6 @@ #include "webkit/plugins/ppapi/common.h" #include "webkit/plugins/ppapi/event_conversion.h" #include "webkit/plugins/ppapi/fullscreen_container.h" -#include "webkit/plugins/ppapi/host_globals.h" #include "webkit/plugins/ppapi/message_channel.h" #include "webkit/plugins/ppapi/npapi_glue.h" #include "webkit/plugins/ppapi/plugin_delegate.h" @@ -103,7 +102,6 @@ using base::StringPrintf; using ppapi::InputEventImpl; -using ppapi::PpapiGlobals; using ppapi::StringVar; using ppapi::thunk::EnterResourceNoLock; using ppapi::thunk::PPB_Buffer_API; @@ -244,8 +242,7 @@ void RectToPPRect(const gfx::Rect& input, PP_Rect* output) { // unchanged. bool SecurityOriginForInstance(PP_Instance instance_id, WebKit::WebSecurityOrigin* security_origin) { - PluginInstance* instance = - HostGlobals::Get()->host_resource_tracker()->GetInstance(instance_id); + PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); if (!instance) return false; @@ -309,7 +306,7 @@ PluginInstance::PluginInstance( text_input_caret_bounds_(0, 0, 0, 0), text_input_caret_set_(false), lock_mouse_callback_(PP_BlockUntilComplete()) { - pp_instance_ = HostGlobals::Get()->host_resource_tracker()->AddInstance(this); + pp_instance_ = ResourceTracker::Get()->AddInstance(this); memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); DCHECK(delegate); @@ -338,7 +335,7 @@ PluginInstance::~PluginInstance() { delegate_->InstanceDeleted(this); module_->InstanceDeleted(this); - HostGlobals::Get()->host_resource_tracker()->InstanceDeleted(pp_instance_); + ResourceTracker::Get()->InstanceDeleted(pp_instance_); } // NOTE: Any of these methods that calls into the plugin needs to take into @@ -426,7 +423,7 @@ void PluginInstance::CommitBackingTexture() { void PluginInstance::InstanceCrashed() { // Force free all resources and vars. - HostGlobals::Get()->host_resource_tracker()->InstanceCrashed(pp_instance()); + ResourceTracker::Get()->InstanceCrashed(pp_instance()); // Free any associated graphics. SetFullscreen(false, false); @@ -873,7 +870,7 @@ string16 PluginInstance::GetSelectedText(bool html) { if (string) selection = UTF8ToUTF16(string->value()); // Release the ref the plugin transfered to us. - HostGlobals::Get()->GetVarTracker()->ReleaseVar(rv); + ResourceTracker::Get()->GetVarTracker()->ReleaseVar(rv); return selection; } @@ -892,7 +889,7 @@ string16 PluginInstance::GetLinkAtPosition(const gfx::Point& point) { if (string) link = UTF8ToUTF16(string->value()); // Release the ref the plugin transfered to us. - PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(rv); + ResourceTracker::Get()->GetVarTracker()->ReleaseVar(rv); return link; } diff --git a/webkit/plugins/ppapi/ppb_audio_impl.cc b/webkit/plugins/ppapi/ppb_audio_impl.cc index ea73f38..e0f26e5 100644 --- a/webkit/plugins/ppapi/ppb_audio_impl.cc +++ b/webkit/plugins/ppapi/ppb_audio_impl.cc @@ -17,7 +17,6 @@ #include "webkit/plugins/ppapi/common.h" #include "webkit/plugins/ppapi/resource_helper.h" -using ppapi::PpapiGlobals; using ppapi::thunk::EnterResourceNoLock; using ppapi::thunk::PPB_Audio_API; using ppapi::thunk::PPB_AudioConfig_API; @@ -95,7 +94,7 @@ bool PPB_Audio_Impl::Init(PP_Resource config, PP_Resource PPB_Audio_Impl::GetCurrentConfig() { // AddRef on behalf of caller, while keeping a ref for ourselves. - PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(config_); + ::ppapi::TrackerBase::Get()->GetResourceTracker()->AddRefResource(config_); return config_; } diff --git a/webkit/plugins/ppapi/ppb_directory_reader_impl.cc b/webkit/plugins/ppapi/ppb_directory_reader_impl.cc index 63279cd..da7112b 100644 --- a/webkit/plugins/ppapi/ppb_directory_reader_impl.cc +++ b/webkit/plugins/ppapi/ppb_directory_reader_impl.cc @@ -9,7 +9,6 @@ #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_errors.h" #include "ppapi/c/dev/ppb_directory_reader_dev.h" -#include "ppapi/shared_impl/ppapi_globals.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/ppb_file_ref_api.h" #include "webkit/plugins/ppapi/common.h" @@ -22,7 +21,6 @@ #include "webkit/plugins/ppapi/resource_helper.h" #include "webkit/plugins/ppapi/resource_tracker.h" -using ::ppapi::PpapiGlobals; using ::ppapi::thunk::EnterResourceNoLock; using ::ppapi::thunk::PPB_DirectoryReader_API; using ::ppapi::thunk::PPB_FileRef_API; @@ -130,10 +128,8 @@ bool PPB_DirectoryReader_Impl::FillUpEntry() { if (!entries_.empty()) { base::FileUtilProxy::Entry dir_entry = entries_.front(); entries_.pop(); - if (entry_->file_ref) { - PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource( - entry_->file_ref); - } + if (entry_->file_ref) + ResourceTracker::Get()->ReleaseResource(entry_->file_ref); PPB_FileRef_Impl* file_ref = PPB_FileRef_Impl::CreateInternal( directory_ref_->file_system()->pp_resource(), diff --git a/webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc b/webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc index fdffadf..73ad13e 100644 --- a/webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc +++ b/webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc @@ -18,7 +18,6 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/WebKitPlatformSupport.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" #include "webkit/plugins/ppapi/common.h" -#include "webkit/plugins/ppapi/host_globals.h" #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/resource_tracker.h" @@ -65,8 +64,7 @@ PP_Bool IsFormatAvailable(PP_Instance instance_id, PP_Flash_Clipboard_Type clipboard_type, PP_Flash_Clipboard_Format format) { // If you don't give us an instance, we don't give you anything. - PluginInstance* instance = - HostGlobals::Get()->host_resource_tracker()->GetInstance(instance_id); + PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); if (!instance) return PP_FALSE; @@ -84,8 +82,7 @@ PP_Bool IsFormatAvailable(PP_Instance instance_id, PP_Var ReadPlainText(PP_Instance instance_id, PP_Flash_Clipboard_Type clipboard_type) { - PluginInstance* instance = - HostGlobals::Get()->host_resource_tracker()->GetInstance(instance_id); + PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); if (!instance) return PP_MakeNull(); diff --git a/webkit/plugins/ppapi/ppb_flash_file_impl.cc b/webkit/plugins/ppapi/ppb_flash_file_impl.cc index 47b18f8..de8b939 100644 --- a/webkit/plugins/ppapi/ppb_flash_file_impl.cc +++ b/webkit/plugins/ppapi/ppb_flash_file_impl.cc @@ -16,7 +16,6 @@ #include "webkit/plugins/ppapi/common.h" #include "webkit/plugins/ppapi/file_path.h" #include "webkit/plugins/ppapi/file_type_conversions.h" -#include "webkit/plugins/ppapi/host_globals.h" #include "webkit/plugins/ppapi/plugin_delegate.h" #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" @@ -67,8 +66,7 @@ int32_t OpenModuleLocalFile(PP_Instance pp_instance, if (!path || !PepperFileOpenFlagsToPlatformFileFlags(mode, &flags) || !file) return PP_ERROR_BADARGUMENT; - PluginInstance* instance = - HostGlobals::Get()->host_resource_tracker()->GetInstance(pp_instance); + PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance); if (!instance) return PP_ERROR_FAILED; @@ -87,8 +85,7 @@ int32_t RenameModuleLocalFile(PP_Instance pp_instance, if (!from_path || !to_path) return PP_ERROR_BADARGUMENT; - PluginInstance* instance = - HostGlobals::Get()->host_resource_tracker()->GetInstance(pp_instance); + PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance); if (!instance) return PP_ERROR_FAILED; @@ -104,8 +101,7 @@ int32_t DeleteModuleLocalFileOrDir(PP_Instance pp_instance, if (!path) return PP_ERROR_BADARGUMENT; - PluginInstance* instance = - HostGlobals::Get()->host_resource_tracker()->GetInstance(pp_instance); + PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance); if (!instance) return PP_ERROR_FAILED; @@ -119,8 +115,7 @@ int32_t CreateModuleLocalDir(PP_Instance pp_instance, const char* path) { if (!path) return PP_ERROR_BADARGUMENT; - PluginInstance* instance = - HostGlobals::Get()->host_resource_tracker()->GetInstance(pp_instance); + PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance); if (!instance) return PP_ERROR_FAILED; @@ -135,8 +130,7 @@ int32_t QueryModuleLocalFile(PP_Instance pp_instance, if (!path || !info) return PP_ERROR_BADARGUMENT; - PluginInstance* instance = - HostGlobals::Get()->host_resource_tracker()->GetInstance(pp_instance); + PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance); if (!instance) return PP_ERROR_FAILED; @@ -163,8 +157,7 @@ int32_t GetModuleLocalDirContents(PP_Instance pp_instance, PP_DirContents_Dev** contents) { if (!path || !contents) return PP_ERROR_BADARGUMENT; - PluginInstance* instance = - HostGlobals::Get()->host_resource_tracker()->GetInstance(pp_instance); + PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance); if (!instance) return PP_ERROR_FAILED; diff --git a/webkit/plugins/ppapi/ppb_flash_impl.cc b/webkit/plugins/ppapi/ppb_flash_impl.cc index 78d5677..58354db 100644 --- a/webkit/plugins/ppapi/ppb_flash_impl.cc +++ b/webkit/plugins/ppapi/ppb_flash_impl.cc @@ -14,7 +14,6 @@ #include "ppapi/shared_impl/var.h" #include "ppapi/thunk/enter.h" #include "webkit/plugins/ppapi/common.h" -#include "webkit/plugins/ppapi/host_globals.h" #include "webkit/plugins/ppapi/plugin_delegate.h" #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" @@ -33,16 +32,14 @@ namespace ppapi { namespace { void SetInstanceAlwaysOnTop(PP_Instance pp_instance, PP_Bool on_top) { - PluginInstance* instance = - HostGlobals::Get()->host_resource_tracker()->GetInstance(pp_instance); + PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance); if (!instance) return; instance->set_always_on_top(PPBoolToBool(on_top)); } PP_Var GetProxyForURL(PP_Instance pp_instance, const char* url) { - PluginInstance* instance = - HostGlobals::Get()->host_resource_tracker()->GetInstance(pp_instance); + PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance); if (!instance) return PP_MakeUndefined(); @@ -86,8 +83,7 @@ void QuitMessageLoop(PP_Instance instance) { } double GetLocalTimeZoneOffset(PP_Instance pp_instance, PP_Time t) { - PluginInstance* instance = - HostGlobals::Get()->host_resource_tracker()->GetInstance(pp_instance); + PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance); if (!instance) return 0.0; @@ -105,8 +101,7 @@ double GetLocalTimeZoneOffset(PP_Instance pp_instance, PP_Time t) { } PP_Var GetCommandLineArgs(PP_Module pp_module) { - PluginModule* module = - HostGlobals::Get()->host_resource_tracker()->GetModule(pp_module); + PluginModule* module = ResourceTracker::Get()->GetModule(pp_module); if (!module) return PP_MakeUndefined(); diff --git a/webkit/plugins/ppapi/ppb_proxy_impl.cc b/webkit/plugins/ppapi/ppb_proxy_impl.cc index 884ad7d..ece3410 100644 --- a/webkit/plugins/ppapi/ppb_proxy_impl.cc +++ b/webkit/plugins/ppapi/ppb_proxy_impl.cc @@ -7,13 +7,11 @@ #include "ppapi/c/private/ppb_proxy_private.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/ppb_image_data_api.h" -#include "webkit/plugins/ppapi/host_globals.h" #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/ppb_url_loader_impl.h" #include "webkit/plugins/ppapi/resource_tracker.h" -using ppapi::PpapiGlobals; using ppapi::thunk::EnterResource; using ppapi::thunk::PPB_URLLoader_API; @@ -23,15 +21,13 @@ namespace ppapi { namespace { void PluginCrashed(PP_Module module) { - PluginModule* plugin_module = - HostGlobals::Get()->host_resource_tracker()->GetModule(module); + PluginModule* plugin_module = ResourceTracker::Get()->GetModule(module); if (plugin_module) plugin_module->PluginCrashed(); } PP_Instance GetInstanceForResource(PP_Resource resource) { - ::ppapi::Resource* obj = - PpapiGlobals::Get()->GetResourceTracker()->GetResource(resource); + ::ppapi::Resource* obj = ResourceTracker::Get()->GetResource(resource); if (!obj) return 0; return obj->pp_instance(); @@ -39,8 +35,7 @@ PP_Instance GetInstanceForResource(PP_Resource resource) { void SetReserveInstanceIDCallback(PP_Module module, PP_Bool (*reserve)(PP_Module, PP_Instance)) { - PluginModule* plugin_module = - HostGlobals::Get()->host_resource_tracker()->GetModule(module); + PluginModule* plugin_module = ResourceTracker::Get()->GetModule(module); if (plugin_module) plugin_module->SetReserveInstanceIDCallback(reserve); } @@ -53,22 +48,19 @@ int32_t GetURLLoaderBufferedBytes(PP_Resource url_loader) { } void AddRefModule(PP_Module module) { - PluginModule* plugin_module = - HostGlobals::Get()->host_resource_tracker()->GetModule(module); + PluginModule* plugin_module = ResourceTracker::Get()->GetModule(module); if (plugin_module) plugin_module->AddRef(); } void ReleaseModule(PP_Module module) { - PluginModule* plugin_module = - HostGlobals::Get()->host_resource_tracker()->GetModule(module); + PluginModule* plugin_module = ResourceTracker::Get()->GetModule(module); if (plugin_module) plugin_module->Release(); } PP_Bool IsInModuleDestructor(PP_Module module) { - PluginModule* plugin_module = - HostGlobals::Get()->host_resource_tracker()->GetModule(module); + PluginModule* plugin_module = ResourceTracker::Get()->GetModule(module); if (plugin_module) return PP_FromBool(plugin_module->is_in_destructor()); return PP_FALSE; diff --git a/webkit/plugins/ppapi/ppb_var_impl.cc b/webkit/plugins/ppapi/ppb_var_impl.cc index 59df63d..384d449 100644 --- a/webkit/plugins/ppapi/ppb_var_impl.cc +++ b/webkit/plugins/ppapi/ppb_var_impl.cc @@ -11,7 +11,6 @@ #include "ppapi/c/pp_var.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" #include "webkit/plugins/ppapi/common.h" -#include "webkit/plugins/ppapi/host_globals.h" #include "webkit/plugins/ppapi/npapi_glue.h" #include "webkit/plugins/ppapi/npobject_var.h" #include "webkit/plugins/ppapi/plugin_module.h" @@ -21,7 +20,6 @@ #include "v8/include/v8.h" using ppapi::NPObjectVar; -using ppapi::PpapiGlobals; using ppapi::StringVar; using ppapi::Var; using WebKit::WebBindings; @@ -126,8 +124,7 @@ class ObjectAccessorTryCatch : public TryCatch { NPObjectVar* object() { return object_.get(); } PluginInstance* GetPluginInstance() { - return HostGlobals::Get()->host_resource_tracker()->GetInstance( - object()->pp_instance()); + return ResourceTracker::Get()->GetInstance(object()->pp_instance()); } protected: @@ -173,11 +170,11 @@ class ObjectAccessorWithIdentifierTryCatch : public ObjectAccessorTryCatch { // PPB_Var methods ------------------------------------------------------------- void AddRefVar(PP_Var var) { - PpapiGlobals::Get()->GetVarTracker()->AddRefVar(var); + ResourceTracker::Get()->GetVarTracker()->AddRefVar(var); } void ReleaseVar(PP_Var var) { - PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(var); + ResourceTracker::Get()->GetVarTracker()->ReleaseVar(var); } PP_Var VarFromUtf8(PP_Module module, const char* data, uint32_t len) { @@ -407,11 +404,10 @@ bool IsInstanceOfDeprecated(PP_Var var, ppp_class, ppp_class_data); } -PP_Var CreateObjectDeprecated(PP_Instance pp_instance, +PP_Var CreateObjectDeprecated(PP_Instance instance_id, const PPP_Class_Deprecated* ppp_class, void* ppp_class_data) { - PluginInstance* instance = - HostGlobals::Get()->host_resource_tracker()->GetInstance(pp_instance); + PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); if (!instance) { DLOG(ERROR) << "Create object passed an invalid instance."; return PP_MakeNull(); @@ -419,11 +415,10 @@ PP_Var CreateObjectDeprecated(PP_Instance pp_instance, return PluginObject::Create(instance, ppp_class, ppp_class_data); } -PP_Var CreateObjectWithModuleDeprecated(PP_Module pp_module, +PP_Var CreateObjectWithModuleDeprecated(PP_Module module_id, const PPP_Class_Deprecated* ppp_class, void* ppp_class_data) { - PluginModule* module = - HostGlobals::Get()->host_resource_tracker()->GetModule(pp_module); + PluginModule* module = ResourceTracker::Get()->GetModule(module_id); if (!module) return PP_MakeNull(); return PluginObject::Create(module->GetSomeInstance(), diff --git a/webkit/plugins/ppapi/ppb_video_capture_impl.cc b/webkit/plugins/ppapi/ppb_video_capture_impl.cc index 466125c..de97914 100644 --- a/webkit/plugins/ppapi/ppb_video_capture_impl.cc +++ b/webkit/plugins/ppapi/ppb_video_capture_impl.cc @@ -12,7 +12,6 @@ #include "ppapi/c/dev/ppb_video_capture_dev.h" #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_errors.h" -#include "ppapi/shared_impl/ppapi_globals.h" #include "ppapi/thunk/enter.h" #include "webkit/plugins/ppapi/common.h" #include "webkit/plugins/ppapi/plugin_module.h" @@ -21,7 +20,6 @@ #include "webkit/plugins/ppapi/resource_helper.h" #include "webkit/plugins/ppapi/resource_tracker.h" -using ppapi::PpapiGlobals; using ppapi::thunk::EnterResourceNoLock; using ppapi::thunk::PPB_Buffer_API; using ppapi::thunk::PPB_VideoCapture_API; @@ -267,7 +265,7 @@ void PPB_VideoCapture_Impl::OnDeviceInfoReceived( info.buffer = static_cast<PPB_Buffer_Impl*>(enter.object()); info.data = info.buffer->Map(); if (!info.data) { - PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(resources[i]); + ResourceTracker::Get()->ReleaseResource(resources[i]); break; } buffers_.push_back(info); @@ -288,7 +286,7 @@ void PPB_VideoCapture_Impl::OnDeviceInfoReceived( void PPB_VideoCapture_Impl::ReleaseBuffers() { DCHECK(!is_dead_); - ::ppapi::ResourceTracker* tracker = PpapiGlobals::Get()->GetResourceTracker(); + ResourceTracker *tracker = ResourceTracker::Get(); for (size_t i = 0; i < buffers_.size(); ++i) { buffers_[i].buffer->Unmap(); tracker->ReleaseResource(buffers_[i].buffer->pp_resource()); diff --git a/webkit/plugins/ppapi/quota_file_io.cc b/webkit/plugins/ppapi/quota_file_io.cc index 37e58c0..73b20ca 100644 --- a/webkit/plugins/ppapi/quota_file_io.cc +++ b/webkit/plugins/ppapi/quota_file_io.cc @@ -12,7 +12,6 @@ #include "base/message_loop_proxy.h" #include "base/stl_util.h" #include "base/task.h" -#include "webkit/plugins/ppapi/host_globals.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/resource_helper.h" #include "webkit/plugins/ppapi/resource_tracker.h" @@ -271,8 +270,7 @@ bool QuotaFileIO::WillSetLength(int64_t length, } PluginDelegate* QuotaFileIO::GetPluginDelegate() const { - PluginInstance* instance = - HostGlobals::Get()->host_resource_tracker()->GetInstance(pp_instance_); + PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance_); if (instance) return instance->delegate(); return NULL; diff --git a/webkit/plugins/ppapi/resource_helper.cc b/webkit/plugins/ppapi/resource_helper.cc index cdea783..27f303d 100644 --- a/webkit/plugins/ppapi/resource_helper.cc +++ b/webkit/plugins/ppapi/resource_helper.cc @@ -6,7 +6,6 @@ #include "base/logging.h" #include "ppapi/shared_impl/resource.h" -#include "webkit/plugins/ppapi/host_globals.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" @@ -18,7 +17,7 @@ namespace ppapi { // static PluginInstance* ResourceHelper::GetPluginInstance( const ::ppapi::Resource* resource) { - ResourceTracker* tracker = HostGlobals::Get()->host_resource_tracker(); + ResourceTracker* tracker = ResourceTracker::Get(); return tracker->GetInstance(resource->pp_instance()); } diff --git a/webkit/plugins/ppapi/resource_tracker.cc b/webkit/plugins/ppapi/resource_tracker.cc index 0743723..6b0de7d 100644 --- a/webkit/plugins/ppapi/resource_tracker.cc +++ b/webkit/plugins/ppapi/resource_tracker.cc @@ -15,7 +15,6 @@ #include "ppapi/shared_impl/id_assignment.h" #include "ppapi/shared_impl/tracker_base.h" #include "webkit/plugins/ppapi/callbacks.h" -#include "webkit/plugins/ppapi/host_globals.h" #include "webkit/plugins/ppapi/npobject_var.h" #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" @@ -37,7 +36,7 @@ namespace ppapi { namespace { ::ppapi::TrackerBase* GetTrackerBase() { - return HostGlobals::Get()->host_resource_tracker(); + return ResourceTracker::Get(); } } // namespace @@ -62,6 +61,10 @@ struct ResourceTracker::InstanceData { function_proxies[::ppapi::proxy::INTERFACE_ID_COUNT]; }; +// static +ResourceTracker* ResourceTracker::global_tracker_ = NULL; +ResourceTracker* ResourceTracker::singleton_override_ = NULL; + ResourceTracker::ResourceTracker() { // Wire up the new shared resource tracker base to use our implementation. ::ppapi::TrackerBase::Init(&GetTrackerBase); @@ -70,6 +73,15 @@ ResourceTracker::ResourceTracker() { ResourceTracker::~ResourceTracker() { } +// static +ResourceTracker* ResourceTracker::Get() { + if (singleton_override_) + return singleton_override_; + if (!global_tracker_) + global_tracker_ = new ResourceTracker; + return global_tracker_; +} + void ResourceTracker::CleanupInstanceData(PP_Instance instance, bool delete_instance) { DLOG_IF(ERROR, !CheckIdType(instance, ::ppapi::PP_ID_TYPE_INSTANCE)) @@ -142,6 +154,14 @@ void ResourceTracker::CleanupInstanceData(PP_Instance instance, return proxy.get(); } +::ppapi::VarTracker* ResourceTracker::GetVarTracker() { + return &var_tracker_; +} + +::ppapi::ResourceTracker* ResourceTracker::GetResourceTracker() { + return this; +} + PP_Module ResourceTracker::GetModuleForInstance(PP_Instance instance) { PluginInstance* inst = GetInstance(instance); if (!inst) @@ -289,5 +309,17 @@ PluginModule* ResourceTracker::GetModule(PP_Module module) { return found->second; } +// static +void ResourceTracker::SetSingletonOverride(ResourceTracker* tracker) { + DCHECK(!singleton_override_); + singleton_override_ = tracker; +} + +// static +void ResourceTracker::ClearSingletonOverride() { + DCHECK(singleton_override_); + singleton_override_ = NULL; +} + } // namespace ppapi } // namespace webkit diff --git a/webkit/plugins/ppapi/resource_tracker.h b/webkit/plugins/ppapi/resource_tracker.h index 221a8f9..79de8be 100644 --- a/webkit/plugins/ppapi/resource_tracker.h +++ b/webkit/plugins/ppapi/resource_tracker.h @@ -45,8 +45,8 @@ class ResourceTrackerTest; class ResourceTracker : public ::ppapi::TrackerBase, public ::ppapi::ResourceTracker { public: - ResourceTracker(); - virtual ~ResourceTracker(); + // Returns the pointer to the singleton object. + static ResourceTracker* Get(); // PP_Resources -------------------------------------------------------------- @@ -54,6 +54,8 @@ class ResourceTracker : public ::ppapi::TrackerBase, virtual ::ppapi::FunctionGroupBase* GetFunctionAPI( PP_Instance pp_instance, ::ppapi::proxy::InterfaceID id) OVERRIDE; + virtual ::ppapi::VarTracker* GetVarTracker() OVERRIDE; + virtual ::ppapi::ResourceTracker* GetResourceTracker() OVERRIDE; virtual PP_Module GetModuleForInstance(PP_Instance instance) OVERRIDE; // ppapi::ResourceTracker overrides. @@ -117,11 +119,46 @@ class ResourceTracker : public ::ppapi::TrackerBase, // Per-instance data we track. struct InstanceData; + // Prohibit creation other then by the Singleton class. + ResourceTracker(); + virtual ~ResourceTracker(); + // Force frees all vars and resources associated with the given instance. // If delete_instance is true, the instance tracking information will also // be deleted. void CleanupInstanceData(PP_Instance instance, bool delete_instance); + // Overrides the singleton object. This is used for tests which want to + // specify their own tracker (otherwise, you can get cross-talk between + // tests since the data will live into the subsequent tests). + static void SetSingletonOverride(ResourceTracker* tracker); + static void ClearSingletonOverride(); + + // The lazy-initialized global instance of this object. This is created in + // ::Get() if there is no singleton_override_ specified. + // + // It would be nice to use LazyInstance for this since it manages the + // creation properly, and also cleans up on shutdown. However, the shutdown + // cleanup causes problems in some cases. + // + // For example, say the browser crashes or is killed. The renderer then + // decides to exit. Normally resources are bound to an instance and are + // cleaned up when WebKit deletes the instance (when you go to a different + // page or close that view). In this case, WebKit doesn't clean up. If the + // ResourceTracker was cleaned up by the AtExitManager (which would be the + // case with LazyInstance/Singleton) then we'd try to call up to the renderer + // layer via the delegate, which may be in a random state of shutdown. + // + // So effectively our rule is: any resources still around at shutdown are + // associated with leaked plugins in WebKit, so it's also OK to leak those + // resources from here (avoiding the shutdown race). + static ResourceTracker* global_tracker_; + + // See SetSingletonOverride above. + static ResourceTracker* singleton_override_; + + ::ppapi::VarTracker var_tracker_; + // Like ResourceAndRefCount but for vars, which are associated with modules. typedef std::pair<scoped_refptr< ::ppapi::Var>, size_t> VarAndRefCount; typedef base::hash_map<int32, VarAndRefCount> VarMap; diff --git a/webkit/plugins/ppapi/resource_tracker_unittest.cc b/webkit/plugins/ppapi/resource_tracker_unittest.cc index 68a4b2f..0b418bb 100644 --- a/webkit/plugins/ppapi/resource_tracker_unittest.cc +++ b/webkit/plugins/ppapi/resource_tracker_unittest.cc @@ -9,7 +9,6 @@ #include "ppapi/c/ppp_instance.h" #include "third_party/npapi/bindings/npruntime.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" -#include "webkit/plugins/ppapi/host_globals.h" #include "webkit/plugins/ppapi/mock_plugin_delegate.h" #include "webkit/plugins/ppapi/mock_resource.h" #include "webkit/plugins/ppapi/npapi_glue.h" @@ -79,9 +78,23 @@ class ResourceTrackerTest : public PpapiUnittest { ResourceTrackerTest() { } - ResourceTracker& tracker() { - return *HostGlobals::Get()->host_resource_tracker(); + virtual void SetUp() { + // The singleton override must be installed before the generic setup because + // that creates an instance, etc. which uses the tracker. + ResourceTracker::SetSingletonOverride(&tracker_); + PpapiUnittest::SetUp(); } + virtual void TearDown() { + // Must do normal tear down before clearing the override for the same rason + // as the SetUp. + PpapiUnittest::TearDown(); + ResourceTracker::ClearSingletonOverride(); + } + + ResourceTracker& tracker() { return tracker_; } + + private: + ResourceTracker tracker_; }; TEST_F(ResourceTrackerTest, DeleteObjectVarWithInstance) { @@ -125,8 +138,7 @@ TEST_F(ResourceTrackerTest, ReuseVar) { } // Remove both of the refs we made above. - ::ppapi::VarTracker* var_tracker = - ::ppapi::PpapiGlobals::Get()->GetVarTracker(); + ::ppapi::VarTracker* var_tracker = tracker().GetVarTracker(); var_tracker->ReleaseVar(static_cast<int32_t>(pp_object2.value.as_id)); var_tracker->ReleaseVar(static_cast<int32_t>(pp_object1.value.as_id)); |