| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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.h" | 5 #include "chrome/browser/printing/print_view_manager.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 !web_contents()->GetRenderViewHost()->IsRenderViewLive()) { | 405 !web_contents()->GetRenderViewHost()->IsRenderViewLive()) { |
| 406 return false; | 406 return false; |
| 407 } | 407 } |
| 408 | 408 |
| 409 // Is the document already complete? | 409 // Is the document already complete? |
| 410 if (print_job_->document() && print_job_->document()->IsComplete()) { | 410 if (print_job_->document() && print_job_->document()->IsComplete()) { |
| 411 printing_succeeded_ = true; | 411 printing_succeeded_ = true; |
| 412 return true; | 412 return true; |
| 413 } | 413 } |
| 414 | 414 |
| 415 // TabContents is either dying or a second consecutive request to print | 415 // WebContents is either dying or a second consecutive request to print |
| 416 // happened before the first had time to finish. We need to render all the | 416 // happened before the first had time to finish. We need to render all the |
| 417 // pages in an hurry if a print_job_ is still pending. No need to wait for it | 417 // pages in an hurry if a print_job_ is still pending. No need to wait for it |
| 418 // to actually spool the pages, only to have the renderer generate them. Run | 418 // to actually spool the pages, only to have the renderer generate them. Run |
| 419 // a message loop until we get our signal that the print job is satisfied. | 419 // a message loop until we get our signal that the print job is satisfied. |
| 420 // PrintJob will send a ALL_PAGES_REQUESTED after having received all the | 420 // PrintJob will send a ALL_PAGES_REQUESTED after having received all the |
| 421 // pages it needs. MessageLoop::current()->Quit() will be called as soon as | 421 // pages it needs. MessageLoop::current()->Quit() will be called as soon as |
| 422 // print_job_->document()->IsComplete() is true on either ALL_PAGES_REQUESTED | 422 // print_job_->document()->IsComplete() is true on either ALL_PAGES_REQUESTED |
| 423 // or in DidPrintPage(). The check is done in | 423 // or in DidPrintPage(). The check is done in |
| 424 // ShouldQuitFromInnerMessageLoop(). | 424 // ShouldQuitFromInnerMessageLoop(). |
| 425 // BLOCKS until all the pages are received. (Need to enable recursive task) | 425 // BLOCKS until all the pages are received. (Need to enable recursive task) |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 return; | 503 return; |
| 504 | 504 |
| 505 if (cancel) { | 505 if (cancel) { |
| 506 // We don't need the metafile data anymore because the printing is canceled. | 506 // We don't need the metafile data anymore because the printing is canceled. |
| 507 print_job_->Cancel(); | 507 print_job_->Cancel(); |
| 508 inside_inner_message_loop_ = false; | 508 inside_inner_message_loop_ = false; |
| 509 } else { | 509 } else { |
| 510 DCHECK(!inside_inner_message_loop_); | 510 DCHECK(!inside_inner_message_loop_); |
| 511 DCHECK(!print_job_->document() || print_job_->document()->IsComplete()); | 511 DCHECK(!print_job_->document() || print_job_->document()->IsComplete()); |
| 512 | 512 |
| 513 // TabContents is either dying or navigating elsewhere. We need to render | 513 // WebContents is either dying or navigating elsewhere. We need to render |
| 514 // all the pages in an hurry if a print job is still pending. This does the | 514 // all the pages in an hurry if a print job is still pending. This does the |
| 515 // trick since it runs a blocking message loop: | 515 // trick since it runs a blocking message loop: |
| 516 print_job_->Stop(); | 516 print_job_->Stop(); |
| 517 } | 517 } |
| 518 ReleasePrintJob(); | 518 ReleasePrintJob(); |
| 519 } | 519 } |
| 520 | 520 |
| 521 void PrintViewManager::ReleasePrintJob() { | 521 void PrintViewManager::ReleasePrintJob() { |
| 522 if (!print_job_.get()) | 522 if (!print_job_.get()) |
| 523 return; | 523 return; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 scoped_refptr<printing::PrinterQuery> printer_query; | 622 scoped_refptr<printing::PrinterQuery> printer_query; |
| 623 print_job_manager->PopPrinterQuery(cookie, &printer_query); | 623 print_job_manager->PopPrinterQuery(cookie, &printer_query); |
| 624 if (!printer_query.get()) | 624 if (!printer_query.get()) |
| 625 return; | 625 return; |
| 626 BrowserThread::PostTask( | 626 BrowserThread::PostTask( |
| 627 BrowserThread::IO, FROM_HERE, | 627 BrowserThread::IO, FROM_HERE, |
| 628 base::Bind(&PrinterQuery::StopWorker, printer_query.get())); | 628 base::Bind(&PrinterQuery::StopWorker, printer_query.get())); |
| 629 } | 629 } |
| 630 | 630 |
| 631 } // namespace printing | 631 } // namespace printing |
| OLD | NEW |