Commit 97b30d58 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

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

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: default avatarBo <boliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#710381}
parent ab0fe73c
...@@ -68,7 +68,8 @@ void AwPdfExporter::ExportToPdf(JNIEnv* env, ...@@ -68,7 +68,8 @@ void AwPdfExporter::ExportToPdf(JNIEnv* env,
JNI_AwPdfExporter_GetPageRanges(env, pages, &page_ranges); JNI_AwPdfExporter_GetPageRanges(env, pages, &page_ranges);
AwPrintManager* print_manager = AwPrintManager::CreateForWebContents( AwPrintManager* print_manager = AwPrintManager::CreateForWebContents(
web_contents_, CreatePdfSettings(env, obj, page_ranges), fd, 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()) if (!print_manager->PrintNow())
DidExportPdf(0); DidExportPdf(0);
......
...@@ -64,7 +64,7 @@ AwPrintManager::~AwPrintManager() = default; ...@@ -64,7 +64,7 @@ AwPrintManager::~AwPrintManager() = default;
void AwPrintManager::PdfWritingDone(int page_count) { void AwPrintManager::PdfWritingDone(int page_count) {
if (pdf_writing_done_callback_) 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. // Invalidate the file descriptor so it doesn't get reused.
fd_ = -1; fd_ = -1;
} }
...@@ -132,16 +132,16 @@ void AwPrintManager::OnDidPrintDocument( ...@@ -132,16 +132,16 @@ void AwPrintManager::OnDidPrintDocument(
.get(), .get(),
FROM_HERE, base::BindOnce(&SaveDataToFd, fd_, number_pages_, data), FROM_HERE, base::BindOnce(&SaveDataToFd, fd_, number_pages_, data),
base::BindOnce(&AwPrintManager::OnDidPrintDocumentWritingDone, base::BindOnce(&AwPrintManager::OnDidPrintDocumentWritingDone,
std::move(pdf_writing_done_callback_), std::move(helper))); pdf_writing_done_callback_, std::move(helper)));
} }
// static // static
void AwPrintManager::OnDidPrintDocumentWritingDone( void AwPrintManager::OnDidPrintDocumentWritingDone(
PdfWritingDoneCallback callback, const PdfWritingDoneCallback& callback,
std::unique_ptr<DelayedFrameDispatchHelper> helper, std::unique_ptr<DelayedFrameDispatchHelper> helper,
int page_count) { int page_count) {
if (callback) if (callback)
std::move(callback).Run(page_count); callback.Run(page_count);
helper->SendCompleted(); helper->SendCompleted();
} }
......
...@@ -54,7 +54,7 @@ class AwPrintManager : public printing::PrintManager, ...@@ -54,7 +54,7 @@ class AwPrintManager : public printing::PrintManager,
IPC::Message* reply_msg) override; IPC::Message* reply_msg) override;
static void OnDidPrintDocumentWritingDone( static void OnDidPrintDocumentWritingDone(
PdfWritingDoneCallback callback, const PdfWritingDoneCallback& callback,
std::unique_ptr<DelayedFrameDispatchHelper> helper, std::unique_ptr<DelayedFrameDispatchHelper> helper,
int page_count); int page_count);
......
...@@ -17,7 +17,7 @@ PrintViewManagerBasic::PrintViewManagerBasic(content::WebContents* web_contents) ...@@ -17,7 +17,7 @@ PrintViewManagerBasic::PrintViewManagerBasic(content::WebContents* web_contents)
: PrintViewManagerBase(web_contents) { : PrintViewManagerBase(web_contents) {
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
pdf_writing_done_callback_ = pdf_writing_done_callback_ =
base::Bind(&PrintingContextAndroid::PdfWritingDone); base::BindRepeating(&PrintingContextAndroid::PdfWritingDone);
#endif #endif
} }
...@@ -33,7 +33,7 @@ PrintViewManagerBasic::~PrintViewManagerBasic() { ...@@ -33,7 +33,7 @@ PrintViewManagerBasic::~PrintViewManagerBasic() {
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
void PrintViewManagerBasic::PdfWritingDone(int page_count) { void PrintViewManagerBasic::PdfWritingDone(int page_count) {
if (pdf_writing_done_callback_) if (pdf_writing_done_callback_)
std::move(pdf_writing_done_callback_).Run(page_count); pdf_writing_done_callback_.Run(page_count);
} }
#endif #endif
......
...@@ -30,7 +30,8 @@ class PrintManager : public content::WebContentsObserver { ...@@ -30,7 +30,8 @@ class PrintManager : public content::WebContentsObserver {
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
// TODO(timvolodine): consider introducing PrintManagerAndroid (crbug/500960) // 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; virtual void PdfWritingDone(int page_count) = 0;
#endif #endif
......
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