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

Unified Diff: base/field_trial.cc

Issue 28226: Renovate FieldTrial class to better fit with histogram usage. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 10 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
« no previous file with comments | « base/field_trial.h ('k') | base/field_trial_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/field_trial.cc
===================================================================
--- base/field_trial.cc (revision 10679)
+++ base/field_trial.cc (working copy)
@@ -6,10 +6,48 @@
#include "base/field_trial.h"
#include "base/logging.h"
#include "base/rand_util.h"
+#include "base/string_util.h"
using base::Time;
//------------------------------------------------------------------------------
+// FieldTrial methods and members.
+
+FieldTrial::FieldTrial(const std::string& name,
+ const Probability total_probability)
+ : name_(name),
+ divisor_(total_probability),
+ random_(static_cast<Probability>(divisor_ * base::RandDouble())),
+ accumulated_group_probability_(0),
+ next_group_number_(0),
+ group_(kNotParticipating) {
+ FieldTrialList::Register(this);
+}
+
+int FieldTrial::AppendGroup(const std::string& name,
+ Probability group_probability) {
+ DCHECK(group_probability <= divisor_);
+ accumulated_group_probability_ += group_probability;
+ DCHECK(accumulated_group_probability_ <= divisor_);
+ if (group_ == kNotParticipating && accumulated_group_probability_ > random_) {
+ // This is the group that crossed the random line, so we do teh assignment.
+ group_ = next_group_number_;
+ if (name.empty())
+ StringAppendF(&group_name_, "_%d", group_);
+ else
+ group_name_ = name;
+ }
+ return next_group_number_++;
+}
+
+// static
+std::string FieldTrial::MakeName(const std::string& name_prefix,
+ const std::string& trial_name) {
+ std::string big_string(name_prefix);
+ return big_string.append(FieldTrialList::FindFullName(trial_name));
+}
+
+//------------------------------------------------------------------------------
// FieldTrialList methods and members.
// static
@@ -40,7 +78,23 @@
}
// static
-FieldTrial* FieldTrialList::Find(const std::wstring& name) {
+int FieldTrialList::FindValue(const std::string& name) {
+ FieldTrial* field_trial = Find(name);
+ if (field_trial)
+ return field_trial->group();
+ return FieldTrial::kNotParticipating;
+}
+
+// static
+std::string FieldTrialList::FindFullName(const std::string& name) {
+ FieldTrial* field_trial = Find(name);
+ if (field_trial)
+ return field_trial->group_name();
+ return "";
+}
+
+ // static
+FieldTrial* FieldTrialList::Find(const std::string& name) {
DCHECK(global_->CalledOnValidThread());
RegistrationList::iterator it = global_->registered_.find(name);
if (global_->registered_.end() == it)
@@ -48,13 +102,3 @@
return it->second;
}
-//------------------------------------------------------------------------------
-// FieldTrial methods and members.
-
-FieldTrial::FieldTrial(const std::wstring& name, double probability)
- : name_(name) {
- double rand = base::RandDouble();
- DCHECK(rand >= 0.0 && rand < 1.0);
- boolean_value_ = rand < probability;
- FieldTrialList::Register(this);
-}
« no previous file with comments | « base/field_trial.h ('k') | base/field_trial_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698