Chromium Code Reviews| Index: services/video_capture/video_capture_device_factory_impl.cc |
| diff --git a/services/video_capture/video_capture_device_factory_impl.cc b/services/video_capture/video_capture_device_factory_impl.cc |
| index 045441537a9d483f907dcf02bf269efddd06a3df..3a240debb41d0c31ace3c4a71420ec7a5a5a1e39 100644 |
| --- a/services/video_capture/video_capture_device_factory_impl.cc |
| +++ b/services/video_capture/video_capture_device_factory_impl.cc |
| @@ -2,15 +2,71 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +#include <sstream> |
| + |
| #include "base/logging.h" |
| +#include "base/strings/stringprintf.h" |
| #include "services/video_capture/video_capture_device_factory_impl.h" |
| +namespace { |
| +static const char kFakeDeviceDisplayName[] = "Fake Video Capture Device"; |
| +static const char kFakeDeviceId[] = "FakeDeviceId"; |
| +static const char kFakeModelId[] = "FakeModelId"; |
| +} |
| + |
| namespace video_capture { |
| +VideoCaptureDeviceFactoryImpl::DeviceEntry::DeviceEntry( |
| + mojom::VideoCaptureDeviceDescriptorPtr descriptor, |
| + std::unique_ptr<VideoCaptureDeviceImpl> bindable_target) |
| + : descriptor_(std::move(descriptor)) { |
| + device_ = std::move(bindable_target); |
|
yzshen1
2016/08/16 17:55:08
do it in the initialization list?
chfremer
2016/08/16 18:34:40
Done.
|
| +} |
| + |
| +VideoCaptureDeviceFactoryImpl::DeviceEntry::~DeviceEntry() = default; |
| + |
| +VideoCaptureDeviceFactoryImpl::DeviceEntry::DeviceEntry( |
| + VideoCaptureDeviceFactoryImpl::DeviceEntry&& other) = default; |
| + |
| +VideoCaptureDeviceFactoryImpl::DeviceEntry& |
| +VideoCaptureDeviceFactoryImpl::DeviceEntry::operator=( |
| + VideoCaptureDeviceFactoryImpl::DeviceEntry&& other) = default; |
| + |
| +mojom::VideoCaptureDeviceDescriptorPtr |
| +VideoCaptureDeviceFactoryImpl::DeviceEntry::MakeDescriptorCopy() const { |
| + return descriptor_.Clone(); |
| +} |
| + |
| +VideoCaptureDeviceFactoryImpl::VideoCaptureDeviceFactoryImpl() |
| + : fake_device_count_(0) {} |
| + |
| +VideoCaptureDeviceFactoryImpl::~VideoCaptureDeviceFactoryImpl() = default; |
| + |
| +mojom::VideoCaptureDeviceDescriptorPtr |
| +VideoCaptureDeviceFactoryImpl::AddFakeVideoCaptureDevice() { |
| + auto fake_device_descriptor = mojom::VideoCaptureDeviceDescriptor::New(); |
| + fake_device_descriptor->display_name = |
| + base::StringPrintf("%s (%d)", kFakeDeviceDisplayName, fake_device_count_); |
| + std::ostringstream display_name_oss; |
| + fake_device_descriptor->device_id = |
| + base::StringPrintf("%s_%d", kFakeDeviceId, fake_device_count_); |
| + fake_device_descriptor->model_id = kFakeModelId; |
| + fake_device_descriptor->capture_api = mojom::VideoCaptureApi::UNKNOWN; |
| + fake_device_descriptor->transport_type = |
| + mojom::VideoCaptureTransportType::OTHER_TRANSPORT; |
| + devices_.emplace_back(fake_device_descriptor->Clone(), |
| + base::MakeUnique<VideoCaptureDeviceImpl>()); |
| + |
| + fake_device_count_++; |
| + return fake_device_descriptor; |
| +} |
| + |
| void VideoCaptureDeviceFactoryImpl::EnumerateDeviceDescriptors( |
| const EnumerateDeviceDescriptorsCallback& callback) { |
| - std::vector<mojom::VideoCaptureDeviceDescriptorPtr> empty_descriptors; |
| - callback.Run(std::move(empty_descriptors)); |
| + std::vector<mojom::VideoCaptureDeviceDescriptorPtr> descriptors; |
| + for (const auto& entry : devices_) |
| + descriptors.push_back(entry.MakeDescriptorCopy()); |
| + callback.Run(std::move(descriptors)); |
| } |
| void VideoCaptureDeviceFactoryImpl::GetSupportedFormats( |
| @@ -21,8 +77,9 @@ void VideoCaptureDeviceFactoryImpl::GetSupportedFormats( |
| void VideoCaptureDeviceFactoryImpl::CreateDevice( |
| mojom::VideoCaptureDeviceDescriptorPtr device_descriptor, |
| - mojom::VideoCaptureDeviceRequest device_request) { |
| - NOTIMPLEMENTED(); |
| + mojom::VideoCaptureDeviceRequest request, |
| + const CreateDeviceCallback& callback) { |
| + callback.Run(mojom::DeviceAccessResultCode::SUCCESS); |
| } |
| } // namespace video_capture |