| 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/md5.h" | 10 #include "base/md5.h" |
| 10 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
| 12 #include "base/single_thread_task_runner.h" |
| 11 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/string_split.h" | 14 #include "base/strings/string_split.h" |
| 13 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 14 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "base/thread_task_runner_handle.h" |
| 16 #include "base/values.h" | 19 #include "base/values.h" |
| 17 #include "chrome/common/cloud_print/cloud_print_constants.h" | 20 #include "chrome/common/cloud_print/cloud_print_constants.h" |
| 18 #include "chrome/common/cloud_print/cloud_print_helpers.h" | 21 #include "chrome/common/cloud_print/cloud_print_helpers.h" |
| 19 #include "chrome/grit/generated_resources.h" | 22 #include "chrome/grit/generated_resources.h" |
| 20 #include "chrome/service/cloud_print/cloud_print_service_helpers.h" | 23 #include "chrome/service/cloud_print/cloud_print_service_helpers.h" |
| 21 #include "net/base/mime_util.h" | 24 #include "net/base/mime_util.h" |
| 22 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
| 23 | 26 |
| 24 namespace cloud_print { | 27 namespace cloud_print { |
| 25 | 28 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 44 if (!result.succeeded()) { | 47 if (!result.succeeded()) { |
| 45 print_system_ = NULL; | 48 print_system_ = NULL; |
| 46 // We could not initialize the print system. We need to notify the server. | 49 // We could not initialize the print system. We need to notify the server. |
| 47 ReportUserMessage(kPrintSystemFailedMessageId, result.message()); | 50 ReportUserMessage(kPrintSystemFailedMessageId, result.message()); |
| 48 return false; | 51 return false; |
| 49 } | 52 } |
| 50 return true; | 53 return true; |
| 51 } | 54 } |
| 52 | 55 |
| 53 void CloudPrintConnector::ScheduleStatsReport() { | 56 void CloudPrintConnector::ScheduleStatsReport() { |
| 54 base::MessageLoop::current()->PostDelayedTask( | 57 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 55 FROM_HERE, | 58 FROM_HERE, base::Bind(&CloudPrintConnector::ReportStats, |
| 56 base::Bind(&CloudPrintConnector::ReportStats, | 59 stats_ptr_factory_.GetWeakPtr()), |
| 57 stats_ptr_factory_.GetWeakPtr()), | |
| 58 base::TimeDelta::FromHours(1)); | 60 base::TimeDelta::FromHours(1)); |
| 59 } | 61 } |
| 60 | 62 |
| 61 void CloudPrintConnector::ReportStats() { | 63 void CloudPrintConnector::ReportStats() { |
| 62 PrinterJobHandler::ReportsStats(); | 64 PrinterJobHandler::ReportsStats(); |
| 63 ScheduleStatsReport(); | 65 ScheduleStatsReport(); |
| 64 } | 66 } |
| 65 | 67 |
| 66 bool CloudPrintConnector::Start() { | 68 bool CloudPrintConnector::Start() { |
| 67 VLOG(1) << "CP_CONNECTOR: Starting connector" | 69 VLOG(1) << "CP_CONNECTOR: Starting connector" |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 PendingTask task; | 487 PendingTask task; |
| 486 task.type = PENDING_PRINTER_REGISTER; | 488 task.type = PENDING_PRINTER_REGISTER; |
| 487 task.printer_info = info; | 489 task.printer_info = info; |
| 488 AddPendingTask(task); | 490 AddPendingTask(task); |
| 489 } | 491 } |
| 490 | 492 |
| 491 void CloudPrintConnector::AddPendingTask(const PendingTask& task) { | 493 void CloudPrintConnector::AddPendingTask(const PendingTask& task) { |
| 492 pending_tasks_.push_back(task); | 494 pending_tasks_.push_back(task); |
| 493 // If this is the only pending task, we need to start the process. | 495 // If this is the only pending task, we need to start the process. |
| 494 if (pending_tasks_.size() == 1) { | 496 if (pending_tasks_.size() == 1) { |
| 495 base::MessageLoop::current()->PostTask( | 497 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 496 FROM_HERE, base::Bind(&CloudPrintConnector::ProcessPendingTask, this)); | 498 FROM_HERE, base::Bind(&CloudPrintConnector::ProcessPendingTask, this)); |
| 497 } | 499 } |
| 498 } | 500 } |
| 499 | 501 |
| 500 void CloudPrintConnector::ProcessPendingTask() { | 502 void CloudPrintConnector::ProcessPendingTask() { |
| 501 if (!IsRunning()) | 503 if (!IsRunning()) |
| 502 return; // Orphant call. | 504 return; // Orphant call. |
| 503 if (pending_tasks_.size() == 0) | 505 if (pending_tasks_.size() == 0) |
| 504 return; // No peding tasks. | 506 return; // No peding tasks. |
| 505 | 507 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 520 } | 522 } |
| 521 } | 523 } |
| 522 | 524 |
| 523 void CloudPrintConnector::ContinuePendingTaskProcessing() { | 525 void CloudPrintConnector::ContinuePendingTaskProcessing() { |
| 524 if (pending_tasks_.size() == 0) | 526 if (pending_tasks_.size() == 0) |
| 525 return; // No pending tasks. | 527 return; // No pending tasks. |
| 526 | 528 |
| 527 // Delete current task and repost if we have more task available. | 529 // Delete current task and repost if we have more task available. |
| 528 pending_tasks_.pop_front(); | 530 pending_tasks_.pop_front(); |
| 529 if (pending_tasks_.size() != 0) { | 531 if (pending_tasks_.size() != 0) { |
| 530 base::MessageLoop::current()->PostTask( | 532 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 531 FROM_HERE, base::Bind(&CloudPrintConnector::ProcessPendingTask, this)); | 533 FROM_HERE, base::Bind(&CloudPrintConnector::ProcessPendingTask, this)); |
| 532 } | 534 } |
| 533 } | 535 } |
| 534 | 536 |
| 535 void CloudPrintConnector::OnPrintersAvailable() { | 537 void CloudPrintConnector::OnPrintersAvailable() { |
| 536 GURL printer_list_url = GetUrlForPrinterList( | 538 GURL printer_list_url = GetUrlForPrinterList( |
| 537 settings_.server_url(), settings_.proxy_id()); | 539 settings_.server_url(), settings_.proxy_id()); |
| 538 StartGetRequest(printer_list_url, | 540 StartGetRequest(printer_list_url, |
| 539 kCloudPrintRegisterMaxRetryCount, | 541 kCloudPrintRegisterMaxRetryCount, |
| 540 &CloudPrintConnector::HandlePrinterListResponse); | 542 &CloudPrintConnector::HandlePrinterListResponse); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 kCloudPrintAPIMaxRetryCount, mime_type, post_data, | 649 kCloudPrintAPIMaxRetryCount, mime_type, post_data, |
| 648 &CloudPrintConnector::HandleRegisterPrinterResponse); | 650 &CloudPrintConnector::HandleRegisterPrinterResponse); |
| 649 } | 651 } |
| 650 | 652 |
| 651 bool CloudPrintConnector::IsSamePrinter(const std::string& name1, | 653 bool CloudPrintConnector::IsSamePrinter(const std::string& name1, |
| 652 const std::string& name2) const { | 654 const std::string& name2) const { |
| 653 return (0 == base::strcasecmp(name1.c_str(), name2.c_str())); | 655 return (0 == base::strcasecmp(name1.c_str(), name2.c_str())); |
| 654 } | 656 } |
| 655 | 657 |
| 656 } // namespace cloud_print | 658 } // namespace cloud_print |
| OLD | NEW |