diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-01 01:54:46 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-01 01:54:46 +0000 |
commit | da08956f0d20441e4fa02ae1d053d2ff946d71b7 (patch) | |
tree | cf58ce089686c7f94f11a7629bd7fb44ff9858e6 /chrome/browser/printing | |
parent | 9be09f384d71e63c52957c823c536ef6cb32e649 (diff) | |
download | chromium_src-da08956f0d20441e4fa02ae1d053d2ff946d71b7.zip chromium_src-da08956f0d20441e4fa02ae1d053d2ff946d71b7.tar.gz chromium_src-da08956f0d20441e4fa02ae1d053d2ff946d71b7.tar.bz2 |
Printing: Store the document cookie of the current PrinterQuery on
PrintViewManager and use this to properly release the PrinterQuery when the
initiator tab closes during the middle of a Printing operation.
BUG=84764
TEST=none
R=thestig@chromium.org
Review URL: http://codereview.chromium.org/7272046
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91251 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/printing')
-rw-r--r-- | chrome/browser/printing/print_view_manager.cc | 50 | ||||
-rw-r--r-- | chrome/browser/printing/print_view_manager.h | 10 |
2 files changed, 41 insertions, 19 deletions
diff --git a/chrome/browser/printing/print_view_manager.cc b/chrome/browser/printing/print_view_manager.cc index 3fa10e1..39c485c 100644 --- a/chrome/browser/printing/print_view_manager.cc +++ b/chrome/browser/printing/print_view_manager.cc @@ -38,6 +38,24 @@ string16 GenerateRenderSourceName(TabContents* tab_contents) { return name; } +// Release the PrinterQuery identified by |cookie|. +void ReleasePrinterQuery(int cookie) { + printing::PrintJobManager* print_job_manager = + g_browser_process->print_job_manager(); + // May be NULL in tests. + if (!print_job_manager) + return; + + scoped_refptr<printing::PrinterQuery> printer_query; + print_job_manager->PopPrinterQuery(cookie, &printer_query); + if (printer_query.get()) { + BrowserThread::PostTask( + BrowserThread::IO, FROM_HERE, + NewRunnableMethod(printer_query.get(), + &printing::PrinterQuery::StopWorker)); + } +} + } // namespace namespace printing { @@ -49,13 +67,15 @@ PrintViewManager::PrintViewManager(TabContentsWrapper* tab) printing_succeeded_(false), inside_inner_message_loop_(false), is_title_overridden_(false), - observer_(NULL) { + observer_(NULL), + cookie_(0) { #if defined(OS_POSIX) && !defined(OS_MACOSX) expecting_first_page_ = true; #endif } PrintViewManager::~PrintViewManager() { + ReleasePrinterQuery(cookie_); DisconnectFromCurrentPrintJob(); } @@ -130,6 +150,10 @@ void PrintViewManager::OnDidGetPrintedPagesCount(int cookie, int number_pages) { OpportunisticallyCreatePrintJob(cookie); } +void PrintViewManager::OnDidGetDocumentCookie(int cookie) { + cookie_ = cookie; +} + void PrintViewManager::OnDidShowPrintDialog() { if (observer_) observer_->OnPrintDialogShown(); @@ -196,15 +220,7 @@ void PrintViewManager::OnDidPrintPage( } void PrintViewManager::OnPrintingFailed(int cookie) { - scoped_refptr<PrinterQuery> printer_query; - g_browser_process->print_job_manager()->PopPrinterQuery(cookie, - &printer_query); - if (printer_query.get()) { - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - NewRunnableMethod(printer_query.get(), - &printing::PrinterQuery::StopWorker)); - } + ReleasePrinterQuery(cookie); NotificationService::current()->Notify( NotificationType::PRINT_JOB_RELEASED, @@ -217,6 +233,8 @@ bool PrintViewManager::OnMessageReceived(const IPC::Message& message) { IPC_BEGIN_MESSAGE_MAP(PrintViewManager, message) IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetPrintedPagesCount, OnDidGetPrintedPagesCount) + IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetDocumentCookie, + OnDidGetDocumentCookie) IPC_MESSAGE_HANDLER(PrintHostMsg_DidShowPrintDialog, OnDidShowPrintDialog) IPC_MESSAGE_HANDLER(PrintHostMsg_DidPrintPage, OnDidPrintPage) IPC_MESSAGE_HANDLER(PrintHostMsg_PrintingFailed, OnPrintingFailed) @@ -429,14 +447,14 @@ void PrintViewManager::ReleasePrintJob() { bool PrintViewManager::RunInnerMessageLoop() { // This value may actually be too low: // - // - If we're looping because of printer settings initializaton, the premise - // here is that some poor users have their print server away on a VPN over - // dialup. In this situation, the simple fact of opening the printer can be - // dead slow. On the other side, we don't want to die infinitely for a real - // network error. Give the printer 60 seconds to comply. + // - If we're looping because of printer settings initialization, the premise + // here is that some poor users have their print server away on a VPN over a + // slow connection. In this situation, the simple fact of opening the printer + // can be dead slow. On the other side, we don't want to die infinitely for a + // real network error. Give the printer 60 seconds to comply. // // - If we're looping because of renderer page generation, the renderer could - // be cpu bound, the page overly complex/large or the system just + // be CPU bound, the page overly complex/large or the system just // memory-bound. static const int kPrinterSettingsTimeout = 60000; base::OneShotTimer<MessageLoop> quit_timer; diff --git a/chrome/browser/printing/print_view_manager.h b/chrome/browser/printing/print_view_manager.h index 684c573..6a1314f 100644 --- a/chrome/browser/printing/print_view_manager.h +++ b/chrome/browser/printing/print_view_manager.h @@ -77,6 +77,7 @@ class PrintViewManager : public NotificationObserver, private: // IPC Message handlers. void OnDidGetPrintedPagesCount(int cookie, int number_pages); + void OnDidGetDocumentCookie(int cookie); void OnDidShowPrintDialog(); void OnDidPrintPage(const PrintHostMsg_DidPrintPage_Params& params); void OnPrintingFailed(int cookie); @@ -85,7 +86,7 @@ class PrintViewManager : public NotificationObserver, void OnNotifyPrintJobEvent(const JobEventDetails& event_details); // Requests the RenderView to render all the missing pages for the print job. - // Noop if no print job is pending. Returns true if at least one page has been + // No-op if no print job is pending. Returns true if at least one page has been // requested to the renderer. bool RenderAllMissingPagesNow(); @@ -109,12 +110,12 @@ class PrintViewManager : public NotificationObserver, // Notify that the printing is done. void PrintingDone(bool success); - // Terminates the print job. Noop if no print job has been created. If + // Terminates the print job. No-op if no print job has been created. If // |cancel| is true, cancel it instead of waiting for the job to finish. Will // call ReleasePrintJob(). void TerminatePrintJob(bool cancel); - // Releases print_job_. Correctly deregisters from notifications. Noop if + // Releases print_job_. Correctly deregisters from notifications. No-op if // no print job has been created. void ReleasePrintJob(); @@ -161,6 +162,9 @@ class PrintViewManager : public NotificationObserver, // shown. PrintViewManagerObserver* observer_; + // The document cookie of the current PrinterQuery. + int cookie_; + DISALLOW_COPY_AND_ASSIGN(PrintViewManager); }; |