Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/domain_reliability/scheduler.h" | 5 #include "components/domain_reliability/scheduler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 return default_value; | 30 return default_value; |
| 31 | 31 |
| 32 std::string group_name = base::FieldTrialList::FindFullName(field_trial_name); | 32 std::string group_name = base::FieldTrialList::FindFullName(field_trial_name); |
| 33 int value; | 33 int value; |
| 34 if (!base::StringToInt(group_name, &value)) { | 34 if (!base::StringToInt(group_name, &value)) { |
| 35 LOG(ERROR) << "Expected integer for field trial " << field_trial_name | 35 LOG(ERROR) << "Expected integer for field trial " << field_trial_name |
| 36 << " group name, but got \"" << group_name << "\"."; | 36 << " group name, but got \"" << group_name << "\"."; |
| 37 return default_value; | 37 return default_value; |
| 38 } | 38 } |
| 39 | 39 |
| 40 return value; | 40 return value; |
|
Ryan Sleevi
2014/04/26 02:37:39
Why Int? Why not UInt?
Deprecated (see juliatuttle)
2014/04/28 22:01:13
Done.
| |
| 41 } | 41 } |
| 42 | 42 |
| 43 } // namespace | 43 } // namespace |
| 44 | 44 |
| 45 namespace domain_reliability { | 45 namespace domain_reliability { |
| 46 | 46 |
| 47 // static | 47 // static |
| 48 DomainReliabilityScheduler::Params | 48 DomainReliabilityScheduler::Params |
| 49 DomainReliabilityScheduler::Params::GetFromFieldTrialsOrDefaults() { | 49 DomainReliabilityScheduler::Params::GetFromFieldTrialsOrDefaults() { |
| 50 DomainReliabilityScheduler::Params params; | 50 DomainReliabilityScheduler::Params params; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 base::TimeDelta min_delay = std::max(min_by_deadline, min_by_backoff) - now; | 159 base::TimeDelta min_delay = std::max(min_by_deadline, min_by_backoff) - now; |
| 160 base::TimeDelta max_delay = std::max(max_by_deadline, min_by_backoff) - now; | 160 base::TimeDelta max_delay = std::max(max_by_deadline, min_by_backoff) - now; |
| 161 | 161 |
| 162 VLOG(1) << "Scheduling upload for between " << min_delay.InSeconds() | 162 VLOG(1) << "Scheduling upload for between " << min_delay.InSeconds() |
| 163 << " and " << max_delay.InSeconds() << " seconds from now."; | 163 << " and " << max_delay.InSeconds() << " seconds from now."; |
| 164 | 164 |
| 165 callback_.Run(min_delay, max_delay); | 165 callback_.Run(min_delay, max_delay); |
| 166 } | 166 } |
| 167 | 167 |
| 168 // TODO(ttuttle): Add min and max interval to config, use that instead. | 168 // TODO(ttuttle): Add min and max interval to config, use that instead. |
| 169 | |
| 169 // TODO(ttuttle): Cap min and max intervals received from config. | 170 // TODO(ttuttle): Cap min and max intervals received from config. |
| 170 | 171 |
| 171 void DomainReliabilityScheduler::GetNextUploadTimeAndCollector( | 172 void DomainReliabilityScheduler::GetNextUploadTimeAndCollector( |
| 172 base::TimeTicks now, | 173 base::TimeTicks now, |
| 173 base::TimeTicks* upload_time_out, | 174 base::TimeTicks* upload_time_out, |
| 174 int* collector_index_out) { | 175 int* collector_index_out) { |
| 175 DCHECK(upload_time_out); | 176 DCHECK(upload_time_out); |
| 176 DCHECK(collector_index_out); | 177 DCHECK(collector_index_out); |
| 177 | 178 |
| 178 base::TimeTicks min_time; | 179 base::TimeTicks min_time; |
| 179 int min_index = kInvalidCollectorIndex; | 180 int min_index = kInvalidCollectorIndex; |
| 180 | 181 |
| 181 for (unsigned i = 0; i < collectors_.size(); ++i) { | 182 for (unsigned i = 0; i < collectors_.size(); ++i) { |
|
Ryan Sleevi
2014/04/26 02:37:39
s/unsigned/size_t/ - use the proper type.
Deprecated (see juliatuttle)
2014/04/28 22:01:13
Done.
| |
| 182 CollectorState* collector = &collectors_[i]; | 183 CollectorState* collector = &collectors_[i]; |
| 183 // If a collector is usable, use the first one in the list. | 184 // If a collector is usable, use the first one in the list. |
| 184 if (collector->failures == 0 || collector->next_upload <= now) { | 185 if (collector->failures == 0 || collector->next_upload <= now) { |
| 185 min_time = now; | 186 min_time = now; |
| 186 min_index = i; | 187 min_index = i; |
|
Ryan Sleevi
2014/04/26 02:37:39
SECURITY BUG: You just sunk my battleship :(
You
Deprecated (see juliatuttle)
2014/04/28 22:01:13
Done.
| |
| 187 break; | 188 break; |
| 188 // If not, keep track of which will be usable soonest: | 189 // If not, keep track of which will be usable soonest: |
| 189 } else if (min_index == kInvalidCollectorIndex || | 190 } else if (min_index == kInvalidCollectorIndex || |
| 190 collector->next_upload < min_time) { | 191 collector->next_upload < min_time) { |
| 191 min_time = collector->next_upload; | 192 min_time = collector->next_upload; |
| 192 min_index = i; | 193 min_index = i; |
| 193 } | 194 } |
| 194 } | 195 } |
| 195 | 196 |
| 196 DCHECK_NE(kInvalidCollectorIndex, min_index); | 197 DCHECK_NE(kInvalidCollectorIndex, min_index); |
| 197 *upload_time_out = min_time; | 198 *upload_time_out = min_time; |
| 198 *collector_index_out = min_index; | 199 *collector_index_out = min_index; |
| 199 } | 200 } |
| 200 | 201 |
| 201 base::TimeDelta DomainReliabilityScheduler::GetUploadRetryInterval( | 202 base::TimeDelta DomainReliabilityScheduler::GetUploadRetryInterval( |
| 202 int failures) { | 203 int failures) { |
| 203 if (failures == 0) | 204 if (failures == 0) |
| 204 return base::TimeDelta::FromSeconds(0); | 205 return base::TimeDelta::FromSeconds(0); |
| 205 else { | 206 else { |
| 206 return params_.upload_retry_interval * (1 << std::min(failures - 1, 5)); | 207 return params_.upload_retry_interval * (1 << std::min(failures - 1, 5)); |
| 207 } | 208 } |
| 208 } | 209 } |
| 209 | 210 |
| 210 } // namespace domain_reliability | 211 } // namespace domain_reliability |
| OLD | NEW |