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.
5 #ifndef COMPONENTS_PREFS_COMMAND_LINE_PREF_STORE_H_
6 #define COMPONENTS_PREFS_COMMAND_LINE_PREF_STORE_H_
8 #include "base/containers/span.h"
9 #include "base/memory/raw_ptr.h"
10 #include "components/prefs/value_map_pref_store.h"
16 // Base class for a PrefStore that maps command line switches to preferences.
17 // The Apply...Switches() methods can be called by subclasses with their own
18 // maps, or delegated to other code.
19 class COMPONENTS_PREFS_EXPORT CommandLinePrefStore : public ValueMapPrefStore {
21 struct SwitchToPreferenceMapEntry {
22 const char* switch_name;
23 const char* preference_path;
26 // |set_value| indicates what the preference should be set to if the switch
28 struct BooleanSwitchToPreferenceMapEntry {
29 const char* switch_name;
30 const char* preference_path;
34 CommandLinePrefStore(const CommandLinePrefStore&) = delete;
35 CommandLinePrefStore& operator=(const CommandLinePrefStore&) = delete;
37 // Apply command-line switches to the corresponding preferences of the switch
38 // map, where the value associated with the switch is a string.
39 void ApplyStringSwitches(
40 base::span<const SwitchToPreferenceMapEntry> string_switch_map);
42 // Apply command-line switches to the corresponding preferences of the switch
43 // map, where the value associated with the switch is a path.
44 void ApplyPathSwitches(
45 base::span<const SwitchToPreferenceMapEntry> path_switch_map);
47 // Apply command-line switches to the corresponding preferences of the switch
48 // map, where the value associated with the switch is an integer.
49 void ApplyIntegerSwitches(
50 base::span<const SwitchToPreferenceMapEntry> integer_switch_map);
52 // Apply command-line switches to the corresponding preferences of the
53 // boolean switch map.
54 void ApplyBooleanSwitches(
55 base::span<const BooleanSwitchToPreferenceMapEntry> boolean_switch_map);
58 explicit CommandLinePrefStore(const base::CommandLine* command_line);
59 ~CommandLinePrefStore() override;
61 const base::CommandLine* command_line() { return command_line_; }
65 raw_ptr<const base::CommandLine> command_line_;
68 #endif // COMPONENTS_PREFS_COMMAND_LINE_PREF_STORE_H_