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

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

Issue 10081020: PPAPI: Make blocking completion callbacks work. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated TestURLLoader to test blocking callbacks. Created 8 years, 8 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_video_capture_impl.h" 5 #include "webkit/plugins/ppapi/ppb_video_capture_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "ppapi/c/dev/pp_video_capture_dev.h" 13 #include "ppapi/c/dev/pp_video_capture_dev.h"
14 #include "ppapi/c/dev/ppb_video_capture_dev.h" 14 #include "ppapi/c/dev/ppb_video_capture_dev.h"
15 #include "ppapi/c/pp_completion_callback.h" 15 #include "ppapi/c/pp_completion_callback.h"
16 #include "ppapi/c/pp_errors.h" 16 #include "ppapi/c/pp_errors.h"
17 #include "ppapi/shared_impl/ppapi_globals.h" 17 #include "ppapi/shared_impl/ppapi_globals.h"
18 #include "ppapi/shared_impl/ppb_device_ref_shared.h" 18 #include "ppapi/shared_impl/ppb_device_ref_shared.h"
19 #include "ppapi/shared_impl/resource_tracker.h" 19 #include "ppapi/shared_impl/resource_tracker.h"
20 #include "ppapi/shared_impl/tracked_callback.h" 20 #include "ppapi/shared_impl/tracked_callback.h"
21 #include "ppapi/thunk/enter.h" 21 #include "ppapi/thunk/enter.h"
22 #include "webkit/plugins/ppapi/common.h" 22 #include "webkit/plugins/ppapi/common.h"
23 #include "webkit/plugins/ppapi/plugin_module.h" 23 #include "webkit/plugins/ppapi/plugin_module.h"
24 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 24 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
25 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" 25 #include "webkit/plugins/ppapi/ppb_buffer_impl.h"
26 #include "webkit/plugins/ppapi/resource_helper.h" 26 #include "webkit/plugins/ppapi/resource_helper.h"
27 27
28 using ppapi::ApiCallbackType;
28 using ppapi::DeviceRefData; 29 using ppapi::DeviceRefData;
29 using ppapi::PpapiGlobals; 30 using ppapi::PpapiGlobals;
30 using ppapi::thunk::EnterResourceNoLock; 31 using ppapi::thunk::EnterResourceNoLock;
31 using ppapi::thunk::PPB_Buffer_API; 32 using ppapi::thunk::PPB_Buffer_API;
32 using ppapi::thunk::PPB_VideoCapture_API; 33 using ppapi::thunk::PPB_VideoCapture_API;
33 using ppapi::TrackedCallback; 34 using ppapi::TrackedCallback;
34 35
35 namespace { 36 namespace {
36 37
37 // Maximum number of buffers to actually allocate. 38 // Maximum number of buffers to actually allocate.
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 167
167 void PPB_VideoCapture_Impl::OnInitialized(media::VideoCapture* capture, 168 void PPB_VideoCapture_Impl::OnInitialized(media::VideoCapture* capture,
168 bool succeeded) { 169 bool succeeded) {
169 DCHECK(capture == platform_video_capture_.get()); 170 DCHECK(capture == platform_video_capture_.get());
170 171
171 OnOpenComplete(succeeded ? PP_OK : PP_ERROR_FAILED); 172 OnOpenComplete(succeeded ? PP_OK : PP_ERROR_FAILED);
172 } 173 }
173 174
174 int32_t PPB_VideoCapture_Impl::InternalEnumerateDevices( 175 int32_t PPB_VideoCapture_Impl::InternalEnumerateDevices(
175 PP_Resource* devices, 176 PP_Resource* devices,
176 const PP_CompletionCallback& callback) { 177 ApiCallbackType callback) {
177 PluginInstance* instance = ResourceHelper::GetPluginInstance(this); 178 PluginInstance* instance = ResourceHelper::GetPluginInstance(this);
178 if (!instance) 179 if (!instance)
179 return PP_ERROR_FAILED; 180 return PP_ERROR_FAILED;
180 181
181 devices_ = devices; 182 devices_ = devices;
182 enumerate_devices_callback_ = new TrackedCallback(this, callback); 183 enumerate_devices_callback_ = callback;
183 instance->delegate()->EnumerateDevices( 184 instance->delegate()->EnumerateDevices(
184 PP_DEVICETYPE_DEV_VIDEOCAPTURE, 185 PP_DEVICETYPE_DEV_VIDEOCAPTURE,
185 base::Bind(&PPB_VideoCapture_Impl::EnumerateDevicesCallbackFunc, 186 base::Bind(&PPB_VideoCapture_Impl::EnumerateDevicesCallbackFunc,
186 AsWeakPtr())); 187 AsWeakPtr()));
187 return PP_OK_COMPLETIONPENDING; 188 return PP_OK_COMPLETIONPENDING;
188 } 189 }
189 190
190 int32_t PPB_VideoCapture_Impl::InternalOpen( 191 int32_t PPB_VideoCapture_Impl::InternalOpen(
191 const std::string& device_id, 192 const std::string& device_id,
192 const PP_VideoCaptureDeviceInfo_Dev& requested_info, 193 const PP_VideoCaptureDeviceInfo_Dev& requested_info,
193 uint32_t buffer_count, 194 uint32_t buffer_count,
194 const PP_CompletionCallback& callback) { 195 ApiCallbackType callback) {
195 // It is able to complete synchronously if the default device is used. 196 // It is able to complete synchronously if the default device is used.
196 bool sync_completion = device_id.empty(); 197 bool sync_completion = device_id.empty();
197 198
198 if (!callback.func && !sync_completion)
199 return PP_ERROR_BLOCKS_MAIN_THREAD;
200
201 PluginInstance* instance = ResourceHelper::GetPluginInstance(this); 199 PluginInstance* instance = ResourceHelper::GetPluginInstance(this);
202 if (!instance) 200 if (!instance)
203 return PP_ERROR_FAILED; 201 return PP_ERROR_FAILED;
204 202
205 SetRequestedInfo(requested_info, buffer_count); 203 SetRequestedInfo(requested_info, buffer_count);
206 204
207 DCHECK(!platform_video_capture_.get()); 205 DCHECK(!platform_video_capture_.get());
208 platform_video_capture_ = 206 platform_video_capture_ =
209 instance->delegate()->CreateVideoCapture(device_id, this); 207 instance->delegate()->CreateVideoCapture(device_id, this);
210 208
211 if (sync_completion) { 209 if (sync_completion) {
212 OnInitialized(platform_video_capture_.get(), true); 210 OnInitialized(platform_video_capture_.get(), true);
213 return PP_OK; 211 return PP_OK;
214 } else { 212 } else {
215 open_callback_ = new TrackedCallback(this, callback); 213 open_callback_ = callback;
216 return PP_OK_COMPLETIONPENDING; 214 return PP_OK_COMPLETIONPENDING;
217 } 215 }
218 } 216 }
219 217
220 int32_t PPB_VideoCapture_Impl::InternalStartCapture() { 218 int32_t PPB_VideoCapture_Impl::InternalStartCapture() {
221 DCHECK(buffers_.empty()); 219 DCHECK(buffers_.empty());
222 platform_video_capture_->StartCapture(this, capability_); 220 platform_video_capture_->StartCapture(this, capability_);
223 return PP_OK; 221 return PP_OK;
224 } 222 }
225 223
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 : in_use(false), 316 : in_use(false),
319 data(NULL), 317 data(NULL),
320 buffer() { 318 buffer() {
321 } 319 }
322 320
323 PPB_VideoCapture_Impl::BufferInfo::~BufferInfo() { 321 PPB_VideoCapture_Impl::BufferInfo::~BufferInfo() {
324 } 322 }
325 323
326 } // namespace ppapi 324 } // namespace ppapi
327 } // namespace webkit 325 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698