diff options
author | jar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-23 02:45:11 +0000 |
---|---|---|
committer | jar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-23 02:45:11 +0000 |
commit | 0b48db4400f9a20de3c9f5bea099c1a3cbcf5015 (patch) | |
tree | c7149e77252a1fe846a87cf93c1b98a02fe53296 /base | |
parent | 202dee0077b3756f5fad43c521ceec4f7349c91e (diff) | |
download | chromium_src-0b48db4400f9a20de3c9f5bea099c1a3cbcf5015.zip chromium_src-0b48db4400f9a20de3c9f5bea099c1a3cbcf5015.tar.gz chromium_src-0b48db4400f9a20de3c9f5bea099c1a3cbcf5015.tar.bz2 |
Attempt to detect impact of disabling dns prefetching on transaction latency
This is also meant to exercise the field trial infrastructure.
r=mbelshe
Review URL: http://codereview.chromium.org/50084
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12271 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/field_trial.cc | 19 | ||||
-rw-r--r-- | base/field_trial.h | 11 |
2 files changed, 22 insertions, 8 deletions
diff --git a/base/field_trial.cc b/base/field_trial.cc index 901ba16..d0085e6 100644 --- a/base/field_trial.cc +++ b/base/field_trial.cc @@ -63,6 +63,7 @@ FieldTrialList::FieldTrialList() } FieldTrialList::~FieldTrialList() { + AutoLock auto_lock(lock_); while (!registered_.empty()) { RegistrationList::iterator it = registered_.begin(); it->second->Release(); @@ -74,8 +75,8 @@ FieldTrialList::~FieldTrialList() { // static void FieldTrialList::Register(FieldTrial* trial) { - DCHECK(global_->CalledOnValidThread()); - DCHECK(!Find(trial->name())); + AutoLock auto_lock(global_->lock_); + DCHECK(!global_->PreLockedFind(trial->name())); trial->AddRef(); global_->registered_[trial->name()] = trial; } @@ -96,11 +97,17 @@ std::string FieldTrialList::FindFullName(const std::string& name) { return ""; } - // static +// static FieldTrial* FieldTrialList::Find(const std::string& name) { - DCHECK(global_->CalledOnValidThread()); - RegistrationList::iterator it = global_->registered_.find(name); - if (global_->registered_.end() == it) + if (!global_) + return NULL; + AutoLock auto_lock(global_->lock_); + return global_->PreLockedFind(name); +} + +FieldTrial* FieldTrialList::PreLockedFind(const std::string& name) { + RegistrationList::iterator it = registered_.find(name); + if (registered_.end() == it) return NULL; return it->second; } diff --git a/base/field_trial.h b/base/field_trial.h index bde6717..3d922d1 100644 --- a/base/field_trial.h +++ b/base/field_trial.h @@ -47,7 +47,7 @@ // happened (randomly) to be assigned to: // HISTOGRAM_COUNTS(FieldTrial::MakeName("Memory.RendererTotal", -// "MemoryExperiment"), count); +// "MemoryExperiment").data(), count); // The above code will create 3 distinct histograms, with each run of the // application being assigned to of of teh three groups, and for each group, the @@ -65,6 +65,7 @@ #include <map> #include <string> +#include "base/lock.h" #include "base/non_thread_safe.h" #include "base/ref_counted.h" #include "base/time.h" @@ -140,7 +141,7 @@ class FieldTrial : public base::RefCounted<FieldTrial> { // Class with a list of all active field trials. A trial is active if it has // been registered, which includes evaluating its state based on its probaility. // Only one instance of this class exists. -class FieldTrialList : NonThreadSafe { +class FieldTrialList { public: // This singleton holds the global list of registered FieldTrials. FieldTrialList(); @@ -172,11 +173,17 @@ class FieldTrialList : NonThreadSafe { } private: + // Helper function should be called only while holding lock_. + FieldTrial* PreLockedFind(const std::string& name); + typedef std::map<std::string, FieldTrial*> RegistrationList; static FieldTrialList* global_; // The singleton of this class. base::Time application_start_time_; + + // Lock for access to registered_. + Lock lock_; RegistrationList registered_; DISALLOW_COPY_AND_ASSIGN(FieldTrialList); |