| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/md5.h" | 12 #include "base/md5.h" |
| 13 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
| 14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/strings/string_split.h" | 16 #include "base/strings/string_split.h" |
| 17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 20 #include "base/threading/thread_task_runner_handle.h" | 20 #include "base/threading/thread_task_runner_handle.h" |
| 21 #include "base/values.h" | 21 #include "base/values.h" |
| 22 #include "chrome/common/cloud_print/cloud_print_constants.h" | 22 #include "chrome/common/cloud_print/cloud_print_constants.h" |
| 23 #include "chrome/common/cloud_print/cloud_print_helpers.h" | 23 #include "chrome/common/cloud_print/cloud_print_helpers.h" |
| 24 #include "chrome/grit/generated_resources.h" | 24 #include "chrome/grit/generated_resources.h" |
| 25 #include "chrome/service/cloud_print/cloud_print_service_helpers.h" | 25 #include "chrome/service/cloud_print/cloud_print_service_helpers.h" |
| 26 #include "net/base/mime_util.h" | 26 #include "net/base/mime_util.h" |
| 27 #include "net/traffic_annotation/network_traffic_annotation.h" |
| 27 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
| 28 | 29 |
| 29 namespace cloud_print { | 30 namespace cloud_print { |
| 30 | 31 |
| 31 CloudPrintConnector::CloudPrintConnector(Client* client, | 32 CloudPrintConnector::CloudPrintConnector( |
| 32 const ConnectorSettings& settings) | 33 Client* client, |
| 33 : client_(client), | 34 const ConnectorSettings& settings, |
| 34 next_response_handler_(NULL), | 35 const net::PartialNetworkTrafficAnnotationTag& partial_traffic_annotation) |
| 35 stats_ptr_factory_(this) { | 36 : client_(client), |
| 37 next_response_handler_(NULL), |
| 38 partial_traffic_annotation_(partial_traffic_annotation), |
| 39 stats_ptr_factory_(this) { |
| 36 settings_.CopyFrom(settings); | 40 settings_.CopyFrom(settings); |
| 37 } | 41 } |
| 38 | 42 |
| 39 bool CloudPrintConnector::InitPrintSystem() { | 43 bool CloudPrintConnector::InitPrintSystem() { |
| 40 if (print_system_.get()) | 44 if (print_system_.get()) |
| 41 return true; | 45 return true; |
| 42 print_system_ = PrintSystem::CreateInstance( | 46 print_system_ = PrintSystem::CreateInstance( |
| 43 settings_.print_system_settings()); | 47 settings_.print_system_settings()); |
| 44 if (!print_system_.get()) { | 48 if (!print_system_.get()) { |
| 45 NOTREACHED(); | 49 NOTREACHED(); |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 } | 333 } |
| 330 ContinuePendingTaskProcessing(); // Continue processing background tasks. | 334 ContinuePendingTaskProcessing(); // Continue processing background tasks. |
| 331 return CloudPrintURLFetcher::STOP_PROCESSING; | 335 return CloudPrintURLFetcher::STOP_PROCESSING; |
| 332 } | 336 } |
| 333 | 337 |
| 334 | 338 |
| 335 void CloudPrintConnector::StartGetRequest(const GURL& url, | 339 void CloudPrintConnector::StartGetRequest(const GURL& url, |
| 336 int max_retries, | 340 int max_retries, |
| 337 ResponseHandler handler) { | 341 ResponseHandler handler) { |
| 338 next_response_handler_ = handler; | 342 next_response_handler_ = handler; |
| 339 request_ = CloudPrintURLFetcher::Create(); | 343 request_ = CloudPrintURLFetcher::Create(partial_traffic_annotation_); |
| 340 request_->StartGetRequest(CloudPrintURLFetcher::REQUEST_UPDATE_JOB, | 344 request_->StartGetRequest(CloudPrintURLFetcher::REQUEST_UPDATE_JOB, |
| 341 url, this, max_retries, std::string()); | 345 url, this, max_retries, std::string()); |
| 342 } | 346 } |
| 343 | 347 |
| 344 void CloudPrintConnector::StartPostRequest( | 348 void CloudPrintConnector::StartPostRequest( |
| 345 CloudPrintURLFetcher::RequestType type, | 349 CloudPrintURLFetcher::RequestType type, |
| 346 const GURL& url, | 350 const GURL& url, |
| 347 int max_retries, | 351 int max_retries, |
| 348 const std::string& mime_type, | 352 const std::string& mime_type, |
| 349 const std::string& post_data, | 353 const std::string& post_data, |
| 350 ResponseHandler handler) { | 354 ResponseHandler handler) { |
| 351 next_response_handler_ = handler; | 355 next_response_handler_ = handler; |
| 352 request_ = CloudPrintURLFetcher::Create(); | 356 request_ = CloudPrintURLFetcher::Create(partial_traffic_annotation_); |
| 353 request_->StartPostRequest( | 357 request_->StartPostRequest( |
| 354 type, url, this, max_retries, mime_type, post_data, std::string()); | 358 type, url, this, max_retries, mime_type, post_data, std::string()); |
| 355 } | 359 } |
| 356 | 360 |
| 357 void CloudPrintConnector::ReportUserMessage(const std::string& message_id, | 361 void CloudPrintConnector::ReportUserMessage(const std::string& message_id, |
| 358 const std::string& failure_msg) { | 362 const std::string& failure_msg) { |
| 359 // This is a fire and forget type of function. | 363 // This is a fire and forget type of function. |
| 360 // Result of this request will be ignored. | 364 // Result of this request will be ignored. |
| 361 std::string mime_boundary = net::GenerateMimeMultipartBoundary(); | 365 std::string mime_boundary = net::GenerateMimeMultipartBoundary(); |
| 362 GURL url = GetUrlForUserMessage(settings_.server_url(), message_id); | 366 GURL url = GetUrlForUserMessage(settings_.server_url(), message_id); |
| 363 std::string post_data; | 367 std::string post_data; |
| 364 net::AddMultipartValueForUpload(kMessageTextValue, failure_msg, mime_boundary, | 368 net::AddMultipartValueForUpload(kMessageTextValue, failure_msg, mime_boundary, |
| 365 std::string(), &post_data); | 369 std::string(), &post_data); |
| 366 net::AddMultipartFinalDelimiterForUpload(mime_boundary, &post_data); | 370 net::AddMultipartFinalDelimiterForUpload(mime_boundary, &post_data); |
| 367 std::string mime_type("multipart/form-data; boundary="); | 371 std::string mime_type("multipart/form-data; boundary="); |
| 368 mime_type += mime_boundary; | 372 mime_type += mime_boundary; |
| 369 user_message_request_ = CloudPrintURLFetcher::Create(); | 373 user_message_request_ = |
| 374 CloudPrintURLFetcher::Create(partial_traffic_annotation_); |
| 370 user_message_request_->StartPostRequest( | 375 user_message_request_->StartPostRequest( |
| 371 CloudPrintURLFetcher::REQUEST_USER_MESSAGE, url, this, 1, mime_type, | 376 CloudPrintURLFetcher::REQUEST_USER_MESSAGE, url, this, 1, mime_type, |
| 372 post_data, std::string()); | 377 post_data, std::string()); |
| 373 } | 378 } |
| 374 | 379 |
| 375 bool CloudPrintConnector::RemovePrinterFromList( | 380 bool CloudPrintConnector::RemovePrinterFromList( |
| 376 const std::string& printer_name, | 381 const std::string& printer_name, |
| 377 printing::PrinterList* printer_list) { | 382 printing::PrinterList* printer_list) { |
| 378 for (printing::PrinterList::iterator it = printer_list->begin(); | 383 for (printing::PrinterList::iterator it = printer_list->begin(); |
| 379 it != printer_list->end(); ++it) { | 384 it != printer_list->end(); ++it) { |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 kCloudPrintAPIMaxRetryCount, mime_type, post_data, | 649 kCloudPrintAPIMaxRetryCount, mime_type, post_data, |
| 645 &CloudPrintConnector::HandleRegisterPrinterResponse); | 650 &CloudPrintConnector::HandleRegisterPrinterResponse); |
| 646 } | 651 } |
| 647 | 652 |
| 648 bool CloudPrintConnector::IsSamePrinter(const std::string& name1, | 653 bool CloudPrintConnector::IsSamePrinter(const std::string& name1, |
| 649 const std::string& name2) const { | 654 const std::string& name2) const { |
| 650 return base::EqualsCaseInsensitiveASCII(name1, name2); | 655 return base::EqualsCaseInsensitiveASCII(name1, name2); |
| 651 } | 656 } |
| 652 | 657 |
| 653 } // namespace cloud_print | 658 } // namespace cloud_print |
| OLD | NEW |