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 { ...@@ -66,11 +66,7 @@ struct PrintViewManager::FrameDispatchHelper {
}; };
PrintViewManager::PrintViewManager(content::WebContents* web_contents) PrintViewManager::PrintViewManager(content::WebContents* web_contents)
: PrintViewManagerBase(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) {
if (PrintPreviewDialogController::IsPrintPreviewURL(web_contents->GetURL())) { if (PrintPreviewDialogController::IsPrintPreviewURL(web_contents->GetURL())) {
EnableInternalPDFPluginForContents( EnableInternalPDFPluginForContents(
web_contents->GetMainFrame()->GetProcess()->GetID(), web_contents->GetMainFrame()->GetProcess()->GetID(),
...@@ -83,10 +79,10 @@ PrintViewManager::~PrintViewManager() { ...@@ -83,10 +79,10 @@ PrintViewManager::~PrintViewManager() {
} }
bool PrintViewManager::PrintForSystemDialogNow( bool PrintViewManager::PrintForSystemDialogNow(
const base::Closure& dialog_shown_callback) { base::OnceClosure dialog_shown_callback) {
DCHECK(!dialog_shown_callback.is_null()); DCHECK(dialog_shown_callback);
DCHECK(on_print_dialog_shown_callback_.is_null()); DCHECK(!on_print_dialog_shown_callback_);
on_print_dialog_shown_callback_ = dialog_shown_callback; on_print_dialog_shown_callback_ = std::move(dialog_shown_callback);
is_switching_to_system_dialog_ = true; is_switching_to_system_dialog_ = true;
SetPrintingRFH(print_preview_rfh_); SetPrintingRFH(print_preview_rfh_);
...@@ -193,11 +189,8 @@ void PrintViewManager::OnDidShowPrintDialog(content::RenderFrameHost* rfh) { ...@@ -193,11 +189,8 @@ void PrintViewManager::OnDidShowPrintDialog(content::RenderFrameHost* rfh) {
if (rfh != print_preview_rfh_) if (rfh != print_preview_rfh_)
return; return;
if (on_print_dialog_shown_callback_.is_null()) if (on_print_dialog_shown_callback_)
return; std::move(on_print_dialog_shown_callback_).Run();
on_print_dialog_shown_callback_.Run();
on_print_dialog_shown_callback_.Reset();
} }
void PrintViewManager::OnSetupScriptedPrintPreview( void PrintViewManager::OnSetupScriptedPrintPreview(
......
...@@ -26,7 +26,7 @@ class PrintViewManager : public PrintViewManagerBase, ...@@ -26,7 +26,7 @@ class PrintViewManager : public PrintViewManagerBase,
// Same as PrintNow(), but for the case where a user prints with the system // Same as PrintNow(), but for the case where a user prints with the system
// dialog from print preview. // dialog from print preview.
// |dialog_shown_callback| is called when the print dialog is shown. // |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 // 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 // show the native system dialog. This can happen from both initiator and
...@@ -67,8 +67,9 @@ class PrintViewManager : public PrintViewManagerBase, ...@@ -67,8 +67,9 @@ class PrintViewManager : public PrintViewManagerBase,
SCRIPTED_PREVIEW, SCRIPTED_PREVIEW,
}; };
// IPC Message handlers.
struct FrameDispatchHelper; struct FrameDispatchHelper;
// IPC Message handlers.
void OnDidShowPrintDialog(content::RenderFrameHost* rfh); void OnDidShowPrintDialog(content::RenderFrameHost* rfh);
void OnSetupScriptedPrintPreview(content::RenderFrameHost* rfh, void OnSetupScriptedPrintPreview(content::RenderFrameHost* rfh,
IPC::Message* reply_msg); IPC::Message* reply_msg);
...@@ -76,21 +77,21 @@ class PrintViewManager : public PrintViewManagerBase, ...@@ -76,21 +77,21 @@ class PrintViewManager : public PrintViewManagerBase,
bool source_is_modifiable); bool source_is_modifiable);
void OnScriptedPrintPreviewReply(IPC::Message* reply_msg); 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. // 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 // The current RFH that is print previewing. It should be a nullptr when
// |print_preview_state_| is NOT_PREVIEWING. // |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. // 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 // Indicates whether we're switching from print preview to system dialog. This
// flag is true between PrintForSystemDialogNow() and PrintPreviewDone(). // 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); DISALLOW_COPY_AND_ASSIGN(PrintViewManager);
}; };
......
...@@ -977,7 +977,7 @@ void PrintPreviewHandler::HandleGetAccessToken(const base::ListValue* args) { ...@@ -977,7 +977,7 @@ void PrintPreviewHandler::HandleGetAccessToken(const base::ListValue* args) {
token_service_->RequestToken(type, callback_id); 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) { void PrintPreviewHandler::HandleManagePrinters(const base::ListValue* args) {
GURL local_printers_manage_url( GURL local_printers_manage_url(
chrome::GetSettingsUrl(chrome::kPrintingSettingsSubPage)); chrome::GetSettingsUrl(chrome::kPrintingSettingsSubPage));
...@@ -998,9 +998,8 @@ void PrintPreviewHandler::HandleShowSystemDialog( ...@@ -998,9 +998,8 @@ void PrintPreviewHandler::HandleShowSystemDialog(
return; return;
auto* print_view_manager = PrintViewManager::FromWebContents(initiator); auto* print_view_manager = PrintViewManager::FromWebContents(initiator);
print_view_manager->PrintForSystemDialogNow( print_view_manager->PrintForSystemDialogNow(base::BindOnce(
base::Bind(&PrintPreviewHandler::ClosePreviewDialog, &PrintPreviewHandler::ClosePreviewDialog, weak_factory_.GetWeakPtr()));
weak_factory_.GetWeakPtr()));
// Cancel the pending preview request if exists. // Cancel the pending preview request if exists.
print_preview_ui()->OnCancelPendingPreviewRequest(); 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