This source file includes following definitions.
- GetMode
- GetPacUrl
- GetPacMandatory
- GetProxyServer
- GetBypassList
- HasBypassList
- GetDictionary
- CreateDirect
- CreateAutoDetect
- CreatePacScript
- CreateFixedServers
- CreateSystem
- CreateDictionary
#include "chrome/browser/prefs/proxy_config_dictionary.h"
#include "base/basictypes.h"
#include "base/logging.h"
#include "base/values.h"
namespace {
const char kProxyMode[] = "mode";
const char kProxyServer[] = "server";
const char kProxyPacUrl[] = "pac_url";
const char kProxyPacMandatory[] = "pac_mandatory";
const char kProxyBypassList[] = "bypass_list";
}
ProxyConfigDictionary::ProxyConfigDictionary(const base::DictionaryValue* dict)
: dict_(dict->DeepCopy()) {
}
ProxyConfigDictionary::~ProxyConfigDictionary() {}
bool ProxyConfigDictionary::GetMode(ProxyPrefs::ProxyMode* out) const {
std::string mode_str;
return dict_->GetString(kProxyMode, &mode_str)
&& StringToProxyMode(mode_str, out);
}
bool ProxyConfigDictionary::GetPacUrl(std::string* out) const {
return dict_->GetString(kProxyPacUrl, out);
}
bool ProxyConfigDictionary::GetPacMandatory(bool* out) const {
if (!dict_->HasKey(kProxyPacMandatory)) {
*out = false;
return true;
}
return dict_->GetBoolean(kProxyPacMandatory, out);
}
bool ProxyConfigDictionary::GetProxyServer(std::string* out) const {
return dict_->GetString(kProxyServer, out);
}
bool ProxyConfigDictionary::GetBypassList(std::string* out) const {
return dict_->GetString(kProxyBypassList, out);
}
bool ProxyConfigDictionary::HasBypassList() const {
return dict_->HasKey(kProxyBypassList);
}
const base::DictionaryValue& ProxyConfigDictionary::GetDictionary() const {
return *dict_;
}
base::DictionaryValue* ProxyConfigDictionary::CreateDirect() {
return CreateDictionary(ProxyPrefs::MODE_DIRECT,
std::string(),
false,
std::string(),
std::string());
}
base::DictionaryValue* ProxyConfigDictionary::CreateAutoDetect() {
return CreateDictionary(ProxyPrefs::MODE_AUTO_DETECT,
std::string(),
false,
std::string(),
std::string());
}
base::DictionaryValue* ProxyConfigDictionary::CreatePacScript(
const std::string& pac_url,
bool pac_mandatory) {
return CreateDictionary(ProxyPrefs::MODE_PAC_SCRIPT,
pac_url,
pac_mandatory,
std::string(),
std::string());
}
base::DictionaryValue* ProxyConfigDictionary::CreateFixedServers(
const std::string& proxy_server,
const std::string& bypass_list) {
if (!proxy_server.empty()) {
return CreateDictionary(ProxyPrefs::MODE_FIXED_SERVERS,
std::string(),
false,
proxy_server,
bypass_list);
} else {
return CreateDirect();
}
}
base::DictionaryValue* ProxyConfigDictionary::CreateSystem() {
return CreateDictionary(ProxyPrefs::MODE_SYSTEM,
std::string(),
false,
std::string(),
std::string());
}
base::DictionaryValue* ProxyConfigDictionary::CreateDictionary(
ProxyPrefs::ProxyMode mode,
const std::string& pac_url,
bool pac_mandatory,
const std::string& proxy_server,
const std::string& bypass_list) {
base::DictionaryValue* dict = new base::DictionaryValue();
dict->SetString(kProxyMode, ProxyModeToString(mode));
if (!pac_url.empty()) {
dict->SetString(kProxyPacUrl, pac_url);
dict->SetBoolean(kProxyPacMandatory, pac_mandatory);
}
if (!proxy_server.empty())
dict->SetString(kProxyServer, proxy_server);
if (!bypass_list.empty())
dict->SetString(kProxyBypassList, bypass_list);
return dict;
}