| OLD | NEW |
| 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/printer_job_handler.h" | 5 #include "chrome/service/cloud_print/printer_job_handler.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/md5.h" | 9 #include "base/md5.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 printer_id_(printer_id), | 29 printer_id_(printer_id), |
| 30 auth_token_(auth_token), | 30 auth_token_(auth_token), |
| 31 last_caps_hash_(caps_hash), | 31 last_caps_hash_(caps_hash), |
| 32 cloud_print_server_url_(cloud_print_server_url), | 32 cloud_print_server_url_(cloud_print_server_url), |
| 33 delegate_(delegate), | 33 delegate_(delegate), |
| 34 local_job_id_(-1), | 34 local_job_id_(-1), |
| 35 next_response_handler_(NULL), | 35 next_response_handler_(NULL), |
| 36 next_failure_handler_(NULL), | 36 next_failure_handler_(NULL), |
| 37 server_error_count_(0), | 37 server_error_count_(0), |
| 38 print_thread_("Chrome_CloudPrintJobPrintThread"), | 38 print_thread_("Chrome_CloudPrintJobPrintThread"), |
| 39 job_handler_message_loop_proxy_( |
| 40 base::MessageLoopProxy::CreateForCurrentThread()), |
| 39 shutting_down_(false), | 41 shutting_down_(false), |
| 40 server_job_available_(false), | 42 server_job_available_(false), |
| 41 printer_update_pending_(true), | 43 printer_update_pending_(true), |
| 42 printer_delete_pending_(false), | 44 printer_delete_pending_(false), |
| 43 task_in_progress_(false) { | 45 task_in_progress_(false) { |
| 44 } | 46 } |
| 45 | 47 |
| 46 bool PrinterJobHandler::Initialize() { | 48 bool PrinterJobHandler::Initialize() { |
| 47 if (print_system_->IsValidPrinter(printer_info_.printer_name)) { | 49 if (print_system_->IsValidPrinter(printer_info_.printer_name)) { |
| 48 printer_watcher_ = print_system_->CreatePrinterWatcher( | 50 printer_watcher_ = print_system_->CreatePrinterWatcher( |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 | 426 |
| 425 void PrinterJobHandler::StartPrinting() { | 427 void PrinterJobHandler::StartPrinting() { |
| 426 LOG(INFO) << "CP_PROXY: Start printing, id: " << printer_id_; | 428 LOG(INFO) << "CP_PROXY: Start printing, id: " << printer_id_; |
| 427 // We are done with the request object for now. | 429 // We are done with the request object for now. |
| 428 request_.reset(); | 430 request_.reset(); |
| 429 if (!shutting_down_) { | 431 if (!shutting_down_) { |
| 430 if (!print_thread_.Start()) { | 432 if (!print_thread_.Start()) { |
| 431 JobFailed(PRINT_FAILED); | 433 JobFailed(PRINT_FAILED); |
| 432 } else { | 434 } else { |
| 433 print_thread_.message_loop()->PostTask( | 435 print_thread_.message_loop()->PostTask( |
| 434 FROM_HERE, NewRunnableFunction(&PrinterJobHandler::DoPrint, | 436 FROM_HERE, NewRunnableMethod(this, &PrinterJobHandler::DoPrint, |
| 435 job_details_, | 437 job_details_, |
| 436 printer_info_.printer_name, | 438 printer_info_.printer_name)); |
| 437 print_system_, this, | |
| 438 MessageLoop::current())); | |
| 439 } | 439 } |
| 440 } | 440 } |
| 441 } | 441 } |
| 442 | 442 |
| 443 void PrinterJobHandler::JobFailed(PrintJobError error) { | 443 void PrinterJobHandler::JobFailed(PrintJobError error) { |
| 444 LOG(INFO) << "CP_PROXY: Job failed, id: " << printer_id_; | 444 LOG(INFO) << "CP_PROXY: Job failed, id: " << printer_id_; |
| 445 if (!shutting_down_) { | 445 if (!shutting_down_) { |
| 446 UpdateJobStatus(cloud_print::PRINT_JOB_STATUS_ERROR, error); | 446 UpdateJobStatus(cloud_print::PRINT_JOB_STATUS_ERROR, error); |
| 447 } | 447 } |
| 448 } | 448 } |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 } | 583 } |
| 584 | 584 |
| 585 void PrinterJobHandler::FailedFetchingJobData() { | 585 void PrinterJobHandler::FailedFetchingJobData() { |
| 586 if (!shutting_down_) { | 586 if (!shutting_down_) { |
| 587 LOG(ERROR) << "CP_PROXY: Failed fetching job data for printer: " << | 587 LOG(ERROR) << "CP_PROXY: Failed fetching job data for printer: " << |
| 588 printer_info_.printer_name << ", job id: " << job_details_.job_id_; | 588 printer_info_.printer_name << ", job id: " << job_details_.job_id_; |
| 589 JobFailed(INVALID_JOB_DATA); | 589 JobFailed(INVALID_JOB_DATA); |
| 590 } | 590 } |
| 591 } | 591 } |
| 592 | 592 |
| 593 // The following methods are called on |print_thread_|. It is not safe to |
| 594 // access any members other than |job_handler_message_loop_proxy_|, |
| 595 // |job_spooler_| and |print_system_|. |
| 593 void PrinterJobHandler::DoPrint(const JobDetails& job_details, | 596 void PrinterJobHandler::DoPrint(const JobDetails& job_details, |
| 594 const std::string& printer_name, | 597 const std::string& printer_name) { |
| 595 scoped_refptr<cloud_print::PrintSystem> print_system, | 598 job_spooler_ = print_system_->CreateJobSpooler(); |
| 596 PrinterJobHandler* job_handler, | 599 DCHECK(job_spooler_); |
| 597 MessageLoop* job_message_loop) { | 600 if (job_spooler_) { |
| 598 DCHECK(job_handler); | 601 job_spooler_->Spool(job_details.print_ticket_, |
| 599 DCHECK(job_message_loop); | 602 job_details.print_data_file_path_, |
| 600 LOG(INFO) << "CP_PROXY: Printing: " << printer_name; | 603 job_details.print_data_mime_type_, |
| 601 cloud_print::PlatformJobId job_id = -1; | 604 printer_name, |
| 602 if (print_system->SpoolPrintJob(job_details.print_ticket_, | 605 job_details.job_title_, |
| 603 job_details.print_data_file_path_, | 606 this); |
| 604 job_details.print_data_mime_type_, | |
| 605 printer_name, | |
| 606 job_details.job_title_, &job_id)) { | |
| 607 job_message_loop->PostTask(FROM_HERE, | |
| 608 NewRunnableMethod(job_handler, | |
| 609 &PrinterJobHandler::JobSpooled, | |
| 610 job_id)); | |
| 611 } else { | 607 } else { |
| 612 job_message_loop->PostTask(FROM_HERE, | 608 OnJobSpoolFailed(); |
| 613 NewRunnableMethod(job_handler, | |
| 614 &PrinterJobHandler::JobFailed, | |
| 615 PRINT_FAILED)); | |
| 616 } | 609 } |
| 617 } | 610 } |
| 618 | 611 |
| 612 void PrinterJobHandler::OnJobSpoolSucceeded( |
| 613 const cloud_print::PlatformJobId& job_id) { |
| 614 DCHECK(MessageLoop::current() == print_thread_.message_loop()); |
| 615 job_spooler_ = NULL; |
| 616 job_handler_message_loop_proxy_->PostTask(FROM_HERE, |
| 617 NewRunnableMethod(this, |
| 618 &PrinterJobHandler::JobSpooled, |
| 619 job_id)); |
| 620 } |
| 621 |
| 622 void PrinterJobHandler::OnJobSpoolFailed() { |
| 623 DCHECK(MessageLoop::current() == print_thread_.message_loop()); |
| 624 job_spooler_ = NULL; |
| 625 job_handler_message_loop_proxy_->PostTask(FROM_HERE, |
| 626 NewRunnableMethod(this, |
| 627 &PrinterJobHandler::JobFailed, |
| 628 PRINT_FAILED)); |
| 629 } |
| 630 |
| OLD | NEW |