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

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

Issue 700953002: Send all field trials from the browser. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@finch4
Patch Set: Created 6 years, 1 month 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
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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 216
217 bool FieldTrial::GetActiveGroup(ActiveGroup* active_group) const { 217 bool FieldTrial::GetActiveGroup(ActiveGroup* active_group) const {
218 if (!group_reported_ || !enable_field_trial_) 218 if (!group_reported_ || !enable_field_trial_)
219 return false; 219 return false;
220 DCHECK_NE(group_, kNotFinalized); 220 DCHECK_NE(group_, kNotFinalized);
221 active_group->trial_name = trial_name_; 221 active_group->trial_name = trial_name_;
222 active_group->group_name = group_name_; 222 active_group->group_name = group_name_;
223 return true; 223 return true;
224 } 224 }
225 225
226 bool FieldTrial::GetAllGroup(AllGroup* all_group) const {
227 if (!enable_field_trial_)
228 return false;
229 all_group->trial_name = trial_name_;
230 all_group->group_name = group_name_;
231 all_group->activated = group_reported_;
232 return true;
233 }
234
226 //------------------------------------------------------------------------------ 235 //------------------------------------------------------------------------------
227 // FieldTrialList methods and members. 236 // FieldTrialList methods and members.
228 237
229 // static 238 // static
230 FieldTrialList* FieldTrialList::global_ = NULL; 239 FieldTrialList* FieldTrialList::global_ = NULL;
231 240
232 // static 241 // static
233 bool FieldTrialList::used_without_global_ = false; 242 bool FieldTrialList::used_without_global_ = false;
234 243
235 FieldTrialList::Observer::~Observer() { 244 FieldTrialList::Observer::~Observer() {
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 DCHECK_EQ(std::string::npos, 389 DCHECK_EQ(std::string::npos,
381 it->group_name.find(kPersistentStringSeparator)); 390 it->group_name.find(kPersistentStringSeparator));
382 output->append(it->trial_name); 391 output->append(it->trial_name);
383 output->append(1, kPersistentStringSeparator); 392 output->append(1, kPersistentStringSeparator);
384 output->append(it->group_name); 393 output->append(it->group_name);
385 output->append(1, kPersistentStringSeparator); 394 output->append(1, kPersistentStringSeparator);
386 } 395 }
387 } 396 }
388 397
389 // static 398 // static
399 void FieldTrialList::AllStatesToString(std::string* output) {
400 FieldTrial::AllGroups all_groups;
401 GetAllFieldTrialGroups(&all_groups);
402 for (FieldTrial::AllGroups::const_iterator it = all_groups.begin();
403 it != all_groups.end(); ++it) {
Alexei Svitkine (slow) 2014/11/05 16:17:13 Nit: We now support C++11, so this can be: for (c
Georges Khalil 2014/11/05 20:00:12 Done.
404 DCHECK_EQ(std::string::npos,
405 it->trial_name.find(kPersistentStringSeparator));
406 DCHECK_EQ(std::string::npos,
407 it->group_name.find(kPersistentStringSeparator));
408 if (it->activated)
409 output->append(1, kActivationMarker);
410 output->append(it->trial_name);
411 output->append(1, kPersistentStringSeparator);
412 output->append(it->group_name);
413 output->append(1, kPersistentStringSeparator);
414 }
415 }
416
417 // static
390 void FieldTrialList::GetActiveFieldTrialGroups( 418 void FieldTrialList::GetActiveFieldTrialGroups(
391 FieldTrial::ActiveGroups* active_groups) { 419 FieldTrial::ActiveGroups* active_groups) {
392 DCHECK(active_groups->empty()); 420 DCHECK(active_groups->empty());
393 if (!global_) 421 if (!global_)
394 return; 422 return;
395 AutoLock auto_lock(global_->lock_); 423 AutoLock auto_lock(global_->lock_);
396 424
397 for (RegistrationMap::iterator it = global_->registered_.begin(); 425 for (RegistrationMap::iterator it = global_->registered_.begin();
398 it != global_->registered_.end(); ++it) { 426 it != global_->registered_.end(); ++it) {
399 FieldTrial::ActiveGroup active_group; 427 FieldTrial::ActiveGroup active_group;
400 if (it->second->GetActiveGroup(&active_group)) 428 if (it->second->GetActiveGroup(&active_group))
401 active_groups->push_back(active_group); 429 active_groups->push_back(active_group);
402 } 430 }
403 } 431 }
404 432
405 // static 433 // static
434 void FieldTrialList::GetAllFieldTrialGroups(
435 FieldTrial::AllGroups* all_groups) {
436 DCHECK(all_groups->empty());
437 if (!global_)
438 return;
439 AutoLock auto_lock(global_->lock_);
440
441 for (RegistrationMap::iterator it = global_->registered_.begin();
442 it != global_->registered_.end(); ++it) {
443 FieldTrial::AllGroup all_group;
444 if (it->second->GetAllGroup(&all_group))
445 all_groups->push_back(all_group);
446 }
447 }
448
449 // static
406 bool FieldTrialList::CreateTrialsFromString( 450 bool FieldTrialList::CreateTrialsFromString(
407 const std::string& trials_string, 451 const std::string& trials_string,
408 FieldTrialActivationMode mode, 452 FieldTrialActivationMode mode,
409 const std::set<std::string>& ignored_trial_names) { 453 const std::set<std::string>& ignored_trial_names) {
410 DCHECK(global_); 454 DCHECK(global_);
411 if (trials_string.empty() || !global_) 455 if (trials_string.empty() || !global_)
412 return true; 456 return true;
413 457
414 size_t next_item = 0; 458 size_t next_item = 0;
415 while (next_item < trials_string.length()) { 459 while (next_item < trials_string.length()) {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 return; 592 return;
549 } 593 }
550 AutoLock auto_lock(global_->lock_); 594 AutoLock auto_lock(global_->lock_);
551 DCHECK(!global_->PreLockedFind(trial->trial_name())); 595 DCHECK(!global_->PreLockedFind(trial->trial_name()));
552 trial->AddRef(); 596 trial->AddRef();
553 trial->SetTrialRegistered(); 597 trial->SetTrialRegistered();
554 global_->registered_[trial->trial_name()] = trial; 598 global_->registered_[trial->trial_name()] = trial;
555 } 599 }
556 600
557 } // namespace base 601 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698