diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-25 04:45:58 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-25 04:45:58 +0000 |
commit | ff71e6483669362f5060598214afc1a594427bce (patch) | |
tree | be5be8c112cdfcdc5ebd4a02406ded639751fbdb /ppapi | |
parent | eaeaf86449c9cee06d432759e7ebe128f89317b8 (diff) | |
download | chromium_src-ff71e6483669362f5060598214afc1a594427bce.zip chromium_src-ff71e6483669362f5060598214afc1a594427bce.tar.gz chromium_src-ff71e6483669362f5060598214afc1a594427bce.tar.bz2 |
Merge the plugin and impl side of the audio config and input event resources.
Now that we have a unified resource system, we no longer need the duplication
on both sides of the proxy. This resource is now implemented entirely in
shared_impl.
Review URL: http://codereview.chromium.org/7621070
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98185 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r-- | ppapi/proxy/plugin_resource_tracker.cc | 5 | ||||
-rw-r--r-- | ppapi/proxy/plugin_resource_tracker.h | 1 | ||||
-rw-r--r-- | ppapi/proxy/ppb_audio_config_proxy.cc | 36 | ||||
-rw-r--r-- | ppapi/proxy/ppb_audio_config_proxy.h | 4 | ||||
-rw-r--r-- | ppapi/proxy/ppb_input_event_proxy.cc | 40 | ||||
-rw-r--r-- | ppapi/proxy/ppb_input_event_proxy.h | 3 | ||||
-rw-r--r-- | ppapi/proxy/ppp_input_event_proxy.cc | 15 | ||||
-rw-r--r-- | ppapi/proxy/resource_creation_proxy.cc | 14 | ||||
-rw-r--r-- | ppapi/shared_impl/audio_config_impl.cc | 52 | ||||
-rw-r--r-- | ppapi/shared_impl/audio_config_impl.h | 25 | ||||
-rw-r--r-- | ppapi/shared_impl/input_event_impl.cc | 26 | ||||
-rw-r--r-- | ppapi/shared_impl/input_event_impl.h | 26 | ||||
-rw-r--r-- | ppapi/shared_impl/resource_tracker_unittest.cc | 3 | ||||
-rw-r--r-- | ppapi/shared_impl/tracker_base.h | 5 |
14 files changed, 133 insertions, 122 deletions
diff --git a/ppapi/proxy/plugin_resource_tracker.cc b/ppapi/proxy/plugin_resource_tracker.cc index 9f19d25..e47c35e 100644 --- a/ppapi/proxy/plugin_resource_tracker.cc +++ b/ppapi/proxy/plugin_resource_tracker.cc @@ -75,6 +75,11 @@ 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; +} + PP_Resource PluginResourceTracker::AddResource(Resource* object) { PP_Resource ret = ResourceTracker::AddResource(object); diff --git a/ppapi/proxy/plugin_resource_tracker.h b/ppapi/proxy/plugin_resource_tracker.h index d45ef6d..d3c72c8 100644 --- a/ppapi/proxy/plugin_resource_tracker.h +++ b/ppapi/proxy/plugin_resource_tracker.h @@ -59,6 +59,7 @@ class PluginResourceTracker : public TrackerBase, public ResourceTracker { InterfaceID id) OVERRIDE; virtual VarTracker* GetVarTracker() OVERRIDE; virtual ResourceTracker* GetResourceTracker() OVERRIDE; + virtual PP_Module GetModuleForInstance(PP_Instance instance) OVERRIDE; protected: // ResourceTracker overrides. diff --git a/ppapi/proxy/ppb_audio_config_proxy.cc b/ppapi/proxy/ppb_audio_config_proxy.cc index 5f063e3..d578fd5 100644 --- a/ppapi/proxy/ppb_audio_config_proxy.cc +++ b/ppapi/proxy/ppb_audio_config_proxy.cc @@ -13,30 +13,6 @@ namespace ppapi { namespace proxy { -// The implementation is actually in AudioConfigImpl. -class AudioConfig : public Resource, public AudioConfigImpl { - public: - // Note that you must call Init (on AudioConfigImpl) before using this class. - AudioConfig(const HostResource& resource); - virtual ~AudioConfig(); - - // Resource overrides. - virtual thunk::PPB_AudioConfig_API* AsPPB_AudioConfig_API() OVERRIDE; - - private: - DISALLOW_COPY_AND_ASSIGN(AudioConfig); -}; - -AudioConfig::AudioConfig(const HostResource& resource) : Resource(resource) { -} - -AudioConfig::~AudioConfig() { -} - -thunk::PPB_AudioConfig_API* AudioConfig::AsPPB_AudioConfig_API() { - return this; -} - namespace { InterfaceProxy* CreateAudioConfigProxy(Dispatcher* dispatcher, @@ -66,18 +42,6 @@ const InterfaceProxy::Info* PPB_AudioConfig_Proxy::GetInfo() { return &info; } -// static -PP_Resource PPB_AudioConfig_Proxy::CreateProxyResource( - PP_Instance instance, - PP_AudioSampleRate sample_rate, - uint32_t sample_frame_count) { - scoped_refptr<AudioConfig> object(new AudioConfig( - HostResource::MakeInstanceOnly(instance))); - if (!object->Init(sample_rate, sample_frame_count)) - return 0; - return object->GetReference(); -} - bool PPB_AudioConfig_Proxy::OnMessageReceived(const IPC::Message& msg) { // There are no IPC messages for this interface. NOTREACHED(); diff --git a/ppapi/proxy/ppb_audio_config_proxy.h b/ppapi/proxy/ppb_audio_config_proxy.h index de86d28..d70d2db 100644 --- a/ppapi/proxy/ppb_audio_config_proxy.h +++ b/ppapi/proxy/ppb_audio_config_proxy.h @@ -23,10 +23,6 @@ class PPB_AudioConfig_Proxy : public InterfaceProxy { static const Info* GetInfo(); - static PP_Resource CreateProxyResource(PP_Instance instance, - PP_AudioSampleRate sample_rate, - uint32_t sample_frame_count); - // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg); diff --git a/ppapi/proxy/ppb_input_event_proxy.cc b/ppapi/proxy/ppb_input_event_proxy.cc index f94cdc2..29513bc 100644 --- a/ppapi/proxy/ppb_input_event_proxy.cc +++ b/ppapi/proxy/ppb_input_event_proxy.cc @@ -18,38 +18,6 @@ using ppapi::thunk::PPB_InputEvent_API; namespace ppapi { namespace proxy { -// The implementation is actually in InputEventImpl. -class InputEvent : public Resource, public InputEventImpl { - public: - InputEvent(const HostResource& resource, const InputEventData& data); - virtual ~InputEvent(); - - // Resource overrides. - virtual PPB_InputEvent_API* AsPPB_InputEvent_API() OVERRIDE; - - // InputEventImpl overrides. - virtual PP_Var StringToPPVar(const std::string& str) OVERRIDE; - - private: - DISALLOW_COPY_AND_ASSIGN(InputEvent); -}; - -InputEvent::InputEvent(const HostResource& resource, const InputEventData& data) - : Resource(resource), - InputEventImpl(data) { -} - -InputEvent::~InputEvent() { -} - -PPB_InputEvent_API* InputEvent::AsPPB_InputEvent_API() { - return this; -} - -PP_Var InputEvent::StringToPPVar(const std::string& str) { - return StringVar::StringToPPVar(0, str); -} - namespace { InterfaceProxy* CreateInputEventProxy(Dispatcher* dispatcher, @@ -115,14 +83,6 @@ const InterfaceProxy::Info* PPB_InputEvent_Proxy::GetWheelInputEventInfo() { return &info; } -// static -PP_Resource PPB_InputEvent_Proxy::CreateProxyResource( - PP_Instance instance, - const InputEventData& data) { - return (new InputEvent(HostResource::MakeInstanceOnly(instance), data))-> - GetReference(); -} - bool PPB_InputEvent_Proxy::OnMessageReceived(const IPC::Message& msg) { // There are no IPC messages for this interface. NOTREACHED(); diff --git a/ppapi/proxy/ppb_input_event_proxy.h b/ppapi/proxy/ppb_input_event_proxy.h index 0cefb8d..43aa03c 100644 --- a/ppapi/proxy/ppb_input_event_proxy.h +++ b/ppapi/proxy/ppb_input_event_proxy.h @@ -26,9 +26,6 @@ class PPB_InputEvent_Proxy : public InterfaceProxy { static const Info* GetMouseInputEventInfo(); static const Info* GetWheelInputEventInfo(); - static PP_Resource CreateProxyResource(PP_Instance instance, - const ppapi::InputEventData& data); - // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg); diff --git a/ppapi/proxy/ppp_input_event_proxy.cc b/ppapi/proxy/ppp_input_event_proxy.cc index fce2ca5..a8843f5 100644 --- a/ppapi/proxy/ppp_input_event_proxy.cc +++ b/ppapi/proxy/ppp_input_event_proxy.cc @@ -12,6 +12,7 @@ #include "ppapi/proxy/plugin_resource_tracker.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/ppb_input_event_proxy.h" +#include "ppapi/shared_impl/input_event_impl.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/ppb_input_event_api.h" @@ -93,21 +94,19 @@ bool PPP_InputEvent_Proxy::OnMessageReceived(const IPC::Message& msg) { void PPP_InputEvent_Proxy::OnMsgHandleInputEvent(PP_Instance instance, const InputEventData& data) { - PP_Resource event_resource = PPB_InputEvent_Proxy::CreateProxyResource( - instance, data); - ppp_input_event_target()->HandleInputEvent(instance, event_resource); - PluginResourceTracker::GetInstance()->ReleaseResource(event_resource); + scoped_refptr<InputEventImpl> resource(new InputEventImpl( + InputEventImpl::InitAsProxy(), instance, data)); + ppp_input_event_target()->HandleInputEvent(instance, resource->pp_resource()); } void PPP_InputEvent_Proxy::OnMsgHandleFilteredInputEvent( PP_Instance instance, const InputEventData& data, PP_Bool* result) { - PP_Resource event_resource = PPB_InputEvent_Proxy::CreateProxyResource( - instance, data); + scoped_refptr<InputEventImpl> resource(new InputEventImpl( + InputEventImpl::InitAsProxy(), instance, data)); *result = ppp_input_event_target()->HandleInputEvent(instance, - event_resource); - PluginResourceTracker::GetInstance()->ReleaseResource(event_resource); + resource->pp_resource()); } } // namespace proxy diff --git a/ppapi/proxy/resource_creation_proxy.cc b/ppapi/proxy/resource_creation_proxy.cc index c6d02a7e..70f3f38 100644 --- a/ppapi/proxy/resource_creation_proxy.cc +++ b/ppapi/proxy/resource_creation_proxy.cc @@ -11,7 +11,6 @@ #include "ppapi/c/trusted/ppb_image_data_trusted.h" #include "ppapi/proxy/plugin_resource_tracker.h" #include "ppapi/proxy/ppapi_messages.h" -#include "ppapi/proxy/ppb_audio_config_proxy.h" #include "ppapi/proxy/ppb_audio_proxy.h" #include "ppapi/proxy/ppb_buffer_proxy.h" #include "ppapi/proxy/ppb_broker_proxy.h" @@ -26,12 +25,12 @@ #include "ppapi/proxy/ppb_graphics_2d_proxy.h" #include "ppapi/proxy/ppb_graphics_3d_proxy.h" #include "ppapi/proxy/ppb_image_data_proxy.h" -#include "ppapi/proxy/ppb_input_event_proxy.h" #include "ppapi/proxy/ppb_surface_3d_proxy.h" #include "ppapi/proxy/ppb_url_loader_proxy.h" #include "ppapi/proxy/ppb_url_request_info_proxy.h" #include "ppapi/proxy/ppb_video_capture_proxy.h" #include "ppapi/proxy/ppb_video_decoder_proxy.h" +#include "ppapi/shared_impl/audio_config_impl.h" #include "ppapi/shared_impl/font_impl.h" #include "ppapi/shared_impl/function_group_base.h" #include "ppapi/shared_impl/host_resource.h" @@ -69,7 +68,7 @@ PP_Resource ResourceCreationProxy::CreateAudioConfig( PP_Instance instance, PP_AudioSampleRate sample_rate, uint32_t sample_frame_count) { - return PPB_AudioConfig_Proxy::CreateProxyResource( + return AudioConfigImpl::CreateAsProxy( instance, sample_rate, sample_frame_count); } @@ -217,7 +216,8 @@ PP_Resource ResourceCreationProxy::CreateKeyboardInputEvent( data.character_text = text_str->value(); } - return PPB_InputEvent_Proxy::CreateProxyResource(instance, data); + return (new InputEventImpl(InputEventImpl::InitAsProxy(), + instance, data))->GetReference(); } PP_Resource ResourceCreationProxy::CreateMouseInputEvent( @@ -243,7 +243,8 @@ PP_Resource ResourceCreationProxy::CreateMouseInputEvent( data.mouse_position = *mouse_position; data.mouse_click_count = click_count; - return PPB_InputEvent_Proxy::CreateProxyResource(instance, data); + return (new InputEventImpl(InputEventImpl::InitAsProxy(), + instance, data))->GetReference(); } PP_Resource ResourceCreationProxy::CreateGraphics3D( @@ -326,7 +327,8 @@ PP_Resource ResourceCreationProxy::CreateWheelInputEvent( data.wheel_ticks = *wheel_ticks; data.wheel_scroll_by_page = PP_ToBool(scroll_by_page); - return PPB_InputEvent_Proxy::CreateProxyResource(instance, data); + return (new InputEventImpl(InputEventImpl::InitAsProxy(), + instance, data))->GetReference(); } bool ResourceCreationProxy::Send(IPC::Message* msg) { diff --git a/ppapi/shared_impl/audio_config_impl.cc b/ppapi/shared_impl/audio_config_impl.cc index da4d8c5..843f2d1 100644 --- a/ppapi/shared_impl/audio_config_impl.cc +++ b/ppapi/shared_impl/audio_config_impl.cc @@ -6,14 +6,54 @@ namespace ppapi { -AudioConfigImpl::AudioConfigImpl() - : sample_rate_(PP_AUDIOSAMPLERATE_NONE), +AudioConfigImpl::AudioConfigImpl(PP_Instance instance) + : Resource(instance), + sample_rate_(PP_AUDIOSAMPLERATE_NONE), + sample_frame_count_(0) { +} + +AudioConfigImpl::AudioConfigImpl(const HostResource& host_resource) + : Resource(host_resource), + sample_rate_(PP_AUDIOSAMPLERATE_NONE), sample_frame_count_(0) { } AudioConfigImpl::~AudioConfigImpl() { } +// static +PP_Resource AudioConfigImpl::CreateAsImpl(PP_Instance instance, + PP_AudioSampleRate sample_rate, + uint32_t sample_frame_count) { + scoped_refptr<AudioConfigImpl> object(new AudioConfigImpl(instance)); + if (!object->Init(sample_rate, sample_frame_count)) + return 0; + return object->GetReference(); +} + +// static +PP_Resource AudioConfigImpl::CreateAsProxy(PP_Instance instance, + PP_AudioSampleRate sample_rate, + uint32_t sample_frame_count) { + scoped_refptr<AudioConfigImpl> object(new AudioConfigImpl( + HostResource::MakeInstanceOnly(instance))); + if (!object->Init(sample_rate, sample_frame_count)) + return 0; + return object->GetReference(); +} + +thunk::PPB_AudioConfig_API* AudioConfigImpl::AsPPB_AudioConfig_API() { + return this; +} + +PP_AudioSampleRate AudioConfigImpl::GetSampleRate() { + return sample_rate_; +} + +uint32_t AudioConfigImpl::GetSampleFrameCount() { + return sample_frame_count_; +} + bool AudioConfigImpl::Init(PP_AudioSampleRate sample_rate, uint32_t sample_frame_count) { // TODO(brettw): Currently we don't actually check what the hardware @@ -33,12 +73,4 @@ bool AudioConfigImpl::Init(PP_AudioSampleRate sample_rate, return true; } -PP_AudioSampleRate AudioConfigImpl::GetSampleRate() { - return sample_rate_; -} - -uint32_t AudioConfigImpl::GetSampleFrameCount() { - return sample_frame_count_; -} - } // namespace ppapi diff --git a/ppapi/shared_impl/audio_config_impl.h b/ppapi/shared_impl/audio_config_impl.h index 079df76..69a2b73 100644 --- a/ppapi/shared_impl/audio_config_impl.h +++ b/ppapi/shared_impl/audio_config_impl.h @@ -12,21 +12,34 @@ namespace ppapi { -class AudioConfigImpl : public thunk::PPB_AudioConfig_API { +class AudioConfigImpl : public Resource, + public thunk::PPB_AudioConfig_API { public: - // You must call Init before using this object. - AudioConfigImpl(); virtual ~AudioConfigImpl(); - // Returns false if the arguments are invalid, the object should not be - // used in this case. - bool Init(PP_AudioSampleRate sample_rate, uint32_t sample_frame_count); + static PP_Resource CreateAsImpl(PP_Instance instance, + PP_AudioSampleRate sample_rate, + uint32_t sample_frame_count); + static PP_Resource CreateAsProxy(PP_Instance instance, + PP_AudioSampleRate sample_rate, + uint32_t sample_frame_count); + + // Resource overrides. + virtual thunk::PPB_AudioConfig_API* AsPPB_AudioConfig_API() OVERRIDE; // PPB_AudioConfig_API implementation. virtual PP_AudioSampleRate GetSampleRate() OVERRIDE; virtual uint32_t GetSampleFrameCount() OVERRIDE; private: + // You must call Init before using this object. + explicit AudioConfigImpl(PP_Instance instance); // Impl c'tor. + explicit AudioConfigImpl(const HostResource& host_resource); // Proxy c'tor. + + // Returns false if the arguments are invalid, the object should not be + // used in this case. + bool Init(PP_AudioSampleRate sample_rate, uint32_t sample_frame_count); + PP_AudioSampleRate sample_rate_; uint32_t sample_frame_count_; diff --git a/ppapi/shared_impl/input_event_impl.cc b/ppapi/shared_impl/input_event_impl.cc index 599cfa1..3b455b6 100644 --- a/ppapi/shared_impl/input_event_impl.cc +++ b/ppapi/shared_impl/input_event_impl.cc @@ -4,6 +4,11 @@ #include "ppapi/shared_impl/input_event_impl.h" +#include "ppapi/shared_impl/tracker_base.h" +#include "ppapi/shared_impl/var.h" + +using ppapi::thunk::PPB_InputEvent_API; + namespace ppapi { InputEventData::InputEventData() @@ -24,7 +29,22 @@ InputEventData::InputEventData() InputEventData::~InputEventData() { } -InputEventImpl::InputEventImpl(const InputEventData& data) : data_(data) { +InputEventImpl::InputEventImpl(const InitAsImpl&, + PP_Instance instance, + const InputEventData& data) + : Resource(instance), + data_(data) { +} + +InputEventImpl::InputEventImpl(const InitAsProxy&, + PP_Instance instance, + const InputEventData& data) + : Resource(HostResource::MakeInstanceOnly(instance)), + data_(data) { +} + +PPB_InputEvent_API* InputEventImpl::AsPPB_InputEvent_API() { + return this; } const InputEventData& InputEventImpl::GetInputEventData() const { @@ -72,7 +92,9 @@ uint32_t InputEventImpl::GetKeyCode() { } PP_Var InputEventImpl::GetCharacterText() { - return StringToPPVar(data_.character_text); + return StringVar::StringToPPVar( + TrackerBase::Get()->GetModuleForInstance(pp_instance()), + data_.character_text); } } // namespace ppapi diff --git a/ppapi/shared_impl/input_event_impl.h b/ppapi/shared_impl/input_event_impl.h index b5411dd..baa4bda 100644 --- a/ppapi/shared_impl/input_event_impl.h +++ b/ppapi/shared_impl/input_event_impl.h @@ -7,7 +7,9 @@ #include <string> +#include "base/basictypes.h" #include "base/compiler_specific.h" +#include "ppapi/shared_impl/resource.h" #include "ppapi/thunk/ppb_input_event_api.h" namespace ppapi { @@ -42,9 +44,22 @@ struct InputEventData { // This simple class implements the PPB_InputEvent_API in terms of the // shared InputEventData structure -class InputEventImpl : public thunk::PPB_InputEvent_API { +class InputEventImpl : public Resource, public thunk::PPB_InputEvent_API { public: - explicit InputEventImpl(const InputEventData& data); + struct InitAsImpl {}; + struct InitAsProxy {}; + + // The dummy arguments control which version of Resource's constructor is + // called for this base class. + InputEventImpl(const InitAsImpl&, + PP_Instance instance, + const InputEventData& data); + InputEventImpl(const InitAsProxy&, + PP_Instance instance, + const InputEventData& data); + + // Resource overrides. + virtual PPB_InputEvent_API* AsPPB_InputEvent_API() OVERRIDE; // PPB_InputEvent_API implementation. virtual const InputEventData& GetInputEventData() const OVERRIDE; @@ -60,13 +75,10 @@ class InputEventImpl : public thunk::PPB_InputEvent_API { virtual uint32_t GetKeyCode() OVERRIDE; virtual PP_Var GetCharacterText() OVERRIDE; - protected: - // Derived classes override this to convert a string to a PP_Var in either - // the proxy or the impl. - virtual PP_Var StringToPPVar(const std::string& str) = 0; - private: InputEventData data_; + + DISALLOW_IMPLICIT_CONSTRUCTORS(InputEventImpl); }; } // namespace ppapi diff --git a/ppapi/shared_impl/resource_tracker_unittest.cc b/ppapi/shared_impl/resource_tracker_unittest.cc index 5edf639..371f6e77 100644 --- a/ppapi/shared_impl/resource_tracker_unittest.cc +++ b/ppapi/shared_impl/resource_tracker_unittest.cc @@ -74,6 +74,9 @@ class ResourceTrackerTest : public testing::Test, public TrackerBase { virtual ResourceTracker* GetResourceTracker() OVERRIDE { return &resource_tracker_; } + virtual PP_Module GetModuleForInstance(PP_Instance /* instance */) OVERRIDE { + return 0; + } ResourceTracker& resource_tracker() { return resource_tracker_; } diff --git a/ppapi/shared_impl/tracker_base.h b/ppapi/shared_impl/tracker_base.h index ae9e975..49624c3 100644 --- a/ppapi/shared_impl/tracker_base.h +++ b/ppapi/shared_impl/tracker_base.h @@ -8,6 +8,7 @@ #include "base/basictypes.h" #include "base/memory/ref_counted.h" #include "ppapi/c/pp_instance.h" +#include "ppapi/c/pp_module.h" #include "ppapi/c/pp_resource.h" #include "ppapi/proxy/interface_id.h" @@ -44,6 +45,10 @@ class TrackerBase { 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; }; } // namespace ppapi |