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/cloud_print_connector.h" | 5 #include "chrome/service/cloud_print/cloud_print_connector.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/location.h" | 9 #include "base/location.h" |
10 #include "base/md5.h" | 10 #include "base/md5.h" |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 next_response_handler_ = handler; | 353 next_response_handler_ = handler; |
354 request_ = CloudPrintURLFetcher::Create(); | 354 request_ = CloudPrintURLFetcher::Create(); |
355 request_->StartPostRequest( | 355 request_->StartPostRequest( |
356 type, url, this, max_retries, mime_type, post_data, std::string()); | 356 type, url, this, max_retries, mime_type, post_data, std::string()); |
357 } | 357 } |
358 | 358 |
359 void CloudPrintConnector::ReportUserMessage(const std::string& message_id, | 359 void CloudPrintConnector::ReportUserMessage(const std::string& message_id, |
360 const std::string& failure_msg) { | 360 const std::string& failure_msg) { |
361 // This is a fire and forget type of function. | 361 // This is a fire and forget type of function. |
362 // Result of this request will be ignored. | 362 // Result of this request will be ignored. |
363 std::string mime_boundary; | 363 std::string mime_boundary = net::GenerateMimeMultipartBoundary(); |
364 CreateMimeBoundaryForUpload(&mime_boundary); | |
365 GURL url = GetUrlForUserMessage(settings_.server_url(), message_id); | 364 GURL url = GetUrlForUserMessage(settings_.server_url(), message_id); |
366 std::string post_data; | 365 std::string post_data; |
367 net::AddMultipartValueForUpload(kMessageTextValue, failure_msg, mime_boundary, | 366 net::AddMultipartValueForUpload(kMessageTextValue, failure_msg, mime_boundary, |
368 std::string(), &post_data); | 367 std::string(), &post_data); |
369 net::AddMultipartFinalDelimiterForUpload(mime_boundary, &post_data); | 368 net::AddMultipartFinalDelimiterForUpload(mime_boundary, &post_data); |
370 std::string mime_type("multipart/form-data; boundary="); | 369 std::string mime_type("multipart/form-data; boundary="); |
371 mime_type += mime_boundary; | 370 mime_type += mime_boundary; |
372 user_message_request_ = CloudPrintURLFetcher::Create(); | 371 user_message_request_ = CloudPrintURLFetcher::Create(); |
373 user_message_request_->StartPostRequest( | 372 user_message_request_->StartPostRequest( |
374 CloudPrintURLFetcher::REQUEST_USER_MESSAGE, url, this, 1, mime_type, | 373 CloudPrintURLFetcher::REQUEST_USER_MESSAGE, url, this, 1, mime_type, |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT)); | 599 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT)); |
601 ReportUserMessage(kGetPrinterCapsFailedMessageId, status_message); | 600 ReportUserMessage(kGetPrinterCapsFailedMessageId, status_message); |
602 | 601 |
603 ContinuePendingTaskProcessing(); // Skip this printer registration. | 602 ContinuePendingTaskProcessing(); // Skip this printer registration. |
604 return; | 603 return; |
605 } | 604 } |
606 | 605 |
607 const printing::PrinterBasicInfo& info = pending_tasks_.front().printer_info; | 606 const printing::PrinterBasicInfo& info = pending_tasks_.front().printer_info; |
608 DCHECK(IsSamePrinter(info.printer_name, printer_name)); | 607 DCHECK(IsSamePrinter(info.printer_name, printer_name)); |
609 | 608 |
610 std::string mime_boundary; | 609 std::string mime_boundary = net::GenerateMimeMultipartBoundary(); |
611 CreateMimeBoundaryForUpload(&mime_boundary); | |
612 std::string post_data; | 610 std::string post_data; |
613 | 611 |
614 net::AddMultipartValueForUpload(kProxyIdValue, | 612 net::AddMultipartValueForUpload(kProxyIdValue, |
615 settings_.proxy_id(), mime_boundary, std::string(), &post_data); | 613 settings_.proxy_id(), mime_boundary, std::string(), &post_data); |
616 net::AddMultipartValueForUpload(kPrinterNameValue, | 614 net::AddMultipartValueForUpload(kPrinterNameValue, |
617 info.printer_name, mime_boundary, std::string(), &post_data); | 615 info.printer_name, mime_boundary, std::string(), &post_data); |
618 net::AddMultipartValueForUpload(kPrinterDescValue, | 616 net::AddMultipartValueForUpload(kPrinterDescValue, |
619 info.printer_description, mime_boundary, std::string(), &post_data); | 617 info.printer_description, mime_boundary, std::string(), &post_data); |
620 net::AddMultipartValueForUpload(kPrinterStatusValue, | 618 net::AddMultipartValueForUpload(kPrinterStatusValue, |
621 base::IntToString(info.printer_status), | 619 base::IntToString(info.printer_status), |
(...skipping 28 matching lines...) Expand all Loading... |
650 kCloudPrintAPIMaxRetryCount, mime_type, post_data, | 648 kCloudPrintAPIMaxRetryCount, mime_type, post_data, |
651 &CloudPrintConnector::HandleRegisterPrinterResponse); | 649 &CloudPrintConnector::HandleRegisterPrinterResponse); |
652 } | 650 } |
653 | 651 |
654 bool CloudPrintConnector::IsSamePrinter(const std::string& name1, | 652 bool CloudPrintConnector::IsSamePrinter(const std::string& name1, |
655 const std::string& name2) const { | 653 const std::string& name2) const { |
656 return base::EqualsCaseInsensitiveASCII(name1, name2); | 654 return base::EqualsCaseInsensitiveASCII(name1, name2); |
657 } | 655 } |
658 | 656 |
659 } // namespace cloud_print | 657 } // namespace cloud_print |
OLD | NEW |