about_flags.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef CHROME_BROWSER_ABOUT_FLAGS_H_
  5. #define CHROME_BROWSER_ABOUT_FLAGS_H_
  6. #include <stddef.h>
  7. #include <stdint.h>
  8. #include <map>
  9. #include <set>
  10. #include <string>
  11. #include <vector>
  12. #include "base/command_line.h"
  13. #include "base/containers/span.h"
  14. #include "base/metrics/histogram_base.h"
  15. #include "base/values.h"
  16. #include "build/build_config.h"
  17. #include "components/flags_ui/feature_entry.h"
  18. #include "components/flags_ui/flags_state.h"
  19. namespace base {
  20. class FeatureList;
  21. }
  22. namespace flags_ui {
  23. class FlagsStorage;
  24. }
  25. namespace about_flags {
  26. // Returns true if the FeatureEntry should not be shown.
  27. bool ShouldSkipConditionalFeatureEntry(const flags_ui::FlagsStorage* storage,
  28. const flags_ui::FeatureEntry& entry);
  29. // Reads the state from |flags_storage| and adds the command line flags
  30. // belonging to the active feature entries to |command_line|.
  31. void ConvertFlagsToSwitches(flags_ui::FlagsStorage* flags_storage,
  32. base::CommandLine* command_line,
  33. flags_ui::SentinelsMode sentinels);
  34. // Registers variations parameter values selected for features in about:flags.
  35. // The selected flags are retrieved from |flags_storage|, the registered
  36. // variation parameters are connected to their corresponding features in
  37. // |feature_list|. Returns the (possibly empty) list of additional variation ids
  38. // to register in the MetricsService that come from variations selected using
  39. // chrome://flags.
  40. std::vector<std::string> RegisterAllFeatureVariationParameters(
  41. flags_ui::FlagsStorage* flags_storage,
  42. base::FeatureList* feature_list);
  43. // Gets the list of feature entries. Entries that are available for the current
  44. // platform are appended to |supported_entries|; all other entries are appended
  45. // to |unsupported_entries|.
  46. void GetFlagFeatureEntries(flags_ui::FlagsStorage* flags_storage,
  47. flags_ui::FlagAccess access,
  48. base::Value::List& supported_entries,
  49. base::Value::List& unsupported_entries);
  50. // Gets the list of feature entries for the deprecated flags page. Entries that
  51. // are available for the current platform are appended to |supported_entries|;
  52. // all other entries are appended to |unsupported_entries|.
  53. void GetFlagFeatureEntriesForDeprecatedPage(
  54. flags_ui::FlagsStorage* flags_storage,
  55. flags_ui::FlagAccess access,
  56. base::Value::List& supported_entries,
  57. base::Value::List& unsupported_entries);
  58. // Gets the FlagsState used in about_flags.
  59. flags_ui::FlagsState* GetCurrentFlagsState();
  60. // Returns true if one of the feature entry flags has been flipped since
  61. // startup.
  62. bool IsRestartNeededToCommitChanges();
  63. // Enables or disables the current with id |internal_name|.
  64. void SetFeatureEntryEnabled(flags_ui::FlagsStorage* flags_storage,
  65. const std::string& internal_name,
  66. bool enable);
  67. // Sets a flag value with a list of origins given by |value|. Origins in |value|
  68. // can be separated by a comma or whitespace. Invalid URLs will be dropped when
  69. // setting the command line flag.
  70. // E.g. SetOriginListFlag("test-flag",
  71. // "http://example.test1 http://example.test2",
  72. // flags_storage);
  73. // will add --test-flag=http://example.test to the command line.
  74. void SetOriginListFlag(const std::string& internal_name,
  75. const std::string& value,
  76. flags_ui::FlagsStorage* flags_storage);
  77. // Removes all switches that were added to a command line by a previous call to
  78. // |ConvertFlagsToSwitches()|.
  79. void RemoveFlagsSwitches(base::CommandLine::SwitchMap* switch_list);
  80. // Reset all flags to the default state by clearing all flags.
  81. void ResetAllFlags(flags_ui::FlagsStorage* flags_storage);
  82. #if BUILDFLAG(IS_CHROMEOS)
  83. // Show flags of the other browser (Lacros/Ash).
  84. void CrosUrlFlagsRedirect();
  85. #endif
  86. // Sends UMA stats about experimental flag usage. This should be called once per
  87. // startup.
  88. void RecordUMAStatistics(flags_ui::FlagsStorage* flags_storage,
  89. const std::string& histogram_name);
  90. namespace testing {
  91. // This class sets the testing feature entries to the feature entries passed in
  92. // to Init. It clears the testing feature entries on destruction, so
  93. // the feature entries return to their non test values.
  94. class ScopedFeatureEntries final {
  95. public:
  96. explicit ScopedFeatureEntries(
  97. const std::vector<flags_ui::FeatureEntry>& entries);
  98. ~ScopedFeatureEntries();
  99. };
  100. base::span<const flags_ui::FeatureEntry> GetFeatureEntries();
  101. } // namespace testing
  102. } // namespace about_flags
  103. #endif // CHROME_BROWSER_ABOUT_FLAGS_H_