diff options
Diffstat (limited to 'chrome/browser/command_line_pref_store.cc')
-rw-r--r-- | chrome/browser/command_line_pref_store.cc | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/chrome/browser/command_line_pref_store.cc b/chrome/browser/command_line_pref_store.cc new file mode 100644 index 0000000..26bd0d3 --- /dev/null +++ b/chrome/browser/command_line_pref_store.cc @@ -0,0 +1,66 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/command_line_pref_store.h" + +#include "app/app_switches.h" +#include "base/values.h" +#include "chrome/common/chrome_switches.h" +#include "chrome/common/pref_names.h" + +const CommandLinePrefStore::StringSwitchToPreferenceMapEntry + CommandLinePrefStore::string_switch_map_[] = { + { switches::kLang, prefs::kApplicationLocale }, + { switches::kProxyServer, prefs::kProxyServer }, + { switches::kProxyPacUrl, prefs::kProxyPacUrl }, + { switches::kProxyBypassList, prefs::kProxyBypassList }, +}; + +const CommandLinePrefStore::BooleanSwitchToPreferenceMapEntry + CommandLinePrefStore::boolean_switch_map_[] = { + { switches::kNoProxyServer, prefs::kNoProxyServer, true }, + { switches::kProxyAutoDetect, prefs::kProxyAutoDetect, true }, +}; + +CommandLinePrefStore::CommandLinePrefStore(const CommandLine* command_line) + : command_line_(command_line), + prefs_(new DictionaryValue()) {} + +PrefStore::PrefReadError CommandLinePrefStore::ReadPrefs() { + ApplySimpleSwitches(); + ValidateProxySwitches(); + return PrefStore::PREF_READ_ERROR_NONE; +} + +void CommandLinePrefStore::ApplySimpleSwitches() { + // Look for each switch we know about and set its preference accordingly. + for (size_t i = 0; i < arraysize(string_switch_map_); ++i) { + if (command_line_->HasSwitch(string_switch_map_[i].switch_name)) { + Value* value = Value::CreateStringValue(command_line_-> + GetSwitchValueASCII(string_switch_map_[i].switch_name)); + prefs_->Set(string_switch_map_[i].preference_path, value); + } + } + + for (size_t i = 0; i < arraysize(boolean_switch_map_); ++i) { + if (command_line_->HasSwitch(boolean_switch_map_[i].switch_name)) { + Value* value = Value::CreateBooleanValue( + boolean_switch_map_[i].set_value); + prefs_->Set(boolean_switch_map_[i].preference_path, value); + } + } +} + +bool CommandLinePrefStore::ValidateProxySwitches() { + if (command_line_->HasSwitch(switches::kNoProxyServer) && + (command_line_->HasSwitch(switches::kProxyAutoDetect) || + command_line_->HasSwitch(switches::kProxyServer) || + command_line_->HasSwitch(switches::kProxyPacUrl) || + command_line_->HasSwitch(switches::kProxyBypassList))) { + LOG(WARNING) << "Additional command-line proxy switches specified when --" + << switches::kNoProxyServer << " was also specified."; + return false; + } + return true; +} |