Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(306)

Side by Side Diff: content/browser/renderer_host/media/service_video_capture_provider.cc

Issue 2848973002: [Mojo Video Capture] Implement a VideoCaptureProvider using the Mojo service (part 1) (Closed)
Patch Set: Incorporated mcasas@'s suggestions from PatchSet 3 Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 content {
14
15 ServiceVideoCaptureProvider::ServiceVideoCaptureProvider() {
16 thread_checker_.DetachFromThread();
17 DCHECK(BrowserThread::CurrentlyOn(content::BrowserThread::UI));
18 connector_ =
19 ServiceManagerConnection::GetForProcess()->GetConnector()->Clone();
20 }
21
22 ServiceVideoCaptureProvider::~ServiceVideoCaptureProvider() {
23 DCHECK(thread_checker_.CalledOnValidThread());
24 }
25
26 void ServiceVideoCaptureProvider::Uninitialize() {
27 DCHECK(thread_checker_.CalledOnValidThread());
28 device_factory_.reset();
29 device_factory_provider_.reset();
30 }
31
32 void ServiceVideoCaptureProvider::GetDeviceInfosAsync(
33 const base::Callback<void(
34 const std::vector<media::VideoCaptureDeviceInfo>&)>& result_callback) {
35 DCHECK(thread_checker_.CalledOnValidThread());
36 LazyConnectToService();
37 device_factory_->GetDeviceInfos(result_callback);
38 }
39
40 std::unique_ptr<VideoCaptureDeviceLauncher>
41 ServiceVideoCaptureProvider::CreateDeviceLauncher() {
42 DCHECK(thread_checker_.CalledOnValidThread());
43 LazyConnectToService();
44 return base::MakeUnique<ServiceVideoCaptureDeviceLauncher>(&device_factory_);
45 }
46
47 void ServiceVideoCaptureProvider::LazyConnectToService() {
48 if (device_factory_provider_.is_bound())
49 return;
50
51 connector_->BindInterface(video_capture::mojom::kServiceName,
52 &device_factory_provider_);
53 device_factory_provider_->ConnectToDeviceFactory(
54 mojo::MakeRequest(&device_factory_));
55 // Unretained |this| is safe, because |this| owns |device_factory_|.
56 device_factory_.set_connection_error_handler(
57 base::Bind(&ServiceVideoCaptureProvider::OnLostConnectionToDeviceFactory,
58 base::Unretained(this)));
59 }
60
61 void ServiceVideoCaptureProvider::OnLostConnectionToDeviceFactory() {
62 DCHECK(thread_checker_.CalledOnValidThread());
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
65 // reconnect.
66 Uninitialize();
67 }
68
69 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698