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

Unified Diff: services/video_capture/device_factory_media_to_mojo_adapter.cc

Issue 2824883005: [Mojo Video Capture] Stop service when last client disconnects. (Closed)
Patch Set: Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: services/video_capture/device_factory_media_to_mojo_adapter.cc
diff --git a/services/video_capture/device_factory_media_to_mojo_adapter.cc b/services/video_capture/device_factory_media_to_mojo_adapter.cc
index 12b3a0083c4abe9265745da573b968be3e3be1f1..bdafa15c7498d81e7e92433042c526859094dfa2 100644
--- a/services/video_capture/device_factory_media_to_mojo_adapter.cc
+++ b/services/video_capture/device_factory_media_to_mojo_adapter.cc
@@ -79,11 +79,14 @@ DeviceFactoryMediaToMojoAdapter::ActiveDeviceEntry::operator=(
DeviceFactoryMediaToMojoAdapter::ActiveDeviceEntry&& other) = default;
DeviceFactoryMediaToMojoAdapter::DeviceFactoryMediaToMojoAdapter(
+ std::unique_ptr<service_manager::ServiceContextRef> service_ref,
std::unique_ptr<media::VideoCaptureSystem> capture_system,
const media::VideoCaptureJpegDecoderFactoryCB&
jpeg_decoder_factory_callback)
- : capture_system_(std::move(capture_system)),
- jpeg_decoder_factory_callback_(jpeg_decoder_factory_callback) {}
+ : service_ref_(std::move(service_ref)),
+ capture_system_(std::move(capture_system)),
+ jpeg_decoder_factory_callback_(jpeg_decoder_factory_callback),
+ weak_factory_(this) {}
DeviceFactoryMediaToMojoAdapter::~DeviceFactoryMediaToMojoAdapter() = default;
@@ -91,6 +94,7 @@ void DeviceFactoryMediaToMojoAdapter::GetDeviceInfos(
const GetDeviceInfosCallback& callback) {
capture_system_->GetDeviceInfosAsync(
base::Bind(&TranslateDeviceInfos, callback));
+ has_called_get_device_infos_ = true;
}
void DeviceFactoryMediaToMojoAdapter::CreateDevice(
@@ -112,6 +116,29 @@ void DeviceFactoryMediaToMojoAdapter::CreateDevice(
return;
}
+ if (!has_called_get_device_infos_) {
+ capture_system_->GetDeviceInfosAsync(base::Bind(
+ &DeviceFactoryMediaToMojoAdapter::DiscardDeviceInfosAndCallContinuation,
+ weak_factory_.GetWeakPtr(),
+ base::Bind(&DeviceFactoryMediaToMojoAdapter::CreateAndAddNewDevice,
+ weak_factory_.GetWeakPtr(), device_id,
+ base::Passed(&device_request), callback)));
+ } else {
+ CreateAndAddNewDevice(device_id, std::move(device_request),
+ std::move(callback));
+ }
mcasas 2017/04/26 22:12:31 This if-else reads complex, what about: const a
chfremer 2017/04/26 23:33:35 Done.
+}
+
+void DeviceFactoryMediaToMojoAdapter::DiscardDeviceInfosAndCallContinuation(
mcasas 2017/04/26 22:12:31 This doesn't need to be a member: make it file-sta
chfremer 2017/04/26 23:33:35 Done.
+ base::Closure continuation,
+ const std::vector<media::VideoCaptureDeviceInfo>&) {
+ continuation.Run();
+}
+
+void DeviceFactoryMediaToMojoAdapter::CreateAndAddNewDevice(
+ const std::string& device_id,
+ mojom::DeviceRequest device_request,
+ const CreateDeviceCallback& callback) {
std::unique_ptr<media::VideoCaptureDevice> media_device =
capture_system_->CreateDevice(device_id);
if (media_device == nullptr) {
@@ -122,7 +149,8 @@ void DeviceFactoryMediaToMojoAdapter::CreateDevice(
// Add entry to active_devices to keep track of it
ActiveDeviceEntry device_entry;
device_entry.device = base::MakeUnique<DeviceMediaToMojoAdapter>(
- std::move(media_device), jpeg_decoder_factory_callback_);
+ service_ref_->Clone(), std::move(media_device),
+ jpeg_decoder_factory_callback_);
device_entry.binding = base::MakeUnique<mojo::Binding<mojom::Device>>(
device_entry.device.get(), std::move(device_request));
device_entry.binding->set_connection_error_handler(base::Bind(

Powered by Google App Engine
This is Rietveld 408576698