OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/browser/renderer_host/media/service_video_capture_provider.h" | |
6 | |
7 #include "content/browser/renderer_host/media/service_video_capture_device_launc her.h" | |
8 #include "content/public/browser/browser_thread.h" | |
9 #include "content/public/common/service_manager_connection.h" | |
10 #include "services/service_manager/public/cpp/connector.h" | |
11 #include "services/video_capture/public/interfaces/constants.mojom.h" | |
12 | |
13 namespace { | |
14 | |
15 void BindToBrowserConnector(service_manager::mojom::ConnectorRequest request) { | |
16 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { | |
17 content::BrowserThread::PostTask( | |
18 content::BrowserThread::UI, FROM_HERE, | |
19 base::Bind(&BindToBrowserConnector, base::Passed(&request))); | |
20 return; | |
21 } | |
22 | |
23 content::ServiceManagerConnection::GetForProcess() | |
24 ->GetConnector() | |
25 ->BindConnectorRequest(std::move(request)); | |
26 } | |
27 | |
28 } // 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
| |
29 | |
30 namespace content { | |
31 | |
32 ServiceVideoCaptureProvider::ServiceVideoCaptureProvider() = default; | |
33 | |
34 ServiceVideoCaptureProvider::~ServiceVideoCaptureProvider() { | |
35 DCHECK(thread_checker_.CalledOnValidThread()); | |
36 } | |
37 | |
38 void ServiceVideoCaptureProvider::Uninitialize() { | |
39 DCHECK(thread_checker_.CalledOnValidThread()); | |
40 device_factory_.reset(); | |
41 device_factory_provider_.reset(); | |
42 } | |
43 | |
44 void ServiceVideoCaptureProvider::GetDeviceInfosAsync( | |
45 const base::Callback<void( | |
46 const std::vector<media::VideoCaptureDeviceInfo>&)>& result_callback) { | |
47 DCHECK(thread_checker_.CalledOnValidThread()); | |
48 LazyConnectToService(); | |
49 device_factory_->GetDeviceInfos(result_callback); | |
50 } | |
51 | |
52 std::unique_ptr<VideoCaptureDeviceLauncher> | |
53 ServiceVideoCaptureProvider::CreateDeviceLauncher() { | |
54 DCHECK(thread_checker_.CalledOnValidThread()); | |
55 LazyConnectToService(); | |
56 return base::MakeUnique<ServiceVideoCaptureDeviceLauncher>(&device_factory_); | |
57 } | |
58 | |
59 void ServiceVideoCaptureProvider::LazyConnectToService() { | |
60 if (device_factory_provider_.is_bound()) | |
61 return; | |
62 | |
63 service_manager::mojom::ConnectorRequest connector_request; | |
64 std::unique_ptr<service_manager::Connector> connector = | |
65 service_manager::Connector::Create(&connector_request); | |
66 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.
| |
67 | |
68 connector->BindInterface(video_capture::mojom::kServiceName, | |
69 &device_factory_provider_); | |
70 device_factory_provider_->ConnectToDeviceFactory( | |
71 mojo::MakeRequest(&device_factory_)); | |
72 // Unretained |this| is safe, because |this| owns |device_factory_|. | |
73 device_factory_.set_connection_error_handler( | |
74 base::Bind(&ServiceVideoCaptureProvider::OnLostConnectionToDeviceFactory, | |
75 base::Unretained(this))); | |
76 } | |
77 | |
78 void ServiceVideoCaptureProvider::OnLostConnectionToDeviceFactory() { | |
79 DCHECK(thread_checker_.CalledOnValidThread()); | |
80 // This may indicate that the video capture service has crashed. Uninitialize | |
81 // here, so that a new connection will be established when clients try to | |
82 // reconnect. | |
83 Uninitialize(); | |
84 } | |
85 | |
86 } // namespace content | |
OLD | NEW |