diff options
Diffstat (limited to 'base/field_trial.cc')
-rw-r--r-- | base/field_trial.cc | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/base/field_trial.cc b/base/field_trial.cc index d0085e6..fc12f31 100644 --- a/base/field_trial.cc +++ b/base/field_trial.cc @@ -13,6 +13,9 @@ using base::Time; // static const int FieldTrial::kNotParticipating = -1; +// static +const char FieldTrial::kPersistentStringSeparator('/'); + //------------------------------------------------------------------------------ // FieldTrial methods and members. @@ -50,6 +53,40 @@ std::string FieldTrial::MakeName(const std::string& name_prefix, return big_string.append(FieldTrialList::FindFullName(trial_name)); } +std::string FieldTrial::MakePersistentString() const { + DCHECK_EQ(name_.find(kPersistentStringSeparator), std::string::npos); + DCHECK_EQ(group_name_.find(kPersistentStringSeparator), std::string::npos); + + std::string persistent(name_); + persistent = persistent.append(1, kPersistentStringSeparator); + persistent = persistent.append(group_name_); + return persistent; +} + +// static +FieldTrial* FieldTrial::RestorePersistentString(const std::string &persistent) { + size_t split_point = persistent.find(kPersistentStringSeparator); + if (std::string::npos == split_point) + return NULL; // Bogus string. + std::string new_name(persistent, 0, split_point); + std::string new_group_name(persistent, split_point + 1); + if (new_name.empty() || new_group_name.empty()) + return NULL; // Incomplete string. + + FieldTrial *field_trial; + field_trial = FieldTrialList::Find(new_name); + if (field_trial) { + // In single process mode, we may have already created the field trial. + if (field_trial->group_name_ != new_group_name) + return NULL; // Conflicting group name :-(. + } else { + const int kTotalProbability = 100; + field_trial = new FieldTrial(new_name, kTotalProbability); + field_trial->AppendGroup(new_group_name, kTotalProbability); + } + return field_trial; +} + //------------------------------------------------------------------------------ // FieldTrialList methods and members. @@ -75,6 +112,9 @@ FieldTrialList::~FieldTrialList() { // static void FieldTrialList::Register(FieldTrial* trial) { + DCHECK(global_); + if (!global_) + return; AutoLock auto_lock(global_->lock_); DCHECK(!global_->PreLockedFind(trial->name())); trial->AddRef(); |