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/md5.h" | 9 #include "base/md5.h" |
10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
11 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "chrome/common/cloud_print/cloud_print_constants.h" | 16 #include "chrome/common/cloud_print/cloud_print_constants.h" |
17 #include "chrome/common/cloud_print/cloud_print_helpers.h" | 17 #include "chrome/common/cloud_print/cloud_print_helpers.h" |
18 #include "chrome/service/cloud_print/cloud_print_helpers.h" | 18 #include "chrome/service/cloud_print/cloud_print_helpers.h" |
19 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
| 20 #include "net/base/mime_util.h" |
20 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
21 | 22 |
22 namespace cloud_print { | 23 namespace cloud_print { |
23 | 24 |
24 CloudPrintConnector::CloudPrintConnector(Client* client, | 25 CloudPrintConnector::CloudPrintConnector(Client* client, |
25 const ConnectorSettings& settings) | 26 const ConnectorSettings& settings) |
26 : client_(client), | 27 : client_(client), |
27 next_response_handler_(NULL) { | 28 next_response_handler_(NULL) { |
28 settings_.CopyFrom(settings); | 29 settings_.CopyFrom(settings); |
29 } | 30 } |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 } | 307 } |
307 | 308 |
308 void CloudPrintConnector::ReportUserMessage(const std::string& message_id, | 309 void CloudPrintConnector::ReportUserMessage(const std::string& message_id, |
309 const std::string& failure_msg) { | 310 const std::string& failure_msg) { |
310 // This is a fire and forget type of function. | 311 // This is a fire and forget type of function. |
311 // Result of this request will be ignored. | 312 // Result of this request will be ignored. |
312 std::string mime_boundary; | 313 std::string mime_boundary; |
313 CreateMimeBoundaryForUpload(&mime_boundary); | 314 CreateMimeBoundaryForUpload(&mime_boundary); |
314 GURL url = GetUrlForUserMessage(settings_.server_url(), message_id); | 315 GURL url = GetUrlForUserMessage(settings_.server_url(), message_id); |
315 std::string post_data; | 316 std::string post_data; |
316 AddMultipartValueForUpload(kMessageTextValue, failure_msg, mime_boundary, | 317 net::AddMultipartValueForUpload(kMessageTextValue, failure_msg, mime_boundary, |
317 std::string(), &post_data); | 318 std::string(), &post_data); |
318 // Terminate the request body | 319 // Terminate the request body |
319 post_data.append("--" + mime_boundary + "--\r\n"); | 320 post_data.append("--" + mime_boundary + "--\r\n"); |
320 std::string mime_type("multipart/form-data; boundary="); | 321 std::string mime_type("multipart/form-data; boundary="); |
321 mime_type += mime_boundary; | 322 mime_type += mime_boundary; |
322 user_message_request_ = CloudPrintURLFetcher::Create(); | 323 user_message_request_ = CloudPrintURLFetcher::Create(); |
323 user_message_request_->StartPostRequest(url, this, 1, mime_type, post_data, | 324 user_message_request_->StartPostRequest(url, this, 1, mime_type, post_data, |
324 std::string()); | 325 std::string()); |
325 } | 326 } |
326 | 327 |
327 bool CloudPrintConnector::RemovePrinterFromList( | 328 bool CloudPrintConnector::RemovePrinterFromList( |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 return; | 521 return; |
521 } | 522 } |
522 | 523 |
523 const printing::PrinterBasicInfo& info = pending_tasks_.front().printer_info; | 524 const printing::PrinterBasicInfo& info = pending_tasks_.front().printer_info; |
524 DCHECK(IsSamePrinter(info.printer_name, printer_name)); | 525 DCHECK(IsSamePrinter(info.printer_name, printer_name)); |
525 | 526 |
526 std::string mime_boundary; | 527 std::string mime_boundary; |
527 CreateMimeBoundaryForUpload(&mime_boundary); | 528 CreateMimeBoundaryForUpload(&mime_boundary); |
528 std::string post_data; | 529 std::string post_data; |
529 | 530 |
530 AddMultipartValueForUpload(kProxyIdValue, | 531 net::AddMultipartValueForUpload(kProxyIdValue, |
531 settings_.proxy_id(), mime_boundary, std::string(), &post_data); | 532 settings_.proxy_id(), mime_boundary, std::string(), &post_data); |
532 AddMultipartValueForUpload(kPrinterNameValue, | 533 net::AddMultipartValueForUpload(kPrinterNameValue, |
533 info.printer_name, mime_boundary, std::string(), &post_data); | 534 info.printer_name, mime_boundary, std::string(), &post_data); |
534 AddMultipartValueForUpload(kPrinterDescValue, | 535 net::AddMultipartValueForUpload(kPrinterDescValue, |
535 info.printer_description, mime_boundary, std::string(), &post_data); | 536 info.printer_description, mime_boundary, std::string(), &post_data); |
536 AddMultipartValueForUpload(kPrinterStatusValue, | 537 net::AddMultipartValueForUpload(kPrinterStatusValue, |
537 base::StringPrintf("%d", info.printer_status), | 538 base::StringPrintf("%d", info.printer_status), |
538 mime_boundary, std::string(), &post_data); | 539 mime_boundary, std::string(), &post_data); |
539 post_data += GetPostDataForPrinterInfo(info, mime_boundary); | 540 post_data += GetPostDataForPrinterInfo(info, mime_boundary); |
540 AddMultipartValueForUpload(kPrinterCapsValue, | 541 net::AddMultipartValueForUpload(kPrinterCapsValue, |
541 caps_and_defaults.printer_capabilities, mime_boundary, | 542 caps_and_defaults.printer_capabilities, mime_boundary, |
542 caps_and_defaults.caps_mime_type, &post_data); | 543 caps_and_defaults.caps_mime_type, &post_data); |
543 AddMultipartValueForUpload(kPrinterDefaultsValue, | 544 net::AddMultipartValueForUpload(kPrinterDefaultsValue, |
544 caps_and_defaults.printer_defaults, mime_boundary, | 545 caps_and_defaults.printer_defaults, mime_boundary, |
545 caps_and_defaults.defaults_mime_type, &post_data); | 546 caps_and_defaults.defaults_mime_type, &post_data); |
546 // Send a hash of the printer capabilities to the server. We will use this | 547 // Send a hash of the printer capabilities to the server. We will use this |
547 // later to check if the capabilities have changed | 548 // later to check if the capabilities have changed |
548 AddMultipartValueForUpload(kPrinterCapsHashValue, | 549 net::AddMultipartValueForUpload(kPrinterCapsHashValue, |
549 base::MD5String(caps_and_defaults.printer_capabilities), | 550 base::MD5String(caps_and_defaults.printer_capabilities), |
550 mime_boundary, std::string(), &post_data); | 551 mime_boundary, std::string(), &post_data); |
551 | 552 |
552 // Terminate the request body | 553 // Terminate the request body |
553 post_data.append("--" + mime_boundary + "--\r\n"); | 554 post_data.append("--" + mime_boundary + "--\r\n"); |
554 std::string mime_type("multipart/form-data; boundary="); | 555 std::string mime_type("multipart/form-data; boundary="); |
555 mime_type += mime_boundary; | 556 mime_type += mime_boundary; |
556 | 557 |
557 GURL post_url = GetUrlForPrinterRegistration(settings_.server_url()); | 558 GURL post_url = GetUrlForPrinterRegistration(settings_.server_url()); |
558 StartPostRequest(post_url, | 559 StartPostRequest(post_url, |
559 kCloudPrintAPIMaxRetryCount, | 560 kCloudPrintAPIMaxRetryCount, |
560 mime_type, | 561 mime_type, |
561 post_data, | 562 post_data, |
562 &CloudPrintConnector::HandleRegisterPrinterResponse); | 563 &CloudPrintConnector::HandleRegisterPrinterResponse); |
563 } | 564 } |
564 | 565 |
565 bool CloudPrintConnector::IsSamePrinter(const std::string& name1, | 566 bool CloudPrintConnector::IsSamePrinter(const std::string& name1, |
566 const std::string& name2) const { | 567 const std::string& name2) const { |
567 return (0 == base::strcasecmp(name1.c_str(), name2.c_str())); | 568 return (0 == base::strcasecmp(name1.c_str(), name2.c_str())); |
568 } | 569 } |
569 | 570 |
570 } // namespace cloud_print | 571 } // namespace cloud_print |
OLD | NEW |