command_line_pref_store.cc revision ac1e49eb6695f711d72215fcdf9388548942a00d
1// Copyright (c) 2010 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 "chrome/browser/prefs/command_line_pref_store.h" 6 7#include "app/app_switches.h" 8#include "base/logging.h" 9#include "base/values.h" 10#include "chrome/common/chrome_switches.h" 11#include "chrome/common/pref_names.h" 12 13const CommandLinePrefStore::StringSwitchToPreferenceMapEntry 14 CommandLinePrefStore::string_switch_map_[] = { 15 { switches::kLang, prefs::kApplicationLocale }, 16 { switches::kProxyServer, prefs::kProxyServer }, 17 { switches::kProxyPacUrl, prefs::kProxyPacUrl }, 18 { switches::kProxyBypassList, prefs::kProxyBypassList }, 19 { switches::kAuthSchemes, prefs::kAuthSchemes }, 20 { switches::kAuthServerWhitelist, prefs::kAuthServerWhitelist }, 21 { switches::kAuthNegotiateDelegateWhitelist, 22 prefs::kAuthNegotiateDelegateWhitelist }, 23 { switches::kGSSAPILibraryName, prefs::kGSSAPILibraryName }, 24}; 25 26const CommandLinePrefStore::BooleanSwitchToPreferenceMapEntry 27 CommandLinePrefStore::boolean_switch_map_[] = { 28 { switches::kNoProxyServer, prefs::kNoProxyServer, true }, 29 { switches::kProxyAutoDetect, prefs::kProxyAutoDetect, true }, 30 { switches::kDisableAuthNegotiateCnameLookup, 31 prefs::kDisableAuthNegotiateCnameLookup, true }, 32 { switches::kEnableAuthNegotiatePort, prefs::kEnableAuthNegotiatePort, 33 true }, 34 { switches::kDisable3DAPIs, prefs::kDisable3DAPIs, true }, 35}; 36 37CommandLinePrefStore::CommandLinePrefStore(const CommandLine* command_line) 38 : command_line_(command_line), 39 prefs_(new DictionaryValue()) {} 40 41CommandLinePrefStore::~CommandLinePrefStore() {} 42 43PrefStore::PrefReadError CommandLinePrefStore::ReadPrefs() { 44 ApplySimpleSwitches(); 45 ValidateProxySwitches(); 46 return PrefStore::PREF_READ_ERROR_NONE; 47} 48 49void CommandLinePrefStore::ApplySimpleSwitches() { 50 // Look for each switch we know about and set its preference accordingly. 51 for (size_t i = 0; i < arraysize(string_switch_map_); ++i) { 52 if (command_line_->HasSwitch(string_switch_map_[i].switch_name)) { 53 Value* value = Value::CreateStringValue(command_line_-> 54 GetSwitchValueASCII(string_switch_map_[i].switch_name)); 55 prefs_->Set(string_switch_map_[i].preference_path, value); 56 } 57 } 58 59 for (size_t i = 0; i < arraysize(boolean_switch_map_); ++i) { 60 if (command_line_->HasSwitch(boolean_switch_map_[i].switch_name)) { 61 Value* value = Value::CreateBooleanValue( 62 boolean_switch_map_[i].set_value); 63 prefs_->Set(boolean_switch_map_[i].preference_path, value); 64 } 65 } 66} 67 68bool CommandLinePrefStore::ValidateProxySwitches() { 69 if (command_line_->HasSwitch(switches::kNoProxyServer) && 70 (command_line_->HasSwitch(switches::kProxyAutoDetect) || 71 command_line_->HasSwitch(switches::kProxyServer) || 72 command_line_->HasSwitch(switches::kProxyPacUrl) || 73 command_line_->HasSwitch(switches::kProxyBypassList))) { 74 LOG(WARNING) << "Additional command-line proxy switches specified when --" 75 << switches::kNoProxyServer << " was also specified."; 76 return false; 77 } 78 return true; 79} 80