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 <memory> |
| 8 |
7 #include "base/command_line.h" | 9 #include "base/command_line.h" |
8 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
9 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
10 #include "base/macros.h" | 12 #include "base/macros.h" |
11 #include "base/memory/free_deleter.h" | 13 #include "base/memory/free_deleter.h" |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
14 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
15 #include "base/win/object_watcher.h" | 16 #include "base/win/object_watcher.h" |
16 #include "base/win/scoped_bstr.h" | 17 #include "base/win/scoped_bstr.h" |
17 #include "base/win/scoped_comptr.h" | 18 #include "base/win/scoped_comptr.h" |
18 #include "base/win/scoped_hdc.h" | 19 #include "base/win/scoped_hdc.h" |
19 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
20 #include "chrome/common/cloud_print/cloud_print_cdd_conversion.h" | 21 #include "chrome/common/cloud_print/cloud_print_cdd_conversion.h" |
21 #include "chrome/common/cloud_print/cloud_print_constants.h" | 22 #include "chrome/common/cloud_print/cloud_print_constants.h" |
22 #include "chrome/common/crash_keys.h" | 23 #include "chrome/common/crash_keys.h" |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 const std::string& job_title, | 256 const std::string& job_title, |
256 JobSpooler::Delegate* delegate) { | 257 JobSpooler::Delegate* delegate) { |
257 if (delegate_) { | 258 if (delegate_) { |
258 // We are already in the process of printing. | 259 // We are already in the process of printing. |
259 NOTREACHED(); | 260 NOTREACHED(); |
260 return false; | 261 return false; |
261 } | 262 } |
262 base::string16 printer_wide = base::UTF8ToWide(printer_name); | 263 base::string16 printer_wide = base::UTF8ToWide(printer_name); |
263 // We only support PDF and XPS documents for now. | 264 // We only support PDF and XPS documents for now. |
264 if (print_data_mime_type == kContentTypePDF) { | 265 if (print_data_mime_type == kContentTypePDF) { |
265 scoped_ptr<DEVMODE, base::FreeDeleter> dev_mode; | 266 std::unique_ptr<DEVMODE, base::FreeDeleter> dev_mode; |
266 if (print_ticket_mime_type == kContentTypeJSON) { | 267 if (print_ticket_mime_type == kContentTypeJSON) { |
267 dev_mode = CjtToDevMode(printer_wide, print_ticket); | 268 dev_mode = CjtToDevMode(printer_wide, print_ticket); |
268 } else { | 269 } else { |
269 DCHECK(print_ticket_mime_type == kContentTypeXML); | 270 DCHECK(print_ticket_mime_type == kContentTypeXML); |
270 dev_mode = printing::XpsTicketToDevMode(printer_wide, print_ticket); | 271 dev_mode = printing::XpsTicketToDevMode(printer_wide, print_ticket); |
271 } | 272 } |
272 | 273 |
273 if (!dev_mode) { | 274 if (!dev_mode) { |
274 NOTREACHED(); | 275 NOTREACHED(); |
275 return false; | 276 return false; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 base::ThreadTaskRunnerHandle::Get())); | 420 base::ThreadTaskRunnerHandle::Get())); |
420 } | 421 } |
421 | 422 |
422 // Called on the service process IO thread. | 423 // Called on the service process IO thread. |
423 void RenderPDFPagesInSandbox( | 424 void RenderPDFPagesInSandbox( |
424 const base::FilePath& pdf_path, | 425 const base::FilePath& pdf_path, |
425 const gfx::Rect& render_area, | 426 const gfx::Rect& render_area, |
426 int render_dpi, | 427 int render_dpi, |
427 const scoped_refptr<base::SingleThreadTaskRunner>& client_task_runner) { | 428 const scoped_refptr<base::SingleThreadTaskRunner>& client_task_runner) { |
428 DCHECK(g_service_process->io_task_runner()->BelongsToCurrentThread()); | 429 DCHECK(g_service_process->io_task_runner()->BelongsToCurrentThread()); |
429 scoped_ptr<ServiceUtilityProcessHost> utility_host( | 430 std::unique_ptr<ServiceUtilityProcessHost> utility_host( |
430 new ServiceUtilityProcessHost(this, client_task_runner.get())); | 431 new ServiceUtilityProcessHost(this, client_task_runner.get())); |
431 // TODO(gene): For now we disabling autorotation for CloudPrinting. | 432 // TODO(gene): For now we disabling autorotation for CloudPrinting. |
432 // Landscape/Portrait setting is passed in the print ticket and | 433 // Landscape/Portrait setting is passed in the print ticket and |
433 // server is generating portrait PDF always. | 434 // server is generating portrait PDF always. |
434 // We should enable autorotation once server will be able to generate | 435 // We should enable autorotation once server will be able to generate |
435 // PDF that matches paper size and orientation. | 436 // PDF that matches paper size and orientation. |
436 if (utility_host->StartRenderPDFPagesToMetafile( | 437 if (utility_host->StartRenderPDFPagesToMetafile( |
437 pdf_path, | 438 pdf_path, |
438 printing::PdfRenderSettings(render_area, render_dpi, false))) { | 439 printing::PdfRenderSettings(render_area, render_dpi, false))) { |
439 // The object will self-destruct when the child process dies. | 440 // The object will self-destruct when the child process dies. |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 Release(); | 534 Release(); |
534 } | 535 } |
535 | 536 |
536 void OnGetPrinterSemanticCapsAndDefaults( | 537 void OnGetPrinterSemanticCapsAndDefaults( |
537 bool succeeded, | 538 bool succeeded, |
538 const std::string& printer_name, | 539 const std::string& printer_name, |
539 const printing::PrinterSemanticCapsAndDefaults& semantic_info) override { | 540 const printing::PrinterSemanticCapsAndDefaults& semantic_info) override { |
540 printing::PrinterCapsAndDefaults printer_info; | 541 printing::PrinterCapsAndDefaults printer_info; |
541 if (succeeded) { | 542 if (succeeded) { |
542 printer_info.caps_mime_type = kContentTypeJSON; | 543 printer_info.caps_mime_type = kContentTypeJSON; |
543 scoped_ptr<base::DictionaryValue> description( | 544 std::unique_ptr<base::DictionaryValue> description( |
544 PrinterSemanticCapsAndDefaultsToCdd(semantic_info)); | 545 PrinterSemanticCapsAndDefaultsToCdd(semantic_info)); |
545 if (description) { | 546 if (description) { |
546 base::JSONWriter::WriteWithOptions( | 547 base::JSONWriter::WriteWithOptions( |
547 *description, base::JSONWriter::OPTIONS_PRETTY_PRINT, | 548 *description, base::JSONWriter::OPTIONS_PRETTY_PRINT, |
548 &printer_info.printer_capabilities); | 549 &printer_info.printer_capabilities); |
549 } | 550 } |
550 } | 551 } |
551 callback_.Run(succeeded, printer_name, printer_info); | 552 callback_.Run(succeeded, printer_name, printer_info); |
552 callback_.Reset(); | 553 callback_.Reset(); |
553 Release(); | 554 Release(); |
(...skipping 12 matching lines...) Expand all Loading... |
566 base::Bind(&PrinterCapsHandler::GetPrinterSemanticCapsAndDefaultsImpl, | 567 base::Bind(&PrinterCapsHandler::GetPrinterSemanticCapsAndDefaultsImpl, |
567 this, base::ThreadTaskRunnerHandle::Get())); | 568 this, base::ThreadTaskRunnerHandle::Get())); |
568 } | 569 } |
569 | 570 |
570 private: | 571 private: |
571 ~PrinterCapsHandler() override {} | 572 ~PrinterCapsHandler() override {} |
572 | 573 |
573 void GetPrinterCapsAndDefaultsImpl( | 574 void GetPrinterCapsAndDefaultsImpl( |
574 const scoped_refptr<base::SingleThreadTaskRunner>& client_task_runner) { | 575 const scoped_refptr<base::SingleThreadTaskRunner>& client_task_runner) { |
575 DCHECK(g_service_process->io_task_runner()->BelongsToCurrentThread()); | 576 DCHECK(g_service_process->io_task_runner()->BelongsToCurrentThread()); |
576 scoped_ptr<ServiceUtilityProcessHost> utility_host( | 577 std::unique_ptr<ServiceUtilityProcessHost> utility_host( |
577 new ServiceUtilityProcessHost(this, client_task_runner.get())); | 578 new ServiceUtilityProcessHost(this, client_task_runner.get())); |
578 if (utility_host->StartGetPrinterCapsAndDefaults(printer_name_)) { | 579 if (utility_host->StartGetPrinterCapsAndDefaults(printer_name_)) { |
579 // The object will self-destruct when the child process dies. | 580 // The object will self-destruct when the child process dies. |
580 ignore_result(utility_host.release()); | 581 ignore_result(utility_host.release()); |
581 } else { | 582 } else { |
582 client_task_runner->PostTask( | 583 client_task_runner->PostTask( |
583 FROM_HERE, base::Bind(&PrinterCapsHandler::OnChildDied, this)); | 584 FROM_HERE, base::Bind(&PrinterCapsHandler::OnChildDied, this)); |
584 } | 585 } |
585 } | 586 } |
586 | 587 |
587 void GetPrinterSemanticCapsAndDefaultsImpl( | 588 void GetPrinterSemanticCapsAndDefaultsImpl( |
588 const scoped_refptr<base::SingleThreadTaskRunner>& client_task_runner) { | 589 const scoped_refptr<base::SingleThreadTaskRunner>& client_task_runner) { |
589 DCHECK(g_service_process->io_task_runner()->BelongsToCurrentThread()); | 590 DCHECK(g_service_process->io_task_runner()->BelongsToCurrentThread()); |
590 scoped_ptr<ServiceUtilityProcessHost> utility_host( | 591 std::unique_ptr<ServiceUtilityProcessHost> utility_host( |
591 new ServiceUtilityProcessHost(this, client_task_runner.get())); | 592 new ServiceUtilityProcessHost(this, client_task_runner.get())); |
592 if (utility_host->StartGetPrinterSemanticCapsAndDefaults(printer_name_)) { | 593 if (utility_host->StartGetPrinterSemanticCapsAndDefaults(printer_name_)) { |
593 // The object will self-destruct when the child process dies. | 594 // The object will self-destruct when the child process dies. |
594 ignore_result(utility_host.release()); | 595 ignore_result(utility_host.release()); |
595 } else { | 596 } else { |
596 client_task_runner->PostTask( | 597 client_task_runner->PostTask( |
597 FROM_HERE, base::Bind(&PrinterCapsHandler::OnChildDied, this)); | 598 FROM_HERE, base::Bind(&PrinterCapsHandler::OnChildDied, this)); |
598 } | 599 } |
599 } | 600 } |
600 | 601 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 printer_handle.OpenPrinter(printer_name_wide.c_str()); | 744 printer_handle.OpenPrinter(printer_name_wide.c_str()); |
744 DCHECK(printer_handle.IsValid()); | 745 DCHECK(printer_handle.IsValid()); |
745 bool ret = false; | 746 bool ret = false; |
746 if (printer_handle.IsValid()) { | 747 if (printer_handle.IsValid()) { |
747 DWORD bytes_needed = 0; | 748 DWORD bytes_needed = 0; |
748 GetJob(printer_handle.Get(), job_id, 1, NULL, 0, &bytes_needed); | 749 GetJob(printer_handle.Get(), job_id, 1, NULL, 0, &bytes_needed); |
749 DWORD last_error = GetLastError(); | 750 DWORD last_error = GetLastError(); |
750 if (ERROR_INVALID_PARAMETER != last_error) { | 751 if (ERROR_INVALID_PARAMETER != last_error) { |
751 // ERROR_INVALID_PARAMETER normally means that the job id is not valid. | 752 // ERROR_INVALID_PARAMETER normally means that the job id is not valid. |
752 DCHECK(last_error == ERROR_INSUFFICIENT_BUFFER); | 753 DCHECK(last_error == ERROR_INSUFFICIENT_BUFFER); |
753 scoped_ptr<BYTE[]> job_info_buffer(new BYTE[bytes_needed]); | 754 std::unique_ptr<BYTE[]> job_info_buffer(new BYTE[bytes_needed]); |
754 if (GetJob(printer_handle.Get(), job_id, 1, job_info_buffer.get(), | 755 if (GetJob(printer_handle.Get(), job_id, 1, job_info_buffer.get(), |
755 bytes_needed, &bytes_needed)) { | 756 bytes_needed, &bytes_needed)) { |
756 JOB_INFO_1 *job_info = | 757 JOB_INFO_1 *job_info = |
757 reinterpret_cast<JOB_INFO_1 *>(job_info_buffer.get()); | 758 reinterpret_cast<JOB_INFO_1 *>(job_info_buffer.get()); |
758 if (job_info->pStatus) { | 759 if (job_info->pStatus) { |
759 base::WideToUTF8(job_info->pStatus, wcslen(job_info->pStatus), | 760 base::WideToUTF8(job_info->pStatus, wcslen(job_info->pStatus), |
760 &job_details->status_message); | 761 &job_details->status_message); |
761 } | 762 } |
762 job_details->platform_status_flags = job_info->Status; | 763 job_details->platform_status_flags = job_info->Status; |
763 if ((job_info->Status & JOB_STATUS_COMPLETE) || | 764 if ((job_info->Status & JOB_STATUS_COMPLETE) || |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 } | 813 } |
813 | 814 |
814 } // namespace | 815 } // namespace |
815 | 816 |
816 scoped_refptr<PrintSystem> PrintSystem::CreateInstance( | 817 scoped_refptr<PrintSystem> PrintSystem::CreateInstance( |
817 const base::DictionaryValue* print_system_settings) { | 818 const base::DictionaryValue* print_system_settings) { |
818 return new PrintSystemWin; | 819 return new PrintSystemWin; |
819 } | 820 } |
820 | 821 |
821 } // namespace cloud_print | 822 } // namespace cloud_print |
OLD | NEW |