Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(558)

Side by Side Diff: ppapi/proxy/ppb_audio_proxy.cc

Issue 7629017: Add a unified resource tracker shared between the proxy and the impl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Assertion fixed Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/proxy/ppb_audio_proxy.h" 5 #include "ppapi/proxy/ppb_audio_proxy.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/threading/simple_thread.h" 8 #include "base/threading/simple_thread.h"
9 #include "ppapi/c/pp_errors.h" 9 #include "ppapi/c/pp_errors.h"
10 #include "ppapi/c/ppb_audio.h" 10 #include "ppapi/c/ppb_audio.h"
11 #include "ppapi/c/ppb_audio_config.h" 11 #include "ppapi/c/ppb_audio_config.h"
12 #include "ppapi/c/ppb_var.h" 12 #include "ppapi/c/ppb_var.h"
13 #include "ppapi/c/trusted/ppb_audio_trusted.h" 13 #include "ppapi/c/trusted/ppb_audio_trusted.h"
14 #include "ppapi/proxy/enter_proxy.h" 14 #include "ppapi/proxy/enter_proxy.h"
15 #include "ppapi/proxy/interface_id.h" 15 #include "ppapi/proxy/interface_id.h"
16 #include "ppapi/proxy/plugin_dispatcher.h" 16 #include "ppapi/proxy/plugin_dispatcher.h"
17 #include "ppapi/proxy/plugin_resource.h"
18 #include "ppapi/proxy/ppapi_messages.h" 17 #include "ppapi/proxy/ppapi_messages.h"
19 #include "ppapi/shared_impl/audio_impl.h" 18 #include "ppapi/shared_impl/audio_impl.h"
19 #include "ppapi/shared_impl/resource.h"
20 #include "ppapi/thunk/ppb_audio_config_api.h" 20 #include "ppapi/thunk/ppb_audio_config_api.h"
21 #include "ppapi/thunk/enter.h" 21 #include "ppapi/thunk/enter.h"
22 #include "ppapi/thunk/resource_creation_api.h" 22 #include "ppapi/thunk/resource_creation_api.h"
23 #include "ppapi/thunk/thunk.h" 23 #include "ppapi/thunk/thunk.h"
24 24
25 using ppapi::HostResource; 25 using ppapi::HostResource;
26 using ppapi::Resource;
26 using ppapi::thunk::EnterResourceNoLock; 27 using ppapi::thunk::EnterResourceNoLock;
27 using ppapi::thunk::PPB_Audio_API; 28 using ppapi::thunk::PPB_Audio_API;
28 using ppapi::thunk::PPB_AudioConfig_API; 29 using ppapi::thunk::PPB_AudioConfig_API;
29 30
30 namespace pp { 31 namespace pp {
31 namespace proxy { 32 namespace proxy {
32 33
33 class Audio : public PluginResource, public ppapi::AudioImpl { 34 class Audio : public Resource, public ppapi::AudioImpl {
34 public: 35 public:
35 Audio(const HostResource& audio_id, 36 Audio(const HostResource& audio_id,
36 PP_Resource config_id, 37 PP_Resource config_id,
37 PPB_Audio_Callback callback, 38 PPB_Audio_Callback callback,
38 void* user_data); 39 void* user_data);
39 virtual ~Audio(); 40 virtual ~Audio();
40 41
41 // ResourceObjectBase overrides. 42 // Resource overrides.
42 virtual PPB_Audio_API* AsPPB_Audio_API(); 43 virtual PPB_Audio_API* AsPPB_Audio_API();
43 44
44 // PPB_Audio_API implementation. 45 // PPB_Audio_API implementation.
45 virtual PP_Resource GetCurrentConfig() OVERRIDE; 46 virtual PP_Resource GetCurrentConfig() OVERRIDE;
46 virtual PP_Bool StartPlayback() OVERRIDE; 47 virtual PP_Bool StartPlayback() OVERRIDE;
47 virtual PP_Bool StopPlayback() OVERRIDE; 48 virtual PP_Bool StopPlayback() OVERRIDE;
48 virtual int32_t OpenTrusted(PP_Resource config_id, 49 virtual int32_t OpenTrusted(PP_Resource config_id,
49 PP_CompletionCallback create_callback) OVERRIDE; 50 PP_CompletionCallback create_callback) OVERRIDE;
50 virtual int32_t GetSyncSocket(int* sync_socket) OVERRIDE; 51 virtual int32_t GetSyncSocket(int* sync_socket) OVERRIDE;
51 virtual int32_t GetSharedMemory(int* shm_handle, uint32_t* shm_size) OVERRIDE; 52 virtual int32_t GetSharedMemory(int* shm_handle, uint32_t* shm_size) OVERRIDE;
52 53
53 private: 54 private:
54 // Owning reference to the current config object. This isn't actually used, 55 // Owning reference to the current config object. This isn't actually used,
55 // we just dish it out as requested by the plugin. 56 // we just dish it out as requested by the plugin.
56 PP_Resource config_; 57 PP_Resource config_;
57 58
58 DISALLOW_COPY_AND_ASSIGN(Audio); 59 DISALLOW_COPY_AND_ASSIGN(Audio);
59 }; 60 };
60 61
61 Audio::Audio(const HostResource& audio_id, 62 Audio::Audio(const HostResource& audio_id,
62 PP_Resource config_id, 63 PP_Resource config_id,
63 PPB_Audio_Callback callback, 64 PPB_Audio_Callback callback,
64 void* user_data) 65 void* user_data)
65 : PluginResource(audio_id), 66 : Resource(audio_id),
66 config_(config_id) { 67 config_(config_id) {
67 SetCallback(callback, user_data); 68 SetCallback(callback, user_data);
68 PluginResourceTracker::GetInstance()->AddRefResource(config_); 69 PluginResourceTracker::GetInstance()->AddRefResource(config_);
69 } 70 }
70 71
71 Audio::~Audio() { 72 Audio::~Audio() {
72 PluginResourceTracker::GetInstance()->ReleaseResource(config_); 73 PluginResourceTracker::GetInstance()->ReleaseResource(config_);
73 } 74 }
74 75
75 PPB_Audio_API* Audio::AsPPB_Audio_API() { 76 PPB_Audio_API* Audio::AsPPB_Audio_API() {
76 return this; 77 return this;
77 } 78 }
78 79
79 PP_Resource Audio::GetCurrentConfig() { 80 PP_Resource Audio::GetCurrentConfig() {
80 // AddRef for the caller. 81 // AddRef for the caller.
81 PluginResourceTracker::GetInstance()->AddRefResource(config_); 82 PluginResourceTracker::GetInstance()->AddRefResource(config_);
82 return config_; 83 return config_;
83 } 84 }
84 85
85 PP_Bool Audio::StartPlayback() { 86 PP_Bool Audio::StartPlayback() {
86 if (playing()) 87 if (playing())
87 return PP_TRUE; 88 return PP_TRUE;
88 SetStartPlaybackState(); 89 SetStartPlaybackState();
89 PluginDispatcher::GetForInstance(instance())->Send( 90 PluginDispatcher::GetForInstance(pp_instance())->Send(
90 new PpapiHostMsg_PPBAudio_StartOrStop( 91 new PpapiHostMsg_PPBAudio_StartOrStop(
91 INTERFACE_ID_PPB_AUDIO, host_resource(), true)); 92 INTERFACE_ID_PPB_AUDIO, host_resource(), true));
92 return PP_TRUE; 93 return PP_TRUE;
93 } 94 }
94 95
95 PP_Bool Audio::StopPlayback() { 96 PP_Bool Audio::StopPlayback() {
96 if (!playing()) 97 if (!playing())
97 return PP_TRUE; 98 return PP_TRUE;
98 PluginDispatcher::GetForInstance(instance())->Send( 99 PluginDispatcher::GetForInstance(pp_instance())->Send(
99 new PpapiHostMsg_PPBAudio_StartOrStop( 100 new PpapiHostMsg_PPBAudio_StartOrStop(
100 INTERFACE_ID_PPB_AUDIO, host_resource(), false)); 101 INTERFACE_ID_PPB_AUDIO, host_resource(), false));
101 SetStopPlaybackState(); 102 SetStopPlaybackState();
102 return PP_TRUE; 103 return PP_TRUE;
103 } 104 }
104 105
105 int32_t Audio::OpenTrusted(PP_Resource config_id, 106 int32_t Audio::OpenTrusted(PP_Resource config_id,
106 PP_CompletionCallback create_callback) { 107 PP_CompletionCallback create_callback) {
107 return PP_ERROR_NOTSUPPORTED; // Don't proxy the trusted interface. 108 return PP_ERROR_NOTSUPPORTED; // Don't proxy the trusted interface.
108 } 109 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 return 0; 173 return 0;
173 174
174 HostResource result; 175 HostResource result;
175 dispatcher->Send(new PpapiHostMsg_PPBAudio_Create( 176 dispatcher->Send(new PpapiHostMsg_PPBAudio_Create(
176 INTERFACE_ID_PPB_AUDIO, instance_id, 177 INTERFACE_ID_PPB_AUDIO, instance_id,
177 config.object()->GetSampleRate(), config.object()->GetSampleFrameCount(), 178 config.object()->GetSampleRate(), config.object()->GetSampleFrameCount(),
178 &result)); 179 &result));
179 if (result.is_null()) 180 if (result.is_null())
180 return 0; 181 return 0;
181 182
182 return PluginResourceTracker::GetInstance()->AddResource( 183 return (new Audio(result, config_id, audio_callback, user_data))->
183 new Audio(result, config_id, audio_callback, user_data)); 184 GetReference();
dmichael (off chromium) 2011/08/17 16:28:07 optional nit: I think this would be more readable
brettw 2011/08/17 17:16:25 I want to be consistent so people that copy & past
184 } 185 }
185 186
186 bool PPB_Audio_Proxy::OnMessageReceived(const IPC::Message& msg) { 187 bool PPB_Audio_Proxy::OnMessageReceived(const IPC::Message& msg) {
187 bool handled = true; 188 bool handled = true;
188 IPC_BEGIN_MESSAGE_MAP(PPB_Audio_Proxy, msg) 189 IPC_BEGIN_MESSAGE_MAP(PPB_Audio_Proxy, msg)
189 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBAudio_Create, OnMsgCreate) 190 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBAudio_Create, OnMsgCreate)
190 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBAudio_StartOrStop, 191 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBAudio_StartOrStop,
191 OnMsgStartOrStop) 192 OnMsgStartOrStop)
192 IPC_MESSAGE_HANDLER(PpapiMsg_PPBAudio_NotifyAudioStreamCreated, 193 IPC_MESSAGE_HANDLER(PpapiMsg_PPBAudio_NotifyAudioStreamCreated,
193 OnMsgNotifyAudioStreamCreated) 194 OnMsgNotifyAudioStreamCreated)
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 *foreign_shared_memory_handle = dispatcher()->ShareHandleWithRemote( 336 *foreign_shared_memory_handle = dispatcher()->ShareHandleWithRemote(
336 IntToPlatformFile(shared_memory_handle), false); 337 IntToPlatformFile(shared_memory_handle), false);
337 if (*foreign_shared_memory_handle == IPC::InvalidPlatformFileForTransit()) 338 if (*foreign_shared_memory_handle == IPC::InvalidPlatformFileForTransit())
338 return PP_ERROR_FAILED; 339 return PP_ERROR_FAILED;
339 340
340 return PP_OK; 341 return PP_OK;
341 } 342 }
342 343
343 } // namespace proxy 344 } // namespace proxy
344 } // namespace pp 345 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698