| 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" | 8 #include "content/browser/browser_main_loop.h" |
| 9 #include "content/browser/renderer_host/media/media_stream_manager.h" | 9 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 10 #include "content/browser/renderer_host/media/video_capture_manager.h" | 10 #include "content/browser/renderer_host/media/video_capture_manager.h" |
| 11 #include "content/common/media/media_stream_options.h" | 11 #include "content/common/media/media_stream_options.h" |
| 12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 13 #include "media/base/bind_to_current_loop.h" | 13 #include "media/base/bind_to_current_loop.h" |
| 14 #include "media/capture/video/video_capture_device.h" | 14 #include "media/capture/video/video_capture_device.h" |
| 15 | 15 |
| 16 namespace content { | 16 namespace content { |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 template<typename R, typename... Args> |
| 21 void RunMojoCallback(const mojo::Callback<R(Args...)>& callback, Args... args) { |
| 22 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 23 callback.Run(std::forward<Args>(args)...); |
| 24 } |
| 25 |
| 20 void RunFailedGetCapabilitiesCallback( | 26 void RunFailedGetCapabilitiesCallback( |
| 21 const ImageCaptureImpl::GetCapabilitiesCallback& cb) { | 27 const ImageCaptureImpl::GetCapabilitiesCallback& cb) { |
| 22 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 28 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 23 media::mojom::PhotoCapabilitiesPtr empty_capabilities = | 29 media::mojom::PhotoCapabilitiesPtr empty_capabilities = |
| 24 media::mojom::PhotoCapabilities::New(); | 30 media::mojom::PhotoCapabilities::New(); |
| 25 empty_capabilities->zoom = media::mojom::Range::New(); | 31 empty_capabilities->zoom = media::mojom::Range::New(); |
| 26 cb.Run(std::move(empty_capabilities)); | 32 cb.Run(std::move(empty_capabilities)); |
| 27 } | 33 } |
| 28 | 34 |
| 29 void RunTakePhotoCallbackOnUIThread( | 35 void RunTakePhotoCallbackOnUIThread( |
| 30 const ImageCaptureImpl::TakePhotoCallback& callback, | 36 const ImageCaptureImpl::TakePhotoCallback& callback, |
| 31 mojo::String mime_type, | 37 mojo::String mime_type, |
| 32 mojo::Array<uint8_t> data) { | 38 mojo::Array<uint8_t> data) { |
| 33 BrowserThread::PostTask( | 39 BrowserThread::PostTask( |
| 34 BrowserThread::UI, FROM_HERE, | 40 BrowserThread::UI, FROM_HERE, |
| 35 base::Bind(callback, mime_type, base::Passed(std::move(data)))); | 41 base::Bind(&RunMojoCallback<void, mojo::String, mojo::Array<uint8_t>>, |
| 42 callback, mime_type, base::Passed(std::move(data)))); |
| 36 } | 43 } |
| 37 | 44 |
| 38 void RunFailedTakePhotoCallback(const ImageCaptureImpl::TakePhotoCallback& cb) { | 45 void RunFailedTakePhotoCallback(const ImageCaptureImpl::TakePhotoCallback& cb) { |
| 39 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 46 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 40 cb.Run("", mojo::Array<uint8_t>()); | 47 cb.Run("", mojo::Array<uint8_t>()); |
| 41 } | 48 } |
| 42 | 49 |
| 43 void TakePhotoOnIOThread( | 50 void TakePhotoOnIOThread( |
| 44 const mojo::String& source_id, | 51 const mojo::String& source_id, |
| 45 MediaStreamManager* media_stream_manager, | 52 MediaStreamManager* media_stream_manager, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 base::Bind(&TakePhotoOnIOThread, source_id, | 107 base::Bind(&TakePhotoOnIOThread, source_id, |
| 101 BrowserMainLoop::GetInstance()->media_stream_manager(), | 108 BrowserMainLoop::GetInstance()->media_stream_manager(), |
| 102 base::Passed(&scoped_callback))); | 109 base::Passed(&scoped_callback))); |
| 103 } | 110 } |
| 104 | 111 |
| 105 ImageCaptureImpl::ImageCaptureImpl( | 112 ImageCaptureImpl::ImageCaptureImpl( |
| 106 mojo::InterfaceRequest<media::mojom::ImageCapture> request) | 113 mojo::InterfaceRequest<media::mojom::ImageCapture> request) |
| 107 : binding_(this, std::move(request)) {} | 114 : binding_(this, std::move(request)) {} |
| 108 | 115 |
| 109 } // namespace content | 116 } // namespace content |
| OLD | NEW |