Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7130)

Unified Diff: chrome/browser/printing/print_preview_message_handler.cc

Issue 7365003: Print Preview: Make preview generation event driven to eliminate synchronous messages. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix broken test, add more DCHECKs Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/printing/print_preview_message_handler.cc
===================================================================
--- chrome/browser/printing/print_preview_message_handler.cc (revision 92494)
+++ chrome/browser/printing/print_preview_message_handler.cc (working copy)
@@ -76,20 +76,31 @@
}
void PrintPreviewMessageHandler::OnDidPreviewPage(int page_number,
- bool* cancel) {
+ int document_cookie) {
+ RenderViewHost* rvh = tab_contents()->render_view_host();
TabContents* print_preview_tab = GetPrintPreviewTab();
if (!print_preview_tab) {
kmadhusu 2011/07/15 01:22:46 Can you make this if condition (!print_preview_tab
Lei Zhang 2011/07/15 01:48:02 I don't think we need it. I've never seen a crash
kmadhusu 2011/07/15 19:25:46 As we discussed, it can happen. So, modify the if
Lei Zhang 2011/07/15 20:23:35 Done.
- // Can't find print preview tab means we should cancel.
- *cancel = true;
+ // Can't find print preview tab means we should abort.
+ StopWorker(document_cookie);
+ rvh->Send(new PrintMsg_AbortPreview(rvh->routing_id()));
return;
}
PrintPreviewUI* print_preview_ui =
static_cast<PrintPreviewUI*>(print_preview_tab->web_ui());
bool has_pending = print_preview_ui->HasPendingRequests();
- if (!has_pending && page_number >= 0)
+ if (has_pending) {
+ // Cancel. Next print preview request will cancel the current one.
+ // Just do the required maintainance work here.
+ StopWorker(document_cookie);
+ print_preview_ui->OnPrintPreviewCancelled();
+ return;
+ }
+
+ // Continue
+ if (page_number >= 0)
print_preview_ui->OnDidPreviewPage(page_number);
- *cancel = has_pending;
+ rvh->Send(new PrintMsg_ContinuePreview(rvh->routing_id()));
}
void PrintPreviewMessageHandler::OnPagesReadyForPreview(
@@ -175,19 +186,6 @@
}
}
-void PrintPreviewMessageHandler::OnPrintPreviewCancelled(int document_cookie) {
- // Always need to stop the worker.
- StopWorker(document_cookie);
-
- TabContents* print_preview_tab = GetPrintPreviewTab();
- if (!print_preview_tab)
- return;
-
- PrintPreviewUI* print_preview_ui =
- static_cast<PrintPreviewUI*>(print_preview_tab->web_ui());
- print_preview_ui->OnPrintPreviewCancelled();
-}
-
bool PrintPreviewMessageHandler::OnMessageReceived(
const IPC::Message& message) {
bool handled = true;
@@ -202,8 +200,6 @@
OnPagesReadyForPreview)
IPC_MESSAGE_HANDLER(PrintHostMsg_PrintPreviewFailed,
OnPrintPreviewFailed)
- IPC_MESSAGE_HANDLER(PrintHostMsg_PrintPreviewCancelled,
- OnPrintPreviewCancelled)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;

Powered by Google App Engine
This is Rietveld 408576698