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 bool activate_trials) { | |
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 // Call |group()| to mark the trial as "used" and notify observers, if any. |
392 // This is needed to ensure the trial is properly reported in child process | 393 // This is needed to ensure the trial is properly reported in child process |
393 // crash reports. | 394 // crash reports. |
Ilya Sherman
2013/06/28 00:58:07
nit: Please move this comment inside the if-stmt,
Alexei Svitkine (slow)
2013/06/28 17:05:15
Done.
| |
394 trial->group(); | 395 if (activate_trials) |
396 trial->group(); | |
395 } | 397 } |
396 return true; | 398 return true; |
397 } | 399 } |
398 | 400 |
399 // static | 401 // static |
400 FieldTrial* FieldTrialList::CreateFieldTrial( | 402 FieldTrial* FieldTrialList::CreateFieldTrial( |
401 const std::string& name, | 403 const std::string& name, |
402 const std::string& group_name) { | 404 const std::string& group_name) { |
403 DCHECK(global_); | 405 DCHECK(global_); |
404 DCHECK_GE(name.size(), 0u); | 406 DCHECK_GE(name.size(), 0u); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
489 used_without_global_ = true; | 491 used_without_global_ = true; |
490 return; | 492 return; |
491 } | 493 } |
492 AutoLock auto_lock(global_->lock_); | 494 AutoLock auto_lock(global_->lock_); |
493 DCHECK(!global_->PreLockedFind(trial->trial_name())); | 495 DCHECK(!global_->PreLockedFind(trial->trial_name())); |
494 trial->AddRef(); | 496 trial->AddRef(); |
495 global_->registered_[trial->trial_name()] = trial; | 497 global_->registered_[trial->trial_name()] = trial; |
496 } | 498 } |
497 | 499 |
498 } // namespace base | 500 } // namespace base |
OLD | NEW |