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" |
11 #include "base/md5.h" | 11 #include "base/md5.h" |
12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/common/cloud_print/cloud_print_constants.h" |
15 #include "chrome/common/cloud_print/cloud_print_helpers.h" | 16 #include "chrome/common/cloud_print/cloud_print_helpers.h" |
16 #include "chrome/service/cloud_print/cloud_print_consts.h" | |
17 #include "chrome/service/cloud_print/cloud_print_helpers.h" | 17 #include "chrome/service/cloud_print/cloud_print_helpers.h" |
18 #include "chrome/service/cloud_print/job_status_updater.h" | 18 #include "chrome/service/cloud_print/job_status_updater.h" |
19 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
20 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
21 #include "net/http/http_response_headers.h" | 21 #include "net/http/http_response_headers.h" |
22 #include "net/http/http_status_code.h" | 22 #include "net/http/http_status_code.h" |
23 #include "printing/backend/print_backend.h" | 23 #include "printing/backend/print_backend.h" |
24 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
25 | 25 |
| 26 namespace cloud_print { |
| 27 |
26 PrinterJobHandler::JobDetails::JobDetails() {} | 28 PrinterJobHandler::JobDetails::JobDetails() {} |
27 | 29 |
28 PrinterJobHandler::JobDetails::~JobDetails() {} | 30 PrinterJobHandler::JobDetails::~JobDetails() {} |
29 | 31 |
30 void PrinterJobHandler::JobDetails::Clear() { | 32 void PrinterJobHandler::JobDetails::Clear() { |
31 job_id_.clear(); | 33 job_id_.clear(); |
32 job_title_.clear(); | 34 job_title_.clear(); |
33 print_ticket_.clear(); | 35 print_ticket_.clear(); |
34 print_data_mime_type_.clear(); | 36 print_data_mime_type_.clear(); |
35 print_data_file_path_ = FilePath(); | 37 print_data_file_path_ = FilePath(); |
36 tags_.clear(); | 38 tags_.clear(); |
37 } | 39 } |
38 | 40 |
39 PrinterJobHandler::PrinterJobHandler( | 41 PrinterJobHandler::PrinterJobHandler( |
40 const printing::PrinterBasicInfo& printer_info, | 42 const printing::PrinterBasicInfo& printer_info, |
41 const PrinterInfoFromCloud& printer_info_cloud, | 43 const PrinterInfoFromCloud& printer_info_cloud, |
42 const GURL& cloud_print_server_url, | 44 const GURL& cloud_print_server_url, |
43 cloud_print::PrintSystem* print_system, | 45 PrintSystem* print_system, |
44 Delegate* delegate) | 46 Delegate* delegate) |
45 : print_system_(print_system), | 47 : print_system_(print_system), |
46 printer_info_(printer_info), | 48 printer_info_(printer_info), |
47 printer_info_cloud_(printer_info_cloud), | 49 printer_info_cloud_(printer_info_cloud), |
48 cloud_print_server_url_(cloud_print_server_url), | 50 cloud_print_server_url_(cloud_print_server_url), |
49 delegate_(delegate), | 51 delegate_(delegate), |
50 local_job_id_(-1), | 52 local_job_id_(-1), |
51 next_json_data_handler_(NULL), | 53 next_json_data_handler_(NULL), |
52 next_data_handler_(NULL), | 54 next_data_handler_(NULL), |
53 server_error_count_(0), | 55 server_error_count_(0), |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 CloudPrintURLFetcher::ResponseAction PrinterJobHandler::OnRequestAuthError() { | 156 CloudPrintURLFetcher::ResponseAction PrinterJobHandler::OnRequestAuthError() { |
155 // We got an Auth error and have no idea how long it will take to refresh | 157 // We got an Auth error and have no idea how long it will take to refresh |
156 // auth information (may take forever). We'll drop current request and | 158 // auth information (may take forever). We'll drop current request and |
157 // propagate this error to the upper level. After auth issues will be | 159 // propagate this error to the upper level. After auth issues will be |
158 // resolved, GCP connector will restart. | 160 // resolved, GCP connector will restart. |
159 OnAuthError(); | 161 OnAuthError(); |
160 return CloudPrintURLFetcher::STOP_PROCESSING; | 162 return CloudPrintURLFetcher::STOP_PROCESSING; |
161 } | 163 } |
162 | 164 |
163 std::string PrinterJobHandler::GetAuthHeader() { | 165 std::string PrinterJobHandler::GetAuthHeader() { |
164 return CloudPrintHelpers::GetCloudPrintAuthHeaderFromStore(); | 166 return GetCloudPrintAuthHeaderFromStore(); |
165 } | 167 } |
166 | 168 |
167 // JobStatusUpdater::Delegate implementation | 169 // JobStatusUpdater::Delegate implementation |
168 bool PrinterJobHandler::OnJobCompleted(JobStatusUpdater* updater) { | 170 bool PrinterJobHandler::OnJobCompleted(JobStatusUpdater* updater) { |
169 bool ret = false; | 171 bool ret = false; |
170 for (JobStatusUpdaterList::iterator index = job_status_updater_list_.begin(); | 172 for (JobStatusUpdaterList::iterator index = job_status_updater_list_.begin(); |
171 index != job_status_updater_list_.end(); index++) { | 173 index != job_status_updater_list_.end(); index++) { |
172 if (index->get() == updater) { | 174 if (index->get() == updater) { |
173 job_status_updater_list_.erase(index); | 175 job_status_updater_list_.erase(index); |
174 ret = true; | 176 ret = true; |
(...skipping 26 matching lines...) Expand all Loading... |
201 void PrinterJobHandler::OnJobChanged() { | 203 void PrinterJobHandler::OnJobChanged() { |
202 // Some job on the printer changed. Loop through all our JobStatusUpdaters | 204 // Some job on the printer changed. Loop through all our JobStatusUpdaters |
203 // and have them check for updates. | 205 // and have them check for updates. |
204 for (JobStatusUpdaterList::iterator index = job_status_updater_list_.begin(); | 206 for (JobStatusUpdaterList::iterator index = job_status_updater_list_.begin(); |
205 index != job_status_updater_list_.end(); index++) { | 207 index != job_status_updater_list_.end(); index++) { |
206 MessageLoop::current()->PostTask( | 208 MessageLoop::current()->PostTask( |
207 FROM_HERE, base::Bind(&JobStatusUpdater::UpdateStatus, index->get())); | 209 FROM_HERE, base::Bind(&JobStatusUpdater::UpdateStatus, index->get())); |
208 } | 210 } |
209 } | 211 } |
210 | 212 |
211 void PrinterJobHandler::OnJobSpoolSucceeded( | 213 void PrinterJobHandler::OnJobSpoolSucceeded(const PlatformJobId& job_id) { |
212 const cloud_print::PlatformJobId& job_id) { | |
213 DCHECK(MessageLoop::current() == print_thread_.message_loop()); | 214 DCHECK(MessageLoop::current() == print_thread_.message_loop()); |
214 job_spooler_ = NULL; | 215 job_spooler_ = NULL; |
215 job_handler_message_loop_proxy_->PostTask( | 216 job_handler_message_loop_proxy_->PostTask( |
216 FROM_HERE, base::Bind(&PrinterJobHandler::JobSpooled, this, job_id)); | 217 FROM_HERE, base::Bind(&PrinterJobHandler::JobSpooled, this, job_id)); |
217 } | 218 } |
218 | 219 |
219 void PrinterJobHandler::OnJobSpoolFailed() { | 220 void PrinterJobHandler::OnJobSpoolFailed() { |
220 DCHECK(MessageLoop::current() == print_thread_.message_loop()); | 221 DCHECK(MessageLoop::current() == print_thread_.message_loop()); |
221 job_spooler_ = NULL; | 222 job_spooler_ = NULL; |
222 VLOG(1) << "CP_CONNECTOR: Job failed (spool failed)"; | 223 VLOG(1) << "CP_CONNECTOR: Job failed (spool failed)"; |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 if (!task_in_progress_ && job_check_pending_) { | 417 if (!task_in_progress_ && job_check_pending_) { |
417 task_in_progress_ = true; | 418 task_in_progress_ = true; |
418 VLOG(1) << "CP_CONNECTOR: Changed task in progress" | 419 VLOG(1) << "CP_CONNECTOR: Changed task in progress" |
419 ", printer id: " << printer_info_cloud_.printer_id | 420 ", printer id: " << printer_info_cloud_.printer_id |
420 << ", task in progress: " << task_in_progress_; | 421 << ", task in progress: " << task_in_progress_; |
421 job_check_pending_ = false; | 422 job_check_pending_ = false; |
422 // We need to fetch any pending jobs for this printer | 423 // We need to fetch any pending jobs for this printer |
423 SetNextJSONHandler(&PrinterJobHandler::HandleJobMetadataResponse); | 424 SetNextJSONHandler(&PrinterJobHandler::HandleJobMetadataResponse); |
424 request_ = new CloudPrintURLFetcher; | 425 request_ = new CloudPrintURLFetcher; |
425 request_->StartGetRequest( | 426 request_->StartGetRequest( |
426 CloudPrintHelpers::GetUrlForJobFetch( | 427 GetUrlForJobFetch( |
427 cloud_print_server_url_, printer_info_cloud_.printer_id, | 428 cloud_print_server_url_, printer_info_cloud_.printer_id, |
428 job_fetch_reason_), | 429 job_fetch_reason_), |
429 this, | 430 this, |
430 kCloudPrintAPIMaxRetryCount, | 431 kCloudPrintAPIMaxRetryCount, |
431 std::string()); | 432 std::string()); |
432 last_job_fetch_time_ = base::TimeTicks::Now(); | 433 last_job_fetch_time_ = base::TimeTicks::Now(); |
433 VLOG(1) << "CP_CONNECTOR: Last job fetch time" | 434 VLOG(1) << "CP_CONNECTOR: Last job fetch time" |
434 << ", printer name: " << printer_info_.printer_name.c_str() | 435 << ", printer name: " << printer_info_.printer_name.c_str() |
435 << ", timestamp: " << last_job_fetch_time_.ToInternalValue(); | 436 << ", timestamp: " << last_job_fetch_time_.ToInternalValue(); |
436 job_fetch_reason_.clear(); | 437 job_fetch_reason_.clear(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 } | 472 } |
472 } | 473 } |
473 | 474 |
474 void PrinterJobHandler::Reset() { | 475 void PrinterJobHandler::Reset() { |
475 print_data_url_.clear(); | 476 print_data_url_.clear(); |
476 job_details_.Clear(); | 477 job_details_.Clear(); |
477 request_ = NULL; | 478 request_ = NULL; |
478 print_thread_.Stop(); | 479 print_thread_.Stop(); |
479 } | 480 } |
480 | 481 |
481 void PrinterJobHandler::UpdateJobStatus(cloud_print::PrintJobStatus status, | 482 void PrinterJobHandler::UpdateJobStatus(PrintJobStatus status, |
482 PrintJobError error) { | 483 PrintJobError error) { |
483 VLOG(1) << "CP_CONNECTOR: Updating job status" | 484 VLOG(1) << "CP_CONNECTOR: Updating job status" |
484 << ", printer id: " << printer_info_cloud_.printer_id | 485 << ", printer id: " << printer_info_cloud_.printer_id |
485 << ", job id: " << job_details_.job_id_ | 486 << ", job id: " << job_details_.job_id_ |
486 << ", job status: " << status; | 487 << ", job status: " << status; |
487 if (shutting_down_) { | 488 if (shutting_down_) { |
488 VLOG(1) << "CP_CONNECTOR: Job status update aborted (shutting down)" | 489 VLOG(1) << "CP_CONNECTOR: Job status update aborted (shutting down)" |
489 << ", printer id: " << printer_info_cloud_.printer_id | 490 << ", printer id: " << printer_info_cloud_.printer_id |
490 << ", job id: " << job_details_.job_id_; | 491 << ", job id: " << job_details_.job_id_; |
491 return; | 492 return; |
492 } | 493 } |
493 if (job_details_.job_id_.empty()) { | 494 if (job_details_.job_id_.empty()) { |
494 VLOG(1) << "CP_CONNECTOR: Job status update aborted (empty job id)" | 495 VLOG(1) << "CP_CONNECTOR: Job status update aborted (empty job id)" |
495 << ", printer id: " << printer_info_cloud_.printer_id; | 496 << ", printer id: " << printer_info_cloud_.printer_id; |
496 return; | 497 return; |
497 } | 498 } |
498 | 499 |
499 if (error == SUCCESS) { | 500 if (error == SUCCESS) { |
500 SetNextJSONHandler( | 501 SetNextJSONHandler( |
501 &PrinterJobHandler::HandleSuccessStatusUpdateResponse); | 502 &PrinterJobHandler::HandleSuccessStatusUpdateResponse); |
502 } else { | 503 } else { |
503 SetNextJSONHandler( | 504 SetNextJSONHandler( |
504 &PrinterJobHandler::HandleFailureStatusUpdateResponse); | 505 &PrinterJobHandler::HandleFailureStatusUpdateResponse); |
505 } | 506 } |
506 request_ = new CloudPrintURLFetcher; | 507 request_ = new CloudPrintURLFetcher; |
507 request_->StartGetRequest( | 508 request_->StartGetRequest(GetUrlForJobStatusUpdate(cloud_print_server_url_, |
508 CloudPrintHelpers::GetUrlForJobStatusUpdate(cloud_print_server_url_, | 509 job_details_.job_id_, |
509 job_details_.job_id_, | 510 status), |
510 status), | |
511 this, | 511 this, |
512 kCloudPrintAPIMaxRetryCount, | 512 kCloudPrintAPIMaxRetryCount, |
513 std::string()); | 513 std::string()); |
514 } | 514 } |
515 | 515 |
516 void PrinterJobHandler::SetNextJSONHandler(JSONDataHandler handler) { | 516 void PrinterJobHandler::SetNextJSONHandler(JSONDataHandler handler) { |
517 next_json_data_handler_ = handler; | 517 next_json_data_handler_ = handler; |
518 next_data_handler_ = NULL; | 518 next_data_handler_ = NULL; |
519 } | 519 } |
520 | 520 |
521 void PrinterJobHandler::SetNextDataHandler(DataHandler handler) { | 521 void PrinterJobHandler::SetNextDataHandler(DataHandler handler) { |
522 next_data_handler_ = handler; | 522 next_data_handler_ = handler; |
523 next_json_data_handler_ = NULL; | 523 next_json_data_handler_ = NULL; |
524 } | 524 } |
525 | 525 |
526 void PrinterJobHandler::JobFailed(PrintJobError error) { | 526 void PrinterJobHandler::JobFailed(PrintJobError error) { |
527 VLOG(1) << "CP_CONNECTOR: Job failed" | 527 VLOG(1) << "CP_CONNECTOR: Job failed" |
528 << ", printer id: " << printer_info_cloud_.printer_id | 528 << ", printer id: " << printer_info_cloud_.printer_id |
529 << ", job id: " << job_details_.job_id_ | 529 << ", job id: " << job_details_.job_id_ |
530 << ", error: " << error; | 530 << ", error: " << error; |
531 if (!shutting_down_) { | 531 if (!shutting_down_) { |
532 UpdateJobStatus(cloud_print::PRINT_JOB_STATUS_ERROR, error); | 532 UpdateJobStatus(PRINT_JOB_STATUS_ERROR, error); |
533 // This job failed, but others may be pending. Schedule a check. | 533 // This job failed, but others may be pending. Schedule a check. |
534 job_check_pending_ = true; | 534 job_check_pending_ = true; |
535 } | 535 } |
536 } | 536 } |
537 | 537 |
538 void PrinterJobHandler::JobSpooled(cloud_print::PlatformJobId local_job_id) { | 538 void PrinterJobHandler::JobSpooled(PlatformJobId local_job_id) { |
539 VLOG(1) << "CP_CONNECTOR: Job spooled" | 539 VLOG(1) << "CP_CONNECTOR: Job spooled" |
540 << ", printer id: " << printer_info_cloud_.printer_id | 540 << ", printer id: " << printer_info_cloud_.printer_id |
541 << ", job id: " << local_job_id; | 541 << ", job id: " << local_job_id; |
542 if (!shutting_down_) { | 542 if (!shutting_down_) { |
543 local_job_id_ = local_job_id; | 543 local_job_id_ = local_job_id; |
544 UpdateJobStatus(cloud_print::PRINT_JOB_STATUS_IN_PROGRESS, SUCCESS); | 544 UpdateJobStatus(PRINT_JOB_STATUS_IN_PROGRESS, SUCCESS); |
545 print_thread_.Stop(); | 545 print_thread_.Stop(); |
546 } | 546 } |
547 } | 547 } |
548 | 548 |
549 bool PrinterJobHandler::UpdatePrinterInfo() { | 549 bool PrinterJobHandler::UpdatePrinterInfo() { |
550 if (!printer_watcher_) { | 550 if (!printer_watcher_) { |
551 LOG(ERROR) << "CP_CONNECTOR: Printer watcher is missing." | 551 LOG(ERROR) << "CP_CONNECTOR: Printer watcher is missing." |
552 << " Check printer server url for printer id: " | 552 << " Check printer server url for printer id: " |
553 << printer_info_cloud_.printer_id; | 553 << printer_info_cloud_.printer_id; |
554 return false; | 554 return false; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 void PrinterJobHandler::OnReceivePrinterCaps( | 590 void PrinterJobHandler::OnReceivePrinterCaps( |
591 bool succeeded, | 591 bool succeeded, |
592 const std::string& printer_name, | 592 const std::string& printer_name, |
593 const printing::PrinterCapsAndDefaults& caps_and_defaults) { | 593 const printing::PrinterCapsAndDefaults& caps_and_defaults) { |
594 printing::PrinterBasicInfo printer_info; | 594 printing::PrinterBasicInfo printer_info; |
595 if (printer_watcher_) | 595 if (printer_watcher_) |
596 printer_watcher_->GetCurrentPrinterInfo(&printer_info); | 596 printer_watcher_->GetCurrentPrinterInfo(&printer_info); |
597 | 597 |
598 std::string post_data; | 598 std::string post_data; |
599 std::string mime_boundary; | 599 std::string mime_boundary; |
600 cloud_print::CreateMimeBoundaryForUpload(&mime_boundary); | 600 CreateMimeBoundaryForUpload(&mime_boundary); |
601 | 601 |
602 if (succeeded) { | 602 if (succeeded) { |
603 std::string caps_hash = | 603 std::string caps_hash = |
604 base::MD5String(caps_and_defaults.printer_capabilities); | 604 base::MD5String(caps_and_defaults.printer_capabilities); |
605 if (caps_hash != printer_info_cloud_.caps_hash) { | 605 if (caps_hash != printer_info_cloud_.caps_hash) { |
606 // Hashes don't match, we need to upload new capabilities (the defaults | 606 // Hashes don't match, we need to upload new capabilities (the defaults |
607 // go for free along with the capabilities) | 607 // go for free along with the capabilities) |
608 printer_info_cloud_.caps_hash = caps_hash; | 608 printer_info_cloud_.caps_hash = caps_hash; |
609 cloud_print::AddMultipartValueForUpload(kPrinterCapsValue, | 609 AddMultipartValueForUpload(kPrinterCapsValue, |
610 caps_and_defaults.printer_capabilities, mime_boundary, | 610 caps_and_defaults.printer_capabilities, mime_boundary, |
611 caps_and_defaults.caps_mime_type, &post_data); | 611 caps_and_defaults.caps_mime_type, &post_data); |
612 cloud_print::AddMultipartValueForUpload(kPrinterDefaultsValue, | 612 AddMultipartValueForUpload(kPrinterDefaultsValue, |
613 caps_and_defaults.printer_defaults, mime_boundary, | 613 caps_and_defaults.printer_defaults, mime_boundary, |
614 caps_and_defaults.defaults_mime_type, &post_data); | 614 caps_and_defaults.defaults_mime_type, &post_data); |
615 cloud_print::AddMultipartValueForUpload(kPrinterCapsHashValue, | 615 AddMultipartValueForUpload(kPrinterCapsHashValue, |
616 caps_hash, mime_boundary, std::string(), &post_data); | 616 caps_hash, mime_boundary, std::string(), &post_data); |
617 } | 617 } |
618 } else { | 618 } else { |
619 LOG(ERROR) << "Failed to get printer caps and defaults" | 619 LOG(ERROR) << "Failed to get printer caps and defaults" |
620 << ", printer name: " << printer_name; | 620 << ", printer name: " << printer_name; |
621 } | 621 } |
622 | 622 |
623 std::string tags_hash = CloudPrintHelpers::GetHashOfPrinterTags(printer_info); | 623 std::string tags_hash = GetHashOfPrinterInfo(printer_info); |
624 if (tags_hash != printer_info_cloud_.tags_hash) { | 624 if (tags_hash != printer_info_cloud_.tags_hash) { |
625 printer_info_cloud_.tags_hash = tags_hash; | 625 printer_info_cloud_.tags_hash = tags_hash; |
626 post_data += CloudPrintHelpers::GetPostDataForPrinterTags(printer_info, | 626 post_data += GetPostDataForPrinterInfo(printer_info, mime_boundary); |
627 mime_boundary); | |
628 // Remove all the existing proxy tags. | 627 // Remove all the existing proxy tags. |
629 std::string cp_tag_wildcard(kProxyTagPrefix); | 628 std::string cp_tag_wildcard(kCloudPrintServiceProxyTagPrefix); |
630 cp_tag_wildcard += ".*"; | 629 cp_tag_wildcard += ".*"; |
631 cloud_print::AddMultipartValueForUpload(kPrinterRemoveTagValue, | 630 AddMultipartValueForUpload(kPrinterRemoveTagValue, |
632 cp_tag_wildcard, mime_boundary, std::string(), &post_data); | 631 cp_tag_wildcard, mime_boundary, std::string(), &post_data); |
633 } | 632 } |
634 | 633 |
635 if (printer_info.printer_name != printer_info_.printer_name) { | 634 if (printer_info.printer_name != printer_info_.printer_name) { |
636 cloud_print::AddMultipartValueForUpload(kPrinterNameValue, | 635 AddMultipartValueForUpload(kPrinterNameValue, |
637 printer_info.printer_name, mime_boundary, std::string(), &post_data); | 636 printer_info.printer_name, mime_boundary, std::string(), &post_data); |
638 } | 637 } |
639 if (printer_info.printer_description != printer_info_.printer_description) { | 638 if (printer_info.printer_description != printer_info_.printer_description) { |
640 cloud_print::AddMultipartValueForUpload(kPrinterDescValue, | 639 AddMultipartValueForUpload(kPrinterDescValue, |
641 printer_info.printer_description, mime_boundary, | 640 printer_info.printer_description, mime_boundary, |
642 std::string(), &post_data); | 641 std::string(), &post_data); |
643 } | 642 } |
644 if (printer_info.printer_status != printer_info_.printer_status) { | 643 if (printer_info.printer_status != printer_info_.printer_status) { |
645 cloud_print::AddMultipartValueForUpload(kPrinterStatusValue, | 644 AddMultipartValueForUpload(kPrinterStatusValue, |
646 base::StringPrintf("%d", printer_info.printer_status), mime_boundary, | 645 base::StringPrintf("%d", printer_info.printer_status), mime_boundary, |
647 std::string(), &post_data); | 646 std::string(), &post_data); |
648 } | 647 } |
649 printer_info_ = printer_info; | 648 printer_info_ = printer_info; |
650 if (!post_data.empty()) { | 649 if (!post_data.empty()) { |
651 // Terminate the request body | 650 // Terminate the request body |
652 post_data.append("--" + mime_boundary + "--\r\n"); | 651 post_data.append("--" + mime_boundary + "--\r\n"); |
653 std::string mime_type("multipart/form-data; boundary="); | 652 std::string mime_type("multipart/form-data; boundary="); |
654 mime_type += mime_boundary; | 653 mime_type += mime_boundary; |
655 SetNextJSONHandler(&PrinterJobHandler::HandlePrinterUpdateResponse); | 654 SetNextJSONHandler(&PrinterJobHandler::HandlePrinterUpdateResponse); |
656 request_ = new CloudPrintURLFetcher; | 655 request_ = new CloudPrintURLFetcher; |
657 request_->StartPostRequest( | 656 request_->StartPostRequest( |
658 CloudPrintHelpers::GetUrlForPrinterUpdate( | 657 GetUrlForPrinterUpdate( |
659 cloud_print_server_url_, printer_info_cloud_.printer_id), | 658 cloud_print_server_url_, printer_info_cloud_.printer_id), |
660 this, | 659 this, |
661 kCloudPrintAPIMaxRetryCount, | 660 kCloudPrintAPIMaxRetryCount, |
662 mime_type, | 661 mime_type, |
663 post_data, | 662 post_data, |
664 std::string()); | 663 std::string()); |
665 } else { | 664 } else { |
666 // We are done here. Go to the Stop state | 665 // We are done here. Go to the Stop state |
667 VLOG(1) << "CP_CONNECTOR: Stopping printer job handler" | 666 VLOG(1) << "CP_CONNECTOR: Stopping printer job handler" |
668 << ", printer name: " << printer_name; | 667 << ", printer name: " << printer_name; |
(...skipping 21 matching lines...) Expand all Loading... |
690 if (!job_spooler_->Spool(job_details.print_ticket_, | 689 if (!job_spooler_->Spool(job_details.print_ticket_, |
691 job_details.print_data_file_path_, | 690 job_details.print_data_file_path_, |
692 job_details.print_data_mime_type_, | 691 job_details.print_data_mime_type_, |
693 printer_name, | 692 printer_name, |
694 UTF16ToUTF8(document_name), | 693 UTF16ToUTF8(document_name), |
695 job_details.tags_, | 694 job_details.tags_, |
696 this)) { | 695 this)) { |
697 OnJobSpoolFailed(); | 696 OnJobSpoolFailed(); |
698 } | 697 } |
699 } | 698 } |
| 699 |
| 700 } // namespace cloud_print |
OLD | NEW |