| 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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/build_time.h" | 9 #include "base/build_time.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 | 245 |
| 246 Time two_years_from_build_time = GetBuildTime() + TimeDelta::FromDays(730); | 246 Time two_years_from_build_time = GetBuildTime() + TimeDelta::FromDays(730); |
| 247 Time::Exploded exploded; | 247 Time::Exploded exploded; |
| 248 two_years_from_build_time.LocalExplode(&exploded); | 248 two_years_from_build_time.LocalExplode(&exploded); |
| 249 kNoExpirationYear = exploded.year; | 249 kNoExpirationYear = exploded.year; |
| 250 } | 250 } |
| 251 | 251 |
| 252 FieldTrialList::~FieldTrialList() { | 252 FieldTrialList::~FieldTrialList() { |
| 253 AutoLock auto_lock(lock_); | 253 AutoLock auto_lock(lock_); |
| 254 while (!registered_.empty()) { | 254 while (!registered_.empty()) { |
| 255 RegistrationList::iterator it = registered_.begin(); | 255 RegistrationMap::iterator it = registered_.begin(); |
| 256 it->second->Release(); | 256 it->second->Release(); |
| 257 registered_.erase(it->first); | 257 registered_.erase(it->first); |
| 258 } | 258 } |
| 259 DCHECK_EQ(this, global_); | 259 DCHECK_EQ(this, global_); |
| 260 global_ = NULL; | 260 global_ = NULL; |
| 261 } | 261 } |
| 262 | 262 |
| 263 // static | 263 // static |
| 264 FieldTrial* FieldTrialList::FactoryGetFieldTrial( | 264 FieldTrial* FieldTrialList::FactoryGetFieldTrial( |
| 265 const std::string& trial_name, | 265 const std::string& trial_name, |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 } | 383 } |
| 384 | 384 |
| 385 // static | 385 // static |
| 386 void FieldTrialList::GetActiveFieldTrialGroups( | 386 void FieldTrialList::GetActiveFieldTrialGroups( |
| 387 FieldTrial::ActiveGroups* active_groups) { | 387 FieldTrial::ActiveGroups* active_groups) { |
| 388 DCHECK(active_groups->empty()); | 388 DCHECK(active_groups->empty()); |
| 389 if (!global_) | 389 if (!global_) |
| 390 return; | 390 return; |
| 391 AutoLock auto_lock(global_->lock_); | 391 AutoLock auto_lock(global_->lock_); |
| 392 | 392 |
| 393 for (RegistrationList::iterator it = global_->registered_.begin(); | 393 for (RegistrationMap::iterator it = global_->registered_.begin(); |
| 394 it != global_->registered_.end(); ++it) { | 394 it != global_->registered_.end(); ++it) { |
| 395 FieldTrial::ActiveGroup active_group; | 395 FieldTrial::ActiveGroup active_group; |
| 396 if (it->second->GetActiveGroup(&active_group)) | 396 if (it->second->GetActiveGroup(&active_group)) |
| 397 active_groups->push_back(active_group); | 397 active_groups->push_back(active_group); |
| 398 } | 398 } |
| 399 } | 399 } |
| 400 | 400 |
| 401 // static | 401 // static |
| 402 bool FieldTrialList::CreateTrialsFromString(const std::string& trials_string, | 402 bool FieldTrialList::CreateTrialsFromString(const std::string& trials_string, |
| 403 FieldTrialActivationMode mode) { | 403 FieldTrialActivationMode mode) { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 FieldTrialList::GetEntropyProviderForOneTimeRandomization() { | 506 FieldTrialList::GetEntropyProviderForOneTimeRandomization() { |
| 507 if (!global_) { | 507 if (!global_) { |
| 508 used_without_global_ = true; | 508 used_without_global_ = true; |
| 509 return NULL; | 509 return NULL; |
| 510 } | 510 } |
| 511 | 511 |
| 512 return global_->entropy_provider_.get(); | 512 return global_->entropy_provider_.get(); |
| 513 } | 513 } |
| 514 | 514 |
| 515 FieldTrial* FieldTrialList::PreLockedFind(const std::string& name) { | 515 FieldTrial* FieldTrialList::PreLockedFind(const std::string& name) { |
| 516 RegistrationList::iterator it = registered_.find(name); | 516 RegistrationMap::iterator it = registered_.find(name); |
| 517 if (registered_.end() == it) | 517 if (registered_.end() == it) |
| 518 return NULL; | 518 return NULL; |
| 519 return it->second; | 519 return it->second; |
| 520 } | 520 } |
| 521 | 521 |
| 522 // static | 522 // static |
| 523 void FieldTrialList::Register(FieldTrial* trial) { | 523 void FieldTrialList::Register(FieldTrial* trial) { |
| 524 if (!global_) { | 524 if (!global_) { |
| 525 used_without_global_ = true; | 525 used_without_global_ = true; |
| 526 return; | 526 return; |
| 527 } | 527 } |
| 528 AutoLock auto_lock(global_->lock_); | 528 AutoLock auto_lock(global_->lock_); |
| 529 DCHECK(!global_->PreLockedFind(trial->trial_name())); | 529 DCHECK(!global_->PreLockedFind(trial->trial_name())); |
| 530 trial->AddRef(); | 530 trial->AddRef(); |
| 531 trial->SetTrialRegistered(); | 531 trial->SetTrialRegistered(); |
| 532 global_->registered_[trial->trial_name()] = trial; | 532 global_->registered_[trial->trial_name()] = trial; |
| 533 } | 533 } |
| 534 | 534 |
| 535 } // namespace base | 535 } // namespace base |
| OLD | NEW |