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

Side by Side Diff: webkit/plugins/ppapi/ppb_audio_impl.cc

Issue 7585025: Reland 95309. Add a template to handle properly issuing completion callbacks. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: 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
« no previous file with comments | « webkit/plugins/ppapi/ppb_audio_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "webkit/plugins/ppapi/ppb_audio_impl.h" 5 #include "webkit/plugins/ppapi/ppb_audio_impl.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "ppapi/c/pp_completion_callback.h" 8 #include "ppapi/c/pp_completion_callback.h"
9 #include "ppapi/c/ppb_audio.h" 9 #include "ppapi/c/ppb_audio.h"
10 #include "ppapi/c/ppb_audio_config.h" 10 #include "ppapi/c/ppb_audio_config.h"
11 #include "ppapi/c/trusted/ppb_audio_trusted.h" 11 #include "ppapi/c/trusted/ppb_audio_trusted.h"
12 #include "ppapi/thunk/enter.h" 12 #include "ppapi/thunk/enter.h"
13 #include "ppapi/thunk/ppb_audio_config_api.h" 13 #include "ppapi/thunk/ppb_audio_config_api.h"
14 #include "ppapi/thunk/thunk.h" 14 #include "ppapi/thunk/thunk.h"
15 #include "webkit/plugins/ppapi/common.h" 15 #include "webkit/plugins/ppapi/common.h"
16 16
17 using ppapi::thunk::EnterResourceNoLock;
18 using ppapi::thunk::PPB_Audio_API;
19 using ppapi::thunk::PPB_AudioConfig_API;
20
17 namespace webkit { 21 namespace webkit {
18 namespace ppapi { 22 namespace ppapi {
19 23
20 // PPB_AudioConfig ------------------------------------------------------------- 24 // PPB_AudioConfig -------------------------------------------------------------
21 25
22 PPB_AudioConfig_Impl::PPB_AudioConfig_Impl(PluginInstance* instance) 26 PPB_AudioConfig_Impl::PPB_AudioConfig_Impl(PluginInstance* instance)
23 : Resource(instance) { 27 : Resource(instance) {
24 } 28 }
25 29
26 PPB_AudioConfig_Impl::~PPB_AudioConfig_Impl() { 30 PPB_AudioConfig_Impl::~PPB_AudioConfig_Impl() {
27 } 31 }
28 32
29 // static 33 // static
30 PP_Resource PPB_AudioConfig_Impl::Create(PluginInstance* instance, 34 PP_Resource PPB_AudioConfig_Impl::Create(PluginInstance* instance,
31 PP_AudioSampleRate sample_rate, 35 PP_AudioSampleRate sample_rate,
32 uint32_t sample_frame_count) { 36 uint32_t sample_frame_count) {
33 scoped_refptr<PPB_AudioConfig_Impl> config( 37 scoped_refptr<PPB_AudioConfig_Impl> config(
34 new PPB_AudioConfig_Impl(instance)); 38 new PPB_AudioConfig_Impl(instance));
35 if (!config->Init(sample_rate, sample_frame_count)) 39 if (!config->Init(sample_rate, sample_frame_count))
36 return 0; 40 return 0;
37 return config->GetReference(); 41 return config->GetReference();
38 } 42 }
39 43
40 ::ppapi::thunk::PPB_AudioConfig_API* 44 PPB_AudioConfig_API* PPB_AudioConfig_Impl::AsPPB_AudioConfig_API() {
41 PPB_AudioConfig_Impl::AsPPB_AudioConfig_API() {
42 return this; 45 return this;
43 } 46 }
44 47
45 // PPB_Audio_Impl -------------------------------------------------------------- 48 // PPB_Audio_Impl --------------------------------------------------------------
46 49
47 PPB_Audio_Impl::PPB_Audio_Impl(PluginInstance* instance) 50 PPB_Audio_Impl::PPB_Audio_Impl(PluginInstance* instance)
48 : Resource(instance), 51 : Resource(instance),
49 config_id_(0), 52 config_id_(0),
50 audio_(NULL), 53 audio_(NULL),
51 create_callback_pending_(false), 54 create_callback_pending_(false),
(...skipping 27 matching lines...) Expand all
79 PP_Resource PPB_Audio_Impl::Create(PluginInstance* instance, 82 PP_Resource PPB_Audio_Impl::Create(PluginInstance* instance,
80 PP_Resource config_id, 83 PP_Resource config_id,
81 PPB_Audio_Callback audio_callback, 84 PPB_Audio_Callback audio_callback,
82 void* user_data) { 85 void* user_data) {
83 scoped_refptr<PPB_Audio_Impl> audio(new PPB_Audio_Impl(instance)); 86 scoped_refptr<PPB_Audio_Impl> audio(new PPB_Audio_Impl(instance));
84 if (!audio->Init(config_id, audio_callback, user_data)) 87 if (!audio->Init(config_id, audio_callback, user_data))
85 return 0; 88 return 0;
86 return audio->GetReference(); 89 return audio->GetReference();
87 } 90 }
88 91
89 ::ppapi::thunk::PPB_Audio_API* PPB_Audio_Impl::AsPPB_Audio_API() { 92 PPB_Audio_API* PPB_Audio_Impl::AsPPB_Audio_API() {
90 return this;
91 }
92
93 ::ppapi::thunk::PPB_AudioTrusted_API* PPB_Audio_Impl::AsPPB_AudioTrusted_API() {
94 return this; 93 return this;
95 } 94 }
96 95
97 bool PPB_Audio_Impl::Init(PP_Resource config_id, 96 bool PPB_Audio_Impl::Init(PP_Resource config_id,
98 PPB_Audio_Callback callback, void* user_data) { 97 PPB_Audio_Callback callback, void* user_data) {
99 // Validate the config and keep a reference to it. 98 // Validate the config and keep a reference to it.
100 ::ppapi::thunk::EnterResourceNoLock< ::ppapi::thunk::PPB_AudioConfig_API> 99 EnterResourceNoLock<PPB_AudioConfig_API> enter(config_id, true);
101 enter(config_id, true);
102 if (enter.failed()) 100 if (enter.failed())
103 return false; 101 return false;
104 config_id_ = config_id; 102 config_id_ = config_id;
105 ResourceTracker::Get()->AddRefResource(config_id); 103 ResourceTracker::Get()->AddRefResource(config_id);
106 104
107 if (!callback) 105 if (!callback)
108 return false; 106 return false;
109 SetCallback(callback, user_data); 107 SetCallback(callback, user_data);
110 108
111 // When the stream is created, we'll get called back on StreamCreated(). 109 // When the stream is created, we'll get called back on StreamCreated().
(...skipping 28 matching lines...) Expand all
140 if (!audio_->StopPlayback()) 138 if (!audio_->StopPlayback())
141 return PP_FALSE; 139 return PP_FALSE;
142 SetStopPlaybackState(); 140 SetStopPlaybackState();
143 return PP_TRUE; 141 return PP_TRUE;
144 } 142 }
145 143
146 int32_t PPB_Audio_Impl::OpenTrusted(PP_Resource config_id, 144 int32_t PPB_Audio_Impl::OpenTrusted(PP_Resource config_id,
147 PP_CompletionCallback create_callback) { 145 PP_CompletionCallback create_callback) {
148 146
149 // Validate the config and keep a reference to it. 147 // Validate the config and keep a reference to it.
150 ::ppapi::thunk::EnterResourceNoLock< ::ppapi::thunk::PPB_AudioConfig_API> 148 EnterResourceNoLock<PPB_AudioConfig_API> enter(config_id, true);
151 enter(config_id, true);
152 if (enter.failed()) 149 if (enter.failed())
153 return false; 150 return false;
154 config_id_ = config_id; 151 config_id_ = config_id;
155 ResourceTracker::Get()->AddRefResource(config_id); 152 ResourceTracker::Get()->AddRefResource(config_id);
156 153
157 // When the stream is created, we'll get called back on StreamCreated(). 154 // When the stream is created, we'll get called back on StreamCreated().
158 DCHECK(!audio_); 155 DCHECK(!audio_);
159 audio_ = instance()->delegate()->CreateAudio( 156 audio_ = instance()->delegate()->CreateAudio(
160 enter.object()->GetSampleRate(), 157 enter.object()->GetSampleRate(),
161 enter.object()->GetSampleFrameCount(), 158 enter.object()->GetSampleFrameCount(),
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 // something more elaborate like an ACK from the plugin or post a task to 221 // something more elaborate like an ACK from the plugin or post a task to
225 // the I/O thread and back, but this extra complexity doesn't seem worth it 222 // the I/O thread and back, but this extra complexity doesn't seem worth it
226 // just to clean up these handles faster. 223 // just to clean up these handles faster.
227 } else { 224 } else {
228 SetStreamInfo(shared_memory_handle, shared_memory_size, socket_handle); 225 SetStreamInfo(shared_memory_handle, shared_memory_size, socket_handle);
229 } 226 }
230 } 227 }
231 228
232 } // namespace ppapi 229 } // namespace ppapi
233 } // namespace webkit 230 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppb_audio_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698