Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1019)

Unified Diff: chrome/browser/metrics/perf/random_selector.h

Issue 1392153003: PerfProvider: Get collection parameters from Finch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@perf_commands
Patch Set: Address comments on PS1 Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/metrics/perf/random_selector.h
diff --git a/chrome/browser/metrics/perf/random_selector.h b/chrome/browser/metrics/perf/random_selector.h
index 4500525d50bd5a841560be384e55cc4fd152b18f..b8d294697694118694970422ac2cede776ac16e5 100644
--- a/chrome/browser/metrics/perf/random_selector.h
+++ b/chrome/browser/metrics/perf/random_selector.h
@@ -35,6 +35,10 @@ class RandomSelector {
: weight(weight), value(value) {
}
+ bool operator==(const WeightAndValue& other) const {
+ return weight == other.weight && value == other.value;
+ }
+
// Probability weight for selecting this value.
double weight;
// Value to be returned by Select(), if selected.
@@ -44,8 +48,10 @@ class RandomSelector {
RandomSelector();
virtual ~RandomSelector();
- // Set the probabilities for various strings.
- void SetOdds(const std::vector<WeightAndValue>& odds);
+ // Set the probabilities for various strings. Returns false and doesn't
+ // modify the values if odds contains any invalid weights (<=0.0) or if
+ // odds is empty.
+ bool SetOdds(const std::vector<WeightAndValue>& odds);
// Randomly select one of the values from the set.
const std::string& Select();
@@ -55,7 +61,10 @@ class RandomSelector {
return odds_.size();
}
- // Sum of the |weight| fields in the vector.
+ const std::vector<WeightAndValue>& odds() const { return odds_; }
+
+ // Sum of the |weight| fields in the vector. Returns -1.0 if odds contains any
+ // weight <= 0.0.
static double SumWeights(const std::vector<WeightAndValue>& odds);
private:
@@ -76,4 +85,7 @@ class RandomSelector {
DISALLOW_COPY_AND_ASSIGN(RandomSelector);
};
+::std::ostream& operator<<(
+ ::std::ostream& os, const RandomSelector::WeightAndValue& value);
+
#endif // CHROME_BROWSER_METRICS_PERF_RANDOM_SELECTOR_H_

Powered by Google App Engine
This is Rietveld 408576698