Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 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 #include "components/prefs/command_line_pref_store.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/files/file_path.h" | |
| 10 #include "base/memory/ptr_util.h" | |
| 11 #include "base/strings/string_number_conversions.h" | |
| 12 | |
| 13 CommandLinePrefStore::CommandLinePrefStore( | |
| 14 const base::CommandLine* command_line) | |
| 15 : command_line_(command_line) {} | |
| 16 | |
| 17 CommandLinePrefStore::~CommandLinePrefStore() {} | |
| 18 | |
| 19 void CommandLinePrefStore::ApplyStringSwitches( | |
| 20 const CommandLinePrefStore::SwitchToPreferenceMapEntry string_switch[], | |
| 21 size_t size) { | |
| 22 for (size_t i = 0; i < size; ++i) { | |
| 23 if (command_line_->HasSwitch(string_switch[i].switch_name)) { | |
| 24 SetValue(string_switch[i].preference_path, | |
| 25 base::MakeUnique<base::StringValue>( | |
| 26 command_line_->GetSwitchValueASCII( | |
| 27 string_switch[i].switch_name)), | |
| 28 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | |
| 29 } | |
| 30 } | |
| 31 } | |
| 32 | |
| 33 void CommandLinePrefStore::ApplyPathSwitches( | |
| 34 const CommandLinePrefStore::SwitchToPreferenceMapEntry path_switch[], | |
| 35 size_t size) { | |
| 36 for (size_t i = 0; i < size; ++i) { | |
| 37 if (command_line_->HasSwitch(path_switch[i].switch_name)) { | |
| 38 SetValue( | |
| 39 path_switch[i].preference_path, | |
| 40 base::MakeUnique<base::StringValue>( | |
| 41 command_line_->GetSwitchValuePath(path_switch[i].switch_name) | |
| 42 .value()), | |
| 43 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | |
| 44 } | |
| 45 } | |
| 46 } | |
| 47 | |
| 48 void CommandLinePrefStore::ApplyIntegerSwitches( | |
| 49 const CommandLinePrefStore::SwitchToPreferenceMapEntry integer_switch[], | |
|
Bernhard Bauer
2016/10/14 10:06:31
Nit: Indented incorrectly.
Menglin
2016/10/14 17:12:04
Done.
| |
| 50 size_t size) { | |
| 51 for (size_t i = 0; i < size; ++i) { | |
| 52 if (command_line_->HasSwitch(integer_switch[i].switch_name)) { | |
| 53 std::string str_value = command_line_->GetSwitchValueASCII( | |
| 54 integer_switch[i].switch_name); | |
| 55 int int_value = 0; | |
| 56 if (!base::StringToInt(str_value, &int_value)) { | |
| 57 LOG(ERROR) << "The value " << str_value << " of " | |
| 58 << integer_switch[i].switch_name | |
| 59 << " can not be converted to integer, ignoring!"; | |
| 60 continue; | |
| 61 } | |
| 62 SetValue(integer_switch[i].preference_path, | |
| 63 base::MakeUnique<base::FundamentalValue>(int_value), | |
| 64 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | |
| 65 } | |
| 66 } | |
| 67 } | |
| 68 | |
| 69 void CommandLinePrefStore::ApplyBooleanSwitches( | |
| 70 const CommandLinePrefStore::BooleanSwitchToPreferenceMapEntry | |
| 71 boolean_switch_map[], size_t size) { | |
| 72 for (size_t i = 0; i < size; ++i) { | |
| 73 if (command_line_->HasSwitch(boolean_switch_map[i].switch_name)) { | |
| 74 SetValue(boolean_switch_map[i].preference_path, | |
| 75 base::MakeUnique<base::FundamentalValue>( | |
| 76 boolean_switch_map[i].set_value), | |
| 77 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | |
| 78 } | |
| 79 } | |
| 80 } | |
| OLD | NEW |