Chromium Code Reviews| Index: base/feature_list.cc |
| diff --git a/base/feature_list.cc b/base/feature_list.cc |
| index 46732108dd6fcf0004e14b7ad6da06faf3561718..e1fa6f2787dcbc8a589b2bae1c5f74e64ff04dc7 100644 |
| --- a/base/feature_list.cc |
| +++ b/base/feature_list.cc |
| @@ -35,10 +35,7 @@ bool IsValidFeatureOrFieldTrialName(const std::string& name) { |
| } // namespace |
| -FeatureList::FeatureList() |
| - : initialized_(false), |
| - initialized_from_command_line_(false) { |
| -} |
| +FeatureList::FeatureList() {} |
| FeatureList::~FeatureList() {} |
| @@ -133,11 +130,19 @@ void FeatureList::GetFeatureOverrides(std::string* enable_overrides, |
| // static |
| bool FeatureList::IsEnabled(const Feature& feature) { |
| + if (!GetInstance()) { |
| + CHECK(InitializeInstance(std::string(), std::string())); |
|
Sergey Ulanov
2016/07/01 21:36:10
As discussed offline I think the problem here is t
Alexei Svitkine (slow)
2016/07/04 15:50:06
I don't think we want this class to use base::Sing
Sergey Ulanov
2016/07/04 16:52:53
base::Singleton<>::get() doesn't have any locks. I
Alexei Svitkine (slow)
2016/07/04 16:55:55
Still, that's more overhead than we have currently
joedow
2016/07/05 21:05:56
My concern with the feedback above is that I don't
Alexei Svitkine (slow)
2016/07/05 21:11:34
That's a good point. Returning default state SGTM.
|
| + GetInstance()->initialized_from_accessor_ = true; |
| + } |
| return GetInstance()->IsFeatureEnabled(feature); |
| } |
| // static |
| FieldTrial* FeatureList::GetFieldTrial(const Feature& feature) { |
| + if (!GetInstance()) { |
| + CHECK(InitializeInstance(std::string(), std::string())); |
| + GetInstance()->initialized_from_accessor_ = true; |
| + } |
| return GetInstance()->GetAssociatedFieldTrial(feature); |
| } |
| @@ -158,8 +163,12 @@ bool FeatureList::InitializeInstance(const std::string& enable_features, |
| // For example, we initialize an instance in chrome/browser/ |
| // chrome_browser_main.cc and do not override it in content/browser/ |
| // browser_main_loop.cc. |
| + // If the singleton was previously initialized from within an accessor, we |
| + // want to prevent callers from reinitializing the singleton and masking the |
| + // access call(s) which likely returned incorrect information. |
| bool instance_existed_before = false; |
| if (g_instance) { |
| + DCHECK(!g_instance->initialized_from_accessor_); |
| if (g_instance->initialized_from_command_line_) |
| return false; |