OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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/renderer_host/media/service_video_capture_provider.h" | 5 #include "content/browser/renderer_host/media/service_video_capture_provider.h" |
6 | 6 |
7 #include "content/browser/renderer_host/media/service_video_capture_device_launc
her.h" | 7 #include "content/browser/renderer_host/media/service_video_capture_device_launc
her.h" |
8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
9 #include "content/public/common/service_manager_connection.h" | 9 #include "content/public/common/service_manager_connection.h" |
10 #include "services/service_manager/public/cpp/connector.h" | 10 #include "services/service_manager/public/cpp/connector.h" |
11 #include "services/video_capture/public/interfaces/constants.mojom.h" | 11 #include "services/video_capture/public/interfaces/constants.mojom.h" |
12 | 12 |
13 namespace content { | 13 namespace content { |
14 | 14 |
15 ServiceVideoCaptureProvider::ServiceVideoCaptureProvider() { | 15 ServiceVideoCaptureProvider::ServiceVideoCaptureProvider() { |
16 thread_checker_.DetachFromThread(); | 16 sequence_checker_.DetachFromSequence(); |
17 DCHECK(BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 17 DCHECK(BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
18 connector_ = | 18 connector_ = |
19 ServiceManagerConnection::GetForProcess()->GetConnector()->Clone(); | 19 ServiceManagerConnection::GetForProcess()->GetConnector()->Clone(); |
20 } | 20 } |
21 | 21 |
22 ServiceVideoCaptureProvider::~ServiceVideoCaptureProvider() { | 22 ServiceVideoCaptureProvider::~ServiceVideoCaptureProvider() { |
23 DCHECK(thread_checker_.CalledOnValidThread()); | 23 DCHECK(sequence_checker_.CalledOnValidSequence()); |
24 } | 24 } |
25 | 25 |
26 void ServiceVideoCaptureProvider::Uninitialize() { | 26 void ServiceVideoCaptureProvider::Uninitialize() { |
27 DCHECK(thread_checker_.CalledOnValidThread()); | 27 DCHECK(sequence_checker_.CalledOnValidSequence()); |
28 device_factory_.reset(); | 28 device_factory_.reset(); |
29 device_factory_provider_.reset(); | 29 device_factory_provider_.reset(); |
30 } | 30 } |
31 | 31 |
32 void ServiceVideoCaptureProvider::GetDeviceInfosAsync( | 32 void ServiceVideoCaptureProvider::GetDeviceInfosAsync( |
33 const base::Callback<void( | 33 const base::Callback<void( |
34 const std::vector<media::VideoCaptureDeviceInfo>&)>& result_callback) { | 34 const std::vector<media::VideoCaptureDeviceInfo>&)>& result_callback) { |
35 DCHECK(thread_checker_.CalledOnValidThread()); | 35 DCHECK(sequence_checker_.CalledOnValidSequence()); |
36 LazyConnectToService(); | 36 LazyConnectToService(); |
37 device_factory_->GetDeviceInfos(result_callback); | 37 device_factory_->GetDeviceInfos(result_callback); |
38 } | 38 } |
39 | 39 |
40 std::unique_ptr<VideoCaptureDeviceLauncher> | 40 std::unique_ptr<VideoCaptureDeviceLauncher> |
41 ServiceVideoCaptureProvider::CreateDeviceLauncher() { | 41 ServiceVideoCaptureProvider::CreateDeviceLauncher() { |
42 DCHECK(thread_checker_.CalledOnValidThread()); | 42 DCHECK(sequence_checker_.CalledOnValidSequence()); |
43 LazyConnectToService(); | 43 LazyConnectToService(); |
44 return base::MakeUnique<ServiceVideoCaptureDeviceLauncher>(&device_factory_); | 44 return base::MakeUnique<ServiceVideoCaptureDeviceLauncher>(&device_factory_); |
45 } | 45 } |
46 | 46 |
47 void ServiceVideoCaptureProvider::LazyConnectToService() { | 47 void ServiceVideoCaptureProvider::LazyConnectToService() { |
48 if (device_factory_provider_.is_bound()) | 48 if (device_factory_provider_.is_bound()) |
49 return; | 49 return; |
50 | 50 |
51 connector_->BindInterface(video_capture::mojom::kServiceName, | 51 connector_->BindInterface(video_capture::mojom::kServiceName, |
52 &device_factory_provider_); | 52 &device_factory_provider_); |
53 device_factory_provider_->ConnectToDeviceFactory( | 53 device_factory_provider_->ConnectToDeviceFactory( |
54 mojo::MakeRequest(&device_factory_)); | 54 mojo::MakeRequest(&device_factory_)); |
55 // Unretained |this| is safe, because |this| owns |device_factory_|. | 55 // Unretained |this| is safe, because |this| owns |device_factory_|. |
56 device_factory_.set_connection_error_handler( | 56 device_factory_.set_connection_error_handler( |
57 base::Bind(&ServiceVideoCaptureProvider::OnLostConnectionToDeviceFactory, | 57 base::Bind(&ServiceVideoCaptureProvider::OnLostConnectionToDeviceFactory, |
58 base::Unretained(this))); | 58 base::Unretained(this))); |
59 } | 59 } |
60 | 60 |
61 void ServiceVideoCaptureProvider::OnLostConnectionToDeviceFactory() { | 61 void ServiceVideoCaptureProvider::OnLostConnectionToDeviceFactory() { |
62 DCHECK(thread_checker_.CalledOnValidThread()); | 62 DCHECK(sequence_checker_.CalledOnValidSequence()); |
63 // This may indicate that the video capture service has crashed. Uninitialize | 63 // This may indicate that the video capture service has crashed. Uninitialize |
64 // here, so that a new connection will be established when clients try to | 64 // here, so that a new connection will be established when clients try to |
65 // reconnect. | 65 // reconnect. |
66 Uninitialize(); | 66 Uninitialize(); |
67 } | 67 } |
68 | 68 |
69 } // namespace content | 69 } // namespace content |
OLD | NEW |