Skip to content

Commit

Permalink
Add RenderPrintedDocument to PrintBackendServiceManager
Browse files Browse the repository at this point in the history
If the print backend process terminates then it is necessary to have
extra handling to ensure that callbacks are still made, as otherwise the
UI can end up in a stuck state.

Extend PrintBackendServiceManager to include a wrapper around the
RenderPrintedDocument() call, to include protection against this
scenario.

Bug: 809738
Change-Id: I30a74a655c3a1486254076b78286ce7a9b24ca13
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3564812
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Alan Screen <awscreen@chromium.org>
Cr-Commit-Position: refs/heads/main@{#988186}
  • Loading branch information
Alan Screen authored and Chromium LUCI CQ committed Apr 1, 2022
1 parent b8211e2 commit 3c47ff4
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
41 changes: 41 additions & 0 deletions chrome/browser/printing/print_backend_service_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,29 @@ void PrintBackendServiceManager::RenderPrintedPage(
}
#endif // BUILDFLAG(IS_WIN)

void PrintBackendServiceManager::RenderPrintedDocument(
const std::string& printer_name,
int document_cookie,
mojom::MetafileDataType data_type,
base::ReadOnlySharedMemoryRegion serialized_data,
mojom::PrintBackendService::RenderPrintedDocumentCallback callback) {
CallbackContext context;
auto& service = GetServiceAndCallbackContext(
printer_name, ClientType::kPrintDocument, context);

SaveCallback(
GetRemoteSavedRenderPrintedDocumentCallbacks(context.is_sandboxed),
context.remote_id, context.saved_callback_id, std::move(callback));

SetCrashKeys(printer_name);

LogCallToRemote("RenderPrintedDocument", context);
service->RenderPrintedDocument(
document_cookie, data_type, std::move(serialized_data),
base::BindOnce(&PrintBackendServiceManager::OnDidRenderPrintedDocument,
base::Unretained(this), context));
}

void PrintBackendServiceManager::DocumentDone(
const std::string& printer_name,
int document_cookie,
Expand Down Expand Up @@ -869,6 +892,9 @@ void PrintBackendServiceManager::OnRemoteDisconnected(
RunSavedCallbacksResult(GetRemoteSavedRenderPrintedPageCallbacks(sandboxed),
remote_id, mojom::ResultCode::kFailed);
#endif
RunSavedCallbacksResult(
GetRemoteSavedRenderPrintedDocumentCallbacks(sandboxed), remote_id,
mojom::ResultCode::kFailed);
RunSavedCallbacksResult(GetRemoteSavedDocumentDoneCallbacks(sandboxed),
remote_id, mojom::ResultCode::kFailed);
}
Expand Down Expand Up @@ -943,6 +969,13 @@ PrintBackendServiceManager::GetRemoteSavedRenderPrintedPageCallbacks(
}
#endif

PrintBackendServiceManager::RemoteSavedRenderPrintedDocumentCallbacks&
PrintBackendServiceManager::GetRemoteSavedRenderPrintedDocumentCallbacks(
bool sandboxed) {
return sandboxed ? sandboxed_saved_render_printed_document_callbacks_
: unsandboxed_saved_render_printed_document_callbacks_;
}

PrintBackendServiceManager::RemoteSavedDocumentDoneCallbacks&
PrintBackendServiceManager::GetRemoteSavedDocumentDoneCallbacks(
bool sandboxed) {
Expand Down Expand Up @@ -1076,6 +1109,14 @@ void PrintBackendServiceManager::OnDidRenderPrintedPage(
}
#endif

void PrintBackendServiceManager::OnDidRenderPrintedDocument(
const CallbackContext& context,
mojom::ResultCode result) {
LogCallbackFromRemote("RenderPrintedDocument", context);
ServiceCallbackDone(
GetRemoteSavedRenderPrintedDocumentCallbacks(context.is_sandboxed),
context.remote_id, context.saved_callback_id, result);
}
void PrintBackendServiceManager::OnDidDocumentDone(
const CallbackContext& context,
mojom::ResultCode result) {
Expand Down
16 changes: 16 additions & 0 deletions chrome/browser/printing/print_backend_service_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ class PrintBackendServiceManager {
base::ReadOnlySharedMemoryRegion serialized_page_data,
mojom::PrintBackendService::RenderPrintedPageCallback callback);
#endif
void RenderPrintedDocument(
const std::string& printer_name,
int document_cookie,
mojom::MetafileDataType data_type,
base::ReadOnlySharedMemoryRegion serialized_data,
mojom::PrintBackendService::RenderPrintedDocumentCallback callback);
void DocumentDone(const std::string& printer_name,
int document_cookie,
mojom::PrintBackendService::DocumentDoneCallback callback);
Expand Down Expand Up @@ -213,6 +219,8 @@ class PrintBackendServiceManager {
using RemoteSavedRenderPrintedPageCallbacks =
RemoteSavedCallbacks<mojom::ResultCode>;
#endif
using RemoteSavedRenderPrintedDocumentCallbacks =
RemoteSavedCallbacks<mojom::ResultCode>;
using RemoteSavedDocumentDoneCallbacks =
RemoteSavedCallbacks<mojom::ResultCode>;

Expand Down Expand Up @@ -344,6 +352,8 @@ class PrintBackendServiceManager {
RemoteSavedRenderPrintedPageCallbacks&
GetRemoteSavedRenderPrintedPageCallbacks(bool sandboxed);
#endif
RemoteSavedRenderPrintedDocumentCallbacks&
GetRemoteSavedRenderPrintedDocumentCallbacks(bool sandboxed);
RemoteSavedDocumentDoneCallbacks& GetRemoteSavedDocumentDoneCallbacks(
bool sandboxed);

Expand Down Expand Up @@ -394,6 +404,8 @@ class PrintBackendServiceManager {
void OnDidRenderPrintedPage(const CallbackContext& context,
mojom::ResultCode result);
#endif
void OnDidRenderPrintedDocument(const CallbackContext& context,
mojom::ResultCode result);
void OnDidDocumentDone(const CallbackContext& context,
mojom::ResultCode result);

Expand Down Expand Up @@ -478,6 +490,10 @@ class PrintBackendServiceManager {
RemoteSavedRenderPrintedPageCallbacks
unsandboxed_saved_render_printed_page_callbacks_;
#endif
RemoteSavedRenderPrintedDocumentCallbacks
sandboxed_saved_render_printed_document_callbacks_;
RemoteSavedRenderPrintedDocumentCallbacks
unsandboxed_saved_render_printed_document_callbacks_;
RemoteSavedDocumentDoneCallbacks sandboxed_saved_document_done_callbacks_;
RemoteSavedDocumentDoneCallbacks unsandboxed_saved_document_done_callbacks_;

Expand Down

0 comments on commit 3c47ff4

Please sign in to comment.