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/service/cloud_print/print_system.h" | 5 #include "chrome/service/cloud_print/print_system.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/thread_task_runner_handle.h" |
12 #include "base/win/object_watcher.h" | 13 #include "base/win/object_watcher.h" |
13 #include "base/win/scoped_bstr.h" | 14 #include "base/win/scoped_bstr.h" |
14 #include "base/win/scoped_comptr.h" | 15 #include "base/win/scoped_comptr.h" |
15 #include "base/win/scoped_hdc.h" | 16 #include "base/win/scoped_hdc.h" |
16 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
17 #include "chrome/common/cloud_print/cloud_print_cdd_conversion.h" | 18 #include "chrome/common/cloud_print/cloud_print_cdd_conversion.h" |
18 #include "chrome/common/cloud_print/cloud_print_constants.h" | 19 #include "chrome/common/cloud_print/cloud_print_constants.h" |
19 #include "chrome/common/crash_keys.h" | 20 #include "chrome/common/crash_keys.h" |
20 #include "chrome/service/cloud_print/cdd_conversion_win.h" | 21 #include "chrome/service/cloud_print/cdd_conversion_win.h" |
21 #include "chrome/service/service_process.h" | 22 #include "chrome/service/service_process.h" |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 delegate_->OnJobSpoolFailed(); | 404 delegate_->OnJobSpoolFailed(); |
404 } | 405 } |
405 delegate_ = NULL; | 406 delegate_ = NULL; |
406 } | 407 } |
407 | 408 |
408 void RenderPDFPages() { | 409 void RenderPDFPages() { |
409 int printer_dpi = ::GetDeviceCaps(printer_dc_.Get(), LOGPIXELSX); | 410 int printer_dpi = ::GetDeviceCaps(printer_dc_.Get(), LOGPIXELSX); |
410 int dc_width = GetDeviceCaps(printer_dc_.Get(), PHYSICALWIDTH); | 411 int dc_width = GetDeviceCaps(printer_dc_.Get(), PHYSICALWIDTH); |
411 int dc_height = GetDeviceCaps(printer_dc_.Get(), PHYSICALHEIGHT); | 412 int dc_height = GetDeviceCaps(printer_dc_.Get(), PHYSICALHEIGHT); |
412 gfx::Rect render_area(0, 0, dc_width, dc_height); | 413 gfx::Rect render_area(0, 0, dc_width, dc_height); |
413 g_service_process->io_thread()->message_loop_proxy()->PostTask( | 414 g_service_process->io_thread()->task_runner()->PostTask( |
414 FROM_HERE, | 415 FROM_HERE, |
415 base::Bind(&JobSpoolerWin::Core::RenderPDFPagesInSandbox, | 416 base::Bind(&JobSpoolerWin::Core::RenderPDFPagesInSandbox, this, |
416 this, | 417 print_data_file_path_, render_area, printer_dpi, |
417 print_data_file_path_, | 418 base::ThreadTaskRunnerHandle::Get())); |
418 render_area, | |
419 printer_dpi, | |
420 base::MessageLoopProxy::current())); | |
421 } | 419 } |
422 | 420 |
423 // Called on the service process IO thread. | 421 // Called on the service process IO thread. |
424 void RenderPDFPagesInSandbox(const base::FilePath& pdf_path, | 422 void RenderPDFPagesInSandbox( |
425 const gfx::Rect& render_area, | 423 const base::FilePath& pdf_path, |
426 int render_dpi, | 424 const gfx::Rect& render_area, |
427 const scoped_refptr<base::MessageLoopProxy>& | 425 int render_dpi, |
428 client_message_loop_proxy) { | 426 const scoped_refptr<base::SingleThreadTaskRunner>& client_task_runner) { |
429 DCHECK(g_service_process->io_thread()->message_loop_proxy()-> | 427 DCHECK(g_service_process->io_thread() |
430 BelongsToCurrentThread()); | 428 ->task_runner() |
| 429 ->BelongsToCurrentThread()); |
431 scoped_ptr<ServiceUtilityProcessHost> utility_host( | 430 scoped_ptr<ServiceUtilityProcessHost> utility_host( |
432 new ServiceUtilityProcessHost(this, client_message_loop_proxy.get())); | 431 new ServiceUtilityProcessHost(this, client_task_runner.get())); |
433 // TODO(gene): For now we disabling autorotation for CloudPrinting. | 432 // TODO(gene): For now we disabling autorotation for CloudPrinting. |
434 // Landscape/Portrait setting is passed in the print ticket and | 433 // Landscape/Portrait setting is passed in the print ticket and |
435 // server is generating portrait PDF always. | 434 // server is generating portrait PDF always. |
436 // We should enable autorotation once server will be able to generate | 435 // We should enable autorotation once server will be able to generate |
437 // PDF that matches paper size and orientation. | 436 // PDF that matches paper size and orientation. |
438 if (utility_host->StartRenderPDFPagesToMetafile( | 437 if (utility_host->StartRenderPDFPagesToMetafile( |
439 pdf_path, | 438 pdf_path, |
440 printing::PdfRenderSettings(render_area, render_dpi, false))) { | 439 printing::PdfRenderSettings(render_area, render_dpi, false))) { |
441 // The object will self-destruct when the child process dies. | 440 // The object will self-destruct when the child process dies. |
442 utility_host.release(); | 441 utility_host.release(); |
443 } else { | 442 } else { |
444 client_message_loop_proxy->PostTask( | 443 client_task_runner->PostTask( |
445 FROM_HERE, base::Bind(&Core::PrintJobDone, this, false)); | 444 FROM_HERE, base::Bind(&Core::PrintJobDone, this, false)); |
446 } | 445 } |
447 } | 446 } |
448 | 447 |
449 bool PrintXPSDocument(const std::string& printer_name, | 448 bool PrintXPSDocument(const std::string& printer_name, |
450 const std::string& job_title, | 449 const std::string& job_title, |
451 const base::FilePath& print_data_file_path, | 450 const base::FilePath& print_data_file_path, |
452 const std::string& print_ticket) { | 451 const std::string& print_ticket) { |
453 if (!printing::XPSPrintModule::Init()) | 452 if (!printing::XPSPrintModule::Init()) |
454 return false; | 453 return false; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 *description, base::JSONWriter::OPTIONS_PRETTY_PRINT, | 547 *description, base::JSONWriter::OPTIONS_PRETTY_PRINT, |
549 &printer_info.printer_capabilities); | 548 &printer_info.printer_capabilities); |
550 } | 549 } |
551 } | 550 } |
552 callback_.Run(succeeded, printer_name, printer_info); | 551 callback_.Run(succeeded, printer_name, printer_info); |
553 callback_.Reset(); | 552 callback_.Reset(); |
554 Release(); | 553 Release(); |
555 } | 554 } |
556 | 555 |
557 void StartGetPrinterCapsAndDefaults() { | 556 void StartGetPrinterCapsAndDefaults() { |
558 g_service_process->io_thread()->message_loop_proxy()->PostTask( | 557 g_service_process->io_thread()->task_runner()->PostTask( |
559 FROM_HERE, | 558 FROM_HERE, |
560 base::Bind(&PrinterCapsHandler::GetPrinterCapsAndDefaultsImpl, this, | 559 base::Bind(&PrinterCapsHandler::GetPrinterCapsAndDefaultsImpl, this, |
561 base::MessageLoopProxy::current())); | 560 base::ThreadTaskRunnerHandle::Get())); |
562 } | 561 } |
563 | 562 |
564 void StartGetPrinterSemanticCapsAndDefaults() { | 563 void StartGetPrinterSemanticCapsAndDefaults() { |
565 g_service_process->io_thread()->message_loop_proxy()->PostTask( | 564 g_service_process->io_thread()->task_runner()->PostTask( |
566 FROM_HERE, | 565 FROM_HERE, |
567 base::Bind(&PrinterCapsHandler::GetPrinterSemanticCapsAndDefaultsImpl, | 566 base::Bind(&PrinterCapsHandler::GetPrinterSemanticCapsAndDefaultsImpl, |
568 this, base::MessageLoopProxy::current())); | 567 this, base::ThreadTaskRunnerHandle::Get())); |
569 } | 568 } |
570 | 569 |
571 private: | 570 private: |
572 ~PrinterCapsHandler() override {} | 571 ~PrinterCapsHandler() override {} |
573 | 572 |
574 void GetPrinterCapsAndDefaultsImpl( | 573 void GetPrinterCapsAndDefaultsImpl( |
575 const scoped_refptr<base::MessageLoopProxy>& | 574 const scoped_refptr<base::SingleThreadTaskRunner>& client_task_runner) { |
576 client_message_loop_proxy) { | 575 DCHECK(g_service_process->io_thread() |
577 DCHECK(g_service_process->io_thread()->message_loop_proxy()-> | 576 ->task_runner() |
578 BelongsToCurrentThread()); | 577 ->BelongsToCurrentThread()); |
579 scoped_ptr<ServiceUtilityProcessHost> utility_host( | 578 scoped_ptr<ServiceUtilityProcessHost> utility_host( |
580 new ServiceUtilityProcessHost(this, client_message_loop_proxy.get())); | 579 new ServiceUtilityProcessHost(this, client_task_runner.get())); |
581 if (utility_host->StartGetPrinterCapsAndDefaults(printer_name_)) { | 580 if (utility_host->StartGetPrinterCapsAndDefaults(printer_name_)) { |
582 // The object will self-destruct when the child process dies. | 581 // The object will self-destruct when the child process dies. |
583 utility_host.release(); | 582 utility_host.release(); |
584 } else { | 583 } else { |
585 client_message_loop_proxy->PostTask( | 584 client_task_runner->PostTask( |
586 FROM_HERE, | 585 FROM_HERE, base::Bind(&PrinterCapsHandler::OnChildDied, this)); |
587 base::Bind(&PrinterCapsHandler::OnChildDied, this)); | |
588 } | 586 } |
589 } | 587 } |
590 | 588 |
591 void GetPrinterSemanticCapsAndDefaultsImpl( | 589 void GetPrinterSemanticCapsAndDefaultsImpl( |
592 const scoped_refptr<base::MessageLoopProxy>& | 590 const scoped_refptr<base::SingleThreadTaskRunner>& client_task_runner) { |
593 client_message_loop_proxy) { | 591 DCHECK(g_service_process->io_thread() |
594 DCHECK(g_service_process->io_thread()->message_loop_proxy()-> | 592 ->task_runner() |
595 BelongsToCurrentThread()); | 593 ->BelongsToCurrentThread()); |
596 scoped_ptr<ServiceUtilityProcessHost> utility_host( | 594 scoped_ptr<ServiceUtilityProcessHost> utility_host( |
597 new ServiceUtilityProcessHost(this, client_message_loop_proxy.get())); | 595 new ServiceUtilityProcessHost(this, client_task_runner.get())); |
598 if (utility_host->StartGetPrinterSemanticCapsAndDefaults(printer_name_)) { | 596 if (utility_host->StartGetPrinterSemanticCapsAndDefaults(printer_name_)) { |
599 // The object will self-destruct when the child process dies. | 597 // The object will self-destruct when the child process dies. |
600 utility_host.release(); | 598 utility_host.release(); |
601 } else { | 599 } else { |
602 client_message_loop_proxy->PostTask( | 600 client_task_runner->PostTask( |
603 FROM_HERE, | 601 FROM_HERE, base::Bind(&PrinterCapsHandler::OnChildDied, this)); |
604 base::Bind(&PrinterCapsHandler::OnChildDied, this)); | |
605 } | 602 } |
606 } | 603 } |
607 | 604 |
608 std::string printer_name_; | 605 std::string printer_name_; |
609 PrintSystem::PrinterCapsAndDefaultsCallback callback_; | 606 PrintSystem::PrinterCapsAndDefaultsCallback callback_; |
610 }; | 607 }; |
611 | 608 |
612 class PrintSystemWin : public PrintSystem { | 609 class PrintSystemWin : public PrintSystem { |
613 public: | 610 public: |
614 PrintSystemWin(); | 611 PrintSystemWin(); |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
820 } | 817 } |
821 | 818 |
822 } // namespace | 819 } // namespace |
823 | 820 |
824 scoped_refptr<PrintSystem> PrintSystem::CreateInstance( | 821 scoped_refptr<PrintSystem> PrintSystem::CreateInstance( |
825 const base::DictionaryValue* print_system_settings) { | 822 const base::DictionaryValue* print_system_settings) { |
826 return new PrintSystemWin; | 823 return new PrintSystemWin; |
827 } | 824 } |
828 | 825 |
829 } // namespace cloud_print | 826 } // namespace cloud_print |
OLD | NEW |