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

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

Issue 15076008: Move AddMultipartValueForUpload to net/base/mime_util.h/cc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 7 months 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
« no previous file with comments | « chrome/service/cloud_print/cloud_print_connector.cc ('k') | net/base/mime_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_constants.h"
16 #include "chrome/common/cloud_print/cloud_print_helpers.h" 16 #include "chrome/common/cloud_print/cloud_print_helpers.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/base/mime_util.h"
21 #include "net/http/http_response_headers.h" 22 #include "net/http/http_response_headers.h"
22 #include "net/http/http_status_code.h" 23 #include "net/http/http_status_code.h"
23 #include "printing/backend/print_backend.h" 24 #include "printing/backend/print_backend.h"
24 #include "ui/base/l10n/l10n_util.h" 25 #include "ui/base/l10n/l10n_util.h"
25 26
26 namespace cloud_print { 27 namespace cloud_print {
27 28
28 PrinterJobHandler::PrinterJobHandler( 29 PrinterJobHandler::PrinterJobHandler(
29 const printing::PrinterBasicInfo& printer_info, 30 const printing::PrinterBasicInfo& printer_info,
30 const PrinterInfoFromCloud& printer_info_cloud, 31 const PrinterInfoFromCloud& printer_info_cloud,
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 std::string mime_boundary; 590 std::string mime_boundary;
590 CreateMimeBoundaryForUpload(&mime_boundary); 591 CreateMimeBoundaryForUpload(&mime_boundary);
591 592
592 if (succeeded) { 593 if (succeeded) {
593 std::string caps_hash = 594 std::string caps_hash =
594 base::MD5String(caps_and_defaults.printer_capabilities); 595 base::MD5String(caps_and_defaults.printer_capabilities);
595 if (caps_hash != printer_info_cloud_.caps_hash) { 596 if (caps_hash != printer_info_cloud_.caps_hash) {
596 // Hashes don't match, we need to upload new capabilities (the defaults 597 // Hashes don't match, we need to upload new capabilities (the defaults
597 // go for free along with the capabilities) 598 // go for free along with the capabilities)
598 printer_info_cloud_.caps_hash = caps_hash; 599 printer_info_cloud_.caps_hash = caps_hash;
599 AddMultipartValueForUpload(kPrinterCapsValue, 600 net::AddMultipartValueForUpload(kPrinterCapsValue,
600 caps_and_defaults.printer_capabilities, mime_boundary, 601 caps_and_defaults.printer_capabilities, mime_boundary,
601 caps_and_defaults.caps_mime_type, &post_data); 602 caps_and_defaults.caps_mime_type, &post_data);
602 AddMultipartValueForUpload(kPrinterDefaultsValue, 603 net::AddMultipartValueForUpload(kPrinterDefaultsValue,
603 caps_and_defaults.printer_defaults, mime_boundary, 604 caps_and_defaults.printer_defaults, mime_boundary,
604 caps_and_defaults.defaults_mime_type, &post_data); 605 caps_and_defaults.defaults_mime_type, &post_data);
605 AddMultipartValueForUpload(kPrinterCapsHashValue, 606 net::AddMultipartValueForUpload(kPrinterCapsHashValue,
606 caps_hash, mime_boundary, std::string(), &post_data); 607 caps_hash, mime_boundary, std::string(), &post_data);
607 } 608 }
608 } else { 609 } else {
609 LOG(ERROR) << "Failed to get printer caps and defaults" 610 LOG(ERROR) << "Failed to get printer caps and defaults"
610 << ", printer name: " << printer_name; 611 << ", printer name: " << printer_name;
611 } 612 }
612 613
613 std::string tags_hash = GetHashOfPrinterInfo(printer_info); 614 std::string tags_hash = GetHashOfPrinterInfo(printer_info);
614 if (tags_hash != printer_info_cloud_.tags_hash) { 615 if (tags_hash != printer_info_cloud_.tags_hash) {
615 printer_info_cloud_.tags_hash = tags_hash; 616 printer_info_cloud_.tags_hash = tags_hash;
616 post_data += GetPostDataForPrinterInfo(printer_info, mime_boundary); 617 post_data += GetPostDataForPrinterInfo(printer_info, mime_boundary);
617 // Remove all the existing proxy tags. 618 // Remove all the existing proxy tags.
618 std::string cp_tag_wildcard(kCloudPrintServiceProxyTagPrefix); 619 std::string cp_tag_wildcard(kCloudPrintServiceProxyTagPrefix);
619 cp_tag_wildcard += ".*"; 620 cp_tag_wildcard += ".*";
620 AddMultipartValueForUpload(kPrinterRemoveTagValue, 621 net::AddMultipartValueForUpload(kPrinterRemoveTagValue,
621 cp_tag_wildcard, mime_boundary, std::string(), &post_data); 622 cp_tag_wildcard, mime_boundary, std::string(), &post_data);
622 } 623 }
623 624
624 if (printer_info.printer_name != printer_info_.printer_name) { 625 if (printer_info.printer_name != printer_info_.printer_name) {
625 AddMultipartValueForUpload(kPrinterNameValue, 626 net::AddMultipartValueForUpload(kPrinterNameValue,
626 printer_info.printer_name, mime_boundary, std::string(), &post_data); 627 printer_info.printer_name, mime_boundary, std::string(), &post_data);
627 } 628 }
628 if (printer_info.printer_description != printer_info_.printer_description) { 629 if (printer_info.printer_description != printer_info_.printer_description) {
629 AddMultipartValueForUpload(kPrinterDescValue, 630 net::AddMultipartValueForUpload(kPrinterDescValue,
630 printer_info.printer_description, mime_boundary, 631 printer_info.printer_description, mime_boundary,
631 std::string(), &post_data); 632 std::string(), &post_data);
632 } 633 }
633 if (printer_info.printer_status != printer_info_.printer_status) { 634 if (printer_info.printer_status != printer_info_.printer_status) {
634 AddMultipartValueForUpload(kPrinterStatusValue, 635 net::AddMultipartValueForUpload(kPrinterStatusValue,
635 base::StringPrintf("%d", printer_info.printer_status), mime_boundary, 636 base::StringPrintf("%d", printer_info.printer_status), mime_boundary,
636 std::string(), &post_data); 637 std::string(), &post_data);
637 } 638 }
638 printer_info_ = printer_info; 639 printer_info_ = printer_info;
639 if (!post_data.empty()) { 640 if (!post_data.empty()) {
640 // Terminate the request body 641 net::AddMultipartFinalDelimiterForUpload(mime_boundary, &post_data);
641 post_data.append("--" + mime_boundary + "--\r\n");
642 std::string mime_type("multipart/form-data; boundary="); 642 std::string mime_type("multipart/form-data; boundary=");
643 mime_type += mime_boundary; 643 mime_type += mime_boundary;
644 SetNextJSONHandler(&PrinterJobHandler::HandlePrinterUpdateResponse); 644 SetNextJSONHandler(&PrinterJobHandler::HandlePrinterUpdateResponse);
645 request_ = CloudPrintURLFetcher::Create(); 645 request_ = CloudPrintURLFetcher::Create();
646 request_->StartPostRequest( 646 request_->StartPostRequest(
647 GetUrlForPrinterUpdate( 647 GetUrlForPrinterUpdate(
648 cloud_print_server_url_, printer_info_cloud_.printer_id), 648 cloud_print_server_url_, printer_info_cloud_.printer_id),
649 this, 649 this,
650 kCloudPrintAPIMaxRetryCount, 650 kCloudPrintAPIMaxRetryCount,
651 mime_type, 651 mime_type,
(...skipping 29 matching lines...) Expand all
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
OLDNEW
« no previous file with comments | « chrome/service/cloud_print/cloud_print_connector.cc ('k') | net/base/mime_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698