Commit 3398fa51 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Use OnceCallback in PrintViewManager.

It currently uses RepeatingCallback, and resets the callback after
running it.

Also initialize members in the header and fix some nits.

Change-Id: I92248c94993fa09ab4061a7ef17f4a2a82be4d8d
Reviewed-on: https://chromium-review.googlesource.com/c/1308911Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604339}
parent 18fc8273
......@@ -66,11 +66,7 @@ struct PrintViewManager::FrameDispatchHelper {
};
PrintViewManager::PrintViewManager(content::WebContents* web_contents)
: PrintViewManagerBase(web_contents),
print_preview_state_(NOT_PREVIEWING),
print_preview_rfh_(nullptr),
scripted_print_preview_rph_(nullptr),
is_switching_to_system_dialog_(false) {
: PrintViewManagerBase(web_contents) {
if (PrintPreviewDialogController::IsPrintPreviewURL(web_contents->GetURL())) {
EnableInternalPDFPluginForContents(
web_contents->GetMainFrame()->GetProcess()->GetID(),
......@@ -83,10 +79,10 @@ PrintViewManager::~PrintViewManager() {
}
bool PrintViewManager::PrintForSystemDialogNow(
const base::Closure& dialog_shown_callback) {
DCHECK(!dialog_shown_callback.is_null());
DCHECK(on_print_dialog_shown_callback_.is_null());
on_print_dialog_shown_callback_ = dialog_shown_callback;
base::OnceClosure dialog_shown_callback) {
DCHECK(dialog_shown_callback);
DCHECK(!on_print_dialog_shown_callback_);
on_print_dialog_shown_callback_ = std::move(dialog_shown_callback);
is_switching_to_system_dialog_ = true;
SetPrintingRFH(print_preview_rfh_);
......@@ -193,11 +189,8 @@ void PrintViewManager::OnDidShowPrintDialog(content::RenderFrameHost* rfh) {
if (rfh != print_preview_rfh_)
return;
if (on_print_dialog_shown_callback_.is_null())
return;
on_print_dialog_shown_callback_.Run();
on_print_dialog_shown_callback_.Reset();
if (on_print_dialog_shown_callback_)
std::move(on_print_dialog_shown_callback_).Run();
}
void PrintViewManager::OnSetupScriptedPrintPreview(
......
......@@ -26,7 +26,7 @@ class PrintViewManager : public PrintViewManagerBase,
// Same as PrintNow(), but for the case where a user prints with the system
// dialog from print preview.
// |dialog_shown_callback| is called when the print dialog is shown.
bool PrintForSystemDialogNow(const base::Closure& dialog_shown_callback);
bool PrintForSystemDialogNow(base::OnceClosure dialog_shown_callback);
// Same as PrintNow(), but for the case where a user press "ctrl+shift+p" to
// show the native system dialog. This can happen from both initiator and
......@@ -67,8 +67,9 @@ class PrintViewManager : public PrintViewManagerBase,
SCRIPTED_PREVIEW,
};
// IPC Message handlers.
struct FrameDispatchHelper;
// IPC Message handlers.
void OnDidShowPrintDialog(content::RenderFrameHost* rfh);
void OnSetupScriptedPrintPreview(content::RenderFrameHost* rfh,
IPC::Message* reply_msg);
......@@ -76,21 +77,21 @@ class PrintViewManager : public PrintViewManagerBase,
bool source_is_modifiable);
void OnScriptedPrintPreviewReply(IPC::Message* reply_msg);
base::Closure on_print_dialog_shown_callback_;
base::OnceClosure on_print_dialog_shown_callback_;
// Current state of print preview for this view.
PrintPreviewState print_preview_state_;
PrintPreviewState print_preview_state_ = NOT_PREVIEWING;
// The current RFH that is print previewing. It should be a nullptr when
// |print_preview_state_| is NOT_PREVIEWING.
content::RenderFrameHost* print_preview_rfh_;
content::RenderFrameHost* print_preview_rfh_ = nullptr;
// Keeps track of the pending callback during scripted print preview.
content::RenderProcessHost* scripted_print_preview_rph_;
content::RenderProcessHost* scripted_print_preview_rph_ = nullptr;
// Indicates whether we're switching from print preview to system dialog. This
// flag is true between PrintForSystemDialogNow() and PrintPreviewDone().
bool is_switching_to_system_dialog_;
bool is_switching_to_system_dialog_ = false;
DISALLOW_COPY_AND_ASSIGN(PrintViewManager);
};
......
......@@ -977,7 +977,7 @@ void PrintPreviewHandler::HandleGetAccessToken(const base::ListValue* args) {
token_service_->RequestToken(type, callback_id);
}
// TODO (rbpotter): Remove this when the old Print Preview page is deleted.
// TODO(rbpotter): Remove this when the old Print Preview page is deleted.
void PrintPreviewHandler::HandleManagePrinters(const base::ListValue* args) {
GURL local_printers_manage_url(
chrome::GetSettingsUrl(chrome::kPrintingSettingsSubPage));
......@@ -998,9 +998,8 @@ void PrintPreviewHandler::HandleShowSystemDialog(
return;
auto* print_view_manager = PrintViewManager::FromWebContents(initiator);
print_view_manager->PrintForSystemDialogNow(
base::Bind(&PrintPreviewHandler::ClosePreviewDialog,
weak_factory_.GetWeakPtr()));
print_view_manager->PrintForSystemDialogNow(base::BindOnce(
&PrintPreviewHandler::ClosePreviewDialog, weak_factory_.GetWeakPtr()));
// Cancel the pending preview request if exists.
print_preview_ui()->OnCancelPendingPreviewRequest();
......
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