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

Side by Side Diff: chrome/service/cloud_print/print_system_win.cc

Issue 5947002: As the first step in an effort to improve robustness of the cloud print proxy... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Review comments Created 10 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 9
10 #include "base/file_path.h" 10 #include "base/file_path.h"
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 238
239 class PrintSystemWin : public PrintSystem { 239 class PrintSystemWin : public PrintSystem {
240 public: 240 public:
241 PrintSystemWin(); 241 PrintSystemWin();
242 242
243 // PrintSystem implementation. 243 // PrintSystem implementation.
244 virtual void Init(); 244 virtual void Init();
245 245
246 virtual void EnumeratePrinters(printing::PrinterList* printer_list); 246 virtual void EnumeratePrinters(printing::PrinterList* printer_list);
247 247
248 virtual bool GetPrinterCapsAndDefaults( 248 virtual void GetPrinterCapsAndDefaults(
249 const std::string& printer_name, 249 const std::string& printer_name,
250 printing::PrinterCapsAndDefaults* printer_info); 250 PrinterCapsAndDefaultsCallback* callback);
251 251
252 virtual bool IsValidPrinter(const std::string& printer_name); 252 virtual bool IsValidPrinter(const std::string& printer_name);
253 253
254 virtual bool ValidatePrintTicket(const std::string& printer_name, 254 virtual bool ValidatePrintTicket(const std::string& printer_name,
255 const std::string& print_ticket_data); 255 const std::string& print_ticket_data);
256 256
257 virtual bool GetJobDetails(const std::string& printer_name, 257 virtual bool GetJobDetails(const std::string& printer_name,
258 PlatformJobId job_id, 258 PlatformJobId job_id,
259 PrintJobDetails *job_details); 259 PrintJobDetails *job_details);
260 260
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 PrintSystem::JobSpooler::Delegate* delegate_; 509 PrintSystem::JobSpooler::Delegate* delegate_;
510 int saved_dc_; 510 int saved_dc_;
511 ScopedHDC printer_dc_; 511 ScopedHDC printer_dc_;
512 FilePath print_data_file_path_; 512 FilePath print_data_file_path_;
513 DISALLOW_COPY_AND_ASSIGN(JobSpoolerWin::Core); 513 DISALLOW_COPY_AND_ASSIGN(JobSpoolerWin::Core);
514 }; 514 };
515 scoped_refptr<Core> core_; 515 scoped_refptr<Core> core_;
516 DISALLOW_COPY_AND_ASSIGN(JobSpoolerWin); 516 DISALLOW_COPY_AND_ASSIGN(JobSpoolerWin);
517 }; 517 };
518 518
519 // A helper class to handle the response from the utility process to the
520 // request to fetch printer capabilities and defaults.
521 class PrinterCapsHandler : public ServiceUtilityProcessHost::Client {
522 public:
523 PrinterCapsHandler(
524 const std::string& printer_name,
525 PrinterCapsAndDefaultsCallback* callback)
526 : printer_name_(printer_name), callback_(callback) {
527 }
528 virtual void Start() {
529 g_service_process->io_thread()->message_loop_proxy()->PostTask(
530 FROM_HERE,
531 NewRunnableMethod(
532 this,
533 &PrinterCapsHandler::GetPrinterCapsAndDefaultsImpl,
534 base::MessageLoopProxy::CreateForCurrentThread()));
535 }
536
537 virtual void OnChildDied() {
538 OnGetPrinterCapsAndDefaultsFailed(printer_name_);
539 }
540 virtual void OnGetPrinterCapsAndDefaultsSucceeded(
541 const std::string& printer_name,
542 const printing::PrinterCapsAndDefaults& caps_and_defaults) {
543 callback_->Run(true, printer_name, caps_and_defaults);
544 callback_.reset();
545 Release();
546 }
547
548 virtual void OnGetPrinterCapsAndDefaultsFailed(
549 const std::string& printer_name) {
550 printing::PrinterCapsAndDefaults caps_and_defaults;
551 callback_->Run(false, printer_name, caps_and_defaults);
552 callback_.reset();
553 Release();
554 }
555 private:
556 // Called on the service process IO thread.
557 void GetPrinterCapsAndDefaultsImpl(
558 const scoped_refptr<base::MessageLoopProxy>&
559 client_message_loop_proxy) {
560 DCHECK(g_service_process->io_thread()->message_loop_proxy()->
561 BelongsToCurrentThread());
562 scoped_ptr<ServiceUtilityProcessHost> utility_host(
563 new ServiceUtilityProcessHost(this, client_message_loop_proxy));
564 if (utility_host->StartGetPrinterCapsAndDefaults(printer_name_)) {
565 // The object will self-destruct when the child process dies.
566 utility_host.release();
567 } else {
568 client_message_loop_proxy->PostTask(
569 FROM_HERE,
570 NewRunnableMethod(
571 this,
572 &PrinterCapsHandler::OnGetPrinterCapsAndDefaultsFailed,
573 printer_name_));
574 }
575 }
576
577 std::string printer_name_;
578 scoped_ptr<PrinterCapsAndDefaultsCallback> callback_;
579 };
580
581
519 virtual PrintSystem::PrintServerWatcher* CreatePrintServerWatcher(); 582 virtual PrintSystem::PrintServerWatcher* CreatePrintServerWatcher();
520 virtual PrintSystem::PrinterWatcher* CreatePrinterWatcher( 583 virtual PrintSystem::PrinterWatcher* CreatePrinterWatcher(
521 const std::string& printer_name); 584 const std::string& printer_name);
522 virtual PrintSystem::JobSpooler* CreateJobSpooler(); 585 virtual PrintSystem::JobSpooler* CreateJobSpooler();
523 586
524 private: 587 private:
525 scoped_refptr<printing::PrintBackend> print_backend_; 588 scoped_refptr<printing::PrintBackend> print_backend_;
526 }; 589 };
527 590
528 PrintSystemWin::PrintSystemWin() { 591 PrintSystemWin::PrintSystemWin() {
529 print_backend_ = printing::PrintBackend::CreateInstance(NULL); 592 print_backend_ = printing::PrintBackend::CreateInstance(NULL);
530 } 593 }
531 594
532 void PrintSystemWin::Init() { 595 void PrintSystemWin::Init() {
533 } 596 }
534 597
535 void PrintSystemWin::EnumeratePrinters(printing::PrinterList* printer_list) { 598 void PrintSystemWin::EnumeratePrinters(printing::PrinterList* printer_list) {
536 print_backend_->EnumeratePrinters(printer_list); 599 print_backend_->EnumeratePrinters(printer_list);
537 } 600 }
538 601
539 bool PrintSystemWin::GetPrinterCapsAndDefaults( 602 void PrintSystemWin::GetPrinterCapsAndDefaults(
540 const std::string& printer_name, 603 const std::string& printer_name,
541 printing::PrinterCapsAndDefaults* printer_info) { 604 PrinterCapsAndDefaultsCallback* callback) {
542 return print_backend_->GetPrinterCapsAndDefaults(printer_name, printer_info); 605 // Launch as child process to retrieve the capabilities and defaults because
606 // this involves invoking a printer driver DLL and crashes have been known to
607 // occur.
608 PrinterCapsHandler* handler =
609 new PrinterCapsHandler(printer_name, callback);
610 handler->AddRef();
611 handler->Start();
543 } 612 }
544 613
545 bool PrintSystemWin::IsValidPrinter(const std::string& printer_name) { 614 bool PrintSystemWin::IsValidPrinter(const std::string& printer_name) {
546 return print_backend_->IsValidPrinter(printer_name); 615 return print_backend_->IsValidPrinter(printer_name);
547 } 616 }
548 617
549 bool PrintSystemWin::ValidatePrintTicket( 618 bool PrintSystemWin::ValidatePrintTicket(
550 const std::string& printer_name, 619 const std::string& printer_name,
551 const std::string& print_ticket_data) { 620 const std::string& print_ticket_data) {
552 if (!printing::XPSModule::Init()) { 621 if (!printing::XPSModule::Init()) {
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 RpcStringFree(reinterpret_cast<RPC_WSTR *>(&proxy_id_as_string)); 726 RpcStringFree(reinterpret_cast<RPC_WSTR *>(&proxy_id_as_string));
658 return ret; 727 return ret;
659 } 728 }
660 729
661 scoped_refptr<PrintSystem> PrintSystem::CreateInstance( 730 scoped_refptr<PrintSystem> PrintSystem::CreateInstance(
662 const DictionaryValue* print_system_settings) { 731 const DictionaryValue* print_system_settings) {
663 return new PrintSystemWin; 732 return new PrintSystemWin;
664 } 733 }
665 734
666 } // namespace cloud_print 735 } // namespace cloud_print
OLDNEW
« no previous file with comments | « chrome/service/cloud_print/print_system_cups.cc ('k') | chrome/service/cloud_print/printer_job_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698