| 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" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 std::string printer_info_; // For crash reporting. | 126 std::string printer_info_; // For crash reporting. |
| 127 }; | 127 }; |
| 128 | 128 |
| 129 class PrintServerWatcherWin | 129 class PrintServerWatcherWin |
| 130 : public PrintSystem::PrintServerWatcher, | 130 : public PrintSystem::PrintServerWatcher, |
| 131 public PrintSystemWatcherWin::Delegate { | 131 public PrintSystemWatcherWin::Delegate { |
| 132 public: | 132 public: |
| 133 PrintServerWatcherWin() : delegate_(NULL) {} | 133 PrintServerWatcherWin() : delegate_(NULL) {} |
| 134 | 134 |
| 135 // PrintSystem::PrintServerWatcher implementation. | 135 // PrintSystem::PrintServerWatcher implementation. |
| 136 virtual bool StartWatching( | 136 bool StartWatching( |
| 137 PrintSystem::PrintServerWatcher::Delegate* delegate) override{ | 137 PrintSystem::PrintServerWatcher::Delegate* delegate) override { |
| 138 delegate_ = delegate; | 138 delegate_ = delegate; |
| 139 return watcher_.Start(std::string(), this); | 139 return watcher_.Start(std::string(), this); |
| 140 } | 140 } |
| 141 | 141 |
| 142 virtual bool StopWatching() override{ | 142 bool StopWatching() override { |
| 143 bool ret = watcher_.Stop(); | 143 bool ret = watcher_.Stop(); |
| 144 delegate_ = NULL; | 144 delegate_ = NULL; |
| 145 return ret; | 145 return ret; |
| 146 } | 146 } |
| 147 | 147 |
| 148 // PrintSystemWatcherWin::Delegate implementation. | 148 // PrintSystemWatcherWin::Delegate implementation. |
| 149 virtual void OnPrinterAdded() override { | 149 void OnPrinterAdded() override { |
| 150 delegate_->OnPrinterAdded(); | 150 delegate_->OnPrinterAdded(); |
| 151 } | 151 } |
| 152 virtual void OnPrinterDeleted() override {} | 152 void OnPrinterDeleted() override {} |
| 153 virtual void OnPrinterChanged() override {} | 153 void OnPrinterChanged() override {} |
| 154 virtual void OnJobChanged() override {} | 154 void OnJobChanged() override {} |
| 155 | 155 |
| 156 protected: | 156 protected: |
| 157 virtual ~PrintServerWatcherWin() {} | 157 ~PrintServerWatcherWin() override {} |
| 158 | 158 |
| 159 private: | 159 private: |
| 160 PrintSystem::PrintServerWatcher::Delegate* delegate_; | 160 PrintSystem::PrintServerWatcher::Delegate* delegate_; |
| 161 PrintSystemWatcherWin watcher_; | 161 PrintSystemWatcherWin watcher_; |
| 162 | 162 |
| 163 DISALLOW_COPY_AND_ASSIGN(PrintServerWatcherWin); | 163 DISALLOW_COPY_AND_ASSIGN(PrintServerWatcherWin); |
| 164 }; | 164 }; |
| 165 | 165 |
| 166 class PrinterWatcherWin | 166 class PrinterWatcherWin |
| 167 : public PrintSystem::PrinterWatcher, | 167 : public PrintSystem::PrinterWatcher, |
| 168 public PrintSystemWatcherWin::Delegate { | 168 public PrintSystemWatcherWin::Delegate { |
| 169 public: | 169 public: |
| 170 explicit PrinterWatcherWin(const std::string& printer_name) | 170 explicit PrinterWatcherWin(const std::string& printer_name) |
| 171 : printer_name_(printer_name), | 171 : printer_name_(printer_name), |
| 172 delegate_(NULL) { | 172 delegate_(NULL) { |
| 173 } | 173 } |
| 174 | 174 |
| 175 // PrintSystem::PrinterWatcher implementation. | 175 // PrintSystem::PrinterWatcher implementation. |
| 176 virtual bool StartWatching( | 176 bool StartWatching(PrintSystem::PrinterWatcher::Delegate* delegate) override { |
| 177 PrintSystem::PrinterWatcher::Delegate* delegate) override { | |
| 178 delegate_ = delegate; | 177 delegate_ = delegate; |
| 179 return watcher_.Start(printer_name_, this); | 178 return watcher_.Start(printer_name_, this); |
| 180 } | 179 } |
| 181 | 180 |
| 182 virtual bool StopWatching() override { | 181 bool StopWatching() override { |
| 183 bool ret = watcher_.Stop(); | 182 bool ret = watcher_.Stop(); |
| 184 delegate_ = NULL; | 183 delegate_ = NULL; |
| 185 return ret; | 184 return ret; |
| 186 } | 185 } |
| 187 | 186 |
| 188 virtual bool GetCurrentPrinterInfo( | 187 bool GetCurrentPrinterInfo( |
| 189 printing::PrinterBasicInfo* printer_info) override { | 188 printing::PrinterBasicInfo* printer_info) override { |
| 190 return watcher_.GetCurrentPrinterInfo(printer_info); | 189 return watcher_.GetCurrentPrinterInfo(printer_info); |
| 191 } | 190 } |
| 192 | 191 |
| 193 // PrintSystemWatcherWin::Delegate implementation. | 192 // PrintSystemWatcherWin::Delegate implementation. |
| 194 virtual void OnPrinterAdded() override { | 193 void OnPrinterAdded() override { |
| 195 NOTREACHED(); | 194 NOTREACHED(); |
| 196 } | 195 } |
| 197 virtual void OnPrinterDeleted() override { | 196 void OnPrinterDeleted() override { |
| 198 delegate_->OnPrinterDeleted(); | 197 delegate_->OnPrinterDeleted(); |
| 199 } | 198 } |
| 200 virtual void OnPrinterChanged() override { | 199 void OnPrinterChanged() override { |
| 201 delegate_->OnPrinterChanged(); | 200 delegate_->OnPrinterChanged(); |
| 202 } | 201 } |
| 203 virtual void OnJobChanged() override { | 202 void OnJobChanged() override { |
| 204 delegate_->OnJobChanged(); | 203 delegate_->OnJobChanged(); |
| 205 } | 204 } |
| 206 | 205 |
| 207 protected: | 206 protected: |
| 208 virtual ~PrinterWatcherWin() {} | 207 ~PrinterWatcherWin() override {} |
| 209 | 208 |
| 210 private: | 209 private: |
| 211 std::string printer_name_; | 210 std::string printer_name_; |
| 212 PrintSystem::PrinterWatcher::Delegate* delegate_; | 211 PrintSystem::PrinterWatcher::Delegate* delegate_; |
| 213 PrintSystemWatcherWin watcher_; | 212 PrintSystemWatcherWin watcher_; |
| 214 | 213 |
| 215 DISALLOW_COPY_AND_ASSIGN(PrinterWatcherWin); | 214 DISALLOW_COPY_AND_ASSIGN(PrinterWatcherWin); |
| 216 }; | 215 }; |
| 217 | 216 |
| 218 class JobSpoolerWin : public PrintSystem::JobSpooler { | 217 class JobSpoolerWin : public PrintSystem::JobSpooler { |
| 219 public: | 218 public: |
| 220 JobSpoolerWin() : core_(new Core) {} | 219 JobSpoolerWin() : core_(new Core) {} |
| 221 | 220 |
| 222 // PrintSystem::JobSpooler implementation. | 221 // PrintSystem::JobSpooler implementation. |
| 223 virtual bool Spool(const std::string& print_ticket, | 222 bool Spool(const std::string& print_ticket, |
| 224 const std::string& print_ticket_mime_type, | 223 const std::string& print_ticket_mime_type, |
| 225 const base::FilePath& print_data_file_path, | 224 const base::FilePath& print_data_file_path, |
| 226 const std::string& print_data_mime_type, | 225 const std::string& print_data_mime_type, |
| 227 const std::string& printer_name, | 226 const std::string& printer_name, |
| 228 const std::string& job_title, | 227 const std::string& job_title, |
| 229 const std::vector<std::string>& tags, | 228 const std::vector<std::string>& tags, |
| 230 JobSpooler::Delegate* delegate) override { | 229 JobSpooler::Delegate* delegate) override { |
| 231 // TODO(gene): add tags handling. | 230 // TODO(gene): add tags handling. |
| 232 scoped_refptr<printing::PrintBackend> print_backend( | 231 scoped_refptr<printing::PrintBackend> print_backend( |
| 233 printing::PrintBackend::CreateInstance(NULL)); | 232 printing::PrintBackend::CreateInstance(NULL)); |
| 234 crash_keys::ScopedPrinterInfo crash_key( | 233 crash_keys::ScopedPrinterInfo crash_key( |
| 235 print_backend->GetPrinterDriverInfo(printer_name)); | 234 print_backend->GetPrinterDriverInfo(printer_name)); |
| 236 return core_->Spool(print_ticket, print_ticket_mime_type, | 235 return core_->Spool(print_ticket, print_ticket_mime_type, |
| 237 print_data_file_path, print_data_mime_type, | 236 print_data_file_path, print_data_mime_type, |
| 238 printer_name, job_title, delegate); | 237 printer_name, job_title, delegate); |
| 239 } | 238 } |
| 240 | 239 |
| 241 protected: | 240 protected: |
| 242 virtual ~JobSpoolerWin() {} | 241 ~JobSpoolerWin() override {} |
| 243 | 242 |
| 244 private: | 243 private: |
| 245 // We use a Core class because we want a separate RefCountedThreadSafe | 244 // We use a Core class because we want a separate RefCountedThreadSafe |
| 246 // implementation for ServiceUtilityProcessHost::Client. | 245 // implementation for ServiceUtilityProcessHost::Client. |
| 247 class Core : public ServiceUtilityProcessHost::Client, | 246 class Core : public ServiceUtilityProcessHost::Client, |
| 248 public base::win::ObjectWatcher::Delegate { | 247 public base::win::ObjectWatcher::Delegate { |
| 249 public: | 248 public: |
| 250 Core() : job_id_(-1), delegate_(NULL), saved_dc_(0) {} | 249 Core() : job_id_(-1), delegate_(NULL), saved_dc_(0) {} |
| 251 | 250 |
| 252 ~Core() {} | 251 ~Core() override {} |
| 253 | 252 |
| 254 bool Spool(const std::string& print_ticket, | 253 bool Spool(const std::string& print_ticket, |
| 255 const std::string& print_ticket_mime_type, | 254 const std::string& print_ticket_mime_type, |
| 256 const base::FilePath& print_data_file_path, | 255 const base::FilePath& print_data_file_path, |
| 257 const std::string& print_data_mime_type, | 256 const std::string& print_data_mime_type, |
| 258 const std::string& printer_name, | 257 const std::string& printer_name, |
| 259 const std::string& job_title, | 258 const std::string& job_title, |
| 260 JobSpooler::Delegate* delegate) { | 259 JobSpooler::Delegate* delegate) { |
| 261 if (delegate_) { | 260 if (delegate_) { |
| 262 // We are already in the process of printing. | 261 // We are already in the process of printing. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 int offset_x = ::GetDeviceCaps(printer_dc_.Get(), PHYSICALOFFSETX); | 323 int offset_x = ::GetDeviceCaps(printer_dc_.Get(), PHYSICALOFFSETX); |
| 325 int offset_y = ::GetDeviceCaps(printer_dc_.Get(), PHYSICALOFFSETY); | 324 int offset_y = ::GetDeviceCaps(printer_dc_.Get(), PHYSICALOFFSETY); |
| 326 XFORM xform = {0}; | 325 XFORM xform = {0}; |
| 327 xform.eDx = static_cast<float>(-offset_x); | 326 xform.eDx = static_cast<float>(-offset_x); |
| 328 xform.eDy = static_cast<float>(-offset_y); | 327 xform.eDy = static_cast<float>(-offset_y); |
| 329 xform.eM11 = xform.eM22 = 1.0f / scale_factor; | 328 xform.eM11 = xform.eM22 = 1.0f / scale_factor; |
| 330 SetWorldTransform(printer_dc_.Get(), &xform); | 329 SetWorldTransform(printer_dc_.Get(), &xform); |
| 331 } | 330 } |
| 332 | 331 |
| 333 // ServiceUtilityProcessHost::Client implementation. | 332 // ServiceUtilityProcessHost::Client implementation. |
| 334 virtual void OnRenderPDFPagesToMetafilePageDone( | 333 void OnRenderPDFPagesToMetafilePageDone( |
| 335 float scale_factor, | 334 float scale_factor, |
| 336 const printing::MetafilePlayer& emf) override { | 335 const printing::MetafilePlayer& emf) override { |
| 337 PreparePageDCForPrinting(printer_dc_.Get(), scale_factor); | 336 PreparePageDCForPrinting(printer_dc_.Get(), scale_factor); |
| 338 ::StartPage(printer_dc_.Get()); | 337 ::StartPage(printer_dc_.Get()); |
| 339 emf.SafePlayback(printer_dc_.Get()); | 338 emf.SafePlayback(printer_dc_.Get()); |
| 340 ::EndPage(printer_dc_.Get()); | 339 ::EndPage(printer_dc_.Get()); |
| 341 } | 340 } |
| 342 | 341 |
| 343 // ServiceUtilityProcessHost::Client implementation. | 342 // ServiceUtilityProcessHost::Client implementation. |
| 344 virtual void OnRenderPDFPagesToMetafileDone(bool success) override { | 343 void OnRenderPDFPagesToMetafileDone(bool success) override { |
| 345 PrintJobDone(success); | 344 PrintJobDone(success); |
| 346 } | 345 } |
| 347 | 346 |
| 348 virtual void OnChildDied() override { PrintJobDone(false); } | 347 void OnChildDied() override { PrintJobDone(false); } |
| 349 | 348 |
| 350 // base::win::ObjectWatcher::Delegate implementation. | 349 // base::win::ObjectWatcher::Delegate implementation. |
| 351 virtual void OnObjectSignaled(HANDLE object) override { | 350 void OnObjectSignaled(HANDLE object) override { |
| 352 DCHECK(xps_print_job_.get()); | 351 DCHECK(xps_print_job_.get()); |
| 353 DCHECK(object == job_progress_event_.Get()); | 352 DCHECK(object == job_progress_event_.Get()); |
| 354 ResetEvent(job_progress_event_.Get()); | 353 ResetEvent(job_progress_event_.Get()); |
| 355 if (!delegate_) | 354 if (!delegate_) |
| 356 return; | 355 return; |
| 357 XPS_JOB_STATUS job_status = {0}; | 356 XPS_JOB_STATUS job_status = {0}; |
| 358 xps_print_job_->GetJobStatus(&job_status); | 357 xps_print_job_->GetJobStatus(&job_status); |
| 359 if ((job_status.completion == XPS_JOB_CANCELLED) || | 358 if ((job_status.completion == XPS_JOB_CANCELLED) || |
| 360 (job_status.completion == XPS_JOB_FAILED)) { | 359 (job_status.completion == XPS_JOB_FAILED)) { |
| 361 delegate_->OnJobSpoolFailed(); | 360 delegate_->OnJobSpoolFailed(); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 // request to fetch printer capabilities and defaults. | 515 // request to fetch printer capabilities and defaults. |
| 517 class PrinterCapsHandler : public ServiceUtilityProcessHost::Client { | 516 class PrinterCapsHandler : public ServiceUtilityProcessHost::Client { |
| 518 public: | 517 public: |
| 519 PrinterCapsHandler( | 518 PrinterCapsHandler( |
| 520 const std::string& printer_name, | 519 const std::string& printer_name, |
| 521 const PrintSystem::PrinterCapsAndDefaultsCallback& callback) | 520 const PrintSystem::PrinterCapsAndDefaultsCallback& callback) |
| 522 : printer_name_(printer_name), callback_(callback) { | 521 : printer_name_(printer_name), callback_(callback) { |
| 523 } | 522 } |
| 524 | 523 |
| 525 // ServiceUtilityProcessHost::Client implementation. | 524 // ServiceUtilityProcessHost::Client implementation. |
| 526 virtual void OnChildDied() override { | 525 void OnChildDied() override { |
| 527 OnGetPrinterCapsAndDefaults(false, printer_name_, | 526 OnGetPrinterCapsAndDefaults(false, printer_name_, |
| 528 printing::PrinterCapsAndDefaults()); | 527 printing::PrinterCapsAndDefaults()); |
| 529 } | 528 } |
| 530 | 529 |
| 531 virtual void OnGetPrinterCapsAndDefaults( | 530 void OnGetPrinterCapsAndDefaults( |
| 532 bool succeeded, | 531 bool succeeded, |
| 533 const std::string& printer_name, | 532 const std::string& printer_name, |
| 534 const printing::PrinterCapsAndDefaults& caps_and_defaults) override { | 533 const printing::PrinterCapsAndDefaults& caps_and_defaults) override { |
| 535 callback_.Run(succeeded, printer_name, caps_and_defaults); | 534 callback_.Run(succeeded, printer_name, caps_and_defaults); |
| 536 callback_.Reset(); | 535 callback_.Reset(); |
| 537 Release(); | 536 Release(); |
| 538 } | 537 } |
| 539 | 538 |
| 540 virtual void OnGetPrinterSemanticCapsAndDefaults( | 539 void OnGetPrinterSemanticCapsAndDefaults( |
| 541 bool succeeded, | 540 bool succeeded, |
| 542 const std::string& printer_name, | 541 const std::string& printer_name, |
| 543 const printing::PrinterSemanticCapsAndDefaults& semantic_info) override { | 542 const printing::PrinterSemanticCapsAndDefaults& semantic_info) override { |
| 544 printing::PrinterCapsAndDefaults printer_info; | 543 printing::PrinterCapsAndDefaults printer_info; |
| 545 if (succeeded) { | 544 if (succeeded) { |
| 546 printer_info.caps_mime_type = kContentTypeJSON; | 545 printer_info.caps_mime_type = kContentTypeJSON; |
| 547 scoped_ptr<base::DictionaryValue> description( | 546 scoped_ptr<base::DictionaryValue> description( |
| 548 PrinterSemanticCapsAndDefaultsToCdd(semantic_info)); | 547 PrinterSemanticCapsAndDefaultsToCdd(semantic_info)); |
| 549 if (description) { | 548 if (description) { |
| 550 base::JSONWriter::WriteWithOptions( | 549 base::JSONWriter::WriteWithOptions( |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 | 607 |
| 609 std::string printer_name_; | 608 std::string printer_name_; |
| 610 PrintSystem::PrinterCapsAndDefaultsCallback callback_; | 609 PrintSystem::PrinterCapsAndDefaultsCallback callback_; |
| 611 }; | 610 }; |
| 612 | 611 |
| 613 class PrintSystemWin : public PrintSystem { | 612 class PrintSystemWin : public PrintSystem { |
| 614 public: | 613 public: |
| 615 PrintSystemWin(); | 614 PrintSystemWin(); |
| 616 | 615 |
| 617 // PrintSystem implementation. | 616 // PrintSystem implementation. |
| 618 virtual PrintSystemResult Init() override; | 617 PrintSystemResult Init() override; |
| 619 virtual PrintSystem::PrintSystemResult EnumeratePrinters( | 618 PrintSystem::PrintSystemResult EnumeratePrinters( |
| 620 printing::PrinterList* printer_list) override; | 619 printing::PrinterList* printer_list) override; |
| 621 virtual void GetPrinterCapsAndDefaults( | 620 void GetPrinterCapsAndDefaults( |
| 622 const std::string& printer_name, | 621 const std::string& printer_name, |
| 623 const PrinterCapsAndDefaultsCallback& callback) override; | 622 const PrinterCapsAndDefaultsCallback& callback) override; |
| 624 virtual bool IsValidPrinter(const std::string& printer_name) override; | 623 bool IsValidPrinter(const std::string& printer_name) override; |
| 625 virtual bool ValidatePrintTicket( | 624 bool ValidatePrintTicket( |
| 626 const std::string& printer_name, | 625 const std::string& printer_name, |
| 627 const std::string& print_ticket_data, | 626 const std::string& print_ticket_data, |
| 628 const std::string& print_ticket_data_mime_type) override; | 627 const std::string& print_ticket_data_mime_type) override; |
| 629 virtual bool GetJobDetails(const std::string& printer_name, | 628 bool GetJobDetails(const std::string& printer_name, |
| 630 PlatformJobId job_id, | 629 PlatformJobId job_id, |
| 631 PrintJobDetails *job_details) override; | 630 PrintJobDetails* job_details) override; |
| 632 virtual PrintSystem::PrintServerWatcher* CreatePrintServerWatcher() override; | 631 PrintSystem::PrintServerWatcher* CreatePrintServerWatcher() override; |
| 633 virtual PrintSystem::PrinterWatcher* CreatePrinterWatcher( | 632 PrintSystem::PrinterWatcher* CreatePrinterWatcher( |
| 634 const std::string& printer_name) override; | 633 const std::string& printer_name) override; |
| 635 virtual PrintSystem::JobSpooler* CreateJobSpooler() override; | 634 PrintSystem::JobSpooler* CreateJobSpooler() override; |
| 636 virtual bool UseCddAndCjt() override; | 635 bool UseCddAndCjt() override; |
| 637 virtual std::string GetSupportedMimeTypes() override; | 636 std::string GetSupportedMimeTypes() override; |
| 638 | 637 |
| 639 private: | 638 private: |
| 640 std::string PrintSystemWin::GetPrinterDriverInfo( | 639 std::string PrintSystemWin::GetPrinterDriverInfo( |
| 641 const std::string& printer_name) const; | 640 const std::string& printer_name) const; |
| 642 | 641 |
| 643 scoped_refptr<printing::PrintBackend> print_backend_; | 642 scoped_refptr<printing::PrintBackend> print_backend_; |
| 644 bool use_cdd_; | 643 bool use_cdd_; |
| 645 DISALLOW_COPY_AND_ASSIGN(PrintSystemWin); | 644 DISALLOW_COPY_AND_ASSIGN(PrintSystemWin); |
| 646 }; | 645 }; |
| 647 | 646 |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 819 } | 818 } |
| 820 | 819 |
| 821 } // namespace | 820 } // namespace |
| 822 | 821 |
| 823 scoped_refptr<PrintSystem> PrintSystem::CreateInstance( | 822 scoped_refptr<PrintSystem> PrintSystem::CreateInstance( |
| 824 const base::DictionaryValue* print_system_settings) { | 823 const base::DictionaryValue* print_system_settings) { |
| 825 return new PrintSystemWin; | 824 return new PrintSystemWin; |
| 826 } | 825 } |
| 827 | 826 |
| 828 } // namespace cloud_print | 827 } // namespace cloud_print |
| OLD | NEW |