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