Commit 47efd876 authored by miu's avatar miu Committed by Commit bot

Aura Window Capture: Ensure capture callback is always run.

The capture callback must always be run, or eventually the capture
decision logic will think there are too many captures in-flight.  This
closes some "holes" in content::AuraWindowCaptureMachine where methods
exit early without running the callback.  This is a potential fix for
crbug 600031.

BUG=600031

Review URL: https://codereview.chromium.org/1913283004

Cr-Commit-Position: refs/heads/master@{#389867}
parent 3a4a913c
......@@ -199,7 +199,7 @@ void AuraWindowCaptureMachine::DidCopyOutput(
static bool first_call = true;
bool succeeded = ProcessCopyOutputResponse(
const bool succeeded = ProcessCopyOutputResponse(
video_frame, start_time, capture_frame_cb, std::move(result));
base::TimeDelta capture_time = base::TimeTicks::Now() - start_time;
......@@ -223,6 +223,11 @@ void AuraWindowCaptureMachine::DidCopyOutput(
: FIRST_WINDOW_CAPTURE_FAILED);
}
}
// If ProcessCopyOutputResponse() failed, it will not run |capture_frame_cb|,
// so do that now.
if (!succeeded)
capture_frame_cb.Run(video_frame, start_time, false);
}
bool AuraWindowCaptureMachine::ProcessCopyOutputResponse(
......@@ -310,8 +315,11 @@ void AuraWindowCaptureMachine::CopyOutputFinishedForVideo(
if (machine) {
if (machine->cursor_renderer_ && result)
machine->cursor_renderer_->RenderOnVideoFrame(target);
capture_frame_cb.Run(target, start_time, result);
} else {
result = false;
}
capture_frame_cb.Run(target, start_time, result);
}
void AuraWindowCaptureMachine::OnWindowBoundsChanged(
......
......@@ -89,7 +89,9 @@ class AuraWindowCaptureMachine
std::unique_ptr<cc::CopyOutputResult> result);
// A helper which does the real work for DidCopyOutput. Returns true if
// succeeded.
// succeeded and |capture_frame_cb| will be run at some future point. Returns
// false on error, and |capture_frame_cb| should be run by the caller (with
// failure status).
bool ProcessCopyOutputResponse(scoped_refptr<media::VideoFrame> video_frame,
base::TimeTicks start_time,
const CaptureFrameCallback& capture_frame_cb,
......
......@@ -141,8 +141,15 @@ bool ThreadSafeCaptureOracle::ObserveEventAndDecideCapture(
static_cast<uint8_t*>(output_buffer->data()),
output_buffer->mapped_size(), base::SharedMemory::NULLHandle(), 0u,
base::TimeDelta());
if (!(*storage))
// If creating the VideoFrame wrapper failed, call DidCaptureFrame() with
// !success to execute the required post-capture steps (tracing, notification
// of failure to VideoCaptureOracle, etc.).
if (!(*storage)) {
DidCaptureFrame(frame_number, std::move(output_buffer), capture_begin_time,
estimated_frame_duration, *storage, event_time, false);
return false;
}
*callback = base::Bind(&ThreadSafeCaptureOracle::DidCaptureFrame, this,
frame_number, base::Passed(&output_buffer),
capture_begin_time, estimated_frame_duration);
......
......@@ -48,9 +48,10 @@ class MEDIA_EXPORT ThreadSafeCaptureOracle
// resources.
//
// If this method returns false, the caller should take no further action.
// Otherwise, |storage| is set to the destination for the video frame capture;
// and, the caller should initiate capture, and then run |callback| once the
// video frame has been populated with its content.
// Otherwise, |storage| is set to the destination for the video frame capture
// and the caller should initiate capture. Then, once the video frame has
// been populated with its content, or if capture failed, the |callback|
// should be run.
bool ObserveEventAndDecideCapture(VideoCaptureOracle::Event event,
const gfx::Rect& damage_rect,
base::TimeTicks event_time,
......
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