| Index: chrome/browser/metrics/perf/random_selector.cc
|
| diff --git a/chrome/browser/metrics/perf/random_selector.cc b/chrome/browser/metrics/perf/random_selector.cc
|
| index e32c8a048d6c6c42d2ccdd9b858bd56ec08b29ac..40696180decd8e8b22cc1f7ddc04fa5f4d4fceca 100644
|
| --- a/chrome/browser/metrics/perf/random_selector.cc
|
| +++ b/chrome/browser/metrics/perf/random_selector.cc
|
| @@ -14,17 +14,24 @@ RandomSelector::RandomSelector() : sum_of_weights_(0) {}
|
|
|
| RandomSelector::~RandomSelector() {}
|
|
|
| +// static
|
| double RandomSelector::SumWeights(const std::vector<WeightAndValue>& odds) {
|
| double sum = 0.0;
|
| for (const auto& odd : odds) {
|
| + if (odd.weight <= 0.0)
|
| + return -1.0;
|
| sum += odd.weight;
|
| }
|
| return sum;
|
| }
|
|
|
| -void RandomSelector::SetOdds(const std::vector<WeightAndValue>& odds) {
|
| +bool RandomSelector::SetOdds(const std::vector<WeightAndValue>& odds) {
|
| + double sum = SumWeights(odds);
|
| + if (sum <= 0.0)
|
| + return false;
|
| odds_ = odds;
|
| - sum_of_weights_ = SumWeights(odds_);
|
| + sum_of_weights_ = sum;
|
| + return true;
|
| }
|
|
|
| const std::string& RandomSelector::Select() {
|
| @@ -49,3 +56,8 @@ const std::string& RandomSelector::GetValueFor(double random) {
|
| NOTREACHED() << "Invalid value for key: " << random;
|
| return base::EmptyString();
|
| }
|
| +
|
| +::std::ostream& operator<<(
|
| + ::std::ostream& os, const RandomSelector::WeightAndValue& value) {
|
| + return os << "{" << value.weight << ", \"" << value.value << "\"}";
|
| +}
|
|
|