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

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

Issue 566693002: Use file handles to interact with utility process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mon Sep 15 03:22:54 PDT 2014 Created 6 years, 3 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
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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/threading/thread_restrictions.h" 10 #include "base/threading/thread_restrictions.h"
11 #include "base/threading/worker_pool.h" 11 #include "base/threading/worker_pool.h"
12 #include "base/timer/timer.h" 12 #include "base/timer/timer.h"
13 #include "chrome/browser/chrome_notification_types.h" 13 #include "chrome/browser/chrome_notification_types.h"
14 #include "chrome/browser/printing/print_job_worker.h" 14 #include "chrome/browser/printing/print_job_worker.h"
15 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/notification_service.h" 16 #include "content/public/browser/notification_service.h"
17 #include "printing/printed_document.h" 17 #include "printing/printed_document.h"
18 #include "printing/printed_page.h" 18 #include "printing/printed_page.h"
19 19
20 #if defined(OS_WIN)
21 #include "chrome/browser/printing/pdf_to_emf_converter.h"
22 #include "printing/pdf_render_settings.h"
23 #endif
24
20 using base::TimeDelta; 25 using base::TimeDelta;
21 26
22 namespace { 27 namespace {
23 28
24 // Helper function to ensure |owner| is valid until at least |callback| returns. 29 // Helper function to ensure |owner| is valid until at least |callback| returns.
25 void HoldRefCallback(const scoped_refptr<printing::PrintJobWorkerOwner>& owner, 30 void HoldRefCallback(const scoped_refptr<printing::PrintJobWorkerOwner>& owner,
26 const base::Closure& callback) { 31 const base::Closure& callback) {
27 callback.Run(); 32 callback.Run();
28 } 33 }
29 34
30 } // namespace 35 } // namespace
31 36
32 namespace printing { 37 namespace printing {
33 38
34 PrintJob::PrintJob() 39 PrintJob::PrintJob()
35 : source_(NULL), 40 : source_(NULL),
36 worker_(), 41 worker_(),
37 settings_(), 42 settings_(),
38 is_job_pending_(false), 43 is_job_pending_(false),
39 is_canceling_(false), 44 is_canceling_(false),
45 #if defined(OS_WIN)
46 pdf_to_emf_page_count_(0),
47 pdf_to_emf_current_page_(0),
48 #endif
40 quit_factory_(this) { 49 quit_factory_(this) {
41 // This is normally a UI message loop, but in unit tests, the message loop is 50 // This is normally a UI message loop, but in unit tests, the message loop is
42 // of the 'default' type. 51 // of the 'default' type.
43 DCHECK(base::MessageLoopForUI::IsCurrent() || 52 DCHECK(base::MessageLoopForUI::IsCurrent() ||
44 base::MessageLoop::current()->type() == 53 base::MessageLoop::current()->type() ==
45 base::MessageLoop::TYPE_DEFAULT); 54 base::MessageLoop::TYPE_DEFAULT);
46 } 55 }
47 56
48 PrintJob::~PrintJob() { 57 PrintJob::~PrintJob() {
49 // The job should be finished (or at least canceled) when it is destroyed. 58 // The job should be finished (or at least canceled) when it is destroyed.
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 } 216 }
208 217
209 bool PrintJob::is_job_pending() const { 218 bool PrintJob::is_job_pending() const {
210 return is_job_pending_; 219 return is_job_pending_;
211 } 220 }
212 221
213 PrintedDocument* PrintJob::document() const { 222 PrintedDocument* PrintJob::document() const {
214 return document_.get(); 223 return document_.get();
215 } 224 }
216 225
226 #if defined(OS_WIN)
227 void PrintJob::ConvertPdfToEmf(
228 const scoped_refptr<base::RefCountedMemory>& bytes,
229 gfx::Size page_size,
230 gfx::Rect content_area) {
Lei Zhang 2014/09/15 21:49:53 Can you DCHECK here and in the callbacks to make s
Vitaly Buka (NO REVIEWS) 2014/09/15 22:33:50 Done.
231 DCHECK(!pdf_to_emf_converter_.get());
232 pdf_to_emf_converter_ = PdfToEmfConverter::CreateDefault();
233 const int kPrinterDpi = settings().dpi();
234 pdf_to_emf_page_size_ = page_size;
Lei Zhang 2014/09/15 21:49:53 This is set once here for PDF file. Is the PDF fil
Vitaly Buka (NO REVIEWS) 2014/09/15 22:33:50 That's looks incorrect. But I don't change behaiv
235 pdf_to_emf_content_area_ = content_area;
236 pdf_to_emf_converter_->Start(
237 bytes,
238 printing::PdfRenderSettings(content_area, kPrinterDpi, true),
239 base::Bind(&PrintJob::OnPdfLoaded, this));
240 }
241
242 void PrintJob::OnPdfPageConvertedToEmf(int page_number,
243 double scale_factor,
244 scoped_ptr<MetafilePlayer> emf) {
245 DCHECK(pdf_to_emf_converter_);
246 if (!document_.get() || !emf)
247 return OnPdfLoaded(false);
248
249 // Update the rendered document. It will send notifications to the listener.
250 document_->SetPage(pdf_to_emf_current_page_++,
251 emf.Pass(),
252 scale_factor,
253 pdf_to_emf_page_size_,
254 pdf_to_emf_content_area_);
255
256 if (pdf_to_emf_current_page_ < pdf_to_emf_page_count_)
Lei Zhang 2014/09/15 21:49:53 nit: wrap inner block in braces.
Vitaly Buka (NO REVIEWS) 2014/09/15 22:33:50 Done.
Vitaly Buka (NO REVIEWS) 2014/09/15 22:33:50 Done.
257 pdf_to_emf_converter_->GetPage(
258 pdf_to_emf_current_page_,
259 base::Bind(&PrintJob::OnPdfPageConvertedToEmf, this));
260 }
261
262 void PrintJob::OnPdfLoaded(int page_count) {
263 if (page_count <= 0) {
264 pdf_to_emf_converter_.reset();
265 Cancel();
266 return;
267 }
268 pdf_to_emf_page_count_ = page_count;
269 pdf_to_emf_current_page_ = 0;
270
271 pdf_to_emf_converter_->GetPage(
272 pdf_to_emf_current_page_,
273 base::Bind(&PrintJob::OnPdfPageConvertedToEmf, this));
274 }
275 #endif // OS_WIN
276
217 void PrintJob::UpdatePrintedDocument(PrintedDocument* new_document) { 277 void PrintJob::UpdatePrintedDocument(PrintedDocument* new_document) {
218 if (document_.get() == new_document) 278 if (document_.get() == new_document)
219 return; 279 return;
220 280
221 document_ = new_document; 281 document_ = new_document;
222 282
223 if (document_.get()) { 283 if (document_.get()) {
224 settings_ = document_->settings(); 284 settings_ = document_->settings();
225 } 285 }
226 286
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 } 406 }
347 407
348 JobEventDetails::~JobEventDetails() { 408 JobEventDetails::~JobEventDetails() {
349 } 409 }
350 410
351 PrintedDocument* JobEventDetails::document() const { return document_.get(); } 411 PrintedDocument* JobEventDetails::document() const { return document_.get(); }
352 412
353 PrintedPage* JobEventDetails::page() const { return page_.get(); } 413 PrintedPage* JobEventDetails::page() const { return page_.get(); }
354 414
355 } // namespace printing 415 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698