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

Side by Side Diff: chrome/browser/printing/print_view_manager_base.cc

Issue 1395103003: Don't use base::MessageLoop::{Quit,QuitClosure} in chrome/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/printing/print_view_manager_base.h" 5 #include "chrome/browser/printing/print_view_manager_base.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 printing_succeeded_ = true; 317 printing_succeeded_ = true;
318 return true; 318 return true;
319 } 319 }
320 320
321 // WebContents is either dying or a second consecutive request to print 321 // WebContents is either dying or a second consecutive request to print
322 // happened before the first had time to finish. We need to render all the 322 // happened before the first had time to finish. We need to render all the
323 // pages in an hurry if a print_job_ is still pending. No need to wait for it 323 // pages in an hurry if a print_job_ is still pending. No need to wait for it
324 // to actually spool the pages, only to have the renderer generate them. Run 324 // to actually spool the pages, only to have the renderer generate them. Run
325 // a message loop until we get our signal that the print job is satisfied. 325 // a message loop until we get our signal that the print job is satisfied.
326 // PrintJob will send a ALL_PAGES_REQUESTED after having received all the 326 // PrintJob will send a ALL_PAGES_REQUESTED after having received all the
327 // pages it needs. MessageLoop::current()->Quit() will be called as soon as 327 // pages it needs. MessageLoop::current()->QuitWhenIdle() will be called as
328 // print_job_->document()->IsComplete() is true on either ALL_PAGES_REQUESTED 328 // soon as print_job_->document()->IsComplete() is true on either
329 // or in DidPrintPage(). The check is done in 329 // ALL_PAGES_REQUESTED or in DidPrintPage(). The check is done in
330 // ShouldQuitFromInnerMessageLoop(). 330 // ShouldQuitFromInnerMessageLoop().
331 // BLOCKS until all the pages are received. (Need to enable recursive task) 331 // BLOCKS until all the pages are received. (Need to enable recursive task)
332 if (!RunInnerMessageLoop()) { 332 if (!RunInnerMessageLoop()) {
333 // This function is always called from DisconnectFromCurrentPrintJob() so we 333 // This function is always called from DisconnectFromCurrentPrintJob() so we
334 // know that the job will be stopped/canceled in any case. 334 // know that the job will be stopped/canceled in any case.
335 return false; 335 return false;
336 } 336 }
337 return true; 337 return true;
338 } 338 }
339 339
340 void PrintViewManagerBase::ShouldQuitFromInnerMessageLoop() { 340 void PrintViewManagerBase::ShouldQuitFromInnerMessageLoop() {
341 // Look at the reason. 341 // Look at the reason.
342 DCHECK(print_job_->document()); 342 DCHECK(print_job_->document());
343 if (print_job_->document() && 343 if (print_job_->document() &&
344 print_job_->document()->IsComplete() && 344 print_job_->document()->IsComplete() &&
345 inside_inner_message_loop_) { 345 inside_inner_message_loop_) {
346 // We are in a message loop created by RenderAllMissingPagesNow. Quit from 346 // We are in a message loop created by RenderAllMissingPagesNow. Quit from
347 // it. 347 // it.
348 base::MessageLoop::current()->Quit(); 348 base::MessageLoop::current()->QuitWhenIdle();
349 inside_inner_message_loop_ = false; 349 inside_inner_message_loop_ = false;
350 } 350 }
351 } 351 }
352 352
353 bool PrintViewManagerBase::CreateNewPrintJob(PrintJobWorkerOwner* job) { 353 bool PrintViewManagerBase::CreateNewPrintJob(PrintJobWorkerOwner* job) {
354 DCHECK(!inside_inner_message_loop_); 354 DCHECK(!inside_inner_message_loop_);
355 355
356 // Disconnect the current print_job_. 356 // Disconnect the current print_job_.
357 DisconnectFromCurrentPrintJob(); 357 DisconnectFromCurrentPrintJob();
358 358
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 // here is that some poor users have their print server away on a VPN over a 444 // here is that some poor users have their print server away on a VPN over a
445 // slow connection. In this situation, the simple fact of opening the printer 445 // slow connection. In this situation, the simple fact of opening the printer
446 // can be dead slow. On the other side, we don't want to die infinitely for a 446 // can be dead slow. On the other side, we don't want to die infinitely for a
447 // real network error. Give the printer 60 seconds to comply. 447 // real network error. Give the printer 60 seconds to comply.
448 // 448 //
449 // - If we're looping because of renderer page generation, the renderer could 449 // - If we're looping because of renderer page generation, the renderer could
450 // be CPU bound, the page overly complex/large or the system just 450 // be CPU bound, the page overly complex/large or the system just
451 // memory-bound. 451 // memory-bound.
452 static const int kPrinterSettingsTimeout = 60000; 452 static const int kPrinterSettingsTimeout = 60000;
453 base::OneShotTimer quit_timer; 453 base::OneShotTimer quit_timer;
454 quit_timer.Start(FROM_HERE, 454 quit_timer.Start(
455 TimeDelta::FromMilliseconds(kPrinterSettingsTimeout), 455 FROM_HERE, TimeDelta::FromMilliseconds(kPrinterSettingsTimeout),
456 base::MessageLoop::current(), &base::MessageLoop::Quit); 456 base::MessageLoop::current(), &base::MessageLoop::QuitWhenIdle);
457 457
458 inside_inner_message_loop_ = true; 458 inside_inner_message_loop_ = true;
459 459
460 // Need to enable recursive task. 460 // Need to enable recursive task.
461 { 461 {
462 base::MessageLoop::ScopedNestableTaskAllower allow( 462 base::MessageLoop::ScopedNestableTaskAllower allow(
463 base::MessageLoop::current()); 463 base::MessageLoop::current());
464 base::MessageLoop::current()->Run(); 464 base::MessageLoop::current()->Run();
465 } 465 }
466 466
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 scoped_refptr<printing::PrinterQuery> printer_query; 529 scoped_refptr<printing::PrinterQuery> printer_query;
530 printer_query = queue_->PopPrinterQuery(cookie); 530 printer_query = queue_->PopPrinterQuery(cookie);
531 if (!printer_query.get()) 531 if (!printer_query.get())
532 return; 532 return;
533 BrowserThread::PostTask( 533 BrowserThread::PostTask(
534 BrowserThread::IO, FROM_HERE, 534 BrowserThread::IO, FROM_HERE,
535 base::Bind(&PrinterQuery::StopWorker, printer_query.get())); 535 base::Bind(&PrinterQuery::StopWorker, printer_query.get()));
536 } 536 }
537 537
538 } // namespace printing 538 } // namespace printing
OLDNEW
« no previous file with comments | « chrome/browser/printing/print_job.cc ('k') | chrome/browser/printing/printing_layout_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698