1 // Copyright 2019 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef BASE_SCOPED_ADD_FEATURE_FLAGS_H_
6 #define BASE_SCOPED_ADD_FEATURE_FLAGS_H_
11 #include "base/base_export.h"
12 #include "base/feature_list.h"
13 #include "base/memory/raw_ptr.h"
19 // Helper class to enable and disable features if they are not already set in
20 // the command line. It reads the command line on construction, allows user to
21 // enable and disable features during its lifetime, and writes the modified
22 // --enable-features=... and --disable-features=... flags back to the command
23 // line on destruction.
24 class BASE_EXPORT ScopedAddFeatureFlags {
26 explicit ScopedAddFeatureFlags(CommandLine* command_line);
28 ScopedAddFeatureFlags(const ScopedAddFeatureFlags&) = delete;
29 ScopedAddFeatureFlags& operator=(const ScopedAddFeatureFlags&) = delete;
31 ~ScopedAddFeatureFlags();
33 // Any existing (user set) enable/disable takes precedence.
34 void EnableIfNotSet(const Feature& feature);
35 void DisableIfNotSet(const Feature& feature);
36 void EnableIfNotSetWithParameter(const Feature& feature,
40 // Check if the feature is enabled from command line or functions above
41 bool IsEnabled(const Feature& feature);
43 // Check if the feature with the given parameter name and value is enabled
44 // from command line or functions above. An empty parameter name means that we
45 // are checking if the feature is enabled without any parameter.
46 bool IsEnabledWithParameter(const Feature& feature,
47 StringPiece parameter_name,
48 StringPiece parameter_value);
51 void AddFeatureIfNotSet(const Feature& feature,
55 const raw_ptr<CommandLine> command_line_;
56 std::vector<std::string> enabled_features_;
57 std::vector<std::string> disabled_features_;
62 #endif // BASE_SCOPED_ADD_FEATURE_FLAGS_H_