command_line_pref_store.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright (c) 2016 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 COMPONENTS_PREFS_COMMAND_LINE_PREF_STORE_H_
  5. #define COMPONENTS_PREFS_COMMAND_LINE_PREF_STORE_H_
  6. #include "base/command_line.h"
  7. #include "base/memory/raw_ptr.h"
  8. #include "components/prefs/value_map_pref_store.h"
  9. // Base class for a PrefStore that maps command line switches to preferences.
  10. // The Apply...Switches() methods can be called by subclasses with their own
  11. // maps, or delegated to other code.
  12. class COMPONENTS_PREFS_EXPORT CommandLinePrefStore : public ValueMapPrefStore {
  13. public:
  14. struct SwitchToPreferenceMapEntry {
  15. const char* switch_name;
  16. const char* preference_path;
  17. };
  18. // |set_value| indicates what the preference should be set to if the switch
  19. // is present.
  20. struct BooleanSwitchToPreferenceMapEntry {
  21. const char* switch_name;
  22. const char* preference_path;
  23. bool set_value;
  24. };
  25. CommandLinePrefStore(const CommandLinePrefStore&) = delete;
  26. CommandLinePrefStore& operator=(const CommandLinePrefStore&) = delete;
  27. // Apply command-line switches to the corresponding preferences of the switch
  28. // map, where the value associated with the switch is a string.
  29. void ApplyStringSwitches(
  30. const SwitchToPreferenceMapEntry string_switch_map[], size_t size);
  31. // Apply command-line switches to the corresponding preferences of the switch
  32. // map, where the value associated with the switch is a path.
  33. void ApplyPathSwitches(const SwitchToPreferenceMapEntry path_switch_map[],
  34. size_t size);
  35. // Apply command-line switches to the corresponding preferences of the switch
  36. // map, where the value associated with the switch is an integer.
  37. void ApplyIntegerSwitches(
  38. const SwitchToPreferenceMapEntry integer_switch_map[], size_t size);
  39. // Apply command-line switches to the corresponding preferences of the
  40. // boolean switch map.
  41. void ApplyBooleanSwitches(
  42. const BooleanSwitchToPreferenceMapEntry boolean_switch_map[],
  43. size_t size);
  44. protected:
  45. explicit CommandLinePrefStore(const base::CommandLine* command_line);
  46. ~CommandLinePrefStore() override;
  47. const base::CommandLine* command_line() { return command_line_; }
  48. private:
  49. // Weak reference.
  50. raw_ptr<const base::CommandLine> command_line_;
  51. };
  52. #endif // COMPONENTS_PREFS_COMMAND_LINE_PREF_STORE_H_