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

Side by Side Diff: base/feature_list.cc

Issue 1471693007: Make FeatureList override state be plumbed to renderer processes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Match function order in header file. Created 5 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 | « base/feature_list.h ('k') | base/feature_list_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/feature_list.h" 5 #include "base/feature_list.h"
6 6
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 } 42 }
43 43
44 bool FeatureList::IsFeatureOverriddenFromCommandLine( 44 bool FeatureList::IsFeatureOverriddenFromCommandLine(
45 const std::string& feature_name, 45 const std::string& feature_name,
46 OverrideState state) const { 46 OverrideState state) const {
47 auto it = overrides_.find(feature_name); 47 auto it = overrides_.find(feature_name);
48 return it != overrides_.end() && it->second.overridden_state == state && 48 return it != overrides_.end() && it->second.overridden_state == state &&
49 !it->second.overridden_by_field_trial; 49 !it->second.overridden_by_field_trial;
50 } 50 }
51 51
52 void FeatureList::RegisterFieldTrialOverride(const std::string& feature_name,
53 OverrideState override_state,
54 FieldTrial* field_trial) {
55 DCHECK(field_trial);
56 DCHECK(!ContainsKey(overrides_, feature_name) ||
57 !overrides_.find(feature_name)->second.field_trial)
58 << "Feature " << feature_name
59 << " has conflicting field trial overrides: "
60 << overrides_.find(feature_name)->second.field_trial->trial_name()
61 << " / " << field_trial->trial_name();
62
63 RegisterOverride(feature_name, override_state, field_trial);
64 }
65
66 void FeatureList::AssociateReportingFieldTrial( 52 void FeatureList::AssociateReportingFieldTrial(
67 const std::string& feature_name, 53 const std::string& feature_name,
68 OverrideState for_overridden_state, 54 OverrideState for_overridden_state,
69 FieldTrial* field_trial) { 55 FieldTrial* field_trial) {
70 DCHECK( 56 DCHECK(
71 IsFeatureOverriddenFromCommandLine(feature_name, for_overridden_state)); 57 IsFeatureOverriddenFromCommandLine(feature_name, for_overridden_state));
72 58
73 // Only one associated field trial is supported per feature. This is generally 59 // Only one associated field trial is supported per feature. This is generally
74 // enforced server-side. 60 // enforced server-side.
75 OverrideEntry* entry = &overrides_.find(feature_name)->second; 61 OverrideEntry* entry = &overrides_.find(feature_name)->second;
76 if (entry->field_trial) { 62 if (entry->field_trial) {
77 NOTREACHED() << "Feature " << feature_name 63 NOTREACHED() << "Feature " << feature_name
78 << " already has trial: " << entry->field_trial->trial_name() 64 << " already has trial: " << entry->field_trial->trial_name()
79 << ", associating trial: " << field_trial->trial_name(); 65 << ", associating trial: " << field_trial->trial_name();
80 return; 66 return;
81 } 67 }
82 68
83 entry->field_trial = field_trial; 69 entry->field_trial = field_trial;
84 } 70 }
85 71
72 void FeatureList::RegisterFieldTrialOverride(const std::string& feature_name,
73 OverrideState override_state,
74 FieldTrial* field_trial) {
75 DCHECK(field_trial);
76 DCHECK(!ContainsKey(overrides_, feature_name) ||
77 !overrides_.find(feature_name)->second.field_trial)
78 << "Feature " << feature_name
79 << " has conflicting field trial overrides: "
80 << overrides_.find(feature_name)->second.field_trial->trial_name()
81 << " / " << field_trial->trial_name();
82
83 RegisterOverride(feature_name, override_state, field_trial);
84 }
85
86 void FeatureList::GetFeatureOverrides(std::string* enable_overrides,
87 std::string* disable_overrides) {
88 DCHECK(initialized_);
89
90 enable_overrides->clear();
91 disable_overrides->clear();
92
93 for (const auto& entry : overrides_) {
94 switch (entry.second.overridden_state) {
95 case OVERRIDE_ENABLE_FEATURE:
96 if (!enable_overrides->empty())
97 enable_overrides->push_back(',');
98 enable_overrides->append(entry.first);
99 break;
100 case OVERRIDE_DISABLE_FEATURE:
101 if (!disable_overrides->empty())
102 disable_overrides->push_back(',');
103 disable_overrides->append(entry.first);
104 break;
105 }
106 }
107 }
108
86 // static 109 // static
87 bool FeatureList::IsEnabled(const Feature& feature) { 110 bool FeatureList::IsEnabled(const Feature& feature) {
88 return GetInstance()->IsFeatureEnabled(feature); 111 return GetInstance()->IsFeatureEnabled(feature);
89 } 112 }
90 113
91 // static 114 // static
92 std::vector<std::string> FeatureList::SplitFeatureListString( 115 std::vector<std::string> FeatureList::SplitFeatureListString(
93 const std::string& input) { 116 const std::string& input) {
94 return SplitString(input, ",", TRIM_WHITESPACE, SPLIT_WANT_NONEMPTY); 117 return SplitString(input, ",", TRIM_WHITESPACE, SPLIT_WANT_NONEMPTY);
95 } 118 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 return it->second == &feature; 192 return it->second == &feature;
170 } 193 }
171 194
172 FeatureList::OverrideEntry::OverrideEntry(OverrideState overridden_state, 195 FeatureList::OverrideEntry::OverrideEntry(OverrideState overridden_state,
173 FieldTrial* field_trial) 196 FieldTrial* field_trial)
174 : overridden_state(overridden_state), 197 : overridden_state(overridden_state),
175 field_trial(field_trial), 198 field_trial(field_trial),
176 overridden_by_field_trial(field_trial != nullptr) {} 199 overridden_by_field_trial(field_trial != nullptr) {}
177 200
178 } // namespace base 201 } // namespace base
OLDNEW
« no previous file with comments | « base/feature_list.h ('k') | base/feature_list_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698