Browse files

FieldTrial - Use ObserverListThreadSafe instead of

ObserverList.

R=jar
TEST=base unit tests
BUG=126027

Review URL: http://codereview.chromium.org/10342021

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@135263 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information...
1 parent 0af2a8a commit c50f7585ad3dc9b6ff8bdd37d4644f0b66c5bc81 rtenneti@chromium.org committed May 4, 2012
Showing with 11 additions and 9 deletions.
  1. +8 −6 base/metrics/field_trial.cc
  2. +3 −3 base/metrics/field_trial.h
View
14 base/metrics/field_trial.cc
@@ -213,7 +213,8 @@ bool FieldTrialList::used_without_global_ = false;
FieldTrialList::FieldTrialList(const std::string& client_id)
: application_start_time_(TimeTicks::Now()),
client_id_(client_id),
- observer_list_(ObserverList<Observer>::NOTIFY_EXISTING_ONLY) {
+ observer_list_(new ObserverListThreadSafe<FieldTrialList::Observer>(
+ ObserverListBase<FieldTrialList::Observer>::NOTIFY_EXISTING_ONLY)) {
DCHECK(!global_);
DCHECK(!used_without_global_);
global_ = this;
@@ -393,15 +394,15 @@ void FieldTrialList::AddObserver(Observer* observer) {
if (!global_)
return;
DCHECK(global_);
- global_->observer_list_.AddObserver(observer);
+ global_->observer_list_->AddObserver(observer);
}
// static
void FieldTrialList::RemoveObserver(Observer* observer) {
if (!global_)
return;
DCHECK(global_);
- global_->observer_list_.RemoveObserver(observer);
+ global_->observer_list_->RemoveObserver(observer);
}
// static
@@ -411,9 +412,10 @@ void FieldTrialList::NotifyFieldTrialGroupSelection(
if (!global_)
return;
DCHECK(global_);
- FOR_EACH_OBSERVER(Observer,
- global_->observer_list_,
- OnFieldTrialGroupFinalized(name, group_name));
+ global_->observer_list_->Notify(
+ &FieldTrialList::Observer::OnFieldTrialGroupFinalized,
+ name,
+ group_name);
}
// static
View
6 base/metrics/field_trial.h
@@ -82,7 +82,7 @@
#include "base/base_export.h"
#include "base/gtest_prod_util.h"
#include "base/memory/ref_counted.h"
-#include "base/observer_list.h"
+#include "base/observer_list_threadsafe.h"
#include "base/synchronization/lock.h"
#include "base/time.h"
@@ -256,7 +256,7 @@ class BASE_EXPORT FieldTrialList {
static int kExpirationYearInFuture;
// Observer is notified when a FieldTrial's group is selected.
- class Observer {
+ class BASE_EXPORT Observer {
public:
// Notify observers when FieldTrials's group is selected.
virtual void OnFieldTrialGroupFinalized(const std::string& trial_name,
@@ -423,7 +423,7 @@ class BASE_EXPORT FieldTrialList {
std::string client_id_;
// List of observers to be notified when a group is selected for a FieldTrial.
- ObserverList<Observer> observer_list_;
+ scoped_refptr<ObserverListThreadSafe<Observer> > observer_list_;
DISALLOW_COPY_AND_ASSIGN(FieldTrialList);
};

0 comments on commit c50f758

Please sign in to comment.