Commit 5481b4c6 authored by Christian Fremerey's avatar Christian Fremerey Committed by Commit Bot

[Image Capture, Android] Fix for "Check failed: false. |callback_id| not found"

Fixes a race condition that can lead to a crash when taking a photo via the
image capture web API on Android.

Bug: 846576
Change-Id: I0008391acfd4fd1f84db1d403d33c0dc31410294
Reviewed-on: https://chromium-review.googlesource.com/1117845Reviewed-by: default avatarEmircan Uysaler <emircan@chromium.org>
Commit-Queue: Christian Fremerey <chfremer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#571538}
parent e8f4a6b6
...@@ -466,11 +466,13 @@ void VideoCaptureDeviceAndroid::DoTakePhoto(TakePhotoCallback callback) { ...@@ -466,11 +466,13 @@ void VideoCaptureDeviceAndroid::DoTakePhoto(TakePhotoCallback callback) {
std::unique_ptr<TakePhotoCallback> heap_callback( std::unique_ptr<TakePhotoCallback> heap_callback(
new TakePhotoCallback(std::move(callback))); new TakePhotoCallback(std::move(callback)));
const intptr_t callback_id = reinterpret_cast<intptr_t>(heap_callback.get()); const intptr_t callback_id = reinterpret_cast<intptr_t>(heap_callback.get());
if (!Java_VideoCapture_takePhoto(env, j_capture_, callback_id))
return;
{ // We need lock here because asynchronous response to
base::AutoLock lock(photo_callbacks_lock_); // Java_VideoCapture_takePhoto(), i.e. a call to OnPhotoTaken, arrives from a
// separate thread, and it can arrive before |photo_callbacks_.push_back()|
// has executed.
base::AutoLock lock(photo_callbacks_lock_);
if (Java_VideoCapture_takePhoto(env, j_capture_, callback_id)) {
photo_callbacks_.push_back(std::move(heap_callback)); photo_callbacks_.push_back(std::move(heap_callback));
} }
} }
......
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