Chromium Code Reviews| Index: content/browser/media/capture/image_capture_impl.cc |
| diff --git a/content/browser/media/capture/image_capture_impl.cc b/content/browser/media/capture/image_capture_impl.cc |
| index bfc8b0d0aec9be4af5c1e59d29aeb5512a03753b..1722a4f3a59c4622915872f4099bab3c91fc0e2d 100644 |
| --- a/content/browser/media/capture/image_capture_impl.cc |
| +++ b/content/browser/media/capture/image_capture_impl.cc |
| @@ -5,10 +5,52 @@ |
| #include "content/browser/media/capture/image_capture_impl.h" |
| #include "base/bind_helpers.h" |
| +#include "content/browser/browser_main_loop.h" |
| +#include "content/browser/renderer_host/media/media_stream_manager.h" |
| +#include "content/browser/renderer_host/media/video_capture_manager.h" |
| +#include "content/common/media/media_stream_options.h" |
| #include "content/public/browser/browser_thread.h" |
| +#include "media/capture/video/video_capture_device.h" |
| namespace content { |
| +namespace { |
| + |
| +void RunMojoCallback(const ImageCaptureImpl::TakePhotoCallback& callback, |
| + const std::string& mime_type, |
| + mojo::Array<uint8_t> data) { |
|
tommi (sloooow) - chröme
2016/05/09 11:17:32
just checking - this is moved and not copied, righ
mcasas
2016/05/09 16:48:40
Yeah, mojo::Array is a moveable-not-copyable type
|
| + callback.Run(mime_type, std::move(data)); |
| +} |
| + |
| +void RunTakePhotoCallback(const ImageCaptureImpl::TakePhotoCallback& callback, |
| + const std::string& mime_type, |
| + std::unique_ptr<std::vector<uint8_t>> data) { |
| + DCHECK(data.get()); |
| + BrowserThread::PostTask( |
| + BrowserThread::UI, FROM_HERE, |
| + base::Bind(&RunMojoCallback, callback, mime_type, |
| + base::Passed(mojo::Array<uint8_t>::From(*data)))); |
|
tommi (sloooow) - chröme
2016/05/09 11:17:32
if you find that the array is actually copied, con
mcasas
2016/05/09 16:48:40
Acknowledged.
|
| +} |
| + |
| +void TakePhotoOnIOThread(const mojo::String& source_id, |
| + const ImageCaptureImpl::TakePhotoCallback& callback, |
| + MediaStreamManager* media_stream_manager) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + |
| + const int session_id = |
| + media_stream_manager->VideoDeviceIdToSessionId(source_id); |
| + |
| + if (session_id == StreamDeviceInfo::kNoId || |
| + !media_stream_manager->video_capture_manager()->TakePhoto( |
| + session_id, base::Bind(&RunTakePhotoCallback, callback))) { |
| + std::unique_ptr<std::vector<uint8_t>> empty_vector( |
| + new std::vector<uint8_t>()); |
| + RunTakePhotoCallback(callback, "", std::move(empty_vector)); |
| + } |
| +} |
| + |
| +} // anonymous namespace |
| + |
| // static |
| void ImageCaptureImpl::Create( |
| mojo::InterfaceRequest<blink::mojom::ImageCapture> request) { |
| @@ -18,13 +60,14 @@ void ImageCaptureImpl::Create( |
| ImageCaptureImpl::~ImageCaptureImpl() {} |
| -void ImageCaptureImpl::TakePhoto(const mojo::String& /* source_id */, |
| +void ImageCaptureImpl::TakePhoto(const mojo::String& source_id, |
| const TakePhotoCallback& callback) { |
| DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| - |
| - // TODO(mcasas): Implement this feature., https://crbug.com/518807. |
| - mojo::Array<uint8_t> data(1); |
| - callback.Run("text/plain", std::move(data)); |
| + // media_stream_manager() can only be called on UI thread. |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, FROM_HERE, |
| + base::Bind(&TakePhotoOnIOThread, source_id, callback, |
| + BrowserMainLoop::GetInstance()->media_stream_manager())); |
| } |
| ImageCaptureImpl::ImageCaptureImpl( |