Chromium Code Reviews| Index: content/browser/renderer_host/media/service_video_capture_provider.cc |
| diff --git a/content/browser/renderer_host/media/service_video_capture_provider.cc b/content/browser/renderer_host/media/service_video_capture_provider.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9dca9a01d65999d1e91b7ffd3a4c3f7eb5d9675b |
| --- /dev/null |
| +++ b/content/browser/renderer_host/media/service_video_capture_provider.cc |
| @@ -0,0 +1,86 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/browser/renderer_host/media/service_video_capture_provider.h" |
| + |
| +#include "content/browser/renderer_host/media/service_video_capture_device_launcher.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "content/public/common/service_manager_connection.h" |
| +#include "services/service_manager/public/cpp/connector.h" |
| +#include "services/video_capture/public/interfaces/constants.mojom.h" |
| + |
| +namespace { |
| + |
| +void BindToBrowserConnector(service_manager::mojom::ConnectorRequest request) { |
| + if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { |
| + content::BrowserThread::PostTask( |
| + content::BrowserThread::UI, FROM_HERE, |
| + base::Bind(&BindToBrowserConnector, base::Passed(&request))); |
| + return; |
| + } |
| + |
| + content::ServiceManagerConnection::GetForProcess() |
| + ->GetConnector() |
| + ->BindConnectorRequest(std::move(request)); |
| +} |
| + |
| +} // namespace |
|
mcasas
2017/05/03 19:10:23
IIRC in content/ these anonymous namespaces
are su
chfremer
2017/05/03 21:29:36
Oh. This is confusing. I'll try to remember it.
Lu
|
| + |
| +namespace content { |
| + |
| +ServiceVideoCaptureProvider::ServiceVideoCaptureProvider() = default; |
| + |
| +ServiceVideoCaptureProvider::~ServiceVideoCaptureProvider() { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| +} |
| + |
| +void ServiceVideoCaptureProvider::Uninitialize() { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + device_factory_.reset(); |
| + device_factory_provider_.reset(); |
| +} |
| + |
| +void ServiceVideoCaptureProvider::GetDeviceInfosAsync( |
| + const base::Callback<void( |
| + const std::vector<media::VideoCaptureDeviceInfo>&)>& result_callback) { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + LazyConnectToService(); |
| + device_factory_->GetDeviceInfos(result_callback); |
| +} |
| + |
| +std::unique_ptr<VideoCaptureDeviceLauncher> |
| +ServiceVideoCaptureProvider::CreateDeviceLauncher() { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + LazyConnectToService(); |
| + return base::MakeUnique<ServiceVideoCaptureDeviceLauncher>(&device_factory_); |
| +} |
| + |
| +void ServiceVideoCaptureProvider::LazyConnectToService() { |
| + if (device_factory_provider_.is_bound()) |
| + return; |
| + |
| + service_manager::mojom::ConnectorRequest connector_request; |
| + std::unique_ptr<service_manager::Connector> connector = |
| + service_manager::Connector::Create(&connector_request); |
| + BindToBrowserConnector(std::move(connector_request)); |
|
Ken Rockot(use gerrit already)
2017/05/03 17:59:46
Can ServiceVideoCaptureProvider actually be create
chfremer
2017/05/03 18:29:09
This is not going to be visible and tested before
Ken Rockot(use gerrit already)
2017/05/03 18:32:19
I see. You can probably simply things a bit then,
chfremer
2017/05/03 21:29:36
Done.
|
| + |
| + connector->BindInterface(video_capture::mojom::kServiceName, |
| + &device_factory_provider_); |
| + device_factory_provider_->ConnectToDeviceFactory( |
| + mojo::MakeRequest(&device_factory_)); |
| + // Unretained |this| is safe, because |this| owns |device_factory_|. |
| + device_factory_.set_connection_error_handler( |
| + base::Bind(&ServiceVideoCaptureProvider::OnLostConnectionToDeviceFactory, |
| + base::Unretained(this))); |
| +} |
| + |
| +void ServiceVideoCaptureProvider::OnLostConnectionToDeviceFactory() { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + // This may indicate that the video capture service has crashed. Uninitialize |
| + // here, so that a new connection will be established when clients try to |
| + // reconnect. |
| + Uninitialize(); |
| +} |
| + |
| +} // namespace content |