OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <objidl.h> | 7 #include <objidl.h> |
8 #include <winspool.h> | 8 #include <winspool.h> |
9 #include <xpsprint.h> | 9 #include <xpsprint.h> |
10 | 10 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 printer_change_(NULL), | 124 printer_change_(NULL), |
125 delegate_(NULL), | 125 delegate_(NULL), |
126 did_signal_(false) { | 126 did_signal_(false) { |
127 } | 127 } |
128 ~PrintSystemWatcherWin() { | 128 ~PrintSystemWatcherWin() { |
129 Stop(); | 129 Stop(); |
130 } | 130 } |
131 | 131 |
132 class Delegate { | 132 class Delegate { |
133 public: | 133 public: |
| 134 virtual ~Delegate() {} |
134 virtual void OnPrinterAdded() = 0; | 135 virtual void OnPrinterAdded() = 0; |
135 virtual void OnPrinterDeleted() = 0; | 136 virtual void OnPrinterDeleted() = 0; |
136 virtual void OnPrinterChanged() = 0; | 137 virtual void OnPrinterChanged() = 0; |
137 virtual void OnJobChanged() = 0; | 138 virtual void OnJobChanged() = 0; |
138 }; | 139 }; |
139 | 140 |
140 bool Start(const std::string& printer_name, Delegate* delegate) { | 141 bool Start(const std::string& printer_name, Delegate* delegate) { |
141 delegate_ = delegate; | 142 delegate_ = delegate; |
142 // An empty printer name means watch the current server, we need to pass | 143 // An empty printer name means watch the current server, we need to pass |
143 // NULL to OpenPrinter. | 144 // NULL to OpenPrinter. |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 const std::string& print_data_mime_type, | 357 const std::string& print_data_mime_type, |
357 const std::string& printer_name, | 358 const std::string& printer_name, |
358 const std::string& job_title, | 359 const std::string& job_title, |
359 const std::vector<std::string>& tags, | 360 const std::vector<std::string>& tags, |
360 JobSpooler::Delegate* delegate) { | 361 JobSpooler::Delegate* delegate) { |
361 // TODO(gene): add tags handling. | 362 // TODO(gene): add tags handling. |
362 return core_->Spool(print_ticket, print_data_file_path, | 363 return core_->Spool(print_ticket, print_data_file_path, |
363 print_data_mime_type, printer_name, job_title, | 364 print_data_mime_type, printer_name, job_title, |
364 delegate); | 365 delegate); |
365 } | 366 } |
| 367 |
366 private: | 368 private: |
367 // We use a Core class because we want a separate RefCountedThreadSafe | 369 // We use a Core class because we want a separate RefCountedThreadSafe |
368 // implementation for ServiceUtilityProcessHost::Client. | 370 // implementation for ServiceUtilityProcessHost::Client. |
369 class Core : public ServiceUtilityProcessHost::Client, | 371 class Core : public ServiceUtilityProcessHost::Client, |
370 public base::win::ObjectWatcher::Delegate { | 372 public base::win::ObjectWatcher::Delegate { |
371 public: | 373 public: |
372 Core() | 374 Core() |
373 : last_page_printed_(-1), | 375 : last_page_printed_(-1), |
374 job_id_(-1), | 376 job_id_(-1), |
375 delegate_(NULL), | 377 delegate_(NULL), |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 // Some Cairo-generated PDFs from Chrome OS result in huge metafiles. | 622 // Some Cairo-generated PDFs from Chrome OS result in huge metafiles. |
621 // So the PageCountPerBatch is set to 1 for now. | 623 // So the PageCountPerBatch is set to 1 for now. |
622 // TODO(sanjeevr): Figure out a smarter way to determine the pages per | 624 // TODO(sanjeevr): Figure out a smarter way to determine the pages per |
623 // batch. Filed a bug to track this at | 625 // batch. Filed a bug to track this at |
624 // http://code.google.com/p/chromium/issues/detail?id=57350. | 626 // http://code.google.com/p/chromium/issues/detail?id=57350. |
625 static const int kPageCountPerBatch = 1; | 627 static const int kPageCountPerBatch = 1; |
626 int last_page_printed_; | 628 int last_page_printed_; |
627 PlatformJobId job_id_; | 629 PlatformJobId job_id_; |
628 PrintSystem::JobSpooler::Delegate* delegate_; | 630 PrintSystem::JobSpooler::Delegate* delegate_; |
629 int saved_dc_; | 631 int saved_dc_; |
630 base::win::ScopedHDC printer_dc_; | 632 base::win::ScopedCreateDC printer_dc_; |
631 FilePath print_data_file_path_; | 633 FilePath print_data_file_path_; |
632 base::win::ScopedHandle job_progress_event_; | 634 base::win::ScopedHandle job_progress_event_; |
633 base::win::ObjectWatcher job_progress_watcher_; | 635 base::win::ObjectWatcher job_progress_watcher_; |
634 base::win::ScopedComPtr<IXpsPrintJob> xps_print_job_; | 636 base::win::ScopedComPtr<IXpsPrintJob> xps_print_job_; |
635 bool should_couninit_; | 637 bool should_couninit_; |
636 DISALLOW_COPY_AND_ASSIGN(JobSpoolerWin::Core); | 638 DISALLOW_COPY_AND_ASSIGN(JobSpoolerWin::Core); |
637 }; | 639 }; |
638 scoped_refptr<Core> core_; | 640 scoped_refptr<Core> core_; |
639 DISALLOW_COPY_AND_ASSIGN(JobSpoolerWin); | 641 DISALLOW_COPY_AND_ASSIGN(JobSpoolerWin); |
640 }; | 642 }; |
(...skipping 27 matching lines...) Expand all Loading... |
668 Release(); | 670 Release(); |
669 } | 671 } |
670 | 672 |
671 virtual void OnGetPrinterCapsAndDefaultsFailed( | 673 virtual void OnGetPrinterCapsAndDefaultsFailed( |
672 const std::string& printer_name) { | 674 const std::string& printer_name) { |
673 printing::PrinterCapsAndDefaults caps_and_defaults; | 675 printing::PrinterCapsAndDefaults caps_and_defaults; |
674 callback_->Run(false, printer_name, caps_and_defaults); | 676 callback_->Run(false, printer_name, caps_and_defaults); |
675 callback_.reset(); | 677 callback_.reset(); |
676 Release(); | 678 Release(); |
677 } | 679 } |
| 680 |
678 private: | 681 private: |
679 // Called on the service process IO thread. | 682 // Called on the service process IO thread. |
680 void GetPrinterCapsAndDefaultsImpl( | 683 void GetPrinterCapsAndDefaultsImpl( |
681 const scoped_refptr<base::MessageLoopProxy>& | 684 const scoped_refptr<base::MessageLoopProxy>& |
682 client_message_loop_proxy) { | 685 client_message_loop_proxy) { |
683 DCHECK(g_service_process->io_thread()->message_loop_proxy()-> | 686 DCHECK(g_service_process->io_thread()->message_loop_proxy()-> |
684 BelongsToCurrentThread()); | 687 BelongsToCurrentThread()); |
685 scoped_ptr<ServiceUtilityProcessHost> utility_host( | 688 scoped_ptr<ServiceUtilityProcessHost> utility_host( |
686 new ServiceUtilityProcessHost(this, client_message_loop_proxy)); | 689 new ServiceUtilityProcessHost(this, client_message_loop_proxy)); |
687 if (utility_host->StartGetPrinterCapsAndDefaults(printer_name_)) { | 690 if (utility_host->StartGetPrinterCapsAndDefaults(printer_name_)) { |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
867 RpcStringFree(reinterpret_cast<RPC_WSTR *>(&proxy_id_as_string)); | 870 RpcStringFree(reinterpret_cast<RPC_WSTR *>(&proxy_id_as_string)); |
868 return ret; | 871 return ret; |
869 } | 872 } |
870 | 873 |
871 scoped_refptr<PrintSystem> PrintSystem::CreateInstance( | 874 scoped_refptr<PrintSystem> PrintSystem::CreateInstance( |
872 const base::DictionaryValue* print_system_settings) { | 875 const base::DictionaryValue* print_system_settings) { |
873 return new PrintSystemWin; | 876 return new PrintSystemWin; |
874 } | 877 } |
875 | 878 |
876 } // namespace cloud_print | 879 } // namespace cloud_print |
OLD | NEW |