Skip to content

Commit

Permalink
Support base::Feature entries in chrome://flags.
Browse files Browse the repository at this point in the history
Since base::Features already support toggling via --enable-features=
and --disable-features= flags, integrate with those.

Changes some if statements on FeatureEntry.type to be switch
statements so that future changes to the enum without updating them
result in compile errors.

BUG=544158

Review URL: https://codereview.chromium.org/1408783002

Cr-Commit-Position: refs/heads/master@{#355419}
  • Loading branch information
asvitkine-chromium authored and Commit bot committed Oct 21, 2015
1 parent ac88d90 commit 03007d0
Show file tree
Hide file tree
Showing 6 changed files with 492 additions and 215 deletions.
11 changes: 6 additions & 5 deletions base/feature_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ namespace {
// have more control over initialization timing. Leaky.
FeatureList* g_instance = nullptr;

// Splits a comma-separated string containing feature names into a vector.
std::vector<std::string> SplitFeatureListString(const std::string& input) {
return SplitString(input, ",", TRIM_WHITESPACE, SPLIT_WANT_NONEMPTY);
}

} // namespace

FeatureList::FeatureList() : initialized_(false) {}
Expand Down Expand Up @@ -93,6 +88,12 @@ bool FeatureList::IsEnabled(const Feature& feature) {
return GetInstance()->IsFeatureEnabled(feature);
}

// static
std::vector<std::string> FeatureList::SplitFeatureListString(
const std::string& input) {
return SplitString(input, ",", TRIM_WHITESPACE, SPLIT_WANT_NONEMPTY);
}

// static
FeatureList* FeatureList::GetInstance() {
return g_instance;
Expand Down
7 changes: 6 additions & 1 deletion base/feature_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <map>
#include <string>
#include <vector>

#include "base/base_export.h"
#include "base/basictypes.h"
Expand Down Expand Up @@ -44,7 +45,7 @@ struct BASE_EXPORT Feature {
// The basic use case is for any feature that can be toggled (e.g. through
// command-line or an experiment) to have a defined Feature struct, e.g.:
//
// struct base::Feature kMyGreatFeature {
// const base::Feature kMyGreatFeature {
// "MyGreatFeature", base::FEATURE_ENABLED_BY_DEFAULT
// };
//
Expand Down Expand Up @@ -122,6 +123,10 @@ class BASE_EXPORT FeatureList {
// struct, which is checked in builds with DCHECKs enabled.
static bool IsEnabled(const Feature& feature);

// Splits a comma-separated string containing feature names into a vector.
static std::vector<std::string> SplitFeatureListString(
const std::string& input);

// Returns the singleton instance of FeatureList. Will return null until an
// instance is registered via SetInstance().
static FeatureList* GetInstance();
Expand Down
Loading

0 comments on commit 03007d0

Please sign in to comment.