Commit 1d8bc5d0 authored by Vladislav Kuzkokov's avatar Vladislav Kuzkokov Committed by Commit Bot

[Printing] Remove unnecessary copy of PrintSettings in PrintJob.

Everywhere where needed the copy in PrintedDocument is available.

Bug: 964948
Change-Id: I34a7e1eaddb884f5e0bff9710767ed03eda96ce0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1631598Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Vladislav Kuzkokov <vkuzkokov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#666274}
parent c4618536
...@@ -61,15 +61,15 @@ void PrintJob::Initialize(std::unique_ptr<PrinterQuery> query, ...@@ -61,15 +61,15 @@ void PrintJob::Initialize(std::unique_ptr<PrinterQuery> query,
DCHECK(!document_); DCHECK(!document_);
worker_ = query->DetachWorker(); worker_ = query->DetachWorker();
worker_->SetPrintJob(this); worker_->SetPrintJob(this);
settings_ = query->settings(); const PrintSettings& settings = query->settings();
auto new_doc = auto new_doc =
base::MakeRefCounted<PrintedDocument>(settings_, name, query->cookie()); base::MakeRefCounted<PrintedDocument>(settings, name, query->cookie());
new_doc->set_page_count(page_count); new_doc->set_page_count(page_count);
UpdatePrintedDocument(new_doc); UpdatePrintedDocument(new_doc);
#if defined(OS_WIN) #if defined(OS_WIN)
pdf_page_mapping_ = PageRange::GetPages(settings_.ranges()); pdf_page_mapping_ = PageRange::GetPages(settings.ranges());
if (pdf_page_mapping_.empty()) { if (pdf_page_mapping_.empty()) {
for (int i = 0; i < page_count; i++) for (int i = 0; i < page_count; i++)
pdf_page_mapping_.push_back(i); pdf_page_mapping_.push_back(i);
...@@ -104,13 +104,14 @@ void PrintJob::StartConversionToNativeFormat( ...@@ -104,13 +104,14 @@ void PrintJob::StartConversionToNativeFormat(
if (PrintedDocument::HasDebugDumpPath()) if (PrintedDocument::HasDebugDumpPath())
document()->DebugDumpData(print_data.get(), FILE_PATH_LITERAL(".pdf")); document()->DebugDumpData(print_data.get(), FILE_PATH_LITERAL(".pdf"));
if (settings_.printer_is_textonly()) { const PrintSettings& settings = document()->settings();
if (settings.printer_is_textonly()) {
StartPdfToTextConversion(print_data, page_size); StartPdfToTextConversion(print_data, page_size);
} else if ((settings_.printer_is_ps2() || settings_.printer_is_ps3()) && } else if ((settings.printer_is_ps2() || settings.printer_is_ps3()) &&
!base::FeatureList::IsEnabled( !base::FeatureList::IsEnabled(
features::kDisablePostScriptPrinting)) { features::kDisablePostScriptPrinting)) {
StartPdfToPostScriptConversion(print_data, content_area, physical_offsets, StartPdfToPostScriptConversion(print_data, content_area, physical_offsets,
settings_.printer_is_ps2()); settings.printer_is_ps2());
} else { } else {
StartPdfToEmfConversion(print_data, page_size, content_area); StartPdfToEmfConversion(print_data, page_size, content_area);
} }
...@@ -234,6 +235,10 @@ PrintedDocument* PrintJob::document() const { ...@@ -234,6 +235,10 @@ PrintedDocument* PrintJob::document() const {
return document_.get(); return document_.get();
} }
const PrintSettings& PrintJob::settings() const {
return document()->settings();
}
#if defined(OS_WIN) #if defined(OS_WIN)
class PrintJob::PdfConversionState { class PrintJob::PdfConversionState {
public: public:
...@@ -295,12 +300,13 @@ void PrintJob::StartPdfToEmfConversion( ...@@ -295,12 +300,13 @@ void PrintJob::StartPdfToEmfConversion(
// Update : The missing letters seem to have been caused by the same // Update : The missing letters seem to have been caused by the same
// problem as https://crbug.com/659604 which was resolved. GDI printing // problem as https://crbug.com/659604 which was resolved. GDI printing
// seems to work with the fix for this bug applied. // seems to work with the fix for this bug applied.
const PrintSettings& settings = document()->settings();
bool print_text_with_gdi = bool print_text_with_gdi =
settings_.print_text_with_gdi() && !settings_.printer_is_xps() && settings.print_text_with_gdi() && !settings.printer_is_xps() &&
base::FeatureList::IsEnabled(features::kGdiTextPrinting); base::FeatureList::IsEnabled(features::kGdiTextPrinting);
PdfRenderSettings render_settings( PdfRenderSettings render_settings(
content_area, gfx::Point(0, 0), settings_.dpi_size(), content_area, gfx::Point(0, 0), settings.dpi_size(),
/*autorotate=*/true, settings_.color() == COLOR, /*autorotate=*/true, settings.color() == COLOR,
print_text_with_gdi ? PdfRenderSettings::Mode::GDI_TEXT print_text_with_gdi ? PdfRenderSettings::Mode::GDI_TEXT
: PdfRenderSettings::Mode::NORMAL); : PdfRenderSettings::Mode::NORMAL);
pdf_conversion_state_->Start( pdf_conversion_state_->Start(
...@@ -358,8 +364,9 @@ void PrintJob::StartPdfToTextConversion( ...@@ -358,8 +364,9 @@ void PrintJob::StartPdfToTextConversion(
pdf_conversion_state_ = pdf_conversion_state_ =
std::make_unique<PdfConversionState>(gfx::Size(), gfx::Rect()); std::make_unique<PdfConversionState>(gfx::Size(), gfx::Rect());
gfx::Rect page_area = gfx::Rect(0, 0, page_size.width(), page_size.height()); gfx::Rect page_area = gfx::Rect(0, 0, page_size.width(), page_size.height());
const PrintSettings& settings = document()->settings();
PdfRenderSettings render_settings( PdfRenderSettings render_settings(
page_area, gfx::Point(0, 0), settings_.dpi_size(), page_area, gfx::Point(0, 0), settings.dpi_size(),
/*autorotate=*/true, /*autorotate=*/true,
/*use_color=*/true, PdfRenderSettings::Mode::TEXTONLY); /*use_color=*/true, PdfRenderSettings::Mode::TEXTONLY);
pdf_conversion_state_->Start( pdf_conversion_state_->Start(
...@@ -376,9 +383,10 @@ void PrintJob::StartPdfToPostScriptConversion( ...@@ -376,9 +383,10 @@ void PrintJob::StartPdfToPostScriptConversion(
DCHECK(!pdf_conversion_state_); DCHECK(!pdf_conversion_state_);
pdf_conversion_state_ = std::make_unique<PdfConversionState>( pdf_conversion_state_ = std::make_unique<PdfConversionState>(
gfx::Size(), gfx::Rect()); gfx::Size(), gfx::Rect());
const PrintSettings& settings = document()->settings();
PdfRenderSettings render_settings( PdfRenderSettings render_settings(
content_area, physical_offsets, settings_.dpi_size(), content_area, physical_offsets, settings.dpi_size(),
/*autorotate=*/true, settings_.color() == COLOR, /*autorotate=*/true, settings.color() == COLOR,
ps_level2 ? PdfRenderSettings::Mode::POSTSCRIPT_LEVEL2 ps_level2 ? PdfRenderSettings::Mode::POSTSCRIPT_LEVEL2
: PdfRenderSettings::Mode::POSTSCRIPT_LEVEL3); : PdfRenderSettings::Mode::POSTSCRIPT_LEVEL3);
pdf_conversion_state_->Start( pdf_conversion_state_->Start(
...@@ -425,7 +433,6 @@ void PrintJob::OnNotifyPrintJobEvent(const JobEventDetails& event_details) { ...@@ -425,7 +433,6 @@ void PrintJob::OnNotifyPrintJobEvent(const JobEventDetails& event_details) {
switch (event_details.type()) { switch (event_details.type()) {
case JobEventDetails::FAILED: { case JobEventDetails::FAILED: {
settings_.Clear();
// No need to cancel since the worker already canceled itself. // No need to cancel since the worker already canceled itself.
Stop(); Stop();
break; break;
...@@ -533,10 +540,6 @@ bool PrintJob::PostTask(const base::Location& from_here, ...@@ -533,10 +540,6 @@ bool PrintJob::PostTask(const base::Location& from_here,
void PrintJob::HoldUntilStopIsCalled() { void PrintJob::HoldUntilStopIsCalled() {
} }
void PrintJob::set_settings(const PrintSettings& settings) {
settings_ = settings;
}
void PrintJob::set_job_pending(bool pending) { void PrintJob::set_job_pending(bool pending) {
is_job_pending_ = pending; is_job_pending_ = pending;
} }
......
...@@ -104,7 +104,7 @@ class PrintJob : public base::RefCountedThreadSafe<PrintJob>, ...@@ -104,7 +104,7 @@ class PrintJob : public base::RefCountedThreadSafe<PrintJob>,
PrintedDocument* document() const; PrintedDocument* document() const;
// Access stored settings. // Access stored settings.
const PrintSettings& settings() const { return settings_; } const PrintSettings& settings() const;
// Posts the given task to be run. // Posts the given task to be run.
bool PostTask(const base::Location& from_here, base::OnceClosure task); bool PostTask(const base::Location& from_here, base::OnceClosure task);
...@@ -117,7 +117,6 @@ class PrintJob : public base::RefCountedThreadSafe<PrintJob>, ...@@ -117,7 +117,6 @@ class PrintJob : public base::RefCountedThreadSafe<PrintJob>,
// The functions below are used for tests only. // The functions below are used for tests only.
void set_job_pending(bool pending); void set_job_pending(bool pending);
void set_settings(const PrintSettings& settings);
// Updates |document_| to a new instance. Protected so that tests can access // Updates |document_| to a new instance. Protected so that tests can access
// it. // it.
...@@ -181,9 +180,6 @@ class PrintJob : public base::RefCountedThreadSafe<PrintJob>, ...@@ -181,9 +180,6 @@ class PrintJob : public base::RefCountedThreadSafe<PrintJob>,
// worker thread per print job. // worker thread per print job.
std::unique_ptr<PrintJobWorker> worker_; std::unique_ptr<PrintJobWorker> worker_;
// Cache of the print context settings for access in the UI thread.
PrintSettings settings_;
// The printed document. // The printed document.
scoped_refptr<PrintedDocument> document_; scoped_refptr<PrintedDocument> document_;
......
...@@ -23,8 +23,6 @@ void TestPrintJob::Initialize(std::unique_ptr<PrinterQuery> query, ...@@ -23,8 +23,6 @@ void TestPrintJob::Initialize(std::unique_ptr<PrinterQuery> query,
// when this function exits. // when this function exits.
std::unique_ptr<PrintJobWorker> worker = query->DetachWorker(); std::unique_ptr<PrintJobWorker> worker = query->DetachWorker();
set_settings(query->settings());
scoped_refptr<PrintedDocument> new_doc = scoped_refptr<PrintedDocument> new_doc =
base::MakeRefCounted<PrintedDocument>(query->settings(), name, base::MakeRefCounted<PrintedDocument>(query->settings(), name,
query->cookie()); query->cookie());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment