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

Unified Diff: base/metrics/field_trial.cc

Issue 9117037: Added a Unique ID for a Field Trial containing it's hashed name and the selected group ID. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 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: base/metrics/field_trial.cc
===================================================================
--- base/metrics/field_trial.cc (revision 118842)
+++ base/metrics/field_trial.cc (working copy)
@@ -42,6 +42,7 @@
const int month,
const int day_of_month)
: name_(name),
+ name_hash_(HashName(name)),
divisor_(total_probability),
default_group_name_(default_group_name),
random_(static_cast<Probability>(divisor_ * RandDouble())),
@@ -96,6 +97,7 @@
if (group_ != kNotFinalized) {
group_ = kDefaultGroupNumber;
group_name_ = default_group_name_;
+ group_name_hash_ = HashName(group_name_);
}
}
@@ -117,6 +119,7 @@
StringAppendF(&group_name_, "%d", group_);
else
group_name_ = name;
+ group_name_hash_ = HashName(group_name_);
FieldTrialList::NotifyFieldTrialGroupSelection(name_, group_name_);
}
return next_group_number_++;
@@ -127,6 +130,7 @@
accumulated_group_probability_ = divisor_;
group_ = kDefaultGroupNumber;
group_name_ = default_group_name_;
+ group_name_hash_ = HashName(group_name_);
FieldTrialList::NotifyFieldTrialGroupSelection(name_, group_name_);
}
return group_;
@@ -138,6 +142,14 @@
return group_name_;
}
+bool FieldTrial::GetNameGroupId(NameGroupId* name_group_id) {
+ if (group_ == kNotFinalized)
jar (doing other things) 2012/01/24 21:51:23 You need to check for the (reserved) initial value
MAD 2012/01/25 00:14:48 Done.
+ return false;
+ name_group_id->name = name_hash_;
+ name_group_id->group = group_name_hash_;
+ return true;
+}
+
// static
std::string FieldTrial::MakeName(const std::string& name_prefix,
const std::string& trial_name) {
@@ -173,6 +185,21 @@
return BitsToOpenEndedUnitInterval(*bits);
}
+// static
+uint32 FieldTrial::HashName(const std::string& name) {
+ // SHA-1 is designed to produce a uniformly random spread in its output space,
+ // even for nearly-identical name.
+ unsigned char sha1_hash[kSHA1Length];
+ SHA1HashBytes(reinterpret_cast<const unsigned char*>(name.c_str()),
+ name.size(),
+ sha1_hash);
+
+ COMPILE_ASSERT(sizeof(uint32) < sizeof(sha1_hash), need_more_data);
+ uint32* bits = reinterpret_cast<uint32*>(&sha1_hash[0]);
+
+ return *bits;
+}
+
//------------------------------------------------------------------------------
// FieldTrialList methods and members.
@@ -272,6 +299,22 @@
}
// static
+void FieldTrialList::GetFieldTrialNameGroupIds(
+ std::vector<FieldTrial::NameGroupId>* name_group_ids) {
+ if (!global_)
+ return;
+ DCHECK(name_group_ids->empty());
+ AutoLock auto_lock(global_->lock_);
+
+ for (RegistrationList::iterator it = global_->registered_.begin();
+ it != global_->registered_.end(); ++it) {
+ FieldTrial::NameGroupId name_group_id;
+ if (it->second->GetNameGroupId(&name_group_id))
+ name_group_ids->push_back(name_group_id);
+ }
+}
+
+// static
bool FieldTrialList::CreateTrialsInChildProcess(
const std::string& parent_trials) {
DCHECK(global_);

Powered by Google App Engine
This is Rietveld 408576698