| 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/cloud_print_proxy_backend.h" | 5 #include "chrome/service/cloud_print/cloud_print_proxy_backend.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 } | 468 } |
| 469 | 469 |
| 470 void CloudPrintProxyBackend::Core::GetRegisteredPrinters() { | 470 void CloudPrintProxyBackend::Core::GetRegisteredPrinters() { |
| 471 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); | 471 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); |
| 472 GURL printer_list_url = | 472 GURL printer_list_url = |
| 473 CloudPrintHelpers::GetUrlForPrinterList(cloud_print_server_url_, | 473 CloudPrintHelpers::GetUrlForPrinterList(cloud_print_server_url_, |
| 474 proxy_id_); | 474 proxy_id_); |
| 475 next_response_handler_ = | 475 next_response_handler_ = |
| 476 &CloudPrintProxyBackend::Core::HandlePrinterListResponse; | 476 &CloudPrintProxyBackend::Core::HandlePrinterListResponse; |
| 477 request_ = new CloudPrintURLFetcher; | 477 request_ = new CloudPrintURLFetcher; |
| 478 request_->StartGetRequest(printer_list_url, this, auth_token_, | 478 request_->StartGetRequest(printer_list_url, |
| 479 kCloudPrintAPIMaxRetryCount); | 479 this, |
| 480 auth_token_, |
| 481 kCloudPrintAPIMaxRetryCount, |
| 482 std::string()); |
| 480 } | 483 } |
| 481 | 484 |
| 482 void CloudPrintProxyBackend::Core::RegisterNextPrinter() { | 485 void CloudPrintProxyBackend::Core::RegisterNextPrinter() { |
| 483 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); | 486 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); |
| 484 // For the next printer to be uploaded, create a multi-part post request to | 487 // For the next printer to be uploaded, create a multi-part post request to |
| 485 // upload the printer capabilities and the printer defaults. | 488 // upload the printer capabilities and the printer defaults. |
| 486 if (next_upload_index_ < printer_list_.size()) { | 489 if (next_upload_index_ < printer_list_.size()) { |
| 487 const printing::PrinterBasicInfo& info = | 490 const printing::PrinterBasicInfo& info = |
| 488 printer_list_.at(next_upload_index_); | 491 printer_list_.at(next_upload_index_); |
| 489 // If we are retrying a previous upload, we don't need to fetch the caps | 492 // If we are retrying a previous upload, we don't need to fetch the caps |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 GURL post_url = CloudPrintHelpers::GetUrlForPrinterRegistration( | 561 GURL post_url = CloudPrintHelpers::GetUrlForPrinterRegistration( |
| 559 cloud_print_server_url_); | 562 cloud_print_server_url_); |
| 560 | 563 |
| 561 next_response_handler_ = | 564 next_response_handler_ = |
| 562 &CloudPrintProxyBackend::Core::HandleRegisterPrinterResponse; | 565 &CloudPrintProxyBackend::Core::HandleRegisterPrinterResponse; |
| 563 // Terminate the request body | 566 // Terminate the request body |
| 564 post_data.append("--" + mime_boundary + "--\r\n"); | 567 post_data.append("--" + mime_boundary + "--\r\n"); |
| 565 std::string mime_type("multipart/form-data; boundary="); | 568 std::string mime_type("multipart/form-data; boundary="); |
| 566 mime_type += mime_boundary; | 569 mime_type += mime_boundary; |
| 567 request_ = new CloudPrintURLFetcher; | 570 request_ = new CloudPrintURLFetcher; |
| 568 request_->StartPostRequest(post_url, this, auth_token_, | 571 request_->StartPostRequest(post_url, |
| 569 kCloudPrintAPIMaxRetryCount, mime_type, | 572 this, |
| 570 post_data); | 573 auth_token_, |
| 574 kCloudPrintAPIMaxRetryCount, |
| 575 mime_type, |
| 576 post_data, |
| 577 std::string()); |
| 571 } else { | 578 } else { |
| 572 LOG(ERROR) << "CP_PROXY: Failed to get printer info for: " << | 579 LOG(ERROR) << "CP_PROXY: Failed to get printer info for: " << |
| 573 printer_name; | 580 printer_name; |
| 574 // This printer failed to register, notify the server of this failure. | 581 // This printer failed to register, notify the server of this failure. |
| 575 string16 printer_name_utf16 = UTF8ToUTF16(printer_name); | 582 string16 printer_name_utf16 = UTF8ToUTF16(printer_name); |
| 576 std::string status_message = l10n_util::GetStringFUTF8( | 583 std::string status_message = l10n_util::GetStringFUTF8( |
| 577 IDS_CLOUD_PRINT_REGISTER_PRINTER_FAILED, | 584 IDS_CLOUD_PRINT_REGISTER_PRINTER_FAILED, |
| 578 printer_name_utf16); | 585 printer_name_utf16); |
| 579 ReportUserMessage( | 586 ReportUserMessage( |
| 580 kGetPrinterCapsFailedMessageId, | 587 kGetPrinterCapsFailedMessageId, |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 767 failure_message, | 774 failure_message, |
| 768 mime_boundary, | 775 mime_boundary, |
| 769 std::string(), | 776 std::string(), |
| 770 &post_data); | 777 &post_data); |
| 771 next_response_handler_ = handler; | 778 next_response_handler_ = handler; |
| 772 // Terminate the request body | 779 // Terminate the request body |
| 773 post_data.append("--" + mime_boundary + "--\r\n"); | 780 post_data.append("--" + mime_boundary + "--\r\n"); |
| 774 std::string mime_type("multipart/form-data; boundary="); | 781 std::string mime_type("multipart/form-data; boundary="); |
| 775 mime_type += mime_boundary; | 782 mime_type += mime_boundary; |
| 776 request_ = new CloudPrintURLFetcher; | 783 request_ = new CloudPrintURLFetcher; |
| 777 request_->StartPostRequest(post_url, this, auth_token_, | 784 request_->StartPostRequest(post_url, |
| 778 kCloudPrintAPIMaxRetryCount, mime_type, | 785 this, |
| 779 post_data); | 786 auth_token_, |
| 787 kCloudPrintAPIMaxRetryCount, |
| 788 mime_type, |
| 789 post_data, |
| 790 std::string()); |
| 780 } | 791 } |
| 781 | 792 |
| 782 CloudPrintURLFetcher::ResponseAction | 793 CloudPrintURLFetcher::ResponseAction |
| 783 CloudPrintProxyBackend::Core::HandleRegisterPrinterResponse( | 794 CloudPrintProxyBackend::Core::HandleRegisterPrinterResponse( |
| 784 const URLFetcher* source, | 795 const URLFetcher* source, |
| 785 const GURL& url, | 796 const GURL& url, |
| 786 DictionaryValue* json_data, | 797 DictionaryValue* json_data, |
| 787 bool succeeded) { | 798 bool succeeded) { |
| 788 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); | 799 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); |
| 789 if (succeeded) { | 800 if (succeeded) { |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 925 &Core::NotifyAuthenticationFailed)); | 936 &Core::NotifyAuthenticationFailed)); |
| 926 } | 937 } |
| 927 | 938 |
| 928 void CloudPrintProxyBackend::Core::OnPrinterNotFound( | 939 void CloudPrintProxyBackend::Core::OnPrinterNotFound( |
| 929 const std::string& printer_name, | 940 const std::string& printer_name, |
| 930 bool* delete_from_server) { | 941 bool* delete_from_server) { |
| 931 // If we have a complete list of local printers, then this needs to be deleted | 942 // If we have a complete list of local printers, then this needs to be deleted |
| 932 // from the server. | 943 // from the server. |
| 933 *delete_from_server = complete_list_available_; | 944 *delete_from_server = complete_list_available_; |
| 934 } | 945 } |
| OLD | NEW |