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/mojo_service_video_capture_provide r.h" | |
6 | |
7 #include "content/browser/renderer_host/media/mojo_service_video_capture_device_ launcher.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 | |
29 | |
30 namespace content { | |
31 | |
32 MojoServiceVideoCaptureProvider::MojoServiceVideoCaptureProvider() = default; | |
33 | |
34 MojoServiceVideoCaptureProvider::~MojoServiceVideoCaptureProvider() { | |
35 DCHECK(thread_checker_.CalledOnValidThread()); | |
36 } | |
37 | |
38 void MojoServiceVideoCaptureProvider::Uninitialize() { | |
39 DCHECK(thread_checker_.CalledOnValidThread()); | |
40 device_factory_.reset(); | |
41 device_factory_provider_.reset(); | |
42 } | |
43 | |
44 void MojoServiceVideoCaptureProvider::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 MojoServiceVideoCaptureProvider::CreateDeviceLauncher() { | |
54 DCHECK(thread_checker_.CalledOnValidThread()); | |
55 LazyConnectToService(); | |
56 return base::MakeUnique<MojoServiceVideoCaptureDeviceLauncher>( | |
57 &device_factory_); | |
58 } | |
59 | |
60 void MojoServiceVideoCaptureProvider::LazyConnectToService() { | |
61 if (device_factory_provider_.is_bound()) | |
62 return; | |
63 | |
64 service_manager::mojom::ConnectorRequest connector_request; | |
65 std::unique_ptr<service_manager::Connector> connector = | |
66 service_manager::Connector::Create(&connector_request); | |
67 BindToBrowserConnector(std::move(connector_request)); | |
68 | |
69 connector->BindInterface(video_capture::mojom::kServiceName, | |
70 &device_factory_provider_); | |
71 device_factory_provider_->ConnectToDeviceFactory( | |
72 mojo::MakeRequest(&device_factory_)); | |
73 // Unretained |this| is safe, because |this| owns |device_factory_|. | |
74 device_factory_.set_connection_error_handler(base::Bind( | |
75 &MojoServiceVideoCaptureProvider::OnLostConnectionToDeviceFactory, | |
76 base::Unretained(this))); | |
77 } | |
78 | |
79 void MojoServiceVideoCaptureProvider::OnLostConnectionToDeviceFactory() { | |
80 DCHECK(thread_checker_.CalledOnValidThread()); | |
81 // This may indicate that the video capture service has | |
82 // crashed. Uninitialize here, so that a new connection will be established | |
83 // clients try to reconnect. | |
mcasas
2017/05/02 01:06:23
nit: Reflow text?
chfremer
2017/05/02 16:36:42
Done.
| |
84 Uninitialize(); | |
85 } | |
86 | |
87 } // namespace content | |
OLD | NEW |