| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/proximity_auth/cryptauth/sync_scheduler_impl.h" | 5 #include "components/proximity_auth/cryptauth/sync_scheduler_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <limits> | 9 #include <limits> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/memory/ptr_util.h" |
| 12 #include "base/numerics/safe_conversions.h" | 13 #include "base/numerics/safe_conversions.h" |
| 13 #include "base/rand_util.h" | 14 #include "base/rand_util.h" |
| 14 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 15 #include "components/proximity_auth/logging/logging.h" | 16 #include "components/proximity_auth/logging/logging.h" |
| 16 | 17 |
| 17 namespace proximity_auth { | 18 namespace proximity_auth { |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 // Returns a human readable string given a |time_delta|. | 22 // Returns a human readable string given a |time_delta|. |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 sync_state_ = SyncState::SYNC_IN_PROGRESS; | 106 sync_state_ = SyncState::SYNC_IN_PROGRESS; |
| 106 } else if (strategy_ == Strategy::AGGRESSIVE_RECOVERY) { | 107 } else if (strategy_ == Strategy::AGGRESSIVE_RECOVERY) { |
| 107 PA_LOG(INFO) << "Timer fired for aggressive recovery, making request..."; | 108 PA_LOG(INFO) << "Timer fired for aggressive recovery, making request..."; |
| 108 sync_state_ = SyncState::SYNC_IN_PROGRESS; | 109 sync_state_ = SyncState::SYNC_IN_PROGRESS; |
| 109 } else { | 110 } else { |
| 110 NOTREACHED(); | 111 NOTREACHED(); |
| 111 return; | 112 return; |
| 112 } | 113 } |
| 113 | 114 |
| 114 delegate_->OnSyncRequested( | 115 delegate_->OnSyncRequested( |
| 115 make_scoped_ptr(new SyncRequest(weak_ptr_factory_.GetWeakPtr()))); | 116 base::WrapUnique(new SyncRequest(weak_ptr_factory_.GetWeakPtr()))); |
| 116 } | 117 } |
| 117 | 118 |
| 118 scoped_ptr<base::Timer> SyncSchedulerImpl::CreateTimer() { | 119 std::unique_ptr<base::Timer> SyncSchedulerImpl::CreateTimer() { |
| 119 bool retain_user_task = false; | 120 bool retain_user_task = false; |
| 120 bool is_repeating = false; | 121 bool is_repeating = false; |
| 121 return make_scoped_ptr(new base::Timer(retain_user_task, is_repeating)); | 122 return base::WrapUnique(new base::Timer(retain_user_task, is_repeating)); |
| 122 } | 123 } |
| 123 | 124 |
| 124 void SyncSchedulerImpl::ScheduleNextSync(const base::TimeDelta& sync_delta) { | 125 void SyncSchedulerImpl::ScheduleNextSync(const base::TimeDelta& sync_delta) { |
| 125 if (sync_state_ != SyncState::WAITING_FOR_REFRESH) { | 126 if (sync_state_ != SyncState::WAITING_FOR_REFRESH) { |
| 126 PA_LOG(ERROR) << "Unexpected state when scheduling next sync: sync_state=" | 127 PA_LOG(ERROR) << "Unexpected state when scheduling next sync: sync_state=" |
| 127 << static_cast<int>(sync_state_); | 128 << static_cast<int>(sync_state_); |
| 128 return; | 129 return; |
| 129 } | 130 } |
| 130 | 131 |
| 131 bool is_aggressive_recovery = (strategy_ == Strategy::AGGRESSIVE_RECOVERY); | 132 bool is_aggressive_recovery = (strategy_ == Strategy::AGGRESSIVE_RECOVERY); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 base::TimeDelta backoff_period = base_recovery_period_ * backoff_factor; | 188 base::TimeDelta backoff_period = base_recovery_period_ * backoff_factor; |
| 188 return backoff_period < refresh_period_ ? backoff_period : refresh_period_; | 189 return backoff_period < refresh_period_ ? backoff_period : refresh_period_; |
| 189 } else { | 190 } else { |
| 190 PA_LOG(ERROR) << "Error getting period for strategy: " | 191 PA_LOG(ERROR) << "Error getting period for strategy: " |
| 191 << static_cast<int>(strategy_); | 192 << static_cast<int>(strategy_); |
| 192 return base::TimeDelta(); | 193 return base::TimeDelta(); |
| 193 } | 194 } |
| 194 } | 195 } |
| 195 | 196 |
| 196 } // namespace proximity_auth | 197 } // namespace proximity_auth |
| OLD | NEW |