diff options
author | stuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-07 23:21:12 +0000 |
---|---|---|
committer | stuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-07 23:21:12 +0000 |
commit | e7dd6d8bb28270d49684714aa03f8162ab558bc6 (patch) | |
tree | 18ee34fa7f4b5e35b08094278cff9f9187b0a5ed /chrome | |
parent | 1c0585d585bc9f88ee177553b66e0025d7fe3aa0 (diff) | |
download | chromium_src-e7dd6d8bb28270d49684714aa03f8162ab558bc6.zip chromium_src-e7dd6d8bb28270d49684714aa03f8162ab558bc6.tar.gz chromium_src-e7dd6d8bb28270d49684714aa03f8162ab558bc6.tar.bz2 |
Change the way we wait for print jobs at shutdown on the Mac
Don't try to run a message loop to wait for print jobs after the event loop has already been torn down, or bad things happen.
BUG=28714
TEST=Start a large print job job, then immediately quit. The browser should not crash.
Review URL: http://codereview.chromium.org/3565010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61878 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/app_controller_mac.mm | 5 | ||||
-rw-r--r-- | chrome/browser/printing/print_job_manager.cc | 23 | ||||
-rw-r--r-- | chrome/browser/printing/print_job_manager.h | 4 |
3 files changed, 26 insertions, 6 deletions
diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm index 72a0b75..cbda456 100644 --- a/chrome/browser/app_controller_mac.mm +++ b/chrome/browser/app_controller_mac.mm @@ -39,6 +39,7 @@ #include "chrome/browser/metrics/user_metrics.h" #include "chrome/browser/options_window.h" #include "chrome/browser/prefs/pref_service.h" +#include "chrome/browser/printing/print_job_manager.h" #include "chrome/browser/profile_manager.h" #include "chrome/browser/sessions/tab_restore_service.h" #include "chrome/browser/sync/profile_sync_service.h" @@ -243,6 +244,10 @@ void RecordLastRunAppBundlePath() { size_t num_browsers = BrowserList::size(); + // Give any print jobs in progress time to finish. + if (!browser_shutdown::IsTryingToQuit()) + g_browser_process->print_job_manager()->StopJobs(true); + // Initiate a shutdown (via BrowserList::CloseAllBrowsers()) if we aren't // already shutting down. if (!browser_shutdown::IsTryingToQuit()) diff --git a/chrome/browser/printing/print_job_manager.cc b/chrome/browser/printing/print_job_manager.cc index ce02f9e..91b27ee 100644 --- a/chrome/browser/printing/print_job_manager.cc +++ b/chrome/browser/printing/print_job_manager.cc @@ -26,25 +26,36 @@ PrintJobManager::~PrintJobManager() { } void PrintJobManager::OnQuit() { - // Common case, no print job pending. +#if defined(OS_MACOSX) + // OnQuit is too late to try to wait for jobs on the Mac, since the runloop + // has already been torn down; instead, StopJobs(true) is called earlier in + // the shutdown process, and this is just here in case something sneaks + // in after that. + StopJobs(false); +#else + StopJobs(true); +#endif + registrar_.RemoveAll(); +} + +void PrintJobManager::StopJobs(bool wait_for_finish) { if (current_jobs_.empty()) return; { - // Don't take a chance and copy the array since it can be modified in - // transit. + // Copy the array since it can be modified in transit. PrintJobs current_jobs(current_jobs_); - // Wait for every jobs to finish. + // Wait for each job to finish. for (size_t i = 0; i < current_jobs.size(); ++i) { PrintJob* job = current_jobs[i]; if (!job) continue; // Wait for 120 seconds for the print job to be spooled. - job->FlushJob(120000); + if (wait_for_finish) + job->FlushJob(120000); job->Stop(); } } current_jobs_.clear(); - registrar_.RemoveAll(); } void PrintJobManager::QueuePrinterQuery(PrinterQuery* job) { diff --git a/chrome/browser/printing/print_job_manager.h b/chrome/browser/printing/print_job_manager.h index ca2bb47..017b732 100644 --- a/chrome/browser/printing/print_job_manager.h +++ b/chrome/browser/printing/print_job_manager.h @@ -29,6 +29,10 @@ class PrintJobManager : public NotificationObserver { // On browser quit, we should wait to have the print job finished. void OnQuit(); + // Stops all printing jobs. If wait_for_finish is true, tries to give jobs + // a chance to complete before stopping them. + void StopJobs(bool wait_for_finish); + // Queues a semi-initialized worker thread. Can be called from any thread. // Current use case is queuing from the I/O thread. // TODO(maruel): Have them vanish after a timeout (~5 minutes?) |