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

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

Issue 2643163002: Refactor print_job.cc (Closed)
Patch Set: Fix protected Created 3 years, 11 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
« no previous file with comments | « chrome/browser/printing/print_job.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_job.h" 5 #include "chrome/browser/printing/print_job.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 215
216 bool PrintJob::is_job_pending() const { 216 bool PrintJob::is_job_pending() const {
217 return is_job_pending_; 217 return is_job_pending_;
218 } 218 }
219 219
220 PrintedDocument* PrintJob::document() const { 220 PrintedDocument* PrintJob::document() const {
221 return document_.get(); 221 return document_.get();
222 } 222 }
223 223
224 #if defined(OS_WIN) 224 #if defined(OS_WIN)
225 225 class PrintJob::PdfConversionState {
226 class PrintJob::PdfToEmfState {
227 public: 226 public:
228 PdfToEmfState(const gfx::Size& page_size, const gfx::Rect& content_area) 227 PdfConversionState(gfx::Size page_size,
228 gfx::Rect content_area,
229 std::unique_ptr<PdfConverter> converter)
229 : page_count_(0), 230 : page_count_(0),
230 current_page_(0), 231 current_page_(0),
231 pages_in_progress_(0), 232 pages_in_progress_(0),
232 page_size_(page_size), 233 page_size_(page_size),
233 content_area_(content_area), 234 content_area_(content_area) {
234 converter_(PdfConverter::CreatePdfToEmfConverter()) {} 235 converter_.reset(converter.release());
Vitaly Buka (NO REVIEWS) 2017/01/20 19:18:22 converter_(std::move(converter));
rbpotter 2017/01/20 22:15:20 Done.
236 }
235 237
236 void Start(const scoped_refptr<base::RefCountedMemory>& data, 238 void Start(const scoped_refptr<base::RefCountedMemory>& data,
237 const PdfRenderSettings& conversion_settings, 239 const PdfRenderSettings& conversion_settings,
238 bool print_text_with_gdi, 240 bool print_text_with_gdi,
239 const PdfConverter::StartCallback& start_callback) { 241 const PdfConverter::StartCallback& start_callback) {
240 converter_->Start(data, conversion_settings, print_text_with_gdi, 242 converter_->Start(data, conversion_settings, print_text_with_gdi,
241 start_callback); 243 start_callback);
242 } 244 }
243 245
244 void GetMorePages(const PdfConverter::GetPageCallback& get_page_callback) { 246 void GetMorePages(const PdfConverter::GetPageCallback& get_page_callback) {
(...skipping 28 matching lines...) Expand all
273 275
274 void PrintJob::AppendPrintedPage(int page_number) { 276 void PrintJob::AppendPrintedPage(int page_number) {
275 pdf_page_mapping_.push_back(page_number); 277 pdf_page_mapping_.push_back(page_number);
276 } 278 }
277 279
278 void PrintJob::StartPdfToEmfConversion( 280 void PrintJob::StartPdfToEmfConversion(
279 const scoped_refptr<base::RefCountedMemory>& bytes, 281 const scoped_refptr<base::RefCountedMemory>& bytes,
280 const gfx::Size& page_size, 282 const gfx::Size& page_size,
281 const gfx::Rect& content_area, 283 const gfx::Rect& content_area,
282 bool print_text_with_gdi) { 284 bool print_text_with_gdi) {
283 DCHECK(!pdf_to_emf_state_); 285 DCHECK(!pdf_conversion_state_);
284 pdf_to_emf_state_ = base::MakeUnique<PdfToEmfState>(page_size, content_area); 286 pdf_conversion_state_ =
287 base::MakeUnique<PdfConversionState>(page_size, content_area,
288 PdfConverter::CreatePdfToEmfConverter());
285 const int kPrinterDpi = settings().dpi(); 289 const int kPrinterDpi = settings().dpi();
286 pdf_to_emf_state_->Start( 290 PdfRenderSettings settings(content_area, kPrinterDpi, true /* autorotate? */);
287 bytes, PdfRenderSettings(content_area, kPrinterDpi, true), 291 pdf_conversion_state_->Start(
288 print_text_with_gdi, base::Bind(&PrintJob::OnPdfToEmfStarted, this)); 292 bytes, settings, print_text_with_gdi,
293 base::Bind(&PrintJob::OnPdfConversionStarted, this));
289 } 294 }
290 295
291 void PrintJob::OnPdfToEmfStarted(int page_count) { 296 void PrintJob::OnPdfConversionStarted(int page_count) {
292 if (page_count <= 0) { 297 if (page_count <= 0) {
293 pdf_to_emf_state_.reset(); 298 pdf_conversion_state_.reset();
294 Cancel(); 299 Cancel();
295 return; 300 return;
296 } 301 }
297 pdf_to_emf_state_->set_page_count(page_count); 302 pdf_conversion_state_->set_page_count(page_count);
298 pdf_to_emf_state_->GetMorePages( 303 pdf_conversion_state_->GetMorePages(
299 base::Bind(&PrintJob::OnPdfToEmfPageConverted, this)); 304 base::Bind(&PrintJob::OnPdfPageConverted, this));
300 } 305 }
301 306
302 void PrintJob::OnPdfToEmfPageConverted(int page_number, 307 void PrintJob::OnPdfPageConverted(int page_number,
303 float scale_factor, 308 float scale_factor,
304 std::unique_ptr<MetafilePlayer> emf) { 309 std::unique_ptr<MetafilePlayer> metafile) {
305 DCHECK(pdf_to_emf_state_); 310 DCHECK(pdf_conversion_state_);
306 if (!document_.get() || !emf || page_number < 0 || 311 if (!document_.get() || !metafile || page_number < 0 ||
307 static_cast<size_t>(page_number) >= pdf_page_mapping_.size()) { 312 static_cast<size_t>(page_number) >= pdf_page_mapping_.size()) {
308 pdf_to_emf_state_.reset(); 313 pdf_conversion_state_.reset();
309 Cancel(); 314 Cancel();
310 return; 315 return;
311 } 316 }
312 317
313 // Update the rendered document. It will send notifications to the listener. 318 // Update the rendered document. It will send notifications to the listener.
314 document_->SetPage(pdf_page_mapping_[page_number], std::move(emf), 319 document_->SetPage(pdf_page_mapping_[page_number], std::move(metafile),
315 scale_factor, pdf_to_emf_state_->page_size(), 320 scale_factor, pdf_conversion_state_->page_size(),
316 pdf_to_emf_state_->content_area()); 321 pdf_conversion_state_->content_area());
317 322
318 pdf_to_emf_state_->GetMorePages( 323 pdf_conversion_state_->GetMorePages(
319 base::Bind(&PrintJob::OnPdfToEmfPageConverted, this)); 324 base::Bind(&PrintJob::OnPdfPageConverted, this));
320 } 325 }
321 326 #endif // defined(OS_WIN)
322 #endif // OS_WIN
323 327
324 void PrintJob::UpdatePrintedDocument(PrintedDocument* new_document) { 328 void PrintJob::UpdatePrintedDocument(PrintedDocument* new_document) {
325 if (document_.get() == new_document) 329 if (document_.get() == new_document)
326 return; 330 return;
327 331
328 document_ = new_document; 332 document_ = new_document;
329 333
330 if (document_.get()) 334 if (document_.get())
331 settings_ = document_->settings(); 335 settings_ = document_->settings();
332 336
(...skipping 30 matching lines...) Expand all
363 break; 367 break;
364 } 368 }
365 case JobEventDetails::DOC_DONE: { 369 case JobEventDetails::DOC_DONE: {
366 // This will call Stop() and broadcast a JOB_DONE message. 370 // This will call Stop() and broadcast a JOB_DONE message.
367 base::ThreadTaskRunnerHandle::Get()->PostTask( 371 base::ThreadTaskRunnerHandle::Get()->PostTask(
368 FROM_HERE, base::Bind(&PrintJob::OnDocumentDone, this)); 372 FROM_HERE, base::Bind(&PrintJob::OnDocumentDone, this));
369 break; 373 break;
370 } 374 }
371 case JobEventDetails::PAGE_DONE: 375 case JobEventDetails::PAGE_DONE:
372 #if defined(OS_WIN) 376 #if defined(OS_WIN)
373 pdf_to_emf_state_->OnPageProcessed( 377 if (pdf_conversion_state_) {
374 base::Bind(&PrintJob::OnPdfToEmfPageConverted, this)); 378 pdf_conversion_state_->OnPageProcessed(
379 base::Bind(&PrintJob::OnPdfPageConverted, this));
380 }
375 #endif // defined(OS_WIN) 381 #endif // defined(OS_WIN)
376 break; 382 break;
377 default: { 383 default: {
378 NOTREACHED(); 384 NOTREACHED();
379 break; 385 break;
380 } 386 }
381 } 387 }
382 } 388 }
383 389
384 void PrintJob::OnDocumentDone() { 390 void PrintJob::OnDocumentDone() {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 } 461 }
456 462
457 JobEventDetails::~JobEventDetails() { 463 JobEventDetails::~JobEventDetails() {
458 } 464 }
459 465
460 PrintedDocument* JobEventDetails::document() const { return document_.get(); } 466 PrintedDocument* JobEventDetails::document() const { return document_.get(); }
461 467
462 PrintedPage* JobEventDetails::page() const { return page_.get(); } 468 PrintedPage* JobEventDetails::page() const { return page_.get(); }
463 469
464 } // namespace printing 470 } // namespace printing
OLDNEW
« no previous file with comments | « chrome/browser/printing/print_job.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698