This source file includes following definitions.
- ModeToString
- GetProxyConfig
- IsNetworkProxySettingsEditable
- local_state_prefs_
- SetPrefs
- SetCurrentNetwork
- UpdateFromPrefs
- GetProxyConfig
- SetProxyConfig
- DetermineEffectiveConfig
#include "chrome/browser/chromeos/ui_proxy_config_service.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/values.h"
#include "chrome/browser/chromeos/net/proxy_config_handler.h"
#include "chrome/browser/chromeos/proxy_config_service_impl.h"
#include "chromeos/network/favorite_state.h"
#include "chromeos/network/network_state_handler.h"
#include "grit/generated_resources.h"
#include "net/proxy/proxy_config.h"
namespace chromeos {
namespace {
const char* ModeToString(UIProxyConfig::Mode mode) {
switch (mode) {
case UIProxyConfig::MODE_DIRECT:
return "direct";
case UIProxyConfig::MODE_AUTO_DETECT:
return "auto-detect";
case UIProxyConfig::MODE_PAC_SCRIPT:
return "pacurl";
case UIProxyConfig::MODE_SINGLE_PROXY:
return "single-proxy";
case UIProxyConfig::MODE_PROXY_PER_SCHEME:
return "proxy-per-scheme";
}
NOTREACHED() << "Unrecognized mode type";
return "";
}
bool GetProxyConfig(const PrefService* profile_prefs,
const PrefService* local_state_prefs,
const FavoriteState& network,
net::ProxyConfig* proxy_config,
onc::ONCSource* onc_source) {
scoped_ptr<ProxyConfigDictionary> proxy_dict =
proxy_config::GetProxyConfigForFavoriteNetwork(
profile_prefs, local_state_prefs, network, onc_source);
if (!proxy_dict)
return false;
return PrefProxyConfigTrackerImpl::PrefConfigToNetConfig(*proxy_dict,
proxy_config);
}
bool IsNetworkProxySettingsEditable(const onc::ONCSource onc_source) {
return onc_source != onc::ONC_SOURCE_DEVICE_POLICY &&
onc_source != onc::ONC_SOURCE_USER_POLICY;
}
}
UIProxyConfigService::UIProxyConfigService()
: profile_prefs_(NULL), local_state_prefs_(NULL) {
}
UIProxyConfigService::~UIProxyConfigService() {
}
void UIProxyConfigService::SetPrefs(PrefService* profile_prefs,
PrefService* local_state_prefs) {
profile_prefs_ = profile_prefs;
local_state_prefs_ = local_state_prefs;
}
void UIProxyConfigService::SetCurrentNetwork(
const std::string& current_network) {
current_ui_network_ = current_network;
}
void UIProxyConfigService::UpdateFromPrefs() {
const FavoriteState* network = NULL;
if (!current_ui_network_.empty()) {
network = NetworkHandler::Get()->network_state_handler()->GetFavoriteState(
current_ui_network_);
LOG_IF(ERROR, !network) << "Couldn't find FavoriteState for network "
<< current_ui_network_;
}
if (!network) {
current_ui_network_.clear();
current_ui_config_ = UIProxyConfig();
return;
}
DetermineEffectiveConfig(*network);
VLOG(1) << "Current ui network: " << network->name() << ", "
<< ModeToString(current_ui_config_.mode) << ", "
<< ProxyPrefs::ConfigStateToDebugString(current_ui_config_.state)
<< ", modifiable:" << current_ui_config_.user_modifiable;
}
void UIProxyConfigService::GetProxyConfig(UIProxyConfig* config) const {
*config = current_ui_config_;
}
void UIProxyConfigService::SetProxyConfig(const UIProxyConfig& config) {
current_ui_config_ = config;
if (current_ui_network_.empty())
return;
const FavoriteState* network =
NetworkHandler::Get()->network_state_handler()->GetFavoriteState(
current_ui_network_);
if (!network) {
LOG(ERROR) << "Couldn't find FavoriteState for network "
<< current_ui_network_;
return;
}
scoped_ptr<base::DictionaryValue> proxy_config_value(
config.ToPrefProxyConfig());
ProxyConfigDictionary proxy_config_dict(proxy_config_value.get());
VLOG(1) << "Set proxy for " << current_ui_network_
<< " to " << *proxy_config_value;
proxy_config::SetProxyConfigForFavoriteNetwork(proxy_config_dict, *network);
current_ui_config_.state = ProxyPrefs::CONFIG_SYSTEM;
}
void UIProxyConfigService::DetermineEffectiveConfig(
const FavoriteState& network) {
DCHECK(local_state_prefs_);
PrefService* top_pref_service =
profile_prefs_ ? profile_prefs_ : local_state_prefs_;
net::ProxyConfig pref_config;
ProxyPrefs::ConfigState pref_state = ProxyConfigServiceImpl::ReadPrefConfig(
top_pref_service, &pref_config);
net::ProxyConfig network_config;
net::ProxyConfigService::ConfigAvailability network_availability =
net::ProxyConfigService::CONFIG_UNSET;
onc::ONCSource onc_source = onc::ONC_SOURCE_NONE;
if (chromeos::GetProxyConfig(profile_prefs_,
local_state_prefs_,
network,
&network_config,
&onc_source)) {
VLOG(1) << this << ": using proxy of network: " << network.path();
network_availability = net::ProxyConfigService::CONFIG_VALID;
}
ProxyPrefs::ConfigState effective_config_state;
net::ProxyConfig effective_config;
ProxyConfigServiceImpl::GetEffectiveProxyConfig(
pref_state, pref_config,
network_availability, network_config, false,
&effective_config_state, &effective_config);
current_ui_config_.FromNetProxyConfig(effective_config);
current_ui_config_.state = effective_config_state;
if (ProxyConfigServiceImpl::PrefPrecedes(effective_config_state)) {
current_ui_config_.user_modifiable = false;
} else if (!IsNetworkProxySettingsEditable(onc_source)) {
current_ui_config_.state = ProxyPrefs::CONFIG_POLICY;
current_ui_config_.user_modifiable = false;
} else {
current_ui_config_.user_modifiable = !ProxyConfigServiceImpl::IgnoreProxy(
profile_prefs_, network.profile_path(), onc_source);
}
}
}