Commit d58e3784 authored by Wei Lee's avatar Wei Lee Committed by Chromium LUCI CQ

VCD: Fix the race condition when closing CameraAppDeviceImpl

After https://crrev.com/c/2602969, |OnDeviceClosed()| might be triggered
from different threads. But in |OnDeviceClosed()|, it will access
|camera_app_devices_| and might introduce race condition.

Therefore, to fix it, we can post the task to make sure that
|OnDeviceClosed()| will be called on the same thread.

And since now we will not call |OnDeviceClosed()| directly and the mojo
error handler of a receiver set might be triggered more than once, we
should also handle it properly.

Bug: b/177191321
Test: Consecutively passes CCAUISettings.swa for 20 times

Change-Id: I93e546a98c410017f17071c97336bfe40dcc7b69
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2619247
Commit-Queue: Wei Lee <wtlee@chromium.org>
Commit-Queue: Shik Chen <shik@chromium.org>
Auto-Submit: Wei Lee <wtlee@chromium.org>
Reviewed-by: default avatarShik Chen <shik@chromium.org>
Cr-Commit-Position: refs/heads/master@{#841974}
parent 5004c000
......@@ -7,6 +7,7 @@
#include <string>
#include "base/command_line.h"
#include "media/base/bind_to_current_loop.h"
#include "media/base/media_switches.h"
#include "media/capture/video/chromeos/public/cros_features.h"
#include "media/capture/video/chromeos/video_capture_device_chromeos_halv3.h"
......@@ -69,8 +70,9 @@ media::CameraAppDeviceImpl* CameraAppDeviceBridgeImpl::CreateCameraAppDevice(
auto device_info = camera_info_getter_.Run(device_id);
auto device_impl = std::make_unique<media::CameraAppDeviceImpl>(
device_id, std::move(device_info),
base::BindOnce(&CameraAppDeviceBridgeImpl::OnDeviceClosed,
base::Unretained(this), device_id));
media::BindToCurrentLoop(
base::BindOnce(&CameraAppDeviceBridgeImpl::OnDeviceClosed,
base::Unretained(this), device_id)));
auto result = camera_app_devices_.emplace(device_id, std::move(device_impl));
return result.first->second.get();
}
......
......@@ -295,7 +295,11 @@ void CameraAppDeviceImpl::DisableEeNr(ReprocessTask* task) {
}
void CameraAppDeviceImpl::OnMojoConnectionError() {
std::move(cleanup_callback_).Run();
// Since it is the error handler of a receiver set, it might be triggered more
// than once.
if (!cleanup_callback_.is_null()) {
std::move(cleanup_callback_).Run();
}
}
void CameraAppDeviceImpl::SetReprocessResultOnMojoThread(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment