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

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

Issue 153913009: Make some field trials unforceable via command-line in the official build. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
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 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 392
393 for (RegistrationMap::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(
403 FieldTrialActivationMode mode) { 403 const std::string& trials_string,
404 FieldTrialActivationMode mode,
405 const IsAcceptedFieldTrialCallback& is_accepted_callback) {
404 DCHECK(global_); 406 DCHECK(global_);
405 if (trials_string.empty() || !global_) 407 if (trials_string.empty() || !global_)
406 return true; 408 return true;
407 409
408 size_t next_item = 0; 410 size_t next_item = 0;
409 while (next_item < trials_string.length()) { 411 while (next_item < trials_string.length()) {
410 size_t name_end = trials_string.find(kPersistentStringSeparator, next_item); 412 size_t name_end = trials_string.find(kPersistentStringSeparator, next_item);
411 if (name_end == trials_string.npos || next_item == name_end) 413 if (name_end == trials_string.npos || next_item == name_end)
412 return false; 414 return false;
413 size_t group_name_end = trials_string.find(kPersistentStringSeparator, 415 size_t group_name_end = trials_string.find(kPersistentStringSeparator,
414 name_end + 1); 416 name_end + 1);
415 if (group_name_end == trials_string.npos || name_end + 1 == group_name_end) 417 if (group_name_end == trials_string.npos || name_end + 1 == group_name_end)
416 return false; 418 return false;
417 std::string name(trials_string, next_item, name_end - next_item); 419 std::string name(trials_string, next_item, name_end - next_item);
418 std::string group_name(trials_string, name_end + 1, 420 std::string group_name(trials_string, name_end + 1,
419 group_name_end - name_end - 1); 421 group_name_end - name_end - 1);
420 next_item = group_name_end + 1; 422 next_item = group_name_end + 1;
421 423
422 FieldTrial* trial = CreateFieldTrial(name, group_name); 424 if (is_accepted_callback.is_null() || is_accepted_callback.Run(name)) {
423 if (!trial) 425 FieldTrial* trial = CreateFieldTrial(name, group_name);
424 return false; 426 if (!trial)
425 if (mode == ACTIVATE_TRIALS) { 427 return false;
426 // Call |group()| to mark the trial as "used" and notify observers, if 428 if (mode == ACTIVATE_TRIALS) {
427 // any. This is useful to ensure that field trials created in child 429 // Call |group()| to mark the trial as "used" and notify observers, if
428 // processes are properly reported in crash reports. 430 // any. This is useful to ensure that field trials created in child
429 trial->group(); 431 // processes are properly reported in crash reports.
432 trial->group();
433 }
430 } 434 }
431 } 435 }
432 return true; 436 return true;
433 } 437 }
434 438
435 // static 439 // static
436 FieldTrial* FieldTrialList::CreateFieldTrial( 440 FieldTrial* FieldTrialList::CreateFieldTrial(
437 const std::string& name, 441 const std::string& name,
438 const std::string& group_name) { 442 const std::string& group_name) {
439 DCHECK(global_); 443 DCHECK(global_);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 return; 530 return;
527 } 531 }
528 AutoLock auto_lock(global_->lock_); 532 AutoLock auto_lock(global_->lock_);
529 DCHECK(!global_->PreLockedFind(trial->trial_name())); 533 DCHECK(!global_->PreLockedFind(trial->trial_name()));
530 trial->AddRef(); 534 trial->AddRef();
531 trial->SetTrialRegistered(); 535 trial->SetTrialRegistered();
532 global_->registered_[trial->trial_name()] = trial; 536 global_->registered_[trial->trial_name()] = trial;
533 } 537 }
534 538
535 } // namespace base 539 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698