| 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_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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 224 #if defined(OS_WIN) | 224 #if defined(OS_WIN) | 
| 225 | 225 | 
| 226 class PrintJob::PdfToEmfState { | 226 class PrintJob::PdfToEmfState { | 
| 227  public: | 227  public: | 
| 228   PdfToEmfState(const gfx::Size& page_size, const gfx::Rect& content_area) | 228   PdfToEmfState(const gfx::Size& page_size, const gfx::Rect& content_area) | 
| 229       : page_count_(0), | 229       : page_count_(0), | 
| 230         current_page_(0), | 230         current_page_(0), | 
| 231         pages_in_progress_(0), | 231         pages_in_progress_(0), | 
| 232         page_size_(page_size), | 232         page_size_(page_size), | 
| 233         content_area_(content_area), | 233         content_area_(content_area), | 
| 234         converter_(PdfToEmfConverter::CreateDefault()) {} | 234         converter_(PdfConverter::CreatePdfToEmfConverter()) {} | 
| 235 | 235 | 
| 236   void Start(const scoped_refptr<base::RefCountedMemory>& data, | 236   void Start(const scoped_refptr<base::RefCountedMemory>& data, | 
| 237              const PdfRenderSettings& conversion_settings, | 237              const PdfRenderSettings& conversion_settings, | 
| 238              bool print_text_with_gdi, | 238              bool print_text_with_gdi, | 
| 239              const PdfToEmfConverter::StartCallback& start_callback) { | 239              const PdfConverter::StartCallback& start_callback) { | 
| 240     converter_->Start(data, conversion_settings, print_text_with_gdi, | 240     converter_->Start(data, conversion_settings, print_text_with_gdi, | 
| 241                       start_callback); | 241                       start_callback); | 
| 242   } | 242   } | 
| 243 | 243 | 
| 244   void GetMorePages( | 244   void GetMorePages(const PdfConverter::GetPageCallback& get_page_callback) { | 
| 245       const PdfToEmfConverter::GetPageCallback& get_page_callback) { |  | 
| 246     const int kMaxNumberOfTempFilesPerDocument = 3; | 245     const int kMaxNumberOfTempFilesPerDocument = 3; | 
| 247     while (pages_in_progress_ < kMaxNumberOfTempFilesPerDocument && | 246     while (pages_in_progress_ < kMaxNumberOfTempFilesPerDocument && | 
| 248            current_page_ < page_count_) { | 247            current_page_ < page_count_) { | 
| 249       ++pages_in_progress_; | 248       ++pages_in_progress_; | 
| 250       converter_->GetPage(current_page_++, get_page_callback); | 249       converter_->GetPage(current_page_++, get_page_callback); | 
| 251     } | 250     } | 
| 252   } | 251   } | 
| 253 | 252 | 
| 254   void OnPageProcessed( | 253   void OnPageProcessed(const PdfConverter::GetPageCallback& get_page_callback) { | 
| 255       const PdfToEmfConverter::GetPageCallback& get_page_callback) { |  | 
| 256     --pages_in_progress_; | 254     --pages_in_progress_; | 
| 257     GetMorePages(get_page_callback); | 255     GetMorePages(get_page_callback); | 
| 258     // Release converter if we don't need this any more. | 256     // Release converter if we don't need this any more. | 
| 259     if (!pages_in_progress_ && current_page_ >= page_count_) | 257     if (!pages_in_progress_ && current_page_ >= page_count_) | 
| 260       converter_.reset(); | 258       converter_.reset(); | 
| 261   } | 259   } | 
| 262 | 260 | 
| 263   void set_page_count(int page_count) { page_count_ = page_count; } | 261   void set_page_count(int page_count) { page_count_ = page_count; } | 
| 264   gfx::Size page_size() const { return page_size_; } | 262   gfx::Size page_size() const { return page_size_; } | 
| 265   gfx::Rect content_area() const { return content_area_; } | 263   gfx::Rect content_area() const { return content_area_; } | 
| 266 | 264 | 
| 267  private: | 265  private: | 
| 268   int page_count_; | 266   int page_count_; | 
| 269   int current_page_; | 267   int current_page_; | 
| 270   int pages_in_progress_; | 268   int pages_in_progress_; | 
| 271   gfx::Size page_size_; | 269   gfx::Size page_size_; | 
| 272   gfx::Rect content_area_; | 270   gfx::Rect content_area_; | 
| 273   std::unique_ptr<PdfToEmfConverter> converter_; | 271   std::unique_ptr<PdfConverter> converter_; | 
| 274 }; | 272 }; | 
| 275 | 273 | 
| 276 void PrintJob::AppendPrintedPage(int page_number) { | 274 void PrintJob::AppendPrintedPage(int page_number) { | 
| 277   pdf_page_mapping_.push_back(page_number); | 275   pdf_page_mapping_.push_back(page_number); | 
| 278 } | 276 } | 
| 279 | 277 | 
| 280 void PrintJob::StartPdfToEmfConversion( | 278 void PrintJob::StartPdfToEmfConversion( | 
| 281     const scoped_refptr<base::RefCountedMemory>& bytes, | 279     const scoped_refptr<base::RefCountedMemory>& bytes, | 
| 282     const gfx::Size& page_size, | 280     const gfx::Size& page_size, | 
| 283     const gfx::Rect& content_area, | 281     const gfx::Rect& content_area, | 
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 457 } | 455 } | 
| 458 | 456 | 
| 459 JobEventDetails::~JobEventDetails() { | 457 JobEventDetails::~JobEventDetails() { | 
| 460 } | 458 } | 
| 461 | 459 | 
| 462 PrintedDocument* JobEventDetails::document() const { return document_.get(); } | 460 PrintedDocument* JobEventDetails::document() const { return document_.get(); } | 
| 463 | 461 | 
| 464 PrintedPage* JobEventDetails::page() const { return page_.get(); } | 462 PrintedPage* JobEventDetails::page() const { return page_.get(); } | 
| 465 | 463 | 
| 466 }  // namespace printing | 464 }  // namespace printing | 
| OLD | NEW | 
|---|