Commit 67c4a0f6 authored by Alan Screen's avatar Alan Screen Committed by Commit Bot

Ensure PDF composite failures notify Print Preview UI

Follow-on to crrev.com/c/1823801.

From crbug.com/1000936, failures in doing conversion of PDF for Nup
caused the Print Preview UI to endlessly spin in the
"Loading preview ..." state without ever showing that it had failed.

Similar behavior can be replicated during development by inducing
crashes in PDF composition calls inside PdfCompositorImpl.

Wrap the PDF page composition calls' callbacks with
mojo::WrapCallbackWithDefaultInvokeIfNotRun() so that a status is
provided even if the utility process disappears before completing.

Update the On<composite-something>Done() callbacks to include a
notification call to the Print Preview UI to report errors.

Bug: 1003171
Change-Id: Id351cefd5d91b322a915fa635865969e1cbb1142
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1825661Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Alan Screen <awscreen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#700021}
parent fdd66f4f
......@@ -167,9 +167,12 @@ void PrintPreviewMessageHandler::OnDidPreviewPage(
// Use utility process to convert skia metafile to pdf.
client->DoCompositePageToPdf(
params.document_cookie, render_frame_host, content,
base::BindOnce(&PrintPreviewMessageHandler::OnCompositePdfPageDone,
weak_ptr_factory_.GetWeakPtr(), page_number,
params.document_cookie, ids));
mojo::WrapCallbackWithDefaultInvokeIfNotRun(
base::BindOnce(&PrintPreviewMessageHandler::OnCompositePdfPageDone,
weak_ptr_factory_.GetWeakPtr(), page_number,
params.document_cookie, ids),
mojom::PdfCompositor::Status::kCompositingFailure,
base::ReadOnlySharedMemoryRegion()));
} else {
NotifyUIPreviewPageReady(
print_preview_ui, page_number, ids,
......@@ -208,10 +211,13 @@ void PrintPreviewMessageHandler::OnMetafileReadyForPrinting(
client->DoCompositeDocumentToPdf(
params.document_cookie, render_frame_host, content,
base::BindOnce(&PrintPreviewMessageHandler::OnCompositePdfDocumentDone,
weak_ptr_factory_.GetWeakPtr(),
params.expected_pages_count, params.document_cookie,
ids));
mojo::WrapCallbackWithDefaultInvokeIfNotRun(
base::BindOnce(
&PrintPreviewMessageHandler::OnCompositePdfDocumentDone,
weak_ptr_factory_.GetWeakPtr(), params.expected_pages_count,
params.document_cookie, ids),
mojom::PdfCompositor::Status::kCompositingFailure,
base::ReadOnlySharedMemoryRegion()));
} else {
NotifyUIPreviewDocumentReady(
print_preview_ui, params.expected_pages_count, ids,
......@@ -316,12 +322,14 @@ void PrintPreviewMessageHandler::OnCompositePdfPageDone(
mojom::PdfCompositor::Status status,
base::ReadOnlySharedMemoryRegion region) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
PrintPreviewUI* print_preview_ui = GetPrintPreviewUI(ids.ui_id);
if (status != mojom::PdfCompositor::Status::kSuccess) {
DLOG(ERROR) << "Compositing pdf failed with error " << status;
if (print_preview_ui)
print_preview_ui->OnPrintPreviewFailed(ids.request_id);
return;
}
PrintPreviewUI* print_preview_ui = GetPrintPreviewUI(ids.ui_id);
if (!print_preview_ui)
return;
......@@ -393,12 +401,14 @@ void PrintPreviewMessageHandler::OnCompositePdfDocumentDone(
mojom::PdfCompositor::Status status,
base::ReadOnlySharedMemoryRegion region) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
PrintPreviewUI* print_preview_ui = GetPrintPreviewUI(ids.ui_id);
if (status != mojom::PdfCompositor::Status::kSuccess) {
DLOG(ERROR) << "Compositing pdf failed with error " << status;
if (print_preview_ui)
print_preview_ui->OnPrintPreviewFailed(ids.request_id);
return;
}
PrintPreviewUI* print_preview_ui = GetPrintPreviewUI(ids.ui_id);
if (!print_preview_ui)
return;
......
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