| 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 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 // Even though it is a job list, for now we are only interested in the | 343 // Even though it is a job list, for now we are only interested in the |
| 344 // first job | 344 // first job |
| 345 DictionaryValue* job_data = NULL; | 345 DictionaryValue* job_data = NULL; |
| 346 if (job_list->GetDictionary(0, &job_data)) { | 346 if (job_list->GetDictionary(0, &job_data)) { |
| 347 job_available = true; | 347 job_available = true; |
| 348 job_data->GetString(kIdValue, &job_details_.job_id_); | 348 job_data->GetString(kIdValue, &job_details_.job_id_); |
| 349 job_data->GetString(kTitleValue, &job_details_.job_title_); | 349 job_data->GetString(kTitleValue, &job_details_.job_title_); |
| 350 std::string print_ticket_url; | 350 std::string print_ticket_url; |
| 351 job_data->GetString(kTicketUrlValue, &print_ticket_url); | 351 job_data->GetString(kTicketUrlValue, &print_ticket_url); |
| 352 job_data->GetString(kFileUrlValue, &print_data_url_); | 352 job_data->GetString(kFileUrlValue, &print_data_url_); |
| 353 |
| 354 // Get tags for print job. |
| 355 job_details_.tags_.clear(); |
| 356 ListValue* tags = NULL; |
| 357 if (job_data->GetList(kTagsValue, &tags)) { |
| 358 for (size_t i = 0; i < tags->GetSize(); i++) { |
| 359 std::string value; |
| 360 if (tags->GetString(i, &value)) |
| 361 job_details_.tags_.push_back(value); |
| 362 } |
| 363 } |
| 353 SetNextDataHandler(&PrinterJobHandler::HandlePrintTicketResponse); | 364 SetNextDataHandler(&PrinterJobHandler::HandlePrintTicketResponse); |
| 354 request_ = new CloudPrintURLFetcher; | 365 request_ = new CloudPrintURLFetcher; |
| 355 request_->StartGetRequest(GURL(print_ticket_url.c_str()), | 366 request_->StartGetRequest(GURL(print_ticket_url.c_str()), |
| 356 this, | 367 this, |
| 357 auth_token_, | 368 auth_token_, |
| 358 kCloudPrintAPIMaxRetryCount); | 369 kCloudPrintAPIMaxRetryCount); |
| 359 } | 370 } |
| 360 } | 371 } |
| 361 } | 372 } |
| 362 // If no jobs are available, go to the Stop state. | 373 // If no jobs are available, go to the Stop state. |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 // |job_spooler_| and |print_system_|. | 571 // |job_spooler_| and |print_system_|. |
| 561 void PrinterJobHandler::DoPrint(const JobDetails& job_details, | 572 void PrinterJobHandler::DoPrint(const JobDetails& job_details, |
| 562 const std::string& printer_name) { | 573 const std::string& printer_name) { |
| 563 job_spooler_ = print_system_->CreateJobSpooler(); | 574 job_spooler_ = print_system_->CreateJobSpooler(); |
| 564 DCHECK(job_spooler_); | 575 DCHECK(job_spooler_); |
| 565 if (!job_spooler_ || !job_spooler_->Spool(job_details.print_ticket_, | 576 if (!job_spooler_ || !job_spooler_->Spool(job_details.print_ticket_, |
| 566 job_details.print_data_file_path_, | 577 job_details.print_data_file_path_, |
| 567 job_details.print_data_mime_type_, | 578 job_details.print_data_mime_type_, |
| 568 printer_name, | 579 printer_name, |
| 569 job_details.job_title_, | 580 job_details.job_title_, |
| 581 job_details.tags_, |
| 570 this)) { | 582 this)) { |
| 571 OnJobSpoolFailed(); | 583 OnJobSpoolFailed(); |
| 572 } | 584 } |
| 573 } | 585 } |
| 574 | 586 |
| 575 void PrinterJobHandler::OnJobSpoolSucceeded( | 587 void PrinterJobHandler::OnJobSpoolSucceeded( |
| 576 const cloud_print::PlatformJobId& job_id) { | 588 const cloud_print::PlatformJobId& job_id) { |
| 577 DCHECK(MessageLoop::current() == print_thread_.message_loop()); | 589 DCHECK(MessageLoop::current() == print_thread_.message_loop()); |
| 578 job_spooler_ = NULL; | 590 job_spooler_ = NULL; |
| 579 job_handler_message_loop_proxy_->PostTask(FROM_HERE, | 591 job_handler_message_loop_proxy_->PostTask(FROM_HERE, |
| 580 NewRunnableMethod(this, | 592 NewRunnableMethod(this, |
| 581 &PrinterJobHandler::JobSpooled, | 593 &PrinterJobHandler::JobSpooled, |
| 582 job_id)); | 594 job_id)); |
| 583 } | 595 } |
| 584 | 596 |
| 585 void PrinterJobHandler::OnJobSpoolFailed() { | 597 void PrinterJobHandler::OnJobSpoolFailed() { |
| 586 DCHECK(MessageLoop::current() == print_thread_.message_loop()); | 598 DCHECK(MessageLoop::current() == print_thread_.message_loop()); |
| 587 job_spooler_ = NULL; | 599 job_spooler_ = NULL; |
| 588 job_handler_message_loop_proxy_->PostTask(FROM_HERE, | 600 job_handler_message_loop_proxy_->PostTask(FROM_HERE, |
| 589 NewRunnableMethod(this, | 601 NewRunnableMethod(this, |
| 590 &PrinterJobHandler::JobFailed, | 602 &PrinterJobHandler::JobFailed, |
| 591 PRINT_FAILED)); | 603 PRINT_FAILED)); |
| 592 } | 604 } |
| OLD | NEW |