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

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

Issue 10383254: At browser exit, wait for pending print jobs before starting shutdown. This is to avoid a nested me… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 7 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
« no previous file with comments | « chrome/browser/printing/print_job.h ('k') | chrome/browser/printing/print_job_manager.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/printing/print_job.cc
===================================================================
--- chrome/browser/printing/print_job.cc (revision 137865)
+++ chrome/browser/printing/print_job.cc (working copy)
@@ -35,7 +35,8 @@
worker_(),
settings_(),
is_job_pending_(false),
- is_canceling_(false) {
+ is_canceling_(false),
+ ALLOW_THIS_IN_INITIALIZER_LIST(quit_factory_(this)) {
DCHECK(ui_message_loop_);
// This is normally a UI message loop, but in unit tests, the message loop is
// of the 'default' type.
@@ -148,6 +149,13 @@
void PrintJob::Stop() {
DCHECK_EQ(ui_message_loop_, MessageLoop::current());
+ if (quit_factory_.HasWeakPtrs()) {
+ // In case we're running a nested message loop to wait for a job to finish,
+ // and we finished before the timeout, quit the nested loop right away.
+ Quit();
+ quit_factory_.InvalidateWeakPtrs();
+ }
+
// Be sure to live long enough.
scoped_refptr<PrintJob> handle(this);
@@ -193,14 +201,8 @@
// Make sure the object outlive this message loop.
scoped_refptr<PrintJob> handle(this);
- // Stop() will eventually be called, which will get out of the inner message
- // loop. But, don't take it for granted and set a timer in case something goes
- // wrong.
- base::OneShotTimer<MessageLoop> quit_task;
- if (timeout_ms) {
- quit_task.Start(FROM_HERE, TimeDelta::FromMilliseconds(timeout_ms),
- MessageLoop::current(), &MessageLoop::Quit);
- }
+ MessageLoop::current()->PostDelayedTask(FROM_HERE,
+ base::Bind(&PrintJob::Quit, quit_factory_.GetWeakPtr()), timeout_ms);
MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current());
MessageLoop::current()->Run();
@@ -348,6 +350,10 @@
worker_->Stop();
}
+void PrintJob::Quit() {
+ MessageLoop::current()->Quit();
+}
+
// Takes settings_ ownership and will be deleted in the receiving thread.
JobEventDetails::JobEventDetails(Type type,
PrintedDocument* document,
« no previous file with comments | « chrome/browser/printing/print_job.h ('k') | chrome/browser/printing/print_job_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698