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

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

Issue 2271743003: Win: Fix printing selected pages with native dialog. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: git cl format Created 4 years, 4 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_view_manager_base.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
diff --git a/chrome/browser/printing/print_job.cc b/chrome/browser/printing/print_job.cc
index 6c5f25883d7458be6fd34e03b63c88eb05f6813f..976ef0d4e8268de856568b5d2dc4d5a30b3da0c9 100644
--- a/chrome/browser/printing/print_job.cc
+++ b/chrome/browser/printing/print_job.cc
@@ -5,10 +5,12 @@
#include "chrome/browser/printing/print_job.h"
#include <memory>
+#include <utility>
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/location.h"
+#include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
@@ -30,22 +32,20 @@
using base::TimeDelta;
+namespace printing {
+
namespace {
// Helper function to ensure |owner| is valid until at least |callback| returns.
-void HoldRefCallback(const scoped_refptr<printing::PrintJobWorkerOwner>& owner,
+void HoldRefCallback(const scoped_refptr<PrintJobWorkerOwner>& owner,
const base::Closure& callback) {
callback.Run();
}
} // namespace
-namespace printing {
-
PrintJob::PrintJob()
- : source_(NULL),
- worker_(),
- settings_(),
+ : source_(nullptr),
is_job_pending_(false),
is_canceling_(false),
quit_factory_(this) {
@@ -68,7 +68,7 @@ void PrintJob::Initialize(PrintJobWorkerOwner* job,
PrintedPagesSource* source,
int page_count) {
DCHECK(!source_);
- DCHECK(!worker_.get());
+ DCHECK(!worker_);
DCHECK(!is_job_pending_);
DCHECK(!is_canceling_);
DCHECK(!document_.get());
@@ -105,7 +105,7 @@ void PrintJob::GetSettingsDone(const PrintSettings& new_settings,
PrintJobWorker* PrintJob::DetachWorker(PrintJobWorkerOwner* new_owner) {
NOTREACHED();
- return NULL;
+ return nullptr;
}
const PrintSettings& PrintJob::settings() const {
@@ -113,18 +113,18 @@ const PrintSettings& PrintJob::settings() const {
}
int PrintJob::cookie() const {
+ // Always use an invalid cookie in this case.
if (!document_.get())
- // Always use an invalid cookie in this case.
return 0;
return document_->cookie();
}
void PrintJob::StartPrinting() {
DCHECK(RunsTasksOnCurrentThread());
- DCHECK(worker_->IsRunning());
- DCHECK(!is_job_pending_);
- if (!worker_->IsRunning() || is_job_pending_)
+ if (!worker_->IsRunning() || is_job_pending_) {
+ NOTREACHED();
return;
+ }
// Real work is done in PrintJobWorker::StartPrinting().
worker_->PostTask(FROM_HERE,
@@ -137,7 +137,7 @@ void PrintJob::StartPrinting() {
// Tell everyone!
scoped_refptr<JobEventDetails> details(
- new JobEventDetails(JobEventDetails::NEW_DOC, document_.get(), NULL));
+ new JobEventDetails(JobEventDetails::NEW_DOC, document_.get(), nullptr));
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_PRINT_JOB_EVENT,
content::Source<PrintJob>(this),
@@ -182,7 +182,7 @@ void PrintJob::Cancel() {
}
// Make sure a Cancel() is broadcast.
scoped_refptr<JobEventDetails> details(
- new JobEventDetails(JobEventDetails::FAILED, NULL, NULL));
+ new JobEventDetails(JobEventDetails::FAILED, nullptr, nullptr));
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_PRINT_JOB_EVENT,
content::Source<PrintJob>(this),
@@ -207,7 +207,7 @@ bool PrintJob::FlushJob(base::TimeDelta timeout) {
}
void PrintJob::DisconnectSource() {
- source_ = NULL;
+ source_ = nullptr;
if (document_.get())
document_->DisconnectSource();
}
@@ -270,46 +270,50 @@ class PrintJob::PdfToEmfState {
std::unique_ptr<PdfToEmfConverter> converter_;
};
+void PrintJob::AppendPrintedPage(int page_number) {
+ pdf_page_mapping_.push_back(page_number);
+}
+
void PrintJob::StartPdfToEmfConversion(
const scoped_refptr<base::RefCountedMemory>& bytes,
const gfx::Size& page_size,
const gfx::Rect& content_area) {
- DCHECK(!ptd_to_emf_state_.get());
- ptd_to_emf_state_.reset(new PdfToEmfState(page_size, content_area));
+ DCHECK(!pdf_to_emf_state_);
+ pdf_to_emf_state_ = base::MakeUnique<PdfToEmfState>(page_size, content_area);
const int kPrinterDpi = settings().dpi();
- ptd_to_emf_state_->Start(
- bytes,
- printing::PdfRenderSettings(content_area, kPrinterDpi, true),
- base::Bind(&PrintJob::OnPdfToEmfStarted, this));
+ pdf_to_emf_state_->Start(bytes,
+ PdfRenderSettings(content_area, kPrinterDpi, true),
+ base::Bind(&PrintJob::OnPdfToEmfStarted, this));
}
void PrintJob::OnPdfToEmfStarted(int page_count) {
if (page_count <= 0) {
- ptd_to_emf_state_.reset();
+ pdf_to_emf_state_.reset();
Cancel();
return;
}
- ptd_to_emf_state_->set_page_count(page_count);
- ptd_to_emf_state_->GetMorePages(
+ pdf_to_emf_state_->set_page_count(page_count);
+ pdf_to_emf_state_->GetMorePages(
base::Bind(&PrintJob::OnPdfToEmfPageConverted, this));
}
void PrintJob::OnPdfToEmfPageConverted(int page_number,
float scale_factor,
std::unique_ptr<MetafilePlayer> emf) {
- DCHECK(ptd_to_emf_state_);
- if (!document_.get() || !emf) {
- ptd_to_emf_state_.reset();
+ DCHECK(pdf_to_emf_state_);
+ if (!document_.get() || !emf || page_number < 0 ||
+ static_cast<size_t>(page_number) >= pdf_page_mapping_.size()) {
+ pdf_to_emf_state_.reset();
Cancel();
return;
}
// Update the rendered document. It will send notifications to the listener.
- document_->SetPage(page_number, std::move(emf), scale_factor,
- ptd_to_emf_state_->page_size(),
- ptd_to_emf_state_->content_area());
+ document_->SetPage(pdf_page_mapping_[page_number], std::move(emf),
+ scale_factor, pdf_to_emf_state_->page_size(),
+ pdf_to_emf_state_->content_area());
- ptd_to_emf_state_->GetMorePages(
+ pdf_to_emf_state_->GetMorePages(
base::Bind(&PrintJob::OnPdfToEmfPageConverted, this));
}
@@ -321,9 +325,8 @@ void PrintJob::UpdatePrintedDocument(PrintedDocument* new_document) {
document_ = new_document;
- if (document_.get()) {
+ if (document_.get())
settings_ = document_->settings();
- }
if (worker_) {
DCHECK(!is_job_pending_);
@@ -365,9 +368,9 @@ void PrintJob::OnNotifyPrintJobEvent(const JobEventDetails& event_details) {
}
case JobEventDetails::PAGE_DONE:
#if defined(OS_WIN)
- ptd_to_emf_state_->OnPageProcessed(
+ pdf_to_emf_state_->OnPageProcessed(
base::Bind(&PrintJob::OnPdfToEmfPageConverted, this));
-#endif // OS_WIN
+#endif // defined(OS_WIN)
break;
default: {
NOTREACHED();
@@ -385,7 +388,7 @@ void PrintJob::OnDocumentDone() {
Stop();
scoped_refptr<JobEventDetails> details(
- new JobEventDetails(JobEventDetails::JOB_DONE, document_.get(), NULL));
+ new JobEventDetails(JobEventDetails::JOB_DONE, document_.get(), nullptr));
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_PRINT_JOB_EVENT,
content::Source<PrintJob>(this),
« no previous file with comments | « chrome/browser/printing/print_job.h ('k') | chrome/browser/printing/print_view_manager_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698