| 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/printer_job_handler.h" | 5 #include "chrome/service/cloud_print/printer_job_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 | 215 |
| 216 void PrinterJobHandler::OnJobSpoolFailed() { | 216 void PrinterJobHandler::OnJobSpoolFailed() { |
| 217 DCHECK(base::MessageLoop::current() == print_thread_.message_loop()); | 217 DCHECK(base::MessageLoop::current() == print_thread_.message_loop()); |
| 218 job_spooler_ = NULL; | 218 job_spooler_ = NULL; |
| 219 VLOG(1) << "CP_CONNECTOR: Job failed (spool failed)"; | 219 VLOG(1) << "CP_CONNECTOR: Job failed (spool failed)"; |
| 220 job_handler_message_loop_proxy_->PostTask( | 220 job_handler_message_loop_proxy_->PostTask( |
| 221 FROM_HERE, base::Bind(&PrinterJobHandler::JobFailed, this, PRINT_FAILED)); | 221 FROM_HERE, base::Bind(&PrinterJobHandler::JobFailed, this, PRINT_FAILED)); |
| 222 } | 222 } |
| 223 | 223 |
| 224 PrinterJobHandler::~PrinterJobHandler() { | 224 PrinterJobHandler::~PrinterJobHandler() { |
| 225 if (printer_watcher_) | 225 if (printer_watcher_.get()) |
| 226 printer_watcher_->StopWatching(); | 226 printer_watcher_->StopWatching(); |
| 227 } | 227 } |
| 228 | 228 |
| 229 // Begin Response handlers | 229 // Begin Response handlers |
| 230 CloudPrintURLFetcher::ResponseAction | 230 CloudPrintURLFetcher::ResponseAction |
| 231 PrinterJobHandler::HandlePrinterUpdateResponse( | 231 PrinterJobHandler::HandlePrinterUpdateResponse( |
| 232 const net::URLFetcher* source, | 232 const net::URLFetcher* source, |
| 233 const GURL& url, | 233 const GURL& url, |
| 234 DictionaryValue* json_data, | 234 DictionaryValue* json_data, |
| 235 bool succeeded) { | 235 bool succeeded) { |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 << ", printer id: " << printer_info_cloud_.printer_id | 531 << ", printer id: " << printer_info_cloud_.printer_id |
| 532 << ", job id: " << local_job_id; | 532 << ", job id: " << local_job_id; |
| 533 if (!shutting_down_) { | 533 if (!shutting_down_) { |
| 534 local_job_id_ = local_job_id; | 534 local_job_id_ = local_job_id; |
| 535 UpdateJobStatus(PRINT_JOB_STATUS_IN_PROGRESS, SUCCESS); | 535 UpdateJobStatus(PRINT_JOB_STATUS_IN_PROGRESS, SUCCESS); |
| 536 print_thread_.Stop(); | 536 print_thread_.Stop(); |
| 537 } | 537 } |
| 538 } | 538 } |
| 539 | 539 |
| 540 bool PrinterJobHandler::UpdatePrinterInfo() { | 540 bool PrinterJobHandler::UpdatePrinterInfo() { |
| 541 if (!printer_watcher_) { | 541 if (!printer_watcher_.get()) { |
| 542 LOG(ERROR) << "CP_CONNECTOR: Printer watcher is missing." | 542 LOG(ERROR) << "CP_CONNECTOR: Printer watcher is missing." |
| 543 << " Check printer server url for printer id: " | 543 << " Check printer server url for printer id: " |
| 544 << printer_info_cloud_.printer_id; | 544 << printer_info_cloud_.printer_id; |
| 545 return false; | 545 return false; |
| 546 } | 546 } |
| 547 | 547 |
| 548 VLOG(1) << "CP_CONNECTOR: Updating printer info" | 548 VLOG(1) << "CP_CONNECTOR: Updating printer info" |
| 549 << ", printer id: " << printer_info_cloud_.printer_id; | 549 << ", printer id: " << printer_info_cloud_.printer_id; |
| 550 // We need to update the parts of the printer info that have changed | 550 // We need to update the parts of the printer info that have changed |
| 551 // (could be printer name, description, status or capabilities). | 551 // (could be printer name, description, status or capabilities). |
| (...skipping 24 matching lines...) Expand all Loading... |
| 576 << ", job id: " << job_details_.job_id_; | 576 << ", job id: " << job_details_.job_id_; |
| 577 JobFailed(INVALID_JOB_DATA); | 577 JobFailed(INVALID_JOB_DATA); |
| 578 } | 578 } |
| 579 } | 579 } |
| 580 | 580 |
| 581 void PrinterJobHandler::OnReceivePrinterCaps( | 581 void PrinterJobHandler::OnReceivePrinterCaps( |
| 582 bool succeeded, | 582 bool succeeded, |
| 583 const std::string& printer_name, | 583 const std::string& printer_name, |
| 584 const printing::PrinterCapsAndDefaults& caps_and_defaults) { | 584 const printing::PrinterCapsAndDefaults& caps_and_defaults) { |
| 585 printing::PrinterBasicInfo printer_info; | 585 printing::PrinterBasicInfo printer_info; |
| 586 if (printer_watcher_) | 586 if (printer_watcher_.get()) |
| 587 printer_watcher_->GetCurrentPrinterInfo(&printer_info); | 587 printer_watcher_->GetCurrentPrinterInfo(&printer_info); |
| 588 | 588 |
| 589 std::string post_data; | 589 std::string post_data; |
| 590 std::string mime_boundary; | 590 std::string mime_boundary; |
| 591 CreateMimeBoundaryForUpload(&mime_boundary); | 591 CreateMimeBoundaryForUpload(&mime_boundary); |
| 592 | 592 |
| 593 if (succeeded) { | 593 if (succeeded) { |
| 594 std::string caps_hash = | 594 std::string caps_hash = |
| 595 base::MD5String(caps_and_defaults.printer_capabilities); | 595 base::MD5String(caps_and_defaults.printer_capabilities); |
| 596 if (caps_hash != printer_info_cloud_.caps_hash) { | 596 if (caps_hash != printer_info_cloud_.caps_hash) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 FROM_HERE, base::Bind(&PrinterJobHandler::Stop, this)); | 659 FROM_HERE, base::Bind(&PrinterJobHandler::Stop, this)); |
| 660 } | 660 } |
| 661 } | 661 } |
| 662 | 662 |
| 663 // The following methods are called on |print_thread_|. It is not safe to | 663 // The following methods are called on |print_thread_|. It is not safe to |
| 664 // access any members other than |job_handler_message_loop_proxy_|, | 664 // access any members other than |job_handler_message_loop_proxy_|, |
| 665 // |job_spooler_| and |print_system_|. | 665 // |job_spooler_| and |print_system_|. |
| 666 void PrinterJobHandler::DoPrint(const JobDetails& job_details, | 666 void PrinterJobHandler::DoPrint(const JobDetails& job_details, |
| 667 const std::string& printer_name) { | 667 const std::string& printer_name) { |
| 668 job_spooler_ = print_system_->CreateJobSpooler(); | 668 job_spooler_ = print_system_->CreateJobSpooler(); |
| 669 DCHECK(job_spooler_); | 669 DCHECK(job_spooler_.get()); |
| 670 if (!job_spooler_) | 670 if (!job_spooler_.get()) |
| 671 return; | 671 return; |
| 672 string16 document_name = | 672 string16 document_name = |
| 673 printing::PrintBackend::SimplifyDocumentTitle( | 673 printing::PrintBackend::SimplifyDocumentTitle( |
| 674 UTF8ToUTF16(job_details.job_title_)); | 674 UTF8ToUTF16(job_details.job_title_)); |
| 675 if (document_name.empty()) { | 675 if (document_name.empty()) { |
| 676 document_name = printing::PrintBackend::SimplifyDocumentTitle( | 676 document_name = printing::PrintBackend::SimplifyDocumentTitle( |
| 677 l10n_util::GetStringUTF16(IDS_DEFAULT_PRINT_DOCUMENT_TITLE)); | 677 l10n_util::GetStringUTF16(IDS_DEFAULT_PRINT_DOCUMENT_TITLE)); |
| 678 } | 678 } |
| 679 if (!job_spooler_->Spool(job_details.print_ticket_, | 679 if (!job_spooler_->Spool(job_details.print_ticket_, |
| 680 job_details.print_data_file_path_, | 680 job_details.print_data_file_path_, |
| 681 job_details.print_data_mime_type_, | 681 job_details.print_data_mime_type_, |
| 682 printer_name, | 682 printer_name, |
| 683 UTF16ToUTF8(document_name), | 683 UTF16ToUTF8(document_name), |
| 684 job_details.tags_, | 684 job_details.tags_, |
| 685 this)) { | 685 this)) { |
| 686 OnJobSpoolFailed(); | 686 OnJobSpoolFailed(); |
| 687 } | 687 } |
| 688 } | 688 } |
| 689 | 689 |
| 690 } // namespace cloud_print | 690 } // namespace cloud_print |
| OLD | NEW |