// 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/ppb_audio_proxy.h" #include "base/threading/simple_thread.h" #include "ppapi/c/pp_errors.h" #include "ppapi/c/ppb_audio.h" #include "ppapi/c/trusted/ppb_audio_trusted.h" #include "ppapi/proxy/interface_id.h" #include "ppapi/proxy/plugin_dispatcher.h" #include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/shared_impl/audio_impl.h" namespace pp { namespace proxy { class Audio : public PluginResource, public pp::shared_impl::AudioImpl { public: Audio(const HostResource& audio_id, PP_Resource config_id, PPB_Audio_Callback callback, void* user_data) : PluginResource(audio_id), config_(config_id) { SetCallback(callback, user_data); PluginResourceTracker::GetInstance()->AddRefResource(config_); } virtual ~Audio() { PluginResourceTracker::GetInstance()->ReleaseResource(config_); } // Resource overrides. virtual Audio* AsAudio() { return this; } PP_Resource config() const { return config_; } void StartPlayback(PP_Resource resource) { if (playing()) return; SetStartPlaybackState(); PluginDispatcher::GetForInstance(instance())->Send( new PpapiHostMsg_PPBAudio_StartOrStop( INTERFACE_ID_PPB_AUDIO, host_resource(), true)); } void StopPlayback(PP_Resource resource) { if (!playing()) return; PluginDispatcher::GetForInstance(instance())->Send( new PpapiHostMsg_PPBAudio_StartOrStop( INTERFACE_ID_PPB_AUDIO, host_resource(), false)); SetStopPlaybackState(); } private: PP_Resource config_; DISALLOW_COPY_AND_ASSIGN(Audio); }; namespace { PP_Resource Create(PP_Instance instance_id, PP_Resource config_id, PPB_Audio_Callback callback, void* user_data) { PluginResource* config = PluginResourceTracker::GetInstance()-> GetResourceObject(config_id); if (!config) return 0; PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); if (!dispatcher) return 0; HostResource result; dispatcher->Send(new PpapiHostMsg_PPBAudio_Create( INTERFACE_ID_PPB_AUDIO, instance_id, config->host_resource(), &result)); if (result.is_null()) return 0; linked_ptr