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 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 | 359 |
360 for (RegistrationList::iterator it = global_->registered_.begin(); | 360 for (RegistrationList::iterator it = global_->registered_.begin(); |
361 it != global_->registered_.end(); ++it) { | 361 it != global_->registered_.end(); ++it) { |
362 FieldTrial::ActiveGroup active_group; | 362 FieldTrial::ActiveGroup active_group; |
363 if (it->second->GetActiveGroup(&active_group)) | 363 if (it->second->GetActiveGroup(&active_group)) |
364 active_groups->push_back(active_group); | 364 active_groups->push_back(active_group); |
365 } | 365 } |
366 } | 366 } |
367 | 367 |
368 // static | 368 // static |
369 bool FieldTrialList::CreateTrialsFromString(const std::string& trials_string) { | 369 bool FieldTrialList::CreateTrialsFromString(const std::string& trials_string, |
| 370 FieldTrialActivationMode mode) { |
370 DCHECK(global_); | 371 DCHECK(global_); |
371 if (trials_string.empty() || !global_) | 372 if (trials_string.empty() || !global_) |
372 return true; | 373 return true; |
373 | 374 |
374 size_t next_item = 0; | 375 size_t next_item = 0; |
375 while (next_item < trials_string.length()) { | 376 while (next_item < trials_string.length()) { |
376 size_t name_end = trials_string.find(kPersistentStringSeparator, next_item); | 377 size_t name_end = trials_string.find(kPersistentStringSeparator, next_item); |
377 if (name_end == trials_string.npos || next_item == name_end) | 378 if (name_end == trials_string.npos || next_item == name_end) |
378 return false; | 379 return false; |
379 size_t group_name_end = trials_string.find(kPersistentStringSeparator, | 380 size_t group_name_end = trials_string.find(kPersistentStringSeparator, |
380 name_end + 1); | 381 name_end + 1); |
381 if (group_name_end == trials_string.npos || name_end + 1 == group_name_end) | 382 if (group_name_end == trials_string.npos || name_end + 1 == group_name_end) |
382 return false; | 383 return false; |
383 std::string name(trials_string, next_item, name_end - next_item); | 384 std::string name(trials_string, next_item, name_end - next_item); |
384 std::string group_name(trials_string, name_end + 1, | 385 std::string group_name(trials_string, name_end + 1, |
385 group_name_end - name_end - 1); | 386 group_name_end - name_end - 1); |
386 next_item = group_name_end + 1; | 387 next_item = group_name_end + 1; |
387 | 388 |
388 FieldTrial* trial = CreateFieldTrial(name, group_name); | 389 FieldTrial* trial = CreateFieldTrial(name, group_name); |
389 if (!trial) | 390 if (!trial) |
390 return false; | 391 return false; |
391 // Call |group()| to mark the trial as "used" and notify observers, if any. | 392 if (mode == ACTIVATE_TRIALS) { |
392 // This is needed to ensure the trial is properly reported in child process | 393 // Call |group()| to mark the trial as "used" and notify observers, if |
393 // crash reports. | 394 // any. This is useful to ensure that field trials created in child |
394 trial->group(); | 395 // processes are properly reported in crash reports. |
| 396 trial->group(); |
| 397 } |
395 } | 398 } |
396 return true; | 399 return true; |
397 } | 400 } |
398 | 401 |
399 // static | 402 // static |
400 FieldTrial* FieldTrialList::CreateFieldTrial( | 403 FieldTrial* FieldTrialList::CreateFieldTrial( |
401 const std::string& name, | 404 const std::string& name, |
402 const std::string& group_name) { | 405 const std::string& group_name) { |
403 DCHECK(global_); | 406 DCHECK(global_); |
404 DCHECK_GE(name.size(), 0u); | 407 DCHECK_GE(name.size(), 0u); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 used_without_global_ = true; | 492 used_without_global_ = true; |
490 return; | 493 return; |
491 } | 494 } |
492 AutoLock auto_lock(global_->lock_); | 495 AutoLock auto_lock(global_->lock_); |
493 DCHECK(!global_->PreLockedFind(trial->trial_name())); | 496 DCHECK(!global_->PreLockedFind(trial->trial_name())); |
494 trial->AddRef(); | 497 trial->AddRef(); |
495 global_->registered_[trial->trial_name()] = trial; | 498 global_->registered_[trial->trial_name()] = trial; |
496 } | 499 } |
497 | 500 |
498 } // namespace base | 501 } // namespace base |
OLD | NEW |