| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/printer_job_queue_handler.h" | 5 #include "chrome/service/cloud_print/printer_job_queue_handler.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 #include <stddef.h> |
| 9 #include <stdint.h> |
| 8 | 10 |
| 9 #include <algorithm> | 11 #include <algorithm> |
| 10 | 12 |
| 11 #include "base/values.h" | 13 #include "base/values.h" |
| 12 | 14 |
| 13 namespace cloud_print { | 15 namespace cloud_print { |
| 14 | 16 |
| 15 class TimeProviderImpl : public PrinterJobQueueHandler::TimeProvider { | 17 class TimeProviderImpl : public PrinterJobQueueHandler::TimeProvider { |
| 16 public: | 18 public: |
| 17 base::Time GetNow() override; | 19 base::Time GetNow() override; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 base::TimeDelta PrinterJobQueueHandler::ComputeBackoffTime( | 80 base::TimeDelta PrinterJobQueueHandler::ComputeBackoffTime( |
| 79 const std::string& job_id) { | 81 const std::string& job_id) { |
| 80 FailedJobMap::const_iterator job_location = failed_job_map_.find(job_id); | 82 FailedJobMap::const_iterator job_location = failed_job_map_.find(job_id); |
| 81 if (job_location == failed_job_map_.end()) { | 83 if (job_location == failed_job_map_.end()) { |
| 82 return base::TimeDelta(); | 84 return base::TimeDelta(); |
| 83 } | 85 } |
| 84 | 86 |
| 85 base::TimeDelta backoff_time = | 87 base::TimeDelta backoff_time = |
| 86 base::TimeDelta::FromSeconds(kJobFirstWaitTimeSecs); | 88 base::TimeDelta::FromSeconds(kJobFirstWaitTimeSecs); |
| 87 backoff_time *= | 89 backoff_time *= |
| 88 // casting argument to double and result to uint64 to avoid compilation | 90 // casting argument to double and result to uint64_t to avoid compilation |
| 89 // issues | 91 // issues |
| 90 static_cast<int64>(pow( | 92 static_cast<int64_t>( |
| 91 static_cast<long double>(kJobWaitTimeExponentialMultiplier), | 93 pow(static_cast<long double>(kJobWaitTimeExponentialMultiplier), |
| 92 job_location->second.retries_) + 0.5); | 94 job_location->second.retries_) + |
| 95 0.5); |
| 93 base::Time scheduled_retry = | 96 base::Time scheduled_retry = |
| 94 job_location->second.last_retry_ + backoff_time; | 97 job_location->second.last_retry_ + backoff_time; |
| 95 base::Time now = time_provider_->GetNow(); | 98 base::Time now = time_provider_->GetNow(); |
| 96 base::TimeDelta time_remaining; | 99 base::TimeDelta time_remaining; |
| 97 | 100 |
| 98 if (scheduled_retry < now) { | 101 if (scheduled_retry < now) { |
| 99 return base::TimeDelta(); | 102 return base::TimeDelta(); |
| 100 } | 103 } |
| 101 return scheduled_retry - now; | 104 return scheduled_retry - now; |
| 102 } | 105 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 | 163 |
| 161 job_found.first->second.retries_ += 1; | 164 job_found.first->second.retries_ += 1; |
| 162 job_found.first->second.last_retry_ = time_provider_->GetNow(); | 165 job_found.first->second.last_retry_ = time_provider_->GetNow(); |
| 163 } | 166 } |
| 164 | 167 |
| 165 return true; | 168 return true; |
| 166 } | 169 } |
| 167 | 170 |
| 168 } // namespace cloud_print | 171 } // namespace cloud_print |
| 169 | 172 |
| OLD | NEW |