Skip to content
Permalink
Browse files

M78: Fix issue where Android printing does not work the second time.

In r686771, we converted a base::Callback used by printing::PrintManager
for Android printing to a base::OnceCallback. This was incorrect, as
the PrintManager's lifetime is tied to the tab's lifetime. Now printing
for a given PrintManager works the first time, but never again after the
OnceCallback has been called. The callback needs to remain valid for the
duration of the PrintManager's lifetime, so make it a RepeatingCallback.

TBR=vkuzkokov@chromium.org

(cherry picked from commit 97b30d5)

Bug: 1018377
Change-Id: I367ea2e1850ee67a30ef024da2b93d4cef701f62
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1885001
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Bo <boliu@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#710381}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1890975
Reviewed-by: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/branch-heads/3904@{#838}
Cr-Branched-From: 675968a-refs/heads/master@{#693954}
  • Loading branch information
leizleiz committed Oct 30, 2019
1 parent f1b5017 commit e628e21c983fa6e62a2c31379598eeca0f315713
@@ -68,7 +68,8 @@ void AwPdfExporter::ExportToPdf(JNIEnv* env,
JNI_AwPdfExporter_GetPageRanges(env, pages, &page_ranges);
AwPrintManager* print_manager = AwPrintManager::CreateForWebContents(
web_contents_, CreatePdfSettings(env, obj, page_ranges), fd,
base::BindOnce(&AwPdfExporter::DidExportPdf, base::Unretained(this)));
base::BindRepeating(&AwPdfExporter::DidExportPdf,
base::Unretained(this)));

if (!print_manager->PrintNow())
DidExportPdf(0);
@@ -64,7 +64,7 @@ AwPrintManager::~AwPrintManager() = default;

void AwPrintManager::PdfWritingDone(int page_count) {
if (pdf_writing_done_callback_)
std::move(pdf_writing_done_callback_).Run(page_count);
pdf_writing_done_callback_.Run(page_count);
// Invalidate the file descriptor so it doesn't get reused.
fd_ = -1;
}
@@ -132,16 +132,16 @@ void AwPrintManager::OnDidPrintDocument(
.get(),
FROM_HERE, base::BindOnce(&SaveDataToFd, fd_, number_pages_, data),
base::BindOnce(&AwPrintManager::OnDidPrintDocumentWritingDone,
std::move(pdf_writing_done_callback_), std::move(helper)));
pdf_writing_done_callback_, std::move(helper)));
}

// static
void AwPrintManager::OnDidPrintDocumentWritingDone(
PdfWritingDoneCallback callback,
const PdfWritingDoneCallback& callback,
std::unique_ptr<DelayedFrameDispatchHelper> helper,
int page_count) {
if (callback)
std::move(callback).Run(page_count);
callback.Run(page_count);
helper->SendCompleted();
}

@@ -54,7 +54,7 @@ class AwPrintManager : public printing::PrintManager,
IPC::Message* reply_msg) override;

static void OnDidPrintDocumentWritingDone(
PdfWritingDoneCallback callback,
const PdfWritingDoneCallback& callback,
std::unique_ptr<DelayedFrameDispatchHelper> helper,
int page_count);

@@ -17,7 +17,7 @@ PrintViewManagerBasic::PrintViewManagerBasic(content::WebContents* web_contents)
: PrintViewManagerBase(web_contents) {
#if defined(OS_ANDROID)
pdf_writing_done_callback_ =
base::Bind(&PrintingContextAndroid::PdfWritingDone);
base::BindRepeating(&PrintingContextAndroid::PdfWritingDone);
#endif
}

@@ -33,7 +33,7 @@ PrintViewManagerBasic::~PrintViewManagerBasic() {
#if defined(OS_ANDROID)
void PrintViewManagerBasic::PdfWritingDone(int page_count) {
if (pdf_writing_done_callback_)
std::move(pdf_writing_done_callback_).Run(page_count);
pdf_writing_done_callback_.Run(page_count);
}
#endif

@@ -30,7 +30,8 @@ class PrintManager : public content::WebContentsObserver {

#if defined(OS_ANDROID)
// TODO(timvolodine): consider introducing PrintManagerAndroid (crbug/500960)
using PdfWritingDoneCallback = base::OnceCallback<void(int /* page count */)>;
using PdfWritingDoneCallback =
base::RepeatingCallback<void(int /* page count */)>;

virtual void PdfWritingDone(int page_count) = 0;
#endif

0 comments on commit e628e21

Please sign in to comment.
You can’t perform that action at this time.