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

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

Issue 8600007: base::Bind: Convert chrome/service/cloud_print. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase and review fixes. Created 9 years, 1 month 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) 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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 // Visual Studio where it gets confused between multiple Delegate. 244 // Visual Studio where it gets confused between multiple Delegate.
245 // In this case, some compilers get confused and inherit 245 // In this case, some compilers get confused and inherit
246 // PrintSystemWin watchers from wrong Delegate, giving C2664 and C2259 errors. 246 // PrintSystemWin watchers from wrong Delegate, giving C2664 and C2259 errors.
247 typedef PrintSystemWatcherWin::Delegate PrintSystemWatcherWinDelegate; 247 typedef PrintSystemWatcherWin::Delegate PrintSystemWatcherWinDelegate;
248 248
249 class PrintSystemWin : public PrintSystem { 249 class PrintSystemWin : public PrintSystem {
250 public: 250 public:
251 PrintSystemWin(); 251 PrintSystemWin();
252 252
253 // PrintSystem implementation. 253 // PrintSystem implementation.
254 virtual PrintSystemResult Init(); 254 virtual PrintSystemResult Init() OVERRIDE;
255
256 virtual PrintSystem::PrintSystemResult EnumeratePrinters( 255 virtual PrintSystem::PrintSystemResult EnumeratePrinters(
257 printing::PrinterList* printer_list); 256 printing::PrinterList* printer_list) OVERRIDE;
258
259 virtual void GetPrinterCapsAndDefaults( 257 virtual void GetPrinterCapsAndDefaults(
260 const std::string& printer_name, 258 const std::string& printer_name,
261 PrinterCapsAndDefaultsCallback* callback); 259 const PrinterCapsAndDefaultsCallback& callback) OVERRIDE;
262 260 virtual bool IsValidPrinter(const std::string& printer_name) OVERRIDE;
263 virtual bool IsValidPrinter(const std::string& printer_name); 261 virtual bool ValidatePrintTicket(
264 262 const std::string& printer_name,
265 virtual bool ValidatePrintTicket(const std::string& printer_name, 263 const std::string& print_ticket_data) OVERRIDE;
266 const std::string& print_ticket_data);
267
268 virtual bool GetJobDetails(const std::string& printer_name, 264 virtual bool GetJobDetails(const std::string& printer_name,
269 PlatformJobId job_id, 265 PlatformJobId job_id,
270 PrintJobDetails *job_details); 266 PrintJobDetails *job_details) OVERRIDE;
271 267
272 class PrintServerWatcherWin 268 class PrintServerWatcherWin
273 : public PrintSystem::PrintServerWatcher, 269 : public PrintSystem::PrintServerWatcher,
274 public PrintSystemWatcherWinDelegate { 270 public PrintSystemWatcherWinDelegate {
275 public: 271 public:
276 PrintServerWatcherWin() : delegate_(NULL) {} 272 PrintServerWatcherWin() : delegate_(NULL) {}
277 273
278 // PrintSystem::PrintServerWatcher interface 274 // PrintSystem::PrintServerWatcher implementation.
279 virtual bool StartWatching( 275 virtual bool StartWatching(
280 PrintSystem::PrintServerWatcher::Delegate* delegate) { 276 PrintSystem::PrintServerWatcher::Delegate* delegate) OVERRIDE{
281 delegate_ = delegate; 277 delegate_ = delegate;
282 return watcher_.Start(std::string(), this); 278 return watcher_.Start(std::string(), this);
283 } 279 }
284 virtual bool StopWatching() { 280
281 virtual bool StopWatching() OVERRIDE{
285 bool ret = watcher_.Stop(); 282 bool ret = watcher_.Stop();
286 delegate_ = NULL; 283 delegate_ = NULL;
287 return ret; 284 return ret;
288 } 285 }
289 286
290 // PrintSystemWatcherWin::Delegate interface 287 // PrintSystemWatcherWin::Delegate implementation.
291 virtual void OnPrinterAdded() { 288 virtual void OnPrinterAdded() OVERRIDE {
292 delegate_->OnPrinterAdded(); 289 delegate_->OnPrinterAdded();
293 } 290 }
294 virtual void OnPrinterDeleted() { 291 virtual void OnPrinterDeleted() OVERRIDE {}
295 } 292 virtual void OnPrinterChanged() OVERRIDE {}
296 virtual void OnPrinterChanged() { 293 virtual void OnJobChanged() OVERRIDE {}
297 }
298 virtual void OnJobChanged() {
299 }
300 294
301 private: 295 private:
302 PrintSystem::PrintServerWatcher::Delegate* delegate_; 296 PrintSystem::PrintServerWatcher::Delegate* delegate_;
303 PrintSystemWatcherWin watcher_; 297 PrintSystemWatcherWin watcher_;
298
304 DISALLOW_COPY_AND_ASSIGN(PrintServerWatcherWin); 299 DISALLOW_COPY_AND_ASSIGN(PrintServerWatcherWin);
305 }; 300 };
306 301
307 class PrinterWatcherWin 302 class PrinterWatcherWin
308 : public PrintSystem::PrinterWatcher, 303 : public PrintSystem::PrinterWatcher,
309 public PrintSystemWatcherWinDelegate { 304 public PrintSystemWatcherWinDelegate {
310 public: 305 public:
311 explicit PrinterWatcherWin(const std::string& printer_name) 306 explicit PrinterWatcherWin(const std::string& printer_name)
312 : printer_name_(printer_name), 307 : printer_name_(printer_name),
313 delegate_(NULL) { 308 delegate_(NULL) {
314 } 309 }
315 310
316 // PrintSystem::PrinterWatcher interface 311 // PrintSystem::PrinterWatcher implementation.
317 virtual bool StartWatching( 312 virtual bool StartWatching(
318 PrintSystem::PrinterWatcher::Delegate* delegate) { 313 PrintSystem::PrinterWatcher::Delegate* delegate) OVERRIDE {
319 delegate_ = delegate; 314 delegate_ = delegate;
320 return watcher_.Start(printer_name_, this); 315 return watcher_.Start(printer_name_, this);
321 } 316 }
322 virtual bool StopWatching() { 317
318 virtual bool StopWatching() OVERRIDE {
323 bool ret = watcher_.Stop(); 319 bool ret = watcher_.Stop();
324 delegate_ = NULL; 320 delegate_ = NULL;
325 return ret; 321 return ret;
326 } 322 }
323
327 virtual bool GetCurrentPrinterInfo( 324 virtual bool GetCurrentPrinterInfo(
328 printing::PrinterBasicInfo* printer_info) { 325 printing::PrinterBasicInfo* printer_info) OVERRIDE {
329 return watcher_.GetCurrentPrinterInfo(printer_info); 326 return watcher_.GetCurrentPrinterInfo(printer_info);
330 } 327 }
331 328
332 // PrintSystemWatcherWin::Delegate interface 329 // PrintSystemWatcherWin::Delegate implementation.
333 virtual void OnPrinterAdded() { 330 virtual void OnPrinterAdded() OVERRIDE {
334 NOTREACHED(); 331 NOTREACHED();
335 } 332 }
336 virtual void OnPrinterDeleted() { 333 virtual void OnPrinterDeleted() OVERRIDE {
337 delegate_->OnPrinterDeleted(); 334 delegate_->OnPrinterDeleted();
338 } 335 }
339 virtual void OnPrinterChanged() { 336 virtual void OnPrinterChanged() OVERRIDE {
340 delegate_->OnPrinterChanged(); 337 delegate_->OnPrinterChanged();
341 } 338 }
342 virtual void OnJobChanged() { 339 virtual void OnJobChanged() OVERRIDE {
343 delegate_->OnJobChanged(); 340 delegate_->OnJobChanged();
344 } 341 }
345 342
346 private: 343 private:
347 std::string printer_name_; 344 std::string printer_name_;
348 PrintSystem::PrinterWatcher::Delegate* delegate_; 345 PrintSystem::PrinterWatcher::Delegate* delegate_;
349 PrintSystemWatcherWin watcher_; 346 PrintSystemWatcherWin watcher_;
347
350 DISALLOW_COPY_AND_ASSIGN(PrinterWatcherWin); 348 DISALLOW_COPY_AND_ASSIGN(PrinterWatcherWin);
351 }; 349 };
352 350
353 class JobSpoolerWin : public PrintSystem::JobSpooler { 351 class JobSpoolerWin : public PrintSystem::JobSpooler {
354 public: 352 public:
355 JobSpoolerWin() : core_(new Core) {} 353 JobSpoolerWin() : core_(new Core) {}
354
356 // PrintSystem::JobSpooler implementation. 355 // PrintSystem::JobSpooler implementation.
357 virtual bool Spool(const std::string& print_ticket, 356 virtual bool Spool(const std::string& print_ticket,
358 const FilePath& print_data_file_path, 357 const FilePath& print_data_file_path,
359 const std::string& print_data_mime_type, 358 const std::string& print_data_mime_type,
360 const std::string& printer_name, 359 const std::string& printer_name,
361 const std::string& job_title, 360 const std::string& job_title,
362 const std::vector<std::string>& tags, 361 const std::vector<std::string>& tags,
363 JobSpooler::Delegate* delegate) { 362 JobSpooler::Delegate* delegate) OVERRIDE {
364 // TODO(gene): add tags handling. 363 // TODO(gene): add tags handling.
365 return core_->Spool(print_ticket, print_data_file_path, 364 return core_->Spool(print_ticket, print_data_file_path,
366 print_data_mime_type, printer_name, job_title, 365 print_data_mime_type, printer_name, job_title,
367 delegate); 366 delegate);
368 } 367 }
369 368
370 private: 369 private:
371 // We use a Core class because we want a separate RefCountedThreadSafe 370 // We use a Core class because we want a separate RefCountedThreadSafe
372 // implementation for ServiceUtilityProcessHost::Client. 371 // implementation for ServiceUtilityProcessHost::Client.
373 class Core : public ServiceUtilityProcessHost::Client, 372 class Core : public ServiceUtilityProcessHost::Client,
374 public base::win::ObjectWatcher::Delegate { 373 public base::win::ObjectWatcher::Delegate {
375 public: 374 public:
376 Core() 375 Core()
377 : last_page_printed_(-1), 376 : last_page_printed_(-1),
378 job_id_(-1), 377 job_id_(-1),
379 delegate_(NULL), 378 delegate_(NULL),
380 saved_dc_(0), 379 saved_dc_(0),
381 should_couninit_(false) { 380 should_couninit_(false) {
382 } 381 }
383 ~Core() { 382
384 } 383 ~Core() {}
384
385 bool Spool(const std::string& print_ticket, 385 bool Spool(const std::string& print_ticket,
386 const FilePath& print_data_file_path, 386 const FilePath& print_data_file_path,
387 const std::string& print_data_mime_type, 387 const std::string& print_data_mime_type,
388 const std::string& printer_name, 388 const std::string& printer_name,
389 const std::string& job_title, 389 const std::string& job_title,
390 JobSpooler::Delegate* delegate) { 390 JobSpooler::Delegate* delegate) {
391 if (delegate_) { 391 if (delegate_) {
392 // We are already in the process of printing. 392 // We are already in the process of printing.
393 NOTREACHED(); 393 NOTREACHED();
394 return false; 394 return false;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 } else { 450 } else {
451 NOTREACHED(); 451 NOTREACHED();
452 return false; 452 return false;
453 } 453 }
454 return true; 454 return true;
455 } 455 }
456 456
457 // ServiceUtilityProcessHost::Client implementation. 457 // ServiceUtilityProcessHost::Client implementation.
458 virtual void OnRenderPDFPagesToMetafileSucceeded( 458 virtual void OnRenderPDFPagesToMetafileSucceeded(
459 const printing::Emf& metafile, 459 const printing::Emf& metafile,
460 int highest_rendered_page_number) { 460 int highest_rendered_page_number) OVERRIDE {
461 metafile.SafePlayback(printer_dc_.Get()); 461 metafile.SafePlayback(printer_dc_.Get());
462 bool done_printing = (highest_rendered_page_number != 462 bool done_printing = (highest_rendered_page_number !=
463 last_page_printed_ + kPageCountPerBatch); 463 last_page_printed_ + kPageCountPerBatch);
464 last_page_printed_ = highest_rendered_page_number; 464 last_page_printed_ = highest_rendered_page_number;
465 if (done_printing) 465 if (done_printing)
466 PrintJobDone(); 466 PrintJobDone();
467 else 467 else
468 RenderNextPDFPages(); 468 RenderNextPDFPages();
469 } 469 }
470 470
471 // base::win::ObjectWatcher::Delegate inplementation. 471 // base::win::ObjectWatcher::Delegate implementation.
472 virtual void OnObjectSignaled(HANDLE object) { 472 virtual void OnObjectSignaled(HANDLE object) OVERRIDE {
473 DCHECK(xps_print_job_); 473 DCHECK(xps_print_job_);
474 DCHECK(object == job_progress_event_.Get()); 474 DCHECK(object == job_progress_event_.Get());
475 ResetEvent(job_progress_event_.Get()); 475 ResetEvent(job_progress_event_.Get());
476 if (!delegate_) 476 if (!delegate_)
477 return; 477 return;
478 XPS_JOB_STATUS job_status = {0}; 478 XPS_JOB_STATUS job_status = {0};
479 xps_print_job_->GetJobStatus(&job_status); 479 xps_print_job_->GetJobStatus(&job_status);
480 bool done = false; 480 bool done = false;
481 if ((job_status.completion == XPS_JOB_CANCELLED) || 481 if ((job_status.completion == XPS_JOB_CANCELLED) ||
482 (job_status.completion == XPS_JOB_FAILED)) { 482 (job_status.completion == XPS_JOB_FAILED)) {
483 delegate_->OnJobSpoolFailed(); 483 delegate_->OnJobSpoolFailed();
484 done = true; 484 done = true;
485 } else if (job_status.jobId || 485 } else if (job_status.jobId ||
486 (job_status.completion == XPS_JOB_COMPLETED)) { 486 (job_status.completion == XPS_JOB_COMPLETED)) {
487 // Note: In the case of the XPS document being printed to the 487 // Note: In the case of the XPS document being printed to the
488 // Microsoft XPS Document Writer, it seems to skip spooling the job 488 // Microsoft XPS Document Writer, it seems to skip spooling the job
489 // and goes to the completed state without ever assigning a job id. 489 // and goes to the completed state without ever assigning a job id.
490 delegate_->OnJobSpoolSucceeded(job_status.jobId); 490 delegate_->OnJobSpoolSucceeded(job_status.jobId);
491 done = true; 491 done = true;
492 } else { 492 } else {
493 job_progress_watcher_.StopWatching(); 493 job_progress_watcher_.StopWatching();
494 job_progress_watcher_.StartWatching(job_progress_event_.Get(), this); 494 job_progress_watcher_.StartWatching(job_progress_event_.Get(), this);
495 } 495 }
496 if (done && should_couninit_) { 496 if (done && should_couninit_) {
497 CoUninitialize(); 497 CoUninitialize();
498 should_couninit_ = false; 498 should_couninit_ = false;
499 } 499 }
500 } 500 }
501 501
502 virtual void OnRenderPDFPagesToMetafileFailed() { 502 virtual void OnRenderPDFPagesToMetafileFailed() OVERRIDE {
503 PrintJobDone(); 503 PrintJobDone();
504 } 504 }
505 virtual void OnChildDied() { 505
506 virtual void OnChildDied() OVERRIDE {
506 PrintJobDone(); 507 PrintJobDone();
507 } 508 }
509
508 private: 510 private:
509 void PrintJobDone() { 511 void PrintJobDone() {
510 // If there is no delegate, then there is nothing pending to process. 512 // If there is no delegate, then there is nothing pending to process.
511 if (!delegate_) 513 if (!delegate_)
512 return; 514 return;
513 RestoreDC(printer_dc_.Get(), saved_dc_); 515 RestoreDC(printer_dc_.Get(), saved_dc_);
514 EndDoc(printer_dc_.Get()); 516 EndDoc(printer_dc_.Get());
515 if (-1 == last_page_printed_) { 517 if (-1 == last_page_printed_) {
516 delegate_->OnJobSpoolFailed(); 518 delegate_->OnJobSpoolFailed();
517 } else { 519 } else {
518 delegate_->OnJobSpoolSucceeded(job_id_); 520 delegate_->OnJobSpoolSucceeded(job_id_);
519 } 521 }
520 delegate_ = NULL; 522 delegate_ = NULL;
521 } 523 }
524
522 void RenderNextPDFPages() { 525 void RenderNextPDFPages() {
523 printing::PageRange range; 526 printing::PageRange range;
524 // Render 10 pages at a time. 527 // Render 10 pages at a time.
525 range.from = last_page_printed_ + 1; 528 range.from = last_page_printed_ + 1;
526 range.to = last_page_printed_ + kPageCountPerBatch; 529 range.to = last_page_printed_ + kPageCountPerBatch;
527 std::vector<printing::PageRange> page_ranges; 530 std::vector<printing::PageRange> page_ranges;
528 page_ranges.push_back(range); 531 page_ranges.push_back(range);
529 532
530 int printer_dpi = ::GetDeviceCaps(printer_dc_.Get(), LOGPIXELSX); 533 int printer_dpi = ::GetDeviceCaps(printer_dc_.Get(), LOGPIXELSX);
531 int dc_width = GetDeviceCaps(printer_dc_.Get(), PHYSICALWIDTH); 534 int dc_width = GetDeviceCaps(printer_dc_.Get(), PHYSICALWIDTH);
532 int dc_height = GetDeviceCaps(printer_dc_.Get(), PHYSICALHEIGHT); 535 int dc_height = GetDeviceCaps(printer_dc_.Get(), PHYSICALHEIGHT);
533 gfx::Rect render_area(0, 0, dc_width, dc_height); 536 gfx::Rect render_area(0, 0, dc_width, dc_height);
534 g_service_process->io_thread()->message_loop_proxy()->PostTask( 537 g_service_process->io_thread()->message_loop_proxy()->PostTask(
535 FROM_HERE, 538 FROM_HERE,
536 base::Bind(&JobSpoolerWin::Core::RenderPDFPagesInSandbox, this, 539 base::Bind(&JobSpoolerWin::Core::RenderPDFPagesInSandbox, this,
537 print_data_file_path_, render_area, printer_dpi, 540 print_data_file_path_, render_area, printer_dpi,
538 page_ranges, base::MessageLoopProxy::current())); 541 page_ranges, base::MessageLoopProxy::current()));
539 } 542 }
543
540 // Called on the service process IO thread. 544 // Called on the service process IO thread.
541 void RenderPDFPagesInSandbox( 545 void RenderPDFPagesInSandbox(
542 const FilePath& pdf_path, const gfx::Rect& render_area, 546 const FilePath& pdf_path, const gfx::Rect& render_area,
543 int render_dpi, const std::vector<printing::PageRange>& page_ranges, 547 int render_dpi, const std::vector<printing::PageRange>& page_ranges,
544 const scoped_refptr<base::MessageLoopProxy>& 548 const scoped_refptr<base::MessageLoopProxy>&
545 client_message_loop_proxy) { 549 client_message_loop_proxy) {
546 DCHECK(g_service_process->io_thread()->message_loop_proxy()-> 550 DCHECK(g_service_process->io_thread()->message_loop_proxy()->
547 BelongsToCurrentThread()); 551 BelongsToCurrentThread());
548 scoped_ptr<ServiceUtilityProcessHost> utility_host( 552 scoped_ptr<ServiceUtilityProcessHost> utility_host(
549 new ServiceUtilityProcessHost(this, client_message_loop_proxy)); 553 new ServiceUtilityProcessHost(this, client_message_loop_proxy));
550 // TODO(gene): For now we disabling autorotation for CloudPrinting. 554 // TODO(gene): For now we disabling autorotation for CloudPrinting.
551 // Landscape/Portrait setting is passed in the print ticket and 555 // Landscape/Portrait setting is passed in the print ticket and
552 // server is generating portrait PDF always. 556 // server is generating portrait PDF always.
553 // We should enable autorotation once server will be able to generate 557 // We should enable autorotation once server will be able to generate
554 // PDF that matches paper size and orientation. 558 // PDF that matches paper size and orientation.
555 if (utility_host->StartRenderPDFPagesToMetafile( 559 if (utility_host->StartRenderPDFPagesToMetafile(
556 pdf_path, 560 pdf_path,
557 printing::PdfRenderSettings(render_area, render_dpi, false), 561 printing::PdfRenderSettings(render_area, render_dpi, false),
558 page_ranges)) { 562 page_ranges)) {
559 // The object will self-destruct when the child process dies. 563 // The object will self-destruct when the child process dies.
560 utility_host.release(); 564 utility_host.release();
561 } 565 }
562 } 566 }
567
563 bool PrintXPSDocument(const std::string& printer_name, 568 bool PrintXPSDocument(const std::string& printer_name,
564 const std::string& job_title, 569 const std::string& job_title,
565 const FilePath& print_data_file_path, 570 const FilePath& print_data_file_path,
566 const std::string& print_ticket) { 571 const std::string& print_ticket) {
567 if (!printing::XPSPrintModule::Init()) 572 if (!printing::XPSPrintModule::Init())
568 return false; 573 return false;
569 job_progress_event_.Set(CreateEvent(NULL, TRUE, FALSE, NULL)); 574 job_progress_event_.Set(CreateEvent(NULL, TRUE, FALSE, NULL));
570 if (!job_progress_event_.Get()) 575 if (!job_progress_event_.Get())
571 return false; 576 return false;
572 should_couninit_ = SUCCEEDED(CoInitializeEx(NULL, 577 should_couninit_ = SUCCEEDED(CoInitializeEx(NULL,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 int last_page_printed_; 635 int last_page_printed_;
631 PlatformJobId job_id_; 636 PlatformJobId job_id_;
632 PrintSystem::JobSpooler::Delegate* delegate_; 637 PrintSystem::JobSpooler::Delegate* delegate_;
633 int saved_dc_; 638 int saved_dc_;
634 base::win::ScopedCreateDC printer_dc_; 639 base::win::ScopedCreateDC printer_dc_;
635 FilePath print_data_file_path_; 640 FilePath print_data_file_path_;
636 base::win::ScopedHandle job_progress_event_; 641 base::win::ScopedHandle job_progress_event_;
637 base::win::ObjectWatcher job_progress_watcher_; 642 base::win::ObjectWatcher job_progress_watcher_;
638 base::win::ScopedComPtr<IXpsPrintJob> xps_print_job_; 643 base::win::ScopedComPtr<IXpsPrintJob> xps_print_job_;
639 bool should_couninit_; 644 bool should_couninit_;
645
640 DISALLOW_COPY_AND_ASSIGN(JobSpoolerWin::Core); 646 DISALLOW_COPY_AND_ASSIGN(JobSpoolerWin::Core);
641 }; 647 };
642 scoped_refptr<Core> core_; 648 scoped_refptr<Core> core_;
649
643 DISALLOW_COPY_AND_ASSIGN(JobSpoolerWin); 650 DISALLOW_COPY_AND_ASSIGN(JobSpoolerWin);
644 }; 651 };
645 652
646 // A helper class to handle the response from the utility process to the 653 // A helper class to handle the response from the utility process to the
647 // request to fetch printer capabilities and defaults. 654 // request to fetch printer capabilities and defaults.
648 class PrinterCapsHandler : public ServiceUtilityProcessHost::Client { 655 class PrinterCapsHandler : public ServiceUtilityProcessHost::Client {
649 public: 656 public:
650 PrinterCapsHandler( 657 PrinterCapsHandler(
651 const std::string& printer_name, 658 const std::string& printer_name,
652 PrinterCapsAndDefaultsCallback* callback) 659 const PrinterCapsAndDefaultsCallback& callback)
653 : printer_name_(printer_name), callback_(callback) { 660 : printer_name_(printer_name), callback_(callback) {
654 } 661 }
655 virtual void Start() { 662
663 // ServiceUtilityProcessHost::Client implementation.
664 virtual void OnChildDied() OVERRIDE {
665 OnGetPrinterCapsAndDefaultsFailed(printer_name_);
666 }
667
668 virtual void OnGetPrinterCapsAndDefaultsSucceeded(
669 const std::string& printer_name,
670 const printing::PrinterCapsAndDefaults& caps_and_defaults) OVERRIDE {
671 callback_.Run(true, printer_name, caps_and_defaults);
672 callback_.Reset();
673 Release();
674 }
675
676 virtual void OnGetPrinterCapsAndDefaultsFailed(
677 const std::string& printer_name) OVERRIDE {
678 printing::PrinterCapsAndDefaults caps_and_defaults;
679 callback_.Run(false, printer_name, caps_and_defaults);
680 callback_.Reset();
681 Release();
682 }
683
684 void Start() {
656 g_service_process->io_thread()->message_loop_proxy()->PostTask( 685 g_service_process->io_thread()->message_loop_proxy()->PostTask(
657 FROM_HERE, 686 FROM_HERE,
658 base::Bind(&PrinterCapsHandler::GetPrinterCapsAndDefaultsImpl, this, 687 base::Bind(&PrinterCapsHandler::GetPrinterCapsAndDefaultsImpl, this,
659 base::MessageLoopProxy::current())); 688 base::MessageLoopProxy::current()));
660 } 689 }
661 690
662 virtual void OnChildDied() {
663 OnGetPrinterCapsAndDefaultsFailed(printer_name_);
664 }
665 virtual void OnGetPrinterCapsAndDefaultsSucceeded(
666 const std::string& printer_name,
667 const printing::PrinterCapsAndDefaults& caps_and_defaults) {
668 callback_->Run(true, printer_name, caps_and_defaults);
669 callback_.reset();
670 Release();
671 }
672
673 virtual void OnGetPrinterCapsAndDefaultsFailed(
674 const std::string& printer_name) {
675 printing::PrinterCapsAndDefaults caps_and_defaults;
676 callback_->Run(false, printer_name, caps_and_defaults);
677 callback_.reset();
678 Release();
679 }
680
681 private: 691 private:
682 // Called on the service process IO thread. 692 // Called on the service process IO thread.
683 void GetPrinterCapsAndDefaultsImpl( 693 void GetPrinterCapsAndDefaultsImpl(
684 const scoped_refptr<base::MessageLoopProxy>& 694 const scoped_refptr<base::MessageLoopProxy>&
685 client_message_loop_proxy) { 695 client_message_loop_proxy) {
686 DCHECK(g_service_process->io_thread()->message_loop_proxy()-> 696 DCHECK(g_service_process->io_thread()->message_loop_proxy()->
687 BelongsToCurrentThread()); 697 BelongsToCurrentThread());
688 scoped_ptr<ServiceUtilityProcessHost> utility_host( 698 scoped_ptr<ServiceUtilityProcessHost> utility_host(
689 new ServiceUtilityProcessHost(this, client_message_loop_proxy)); 699 new ServiceUtilityProcessHost(this, client_message_loop_proxy));
690 if (utility_host->StartGetPrinterCapsAndDefaults(printer_name_)) { 700 if (utility_host->StartGetPrinterCapsAndDefaults(printer_name_)) {
691 // The object will self-destruct when the child process dies. 701 // The object will self-destruct when the child process dies.
692 utility_host.release(); 702 utility_host.release();
693 } else { 703 } else {
694 client_message_loop_proxy->PostTask( 704 client_message_loop_proxy->PostTask(
695 FROM_HERE, 705 FROM_HERE,
696 base::Bind(&PrinterCapsHandler::OnGetPrinterCapsAndDefaultsFailed, 706 base::Bind(&PrinterCapsHandler::OnGetPrinterCapsAndDefaultsFailed,
697 this, printer_name_)); 707 this, printer_name_));
698 } 708 }
699 } 709 }
700 710
701 std::string printer_name_; 711 std::string printer_name_;
702 scoped_ptr<PrinterCapsAndDefaultsCallback> callback_; 712 PrinterCapsAndDefaultsCallback callback_;
703 }; 713 };
704 714
705 715
706 virtual PrintSystem::PrintServerWatcher* CreatePrintServerWatcher(); 716 virtual PrintSystem::PrintServerWatcher* CreatePrintServerWatcher() OVERRIDE;
707 virtual PrintSystem::PrinterWatcher* CreatePrinterWatcher( 717 virtual PrintSystem::PrinterWatcher* CreatePrinterWatcher(
708 const std::string& printer_name); 718 const std::string& printer_name) OVERRIDE;
709 virtual PrintSystem::JobSpooler* CreateJobSpooler(); 719 virtual PrintSystem::JobSpooler* CreateJobSpooler() OVERRIDE;
710 virtual std::string GetSupportedMimeTypes(); 720 virtual std::string GetSupportedMimeTypes() OVERRIDE;
711
712 721
713 private: 722 private:
714 scoped_refptr<printing::PrintBackend> print_backend_; 723 scoped_refptr<printing::PrintBackend> print_backend_;
715 }; 724 };
716 725
717 PrintSystemWin::PrintSystemWin() { 726 PrintSystemWin::PrintSystemWin() {
718 print_backend_ = printing::PrintBackend::CreateInstance(NULL); 727 print_backend_ = printing::PrintBackend::CreateInstance(NULL);
719 } 728 }
720 729
721 PrintSystem::PrintSystemResult PrintSystemWin::Init() { 730 PrintSystem::PrintSystemResult PrintSystemWin::Init() {
722 if (!printing::XPSModule::Init()) { 731 if (!printing::XPSModule::Init()) {
723 std::string message = l10n_util::GetStringUTF8( 732 std::string message = l10n_util::GetStringUTF8(
724 IDS_CLOUD_PRINT_XPS_UNAVAILABLE); 733 IDS_CLOUD_PRINT_XPS_UNAVAILABLE);
725 return PrintSystemResult(false, message); 734 return PrintSystemResult(false, message);
726 } 735 }
727 return PrintSystemResult(true, std::string()); 736 return PrintSystemResult(true, std::string());
728 } 737 }
729 738
730 PrintSystem::PrintSystemResult PrintSystemWin::EnumeratePrinters( 739 PrintSystem::PrintSystemResult PrintSystemWin::EnumeratePrinters(
731 printing::PrinterList* printer_list) { 740 printing::PrinterList* printer_list) {
732 bool ret = print_backend_->EnumeratePrinters(printer_list); 741 bool ret = print_backend_->EnumeratePrinters(printer_list);
733 return PrintSystemResult(ret, std::string()); 742 return PrintSystemResult(ret, std::string());
734 } 743 }
735 744
736 void PrintSystemWin::GetPrinterCapsAndDefaults( 745 void PrintSystemWin::GetPrinterCapsAndDefaults(
737 const std::string& printer_name, 746 const std::string& printer_name,
738 PrinterCapsAndDefaultsCallback* callback) { 747 const PrinterCapsAndDefaultsCallback& callback) {
739 // Launch as child process to retrieve the capabilities and defaults because 748 // Launch as child process to retrieve the capabilities and defaults because
740 // this involves invoking a printer driver DLL and crashes have been known to 749 // this involves invoking a printer driver DLL and crashes have been known to
741 // occur. 750 // occur.
742 PrinterCapsHandler* handler = 751 PrinterCapsHandler* handler =
743 new PrinterCapsHandler(printer_name, callback); 752 new PrinterCapsHandler(printer_name, callback);
744 handler->AddRef(); 753 handler->AddRef();
745 handler->Start(); 754 handler->Start();
746 } 755 }
747 756
748 bool PrintSystemWin::IsValidPrinter(const std::string& printer_name) { 757 bool PrintSystemWin::IsValidPrinter(const std::string& printer_name) {
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 RpcStringFree(reinterpret_cast<RPC_WSTR *>(&proxy_id_as_string)); 877 RpcStringFree(reinterpret_cast<RPC_WSTR *>(&proxy_id_as_string));
869 return ret; 878 return ret;
870 } 879 }
871 880
872 scoped_refptr<PrintSystem> PrintSystem::CreateInstance( 881 scoped_refptr<PrintSystem> PrintSystem::CreateInstance(
873 const base::DictionaryValue* print_system_settings) { 882 const base::DictionaryValue* print_system_settings) {
874 return new PrintSystemWin; 883 return new PrintSystemWin;
875 } 884 }
876 885
877 } // namespace cloud_print 886 } // 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.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698