Index: base/metrics/field_trial.cc |
=================================================================== |
--- base/metrics/field_trial.cc (revision 71562) |
+++ base/metrics/field_trial.cc (working copy) |
@@ -7,14 +7,18 @@ |
#include "base/logging.h" |
#include "base/rand_util.h" |
#include "base/stringprintf.h" |
+#include "base/utf_string_conversions.h" |
+using base::Time; |
+using base::TimeDelta; |
jar (doing other things)
2011/01/18 19:39:44
Given that all the code is in a "namespace base" g
rtenneti
2011/01/19 01:45:28
Done.
|
+ |
namespace base { |
// static |
-const int FieldTrial::kNotParticipating = -1; |
+const int FieldTrial::kNotFinalized = -1; |
// static |
-const int FieldTrial::kAllRemainingProbability = -2; |
+const int FieldTrial::kDefaultGroupNumber = 0; |
// static |
bool FieldTrial::enable_benchmarking_ = false; |
@@ -28,30 +32,56 @@ |
// FieldTrial methods and members. |
FieldTrial::FieldTrial(const std::string& name, |
- const Probability total_probability) |
+ const Probability total_probability, |
+ const std::string& default_group_name, |
+ const int year, |
+ const int month, |
+ const int day_of_month) |
: name_(name), |
divisor_(total_probability), |
+ default_group_name_(default_group_name), |
random_(static_cast<Probability>(divisor_ * base::RandDouble())), |
accumulated_group_probability_(0), |
- next_group_number_(0), |
- group_(kNotParticipating) { |
+ next_group_number_(kDefaultGroupNumber+1), |
+ group_(kNotFinalized), |
+ expiration_year_(year), |
jar (doing other things)
2011/01/18 19:39:44
If these are only used in the constructor, and the
rtenneti
2011/01/19 01:45:28
Done.
|
+ expiration_month_(month), |
+ expiration_day_of_month_(day_of_month) { |
+ DCHECK(!default_group_name_.empty()); |
FieldTrialList::Register(this); |
+ |
+ DCHECK_GT(expiration_year_, 1970); |
+ DCHECK_GT(expiration_month_, 0); |
+ DCHECK_LT(expiration_month_, 13); |
+ DCHECK_GT(expiration_day_of_month_, 0); |
+ DCHECK_LT(expiration_day_of_month_, 32); |
+ |
+ base::Time::Exploded exploded; |
+ exploded.year = expiration_year_; |
+ exploded.month = expiration_month_; |
+ exploded.day_of_week = 0; // Should be unusued. |
+ exploded.day_of_month = expiration_day_of_month_; |
+ exploded.hour = 0; |
+ exploded.minute = 0; |
+ exploded.second = 0; |
+ exploded.millisecond = 0; |
+ |
+ base::Time expiration_time = Time::FromLocalExploded(exploded); |
jar (doing other things)
2011/01/18 19:39:44
If we were to save anything (rather than expiratio
rtenneti
2011/01/19 01:45:28
Done.
|
+ disable_field_trial_ = (GetBuildTime() > expiration_time) ? true : false; |
} |
int FieldTrial::AppendGroup(const std::string& name, |
Probability group_probability) { |
DCHECK(group_probability <= divisor_); |
- DCHECK(group_probability >=0 || |
- group_probability == kAllRemainingProbability); |
- if (group_probability == kAllRemainingProbability) { |
- accumulated_group_probability_ = divisor_; |
- } else { |
- if (enable_benchmarking_) |
- group_probability = 0; |
- accumulated_group_probability_ += group_probability; |
- } |
+ DCHECK_GE(group_probability, 0); |
+ |
+ if (enable_benchmarking_ || disable_field_trial_) |
+ group_probability = 0; |
+ |
+ accumulated_group_probability_ += group_probability; |
+ |
DCHECK(accumulated_group_probability_ <= divisor_); |
- if (group_ == kNotParticipating && accumulated_group_probability_ > random_) { |
+ if (group_ == kNotFinalized && accumulated_group_probability_ > random_) { |
// This is the group that crossed the random line, so we do the assignment. |
group_ = next_group_number_; |
if (name.empty()) |
@@ -62,6 +92,20 @@ |
return next_group_number_++; |
} |
+int FieldTrial::group() { |
+ if (group_ == kNotFinalized) { |
+ accumulated_group_probability_ = divisor_; |
+ group_ = kDefaultGroupNumber; |
+ group_name_ = default_group_name_; |
+ } |
+ return group_; |
+} |
+ |
+std::string FieldTrial::group_name() { |
+ group(); // call group() to make group assignment was done. |
+ return group_name_; |
+} |
+ |
// static |
std::string FieldTrial::MakeName(const std::string& name_prefix, |
const std::string& trial_name) { |
@@ -76,6 +120,16 @@ |
enable_benchmarking_ = true; |
} |
+// static |
+Time FieldTrial::GetBuildTime() { |
+ Time integral_build_time; |
+ const char* kDateTime = __DATE__ " " __TIME__; |
+ bool result = Time::FromString(ASCIIToWide(kDateTime).c_str(), |
+ &integral_build_time); |
+ DCHECK(result); |
+ return integral_build_time; |
+} |
+ |
FieldTrial::~FieldTrial() {} |
//------------------------------------------------------------------------------ |
@@ -129,7 +183,7 @@ |
FieldTrial* field_trial = Find(name); |
if (field_trial) |
return field_trial->group(); |
- return FieldTrial::kNotParticipating; |
+ return FieldTrial::kNotFinalized; |
} |
// static |
@@ -149,7 +203,7 @@ |
for (RegistrationList::iterator it = global_->registered_.begin(); |
it != global_->registered_.end(); ++it) { |
const std::string name = it->first; |
- const std::string group_name = it->second->group_name(); |
+ const std::string group_name = it->second->group_name_internal(); |
if (group_name.empty()) |
continue; // No definitive winner in this trial. |
jar (doing other things)
2011/01/18 19:39:44
This method is used to serialize fieldTrial settin
rtenneti
2011/01/19 01:45:28
Done.
|
DCHECK_EQ(name.find(kPersistentStringSeparator), std::string::npos); |
@@ -184,12 +238,13 @@ |
FieldTrial *field_trial(FieldTrialList::Find(name)); |
if (field_trial) { |
// In single process mode, we may have already created the field trial. |
- if (field_trial->group_name() != group_name) |
+ if (field_trial->group_name_internal() != group_name) |
return false; |
continue; |
} |
const int kTotalProbability = 100; |
- field_trial = new FieldTrial(name, kTotalProbability); |
+ field_trial = |
+ new FieldTrial(name, kTotalProbability, group_name, 2011, 6, 30); |
jar (doing other things)
2011/01/18 19:39:44
That code won't define field trials in the rendere
rtenneti
2011/01/19 01:45:28
Done.
|
field_trial->AppendGroup(group_name, kTotalProbability); |
} |
return true; |