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

Side by Side Diff: base/metrics/field_trial.cc

Issue 1366673002: Introduce a new FieldTrialList::IsTrialActive() API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address nit. Created 5 years, 3 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 unified diff | Download patch
« no previous file with comments | « base/metrics/field_trial.h ('k') | components/variations/variations_associated_data.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 347
348 FieldTrial* field_trial = new FieldTrial(trial_name, total_probability, 348 FieldTrial* field_trial = new FieldTrial(trial_name, total_probability,
349 default_group_name, entropy_value); 349 default_group_name, entropy_value);
350 if (GetBuildTime() > CreateTimeFromParams(year, month, day_of_month)) 350 if (GetBuildTime() > CreateTimeFromParams(year, month, day_of_month))
351 field_trial->Disable(); 351 field_trial->Disable();
352 FieldTrialList::Register(field_trial); 352 FieldTrialList::Register(field_trial);
353 return field_trial; 353 return field_trial;
354 } 354 }
355 355
356 // static 356 // static
357 FieldTrial* FieldTrialList::Find(const std::string& name) { 357 FieldTrial* FieldTrialList::Find(const std::string& trial_name) {
358 if (!global_) 358 if (!global_)
359 return NULL; 359 return NULL;
360 AutoLock auto_lock(global_->lock_); 360 AutoLock auto_lock(global_->lock_);
361 return global_->PreLockedFind(name); 361 return global_->PreLockedFind(trial_name);
362 } 362 }
363 363
364 // static 364 // static
365 int FieldTrialList::FindValue(const std::string& name) { 365 int FieldTrialList::FindValue(const std::string& trial_name) {
366 FieldTrial* field_trial = Find(name); 366 FieldTrial* field_trial = Find(trial_name);
367 if (field_trial) 367 if (field_trial)
368 return field_trial->group(); 368 return field_trial->group();
369 return FieldTrial::kNotFinalized; 369 return FieldTrial::kNotFinalized;
370 } 370 }
371 371
372 // static 372 // static
373 std::string FieldTrialList::FindFullName(const std::string& name) { 373 std::string FieldTrialList::FindFullName(const std::string& trial_name) {
374 FieldTrial* field_trial = Find(name); 374 FieldTrial* field_trial = Find(trial_name);
375 if (field_trial) 375 if (field_trial)
376 return field_trial->group_name(); 376 return field_trial->group_name();
377 return std::string(); 377 return std::string();
378 } 378 }
379 379
380 // static 380 // static
381 bool FieldTrialList::TrialExists(const std::string& name) { 381 bool FieldTrialList::TrialExists(const std::string& trial_name) {
382 return Find(name) != NULL; 382 return Find(trial_name) != NULL;
383 } 383 }
384 384
385 // static 385 // static
386 bool FieldTrialList::IsTrialActive(const std::string& trial_name) {
387 FieldTrial* field_trial = Find(trial_name);
388 FieldTrial::ActiveGroup active_group;
389 return field_trial && field_trial->GetActiveGroup(&active_group);
390 }
391
392 // static
386 void FieldTrialList::StatesToString(std::string* output) { 393 void FieldTrialList::StatesToString(std::string* output) {
387 FieldTrial::ActiveGroups active_groups; 394 FieldTrial::ActiveGroups active_groups;
388 GetActiveFieldTrialGroups(&active_groups); 395 GetActiveFieldTrialGroups(&active_groups);
389 for (FieldTrial::ActiveGroups::const_iterator it = active_groups.begin(); 396 for (FieldTrial::ActiveGroups::const_iterator it = active_groups.begin();
390 it != active_groups.end(); ++it) { 397 it != active_groups.end(); ++it) {
391 DCHECK_EQ(std::string::npos, 398 DCHECK_EQ(std::string::npos,
392 it->trial_name.find(kPersistentStringSeparator)); 399 it->trial_name.find(kPersistentStringSeparator));
393 DCHECK_EQ(std::string::npos, 400 DCHECK_EQ(std::string::npos,
394 it->group_name.find(kPersistentStringSeparator)); 401 it->group_name.find(kPersistentStringSeparator));
395 output->append(it->trial_name); 402 output->append(it->trial_name);
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 return; 590 return;
584 } 591 }
585 AutoLock auto_lock(global_->lock_); 592 AutoLock auto_lock(global_->lock_);
586 DCHECK(!global_->PreLockedFind(trial->trial_name())); 593 DCHECK(!global_->PreLockedFind(trial->trial_name()));
587 trial->AddRef(); 594 trial->AddRef();
588 trial->SetTrialRegistered(); 595 trial->SetTrialRegistered();
589 global_->registered_[trial->trial_name()] = trial; 596 global_->registered_[trial->trial_name()] = trial;
590 } 597 }
591 598
592 } // namespace base 599 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/field_trial.h ('k') | components/variations/variations_associated_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698