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

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

Issue 2463223002: Store field trial parameters in shared memory (Closed)
Patch Set: fix tests Created 4 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 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/debug/stack_trace.h"
7 #include "base/metrics/field_trial.h" 8 #include "base/metrics/field_trial.h"
8 9
9 namespace base { 10 namespace base {
10 11
11 FieldTrialParamAssociator::FieldTrialParamAssociator() {} 12 FieldTrialParamAssociator::FieldTrialParamAssociator() {}
12 FieldTrialParamAssociator::~FieldTrialParamAssociator() {} 13 FieldTrialParamAssociator::~FieldTrialParamAssociator() {}
13 14
14 // static 15 // static
15 FieldTrialParamAssociator* FieldTrialParamAssociator::GetInstance() { 16 FieldTrialParamAssociator* FieldTrialParamAssociator::GetInstance() {
16 return Singleton<FieldTrialParamAssociator, 17 return Singleton<FieldTrialParamAssociator,
(...skipping 13 matching lines...) Expand all
30 if (ContainsKey(field_trial_params_, key)) 31 if (ContainsKey(field_trial_params_, key))
31 return false; 32 return false;
32 33
33 field_trial_params_[key] = params; 34 field_trial_params_[key] = params;
34 return true; 35 return true;
35 } 36 }
36 37
37 bool FieldTrialParamAssociator::GetFieldTrialParams( 38 bool FieldTrialParamAssociator::GetFieldTrialParams(
38 const std::string& trial_name, 39 const std::string& trial_name,
39 FieldTrialParams* params) { 40 FieldTrialParams* params) {
41 FieldTrial* field_trial = FieldTrialList::Find(trial_name);
42 if (!field_trial)
43 return false;
44 const FieldTrialKey key(trial_name, field_trial->group_name());
45
46 // We have to scope down here, since calling group_name() might result in a
47 // call to AddToAllocatorWhileLocked(), which might call
Alexei Svitkine (slow) 2016/11/22 17:46:37 So one consequence of this set up is that all fiel
lawrencewu 2016/11/22 20:25:44 Done.
48 // GetFieldTrialParamsWithoutFallback() and cause a deadlock.
40 AutoLock scoped_lock(lock_); 49 AutoLock scoped_lock(lock_);
41
42 const std::string group_name = FieldTrialList::FindFullName(trial_name);
43 const FieldTrialKey key(trial_name, group_name);
44 if (!ContainsKey(field_trial_params_, key)) 50 if (!ContainsKey(field_trial_params_, key))
45 return false; 51 return FieldTrialList::GetParamsFromSharedMemory(field_trial, params);
Alexei Svitkine (slow) 2016/11/22 17:46:37 Please add a comment explaining the flow for futur
lawrencewu 2016/11/22 20:25:44 Done.
46 52
47 *params = field_trial_params_[key]; 53 *params = field_trial_params_[key];
48 return true; 54 return true;
49 } 55 }
50 56
57 void FieldTrialParamAssociator::GetFieldTrialParamsWithoutFallback(
58 const std::string& trial_name,
59 const std::string& group_name,
60 FieldTrialParams* params) {
61 AutoLock scoped_lock(lock_);
62
63 const FieldTrialKey key(trial_name, group_name);
64 if (!ContainsKey(field_trial_params_, key))
65 return;
66
67 *params = field_trial_params_[key];
68 }
69
51 void FieldTrialParamAssociator::ClearAllParamsForTesting() { 70 void FieldTrialParamAssociator::ClearAllParamsForTesting() {
52 AutoLock scoped_lock(lock_); 71 AutoLock scoped_lock(lock_);
53 field_trial_params_.clear(); 72 field_trial_params_.clear();
73 FieldTrialList::ClearParamsFromSharedMemoryForTesting();
74 }
75
76 void FieldTrialParamAssociator::ClearAllCachedParamsForTesting() {
77 AutoLock scoped_lock(lock_);
78 field_trial_params_.clear();
54 } 79 }
55 80
56 } // namespace base 81 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698