Commit 8c21b863 authored by Jesse Schettler's avatar Jesse Schettler Committed by Commit Bot

printing: Handle pending preview document requests

When using a PrintRenderer, preview documents are rendered
asynchronously, and mulitiple preview document requests may be issued
before a preview document is returned. If the returned preview
document's cookie does not match the latest document cookie, ignore it
and wait for the final preview document.

Bug: b:144448724
Test: Print from an ARC app and rapidly change print settings
Change-Id: I2b705abd5c86f3b2e54151d07a4c48201560e320
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1914831Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Jesse Schettler <jschettler@chromium.org>
Cr-Commit-Position: refs/heads/master@{#715276}
parent 642f1f34
......@@ -1457,7 +1457,8 @@ PrintRenderFrameHelper::CreatePreviewDocument() {
print_renderer_->CreatePreviewDocument(
print_renderer_job_settings_.Clone(),
base::BindOnce(&PrintRenderFrameHelper::OnPreviewDocumentCreated,
weak_ptr_factory_.GetWeakPtr(), begin_time));
weak_ptr_factory_.GetWeakPtr(),
print_params.document_cookie, begin_time));
return CREATE_IN_PROGRESS;
}
......@@ -1549,8 +1550,17 @@ bool PrintRenderFrameHelper::FinalizePrintReadyDocument() {
}
void PrintRenderFrameHelper::OnPreviewDocumentCreated(
int document_cookie,
base::TimeTicks begin_time,
base::ReadOnlySharedMemoryRegion preview_document_region) {
// Since the PrintRenderer renders preview documents asynchronously, multiple
// preview document requests may be sent before a preview document is
// returned. If the received preview document's cookie does not match the
// latest document cookie, ignore it and wait for the final preview document.
if (document_cookie != print_pages_params_->params.document_cookie) {
return;
}
bool success =
ProcessPreviewDocument(begin_time, std::move(preview_document_region));
DidFinishPrinting(success ? OK : FAIL_PREVIEW);
......
......@@ -267,6 +267,7 @@ class PrintRenderFrameHelper
// Called after a preview document has been created by a PrintRenderer.
void OnPreviewDocumentCreated(
int document_cookie,
base::TimeTicks begin_time,
base::ReadOnlySharedMemoryRegion preview_document_region);
......
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