Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "content/browser/media/capture/image_capture_impl.h" | 5 #include "content/browser/media/capture/image_capture_impl.h" |
| 6 | 6 |
| 7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
| 8 #include "content/browser/browser_main_loop.h" | |
| 9 #include "content/browser/renderer_host/media/media_stream_manager.h" | |
| 10 #include "content/browser/renderer_host/media/video_capture_manager.h" | |
| 11 #include "content/common/media/media_stream_options.h" | |
| 8 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 13 #include "media/capture/video/video_capture_device.h" | |
| 9 | 14 |
| 10 namespace content { | 15 namespace content { |
| 11 | 16 |
| 17 namespace { | |
| 18 | |
| 19 void RunMojoCallback(const ImageCaptureImpl::TakePhotoCallback& callback, | |
| 20 const std::string& mime_type, | |
| 21 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
| |
| 22 callback.Run(mime_type, std::move(data)); | |
| 23 } | |
| 24 | |
| 25 void RunTakePhotoCallback(const ImageCaptureImpl::TakePhotoCallback& callback, | |
| 26 const std::string& mime_type, | |
| 27 std::unique_ptr<std::vector<uint8_t>> data) { | |
| 28 DCHECK(data.get()); | |
| 29 BrowserThread::PostTask( | |
| 30 BrowserThread::UI, FROM_HERE, | |
| 31 base::Bind(&RunMojoCallback, callback, mime_type, | |
| 32 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.
| |
| 33 } | |
| 34 | |
| 35 void TakePhotoOnIOThread(const mojo::String& source_id, | |
| 36 const ImageCaptureImpl::TakePhotoCallback& callback, | |
| 37 MediaStreamManager* media_stream_manager) { | |
| 38 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 39 | |
| 40 const int session_id = | |
| 41 media_stream_manager->VideoDeviceIdToSessionId(source_id); | |
| 42 | |
| 43 if (session_id == StreamDeviceInfo::kNoId || | |
| 44 !media_stream_manager->video_capture_manager()->TakePhoto( | |
| 45 session_id, base::Bind(&RunTakePhotoCallback, callback))) { | |
| 46 std::unique_ptr<std::vector<uint8_t>> empty_vector( | |
| 47 new std::vector<uint8_t>()); | |
| 48 RunTakePhotoCallback(callback, "", std::move(empty_vector)); | |
| 49 } | |
| 50 } | |
| 51 | |
| 52 } // anonymous namespace | |
| 53 | |
| 12 // static | 54 // static |
| 13 void ImageCaptureImpl::Create( | 55 void ImageCaptureImpl::Create( |
| 14 mojo::InterfaceRequest<blink::mojom::ImageCapture> request) { | 56 mojo::InterfaceRequest<blink::mojom::ImageCapture> request) { |
| 15 // |binding_| will take ownership of ImageCaptureImpl. | 57 // |binding_| will take ownership of ImageCaptureImpl. |
| 16 new ImageCaptureImpl(std::move(request)); | 58 new ImageCaptureImpl(std::move(request)); |
| 17 } | 59 } |
| 18 | 60 |
| 19 ImageCaptureImpl::~ImageCaptureImpl() {} | 61 ImageCaptureImpl::~ImageCaptureImpl() {} |
| 20 | 62 |
| 21 void ImageCaptureImpl::TakePhoto(const mojo::String& /* source_id */, | 63 void ImageCaptureImpl::TakePhoto(const mojo::String& source_id, |
| 22 const TakePhotoCallback& callback) { | 64 const TakePhotoCallback& callback) { |
| 23 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 65 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 24 | 66 // media_stream_manager() can only be called on UI thread. |
| 25 // TODO(mcasas): Implement this feature., https://crbug.com/518807. | 67 BrowserThread::PostTask( |
| 26 mojo::Array<uint8_t> data(1); | 68 BrowserThread::IO, FROM_HERE, |
| 27 callback.Run("text/plain", std::move(data)); | 69 base::Bind(&TakePhotoOnIOThread, source_id, callback, |
| 70 BrowserMainLoop::GetInstance()->media_stream_manager())); | |
| 28 } | 71 } |
| 29 | 72 |
| 30 ImageCaptureImpl::ImageCaptureImpl( | 73 ImageCaptureImpl::ImageCaptureImpl( |
| 31 mojo::InterfaceRequest<blink::mojom::ImageCapture> request) | 74 mojo::InterfaceRequest<blink::mojom::ImageCapture> request) |
| 32 : binding_(this, std::move(request)) {} | 75 : binding_(this, std::move(request)) {} |
| 33 | 76 |
| 34 } // namespace content | 77 } // namespace content |
| OLD | NEW |