| 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 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 std::set<std::string>& ignored_trial_names) { |
| 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 |
| 424 if (ignored_trial_names.find(name) != ignored_trial_names.end()) |
| 425 continue; |
| 426 |
| 422 FieldTrial* trial = CreateFieldTrial(name, group_name); | 427 FieldTrial* trial = CreateFieldTrial(name, group_name); |
| 423 if (!trial) | 428 if (!trial) |
| 424 return false; | 429 return false; |
| 425 if (mode == ACTIVATE_TRIALS) { | 430 if (mode == ACTIVATE_TRIALS) { |
| 426 // Call |group()| to mark the trial as "used" and notify observers, if | 431 // Call |group()| to mark the trial as "used" and notify observers, if |
| 427 // any. This is useful to ensure that field trials created in child | 432 // any. This is useful to ensure that field trials created in child |
| 428 // processes are properly reported in crash reports. | 433 // processes are properly reported in crash reports. |
| 429 trial->group(); | 434 trial->group(); |
| 430 } | 435 } |
| 431 } | 436 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 return; | 531 return; |
| 527 } | 532 } |
| 528 AutoLock auto_lock(global_->lock_); | 533 AutoLock auto_lock(global_->lock_); |
| 529 DCHECK(!global_->PreLockedFind(trial->trial_name())); | 534 DCHECK(!global_->PreLockedFind(trial->trial_name())); |
| 530 trial->AddRef(); | 535 trial->AddRef(); |
| 531 trial->SetTrialRegistered(); | 536 trial->SetTrialRegistered(); |
| 532 global_->registered_[trial->trial_name()] = trial; | 537 global_->registered_[trial->trial_name()] = trial; |
| 533 } | 538 } |
| 534 | 539 |
| 535 } // namespace base | 540 } // namespace base |
| OLD | NEW |