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

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

Issue 2564143003: TSAN startup fix (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_param_associator.h" 5 #include "base/metrics/field_trial_param_associator.h"
6 6
7 #include "base/metrics/field_trial.h" 7 #include "base/metrics/field_trial.h"
8 8
9 namespace base { 9 namespace base {
10 10
11 FieldTrialParamAssociator::FieldTrialParamAssociator() {} 11 FieldTrialParamAssociator::FieldTrialParamAssociator() {}
12 FieldTrialParamAssociator::~FieldTrialParamAssociator() {} 12 FieldTrialParamAssociator::~FieldTrialParamAssociator() {}
13 13
14 // static 14 // static
15 FieldTrialParamAssociator* FieldTrialParamAssociator::GetInstance() { 15 FieldTrialParamAssociator* FieldTrialParamAssociator::GetInstance() {
16 return Singleton<FieldTrialParamAssociator, 16 return Singleton<FieldTrialParamAssociator,
17 LeakySingletonTraits<FieldTrialParamAssociator>>::get(); 17 LeakySingletonTraits<FieldTrialParamAssociator>>::get();
18 } 18 }
19 19
20 bool FieldTrialParamAssociator::AssociateFieldTrialParams( 20 bool FieldTrialParamAssociator::AssociateFieldTrialParams(
21 const std::string& trial_name, 21 const std::string& trial_name,
22 const std::string& group_name, 22 const std::string& group_name,
23 const FieldTrialParams& params) { 23 const FieldTrialParams& params) {
24 AutoLock scoped_lock(lock_);
25
26 if (FieldTrialList::IsTrialActive(trial_name)) 24 if (FieldTrialList::IsTrialActive(trial_name))
27 return false; 25 return false;
28 26
27 AutoLock scoped_lock(lock_);
29 const FieldTrialKey key(trial_name, group_name); 28 const FieldTrialKey key(trial_name, group_name);
30 if (ContainsKey(field_trial_params_, key)) 29 if (ContainsKey(field_trial_params_, key))
31 return false; 30 return false;
32 31
33 field_trial_params_[key] = params; 32 field_trial_params_[key] = params;
34 return true; 33 return true;
35 } 34 }
36 35
37 bool FieldTrialParamAssociator::GetFieldTrialParams( 36 bool FieldTrialParamAssociator::GetFieldTrialParams(
38 const std::string& trial_name, 37 const std::string& trial_name,
39 FieldTrialParams* params) { 38 FieldTrialParams* params) {
40 AutoLock scoped_lock(lock_); 39 AutoLock scoped_lock(lock_);
41 40
42 const std::string group_name = FieldTrialList::FindFullName(trial_name); 41 const std::string group_name = FieldTrialList::FindFullName(trial_name);
43 const FieldTrialKey key(trial_name, group_name); 42 const FieldTrialKey key(trial_name, group_name);
44 if (!ContainsKey(field_trial_params_, key)) 43 if (!ContainsKey(field_trial_params_, key))
45 return false; 44 return false;
46 45
47 *params = field_trial_params_[key]; 46 *params = field_trial_params_[key];
48 return true; 47 return true;
49 } 48 }
50 49
51 void FieldTrialParamAssociator::ClearAllParamsForTesting() { 50 void FieldTrialParamAssociator::ClearAllParamsForTesting() {
52 AutoLock scoped_lock(lock_); 51 AutoLock scoped_lock(lock_);
53 field_trial_params_.clear(); 52 field_trial_params_.clear();
54 } 53 }
55 54
56 } // namespace base 55 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698