| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/metrics/field_trial.h" | 5 #include "base/metrics/field_trial.h" |
| 6 | 6 |
| 7 #include "base/build_time.h" | 7 #include "base/build_time.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
| 10 #include "base/sha1.h" | 10 #include "base/sha1.h" |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 | 206 |
| 207 // static | 207 // static |
| 208 FieldTrialList* FieldTrialList::global_ = NULL; | 208 FieldTrialList* FieldTrialList::global_ = NULL; |
| 209 | 209 |
| 210 // static | 210 // static |
| 211 bool FieldTrialList::used_without_global_ = false; | 211 bool FieldTrialList::used_without_global_ = false; |
| 212 | 212 |
| 213 FieldTrialList::FieldTrialList(const std::string& client_id) | 213 FieldTrialList::FieldTrialList(const std::string& client_id) |
| 214 : application_start_time_(TimeTicks::Now()), | 214 : application_start_time_(TimeTicks::Now()), |
| 215 client_id_(client_id), | 215 client_id_(client_id), |
| 216 observer_list_(ObserverList<Observer>::NOTIFY_EXISTING_ONLY) { | 216 observer_list_(new ObserverListThreadSafe<FieldTrialList::Observer>( |
| 217 ObserverListBase<FieldTrialList::Observer>::NOTIFY_EXISTING_ONLY)) { |
| 217 DCHECK(!global_); | 218 DCHECK(!global_); |
| 218 DCHECK(!used_without_global_); | 219 DCHECK(!used_without_global_); |
| 219 global_ = this; | 220 global_ = this; |
| 220 | 221 |
| 221 Time::Exploded exploded; | 222 Time::Exploded exploded; |
| 222 Time two_years_from_now = | 223 Time two_years_from_now = |
| 223 Time::NowFromSystemTime() + TimeDelta::FromDays(730); | 224 Time::NowFromSystemTime() + TimeDelta::FromDays(730); |
| 224 two_years_from_now.LocalExplode(&exploded); | 225 two_years_from_now.LocalExplode(&exploded); |
| 225 kExpirationYearInFuture = exploded.year; | 226 kExpirationYearInFuture = exploded.year; |
| 226 } | 227 } |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 field_trial->forced_ = true; | 387 field_trial->forced_ = true; |
| 387 FieldTrialList::Register(field_trial); | 388 FieldTrialList::Register(field_trial); |
| 388 return field_trial; | 389 return field_trial; |
| 389 } | 390 } |
| 390 | 391 |
| 391 // static | 392 // static |
| 392 void FieldTrialList::AddObserver(Observer* observer) { | 393 void FieldTrialList::AddObserver(Observer* observer) { |
| 393 if (!global_) | 394 if (!global_) |
| 394 return; | 395 return; |
| 395 DCHECK(global_); | 396 DCHECK(global_); |
| 396 global_->observer_list_.AddObserver(observer); | 397 global_->observer_list_->AddObserver(observer); |
| 397 } | 398 } |
| 398 | 399 |
| 399 // static | 400 // static |
| 400 void FieldTrialList::RemoveObserver(Observer* observer) { | 401 void FieldTrialList::RemoveObserver(Observer* observer) { |
| 401 if (!global_) | 402 if (!global_) |
| 402 return; | 403 return; |
| 403 DCHECK(global_); | 404 DCHECK(global_); |
| 404 global_->observer_list_.RemoveObserver(observer); | 405 global_->observer_list_->RemoveObserver(observer); |
| 405 } | 406 } |
| 406 | 407 |
| 407 // static | 408 // static |
| 408 void FieldTrialList::NotifyFieldTrialGroupSelection( | 409 void FieldTrialList::NotifyFieldTrialGroupSelection( |
| 409 const std::string& name, | 410 const std::string& name, |
| 410 const std::string& group_name) { | 411 const std::string& group_name) { |
| 411 if (!global_) | 412 if (!global_) |
| 412 return; | 413 return; |
| 413 DCHECK(global_); | 414 DCHECK(global_); |
| 414 FOR_EACH_OBSERVER(Observer, | 415 global_->observer_list_->Notify( |
| 415 global_->observer_list_, | 416 &FieldTrialList::Observer::OnFieldTrialGroupFinalized, |
| 416 OnFieldTrialGroupFinalized(name, group_name)); | 417 name, |
| 418 group_name); |
| 417 } | 419 } |
| 418 | 420 |
| 419 // static | 421 // static |
| 420 size_t FieldTrialList::GetFieldTrialCount() { | 422 size_t FieldTrialList::GetFieldTrialCount() { |
| 421 if (!global_) | 423 if (!global_) |
| 422 return 0; | 424 return 0; |
| 423 AutoLock auto_lock(global_->lock_); | 425 AutoLock auto_lock(global_->lock_); |
| 424 return global_->registered_.size(); | 426 return global_->registered_.size(); |
| 425 } | 427 } |
| 426 | 428 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 456 used_without_global_ = true; | 458 used_without_global_ = true; |
| 457 return; | 459 return; |
| 458 } | 460 } |
| 459 AutoLock auto_lock(global_->lock_); | 461 AutoLock auto_lock(global_->lock_); |
| 460 DCHECK(!global_->PreLockedFind(trial->name())); | 462 DCHECK(!global_->PreLockedFind(trial->name())); |
| 461 trial->AddRef(); | 463 trial->AddRef(); |
| 462 global_->registered_[trial->name()] = trial; | 464 global_->registered_[trial->name()] = trial; |
| 463 } | 465 } |
| 464 | 466 |
| 465 } // namespace base | 467 } // namespace base |
| OLD | NEW |