| 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/update_client/update_engine.h" | 5 #include "components/update_client/update_engine.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/location.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 | 121 |
| 122 const int throttle_sec(update_context->retry_after_sec_); | 122 const int throttle_sec(update_context->retry_after_sec_); |
| 123 DCHECK_LE(throttle_sec, 24 * 60 * 60); | 123 DCHECK_LE(throttle_sec, 24 * 60 * 60); |
| 124 | 124 |
| 125 // Only positive values for throttle_sec are effective. 0 means that no | 125 // Only positive values for throttle_sec are effective. 0 means that no |
| 126 // throttling occurs and has the effect of resetting the member. | 126 // throttling occurs and has the effect of resetting the member. |
| 127 // Negative values are not trusted and are ignored. | 127 // Negative values are not trusted and are ignored. |
| 128 if (throttle_sec >= 0) | 128 if (throttle_sec >= 0) |
| 129 throttle_updates_until_ = | 129 throttle_updates_until_ = |
| 130 throttle_sec | 130 throttle_sec |
| 131 ? base::Time::Now() + base::TimeDelta::FromSeconds(throttle_sec) | 131 ? base::TimeTicks::Now() + |
| 132 : base::Time(); | 132 base::TimeDelta::FromSeconds(throttle_sec) |
| 133 : base::TimeTicks(); |
| 133 | 134 |
| 134 auto callback = update_context->callback; | 135 auto callback = update_context->callback; |
| 135 | 136 |
| 136 update_contexts_.erase(update_context); | 137 update_contexts_.erase(update_context); |
| 137 delete update_context; | 138 delete update_context; |
| 138 | 139 |
| 139 callback.Run(error); | 140 callback.Run(error); |
| 140 } | 141 } |
| 141 | 142 |
| 142 bool UpdateEngine::IsThrottled(bool is_foreground) const { | 143 bool UpdateEngine::IsThrottled(bool is_foreground) const { |
| 143 if (is_foreground || throttle_updates_until_.is_null()) | 144 if (is_foreground || throttle_updates_until_.is_null()) |
| 144 return false; | 145 return false; |
| 145 | 146 |
| 146 const auto now(base::Time::Now()); | 147 const auto now(base::TimeTicks::Now()); |
| 147 | 148 |
| 148 // Throttle the calls in the interval (t - 1 day, t) to limit the effect of | 149 // Throttle the calls in the interval (t - 1 day, t) to limit the effect of |
| 149 // unset clocks or clock drift. | 150 // unset clocks or clock drift. |
| 150 return throttle_updates_until_ - base::TimeDelta::FromDays(1) < now && | 151 return throttle_updates_until_ - base::TimeDelta::FromDays(1) < now && |
| 151 now < throttle_updates_until_; | 152 now < throttle_updates_until_; |
| 152 } | 153 } |
| 153 | 154 |
| 154 } // namespace update_client | 155 } // namespace update_client |
| OLD | NEW |