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

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: Responded to comments. 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::GetFieldTrialState(FieldTrialState* field_trial_state) const {
227 if (!enable_field_trial_)
228 return false;
229 field_trial_state->trial_name = trial_name_;
230 field_trial_state->group_name = group_name_;
231 field_trial_state->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 (const FieldTrial::FieldTrialState& trial : all_groups) {
403 DCHECK_EQ(std::string::npos,
404 trial.trial_name.find(kPersistentStringSeparator));
405 DCHECK_EQ(std::string::npos,
406 trial.group_name.find(kPersistentStringSeparator));
407 if (trial.activated)
408 output->append(1, kActivationMarker);
409 output->append(trial.trial_name);
410 output->append(1, kPersistentStringSeparator);
411 output->append(trial.group_name);
412 output->append(1, kPersistentStringSeparator);
413 }
414 }
415
416 // static
390 void FieldTrialList::GetActiveFieldTrialGroups( 417 void FieldTrialList::GetActiveFieldTrialGroups(
391 FieldTrial::ActiveGroups* active_groups) { 418 FieldTrial::ActiveGroups* active_groups) {
392 DCHECK(active_groups->empty()); 419 DCHECK(active_groups->empty());
393 if (!global_) 420 if (!global_)
394 return; 421 return;
395 AutoLock auto_lock(global_->lock_); 422 AutoLock auto_lock(global_->lock_);
396 423
397 for (RegistrationMap::iterator it = global_->registered_.begin(); 424 for (RegistrationMap::iterator it = global_->registered_.begin();
398 it != global_->registered_.end(); ++it) { 425 it != global_->registered_.end(); ++it) {
399 FieldTrial::ActiveGroup active_group; 426 FieldTrial::ActiveGroup active_group;
400 if (it->second->GetActiveGroup(&active_group)) 427 if (it->second->GetActiveGroup(&active_group))
401 active_groups->push_back(active_group); 428 active_groups->push_back(active_group);
402 } 429 }
403 } 430 }
404 431
405 // static 432 // static
433 void FieldTrialList::GetAllFieldTrialGroups(
Alexei Svitkine (slow) 2014/11/05 22:50:53 Hmm, actually if this method is private, I suggest
Georges Khalil 2014/11/06 18:36:28 Done.
434 FieldTrial::AllGroups* all_groups) {
435 DCHECK(all_groups->empty());
436 if (!global_)
437 return;
438 AutoLock auto_lock(global_->lock_);
439
440 for (const auto& it : global_->registered_) {
Alexei Svitkine (slow) 2014/11/05 22:50:53 Nit: I prefer to explicitly name the type for clar
Georges Khalil 2014/11/06 18:36:28 Type is std::pair<string, base::FieldTrial *> and
441 FieldTrial::FieldTrialState field_trial_state;
442 if (it.second->GetFieldTrialState(&field_trial_state))
443 all_groups->push_back(field_trial_state);
444 }
445 }
446
447 // static
406 bool FieldTrialList::CreateTrialsFromString( 448 bool FieldTrialList::CreateTrialsFromString(
407 const std::string& trials_string, 449 const std::string& trials_string,
408 FieldTrialActivationMode mode, 450 FieldTrialActivationMode mode,
409 const std::set<std::string>& ignored_trial_names) { 451 const std::set<std::string>& ignored_trial_names) {
410 DCHECK(global_); 452 DCHECK(global_);
411 if (trials_string.empty() || !global_) 453 if (trials_string.empty() || !global_)
412 return true; 454 return true;
413 455
414 size_t next_item = 0; 456 size_t next_item = 0;
415 while (next_item < trials_string.length()) { 457 while (next_item < trials_string.length()) {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 return; 590 return;
549 } 591 }
550 AutoLock auto_lock(global_->lock_); 592 AutoLock auto_lock(global_->lock_);
551 DCHECK(!global_->PreLockedFind(trial->trial_name())); 593 DCHECK(!global_->PreLockedFind(trial->trial_name()));
552 trial->AddRef(); 594 trial->AddRef();
553 trial->SetTrialRegistered(); 595 trial->SetTrialRegistered();
554 global_->registered_[trial->trial_name()] = trial; 596 global_->registered_[trial->trial_name()] = trial;
555 } 597 }
556 598
557 } // namespace base 599 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698