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