Commit 29c003e0 authored by pneubeck@chromium.org's avatar pneubeck@chromium.org

Migrate ProxyConfigServiceImpl to NetworkStateHandler and NetworkProfileHandler.

- UI part of ProxyConfigServiceImpl is moved to UIProxyConfig and UIProxyConfigService.
- ProxyConfigServiceImpl uses NetworkStateHandler instead of NetworkLibrary except for the legacy migration of device proxy settings.
- UI code continues to use NetworkLibrary for now.

BUG=234982
TBR=willchan@chromium.org (for trivial but reviewed change in net/proxy/proxy_config.*)

Review URL: https://chromiumcodereview.appspot.com/14846004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@204016 0039d316-1c4b-4281-b951-d872f2087c98
parent b8b14be5
......@@ -51,6 +51,7 @@
#include "chromeos/disks/disk_mount_manager.h"
#include "chromeos/disks/mock_disk_mount_manager.h"
#include "chromeos/login/login_state.h"
#include "chromeos/network/network_handler.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/test/test_browser_thread.h"
#include "content/public/test/test_utils.h"
......@@ -216,6 +217,8 @@ class LoginUtilsTest : public testing::Test,
CryptohomeLibrary::Initialize();
LoginState::Initialize();
ConnectivityStateHelper::SetForTest(&mock_connectivity_state_helper_);
EXPECT_CALL(mock_connectivity_state_helper_, DefaultNetworkOnline())
.WillRepeatedly(Return(false));
mock_input_method_manager_ = new input_method::MockInputMethodManager();
input_method::InitializeForTesting(mock_input_method_manager_);
......@@ -276,6 +279,10 @@ class LoginUtilsTest : public testing::Test,
connector_->Init(local_state_.Get(),
browser_process_->system_request_context());
// IOThread creates ProxyConfigServiceImpl which in turn needs
// NetworkHandler. Thus initialize it here before creating IOThread.
NetworkHandler::Initialize();
io_thread_state_.reset(new IOThread(local_state_.Get(),
browser_process_->policy_service(),
NULL, NULL));
......
......@@ -8,6 +8,7 @@
#include "chrome/browser/chromeos/login/helper.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/chromeos/proxy_config_service_impl.h"
#include "chrome/browser/chromeos/ui_proxy_config_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/url_constants.h"
......@@ -59,10 +60,11 @@ ProxySettingsDialog::ProxySettingsDialog(LoginWebDialog::Delegate* delegate,
// Get network name for dialog title.
Profile* profile = ProfileHelper::GetSigninProfile();
PrefProxyConfigTracker* proxy_tracker = profile->GetProxyConfigTracker();
proxy_tracker->UIMakeActiveNetworkCurrent();
UIProxyConfigService& proxy_config_service =
profile->GetProxyConfigTracker()->GetUIService();
proxy_config_service.MakeActiveNetworkCurrent();
std::string network_name;
proxy_tracker->UIGetCurrentNetworkName(&network_name);
proxy_config_service.GetCurrentNetworkName(&network_name);
SetDialogTitle(l10n_util::GetStringFUTF16(IDS_PROXY_PAGE_TITLE_FORMAT,
ASCIIToUTF16(network_name)));
}
......
......@@ -4,11 +4,14 @@
#include "chrome/browser/chromeos/net/onc_utils.h"
#include "base/logging.h"
#include "base/values.h"
#include "chrome/browser/chromeos/proxy_config_service_impl.h"
#include "chrome/browser/chromeos/ui_proxy_config.h"
#include "chrome/browser/prefs/proxy_config_dictionary.h"
#include "chromeos/network/onc/onc_utils.h"
#include "googleurl/src/gurl.h"
#include "net/base/host_port_pair.h"
#include "net/proxy/proxy_bypass_rules.h"
#include "net/proxy/proxy_server.h"
namespace chromeos {
......@@ -62,8 +65,7 @@ void AppendProxyServerForScheme(
net::ProxyServer proxy_server = ConvertOncProxyLocationToHostPort(
default_proxy_scheme, *onc_proxy_location);
ProxyConfigServiceImpl::ProxyConfig::EncodeAndAppendProxyServer(
url_scheme, proxy_server, spec);
UIProxyConfig::EncodeAndAppendProxyServer(url_scheme, proxy_server, spec);
}
net::ProxyBypassRules ConvertOncExcludeDomainsToBypassRules(
......
// Copyright 2013 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/chromeos/ui_proxy_config.h"
#include "base/json/json_writer.h"
#include "base/logging.h"
#include "base/values.h"
#include "chrome/browser/policy/proto/chromeos/chrome_device_policy.pb.h"
#include "chrome/browser/prefs/proxy_config_dictionary.h"
#include "net/proxy/proxy_config.h"
namespace chromeos {
UIProxyConfig::UIProxyConfig()
: mode(MODE_DIRECT),
state(ProxyPrefs::CONFIG_UNSET),
user_modifiable(true) {
}
UIProxyConfig::~UIProxyConfig() {
}
void UIProxyConfig::SetPacUrl(const GURL& pac_url) {
mode = UIProxyConfig::MODE_PAC_SCRIPT;
automatic_proxy.pac_url = pac_url;
}
void UIProxyConfig::SetSingleProxy(const net::ProxyServer& server) {
mode = UIProxyConfig::MODE_SINGLE_PROXY;
single_proxy.server = server;
}
void UIProxyConfig::SetProxyForScheme(const std::string& scheme,
const net::ProxyServer& server) {
ManualProxy* proxy = MapSchemeToProxy(scheme);
if (!proxy) {
NOTREACHED() << "Cannot set proxy: invalid scheme [" << scheme << "]";
return;
}
mode = UIProxyConfig::MODE_PROXY_PER_SCHEME;
proxy->server = server;
}
void UIProxyConfig::SetBypassRules(const net::ProxyBypassRules& rules) {
if (mode != UIProxyConfig::MODE_SINGLE_PROXY &&
mode != UIProxyConfig::MODE_PROXY_PER_SCHEME) {
NOTREACHED() << "Cannot set bypass rules for proxy mode [" << mode << "]";
return;
}
bypass_rules = rules;
}
bool UIProxyConfig::FromNetProxyConfig(const net::ProxyConfig& net_config) {
*this = UIProxyConfig(); // Reset to default.
const net::ProxyConfig::ProxyRules& rules = net_config.proxy_rules();
switch (rules.type) {
case net::ProxyConfig::ProxyRules::TYPE_NO_RULES:
if (!net_config.HasAutomaticSettings()) {
mode = UIProxyConfig::MODE_DIRECT;
} else if (net_config.auto_detect()) {
mode = UIProxyConfig::MODE_AUTO_DETECT;
} else if (net_config.has_pac_url()) {
mode = UIProxyConfig::MODE_PAC_SCRIPT;
automatic_proxy.pac_url = net_config.pac_url();
} else {
return false;
}
return true;
case net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY:
if (rules.single_proxies.IsEmpty())
return false;
mode = MODE_SINGLE_PROXY;
single_proxy.server = rules.single_proxies.Get();
bypass_rules = rules.bypass_rules;
return true;
case net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME:
// Make sure we have valid server for at least one of the protocols.
if (rules.proxies_for_http.IsEmpty() &&
rules.proxies_for_https.IsEmpty() &&
rules.proxies_for_ftp.IsEmpty() &&
rules.fallback_proxies.IsEmpty()) {
return false;
}
mode = MODE_PROXY_PER_SCHEME;
if (!rules.proxies_for_http.IsEmpty())
http_proxy.server = rules.proxies_for_http.Get();
if (!rules.proxies_for_https.IsEmpty())
https_proxy.server = rules.proxies_for_https.Get();
if (!rules.proxies_for_ftp.IsEmpty())
ftp_proxy.server = rules.proxies_for_ftp.Get();
if (!rules.fallback_proxies.IsEmpty())
socks_proxy.server = rules.fallback_proxies.Get();
bypass_rules = rules.bypass_rules;
return true;
default:
NOTREACHED() << "Unrecognized proxy config mode";
break;
}
return false;
}
base::DictionaryValue* UIProxyConfig::ToPrefProxyConfig() {
switch (mode) {
case MODE_DIRECT: {
return ProxyConfigDictionary::CreateDirect();
}
case MODE_AUTO_DETECT: {
return ProxyConfigDictionary::CreateAutoDetect();
}
case MODE_PAC_SCRIPT: {
return ProxyConfigDictionary::CreatePacScript(
automatic_proxy.pac_url.spec(), false);
}
case MODE_SINGLE_PROXY: {
std::string spec;
if (single_proxy.server.is_valid())
spec = single_proxy.server.ToURI();
return ProxyConfigDictionary::CreateFixedServers(
spec, bypass_rules.ToString());
}
case MODE_PROXY_PER_SCHEME: {
std::string spec;
EncodeAndAppendProxyServer("http", http_proxy.server, &spec);
EncodeAndAppendProxyServer("https", https_proxy.server, &spec);
EncodeAndAppendProxyServer("ftp", ftp_proxy.server, &spec);
EncodeAndAppendProxyServer("socks", socks_proxy.server, &spec);
return ProxyConfigDictionary::CreateFixedServers(
spec, bypass_rules.ToString());
}
default:
break;
}
NOTREACHED() << "Unrecognized proxy config mode for preference";
return NULL;
}
UIProxyConfig::ManualProxy* UIProxyConfig::MapSchemeToProxy(
const std::string& scheme) {
if (scheme == "http")
return &http_proxy;
if (scheme == "https")
return &https_proxy;
if (scheme == "ftp")
return &ftp_proxy;
if (scheme == "socks")
return &socks_proxy;
NOTREACHED() << "Invalid scheme: " << scheme;
return NULL;
}
bool UIProxyConfig::SerializeForNetwork(std::string* output) {
scoped_ptr<base::DictionaryValue> proxy_dict_ptr(ToPrefProxyConfig());
if (!proxy_dict_ptr.get())
return false;
// Return empty string for direct mode for portal check to work correctly.
base::DictionaryValue *dict = proxy_dict_ptr.get();
ProxyConfigDictionary proxy_dict(dict);
ProxyPrefs::ProxyMode mode;
if (proxy_dict.GetMode(&mode)) {
if (mode == ProxyPrefs::MODE_DIRECT) {
output->clear();
return true;
}
}
base::JSONWriter::Write(dict, output);
return true;
}
// static
void UIProxyConfig::EncodeAndAppendProxyServer(const std::string& url_scheme,
const net::ProxyServer& server,
std::string* spec) {
if (!server.is_valid())
return;
if (!spec->empty())
*spec += ';';
if (!url_scheme.empty()) {
*spec += url_scheme;
*spec += "=";
}
*spec += server.ToURI();
}
} // namespace chromeos
// Copyright 2013 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.
#ifndef CHROME_BROWSER_CHROMEOS_UI_PROXY_CONFIG_H_
#define CHROME_BROWSER_CHROMEOS_UI_PROXY_CONFIG_H_
#include <string>
#include "chrome/browser/prefs/proxy_prefs.h"
#include "googleurl/src/gurl.h"
#include "net/proxy/proxy_bypass_rules.h"
#include "net/proxy/proxy_server.h"
namespace base {
class DictionaryValue;
}
namespace net {
class ProxyConfig;
}
namespace chromeos {
// Contrary to other platforms which simply use the systems' UI to allow users
// to configure proxies, we have to implement our own UI on the chromeos device.
// This requires extra and specific UI requirements that net::ProxyConfig does
// not supply. So we create an augmented analog to net::ProxyConfig here to
// include and handle these UI requirements, e.g.
// - state of configuration e.g. where it was picked up from - policy,
// extension, etc (refer to ProxyPrefs::ConfigState)
// - the read/write access of a proxy setting
// - may add more stuff later.
// This is then converted to the common net::ProxyConfig before being pushed
// to PrefProxyConfigTrackerImpl::OnProxyConfigChanged and then to the network
// stack.
struct UIProxyConfig {
// Specifies if proxy config is direct, auto-detect, using pac script,
// single-proxy, or proxy-per-scheme.
enum Mode {
MODE_DIRECT,
MODE_AUTO_DETECT,
MODE_PAC_SCRIPT,
MODE_SINGLE_PROXY,
MODE_PROXY_PER_SCHEME,
};
// Proxy setting for mode = direct or auto-detect or using pac script.
struct AutomaticProxy {
GURL pac_url; // Set if proxy is using pac script.
};
// Proxy setting for mode = single-proxy or proxy-per-scheme.
struct ManualProxy {
net::ProxyServer server;
};
UIProxyConfig();
~UIProxyConfig();
void SetPacUrl(const GURL& pac_url);
void SetSingleProxy(const net::ProxyServer& server);
// |scheme| is one of "http", "https", "ftp" or "socks".
void SetProxyForScheme(const std::string& scheme,
const net::ProxyServer& server);
// Only valid for MODE_SINGLE_PROXY or MODE_PROXY_PER_SCHEME.
void SetBypassRules(const net::ProxyBypassRules& rules);
// Converts net::ProxyConfig to |this|.
bool FromNetProxyConfig(const net::ProxyConfig& net_config);
// Converts |this| to Dictionary of ProxyConfigDictionary format (which
// is the same format used by prefs).
base::DictionaryValue* ToPrefProxyConfig();
// Map |scheme| (one of "http", "https", "ftp" or "socks") to the correct
// ManualProxy. Returns NULL if scheme is invalid.
ManualProxy* MapSchemeToProxy(const std::string& scheme);
// Serializes config into a ProxyConfigDictionary and then std::string
// persisted as string property in shill for a network.
bool SerializeForNetwork(std::string* output);
// Encodes the proxy server as "<url-scheme>=<proxy-scheme>://<proxy>"
static void EncodeAndAppendProxyServer(const std::string& url_scheme,
const net::ProxyServer& server,
std::string* spec);
Mode mode;
ProxyPrefs::ConfigState state;
// True if user can modify proxy settings via UI.
// If proxy is managed by policy or extension or other_precde or is for
// shared network but kUseSharedProxies is turned off, it can't be modified
// by user.
bool user_modifiable;
// Set if mode is MODE_DIRECT or MODE_AUTO_DETECT or MODE_PAC_SCRIPT.
AutomaticProxy automatic_proxy;
// Set if mode is MODE_SINGLE_PROXY.
ManualProxy single_proxy;
// Set if mode is MODE_PROXY_PER_SCHEME and has http proxy.
ManualProxy http_proxy;
// Set if mode is MODE_PROXY_PER_SCHEME and has https proxy.
ManualProxy https_proxy;
// Set if mode is MODE_PROXY_PER_SCHEME and has ftp proxy.
ManualProxy ftp_proxy;
// Set if mode is MODE_PROXY_PER_SCHEME and has socks proxy.
ManualProxy socks_proxy;
// Exceptions for when not to use a proxy.
net::ProxyBypassRules bypass_rules;
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_UI_PROXY_CONFIG_H_
// Copyright 2013 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/chromeos/ui_proxy_config_service.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/values.h"
#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/cros/network_library.h"
#include "chrome/browser/chromeos/cros/network_property_ui_data.h"
#include "chrome/browser/chromeos/proxy_config_service_impl.h"
#include "chromeos/network/onc/onc_utils.h"
#include "grit/generated_resources.h"
#include "net/proxy/proxy_config.h"
#include "ui/base/l10n/l10n_util.h"
namespace chromeos {
namespace {
class ClosureEquals {
public:
explicit ClosureEquals(const base::Closure& closure)
: closure_(closure) { }
bool operator() (const base::Closure& other) {
return closure_.Equals(other);
}
private:
const base::Closure& closure_;
};
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 ParseProxyConfig(const std::string& pref_proxy_config,
net::ProxyConfig* proxy_config) {
if (pref_proxy_config.empty())
return false;
scoped_ptr<base::DictionaryValue> proxy_config_dict(
chromeos::onc::ReadDictionaryFromJson(pref_proxy_config));
if (!proxy_config_dict) {
LOG(WARNING) << "Failed to parse proxy config.";
return false;
}
ProxyConfigDictionary proxy_config_dict_wrapper(proxy_config_dict.get());
return PrefProxyConfigTrackerImpl::PrefConfigToNetConfig(
proxy_config_dict_wrapper,
proxy_config);
}
// Returns true if proxy settings of |network| are editable.
bool IsNetworkProxySettingsEditable(const Network& network) {
NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary();
const base::DictionaryValue* onc =
network_library->FindOncForNetwork(network.unique_id());
if (!onc)
return true;
NetworkPropertyUIData proxy_settings_ui_data;
proxy_settings_ui_data.ParseOncProperty(
network.ui_data().onc_source(),
onc,
onc::network_config::kProxySettings);
return proxy_settings_ui_data.IsEditable();
}
} // namespace
UIProxyConfigService::UIProxyConfigService(PrefService* pref_service)
: pref_service_(pref_service) {
}
UIProxyConfigService::~UIProxyConfigService() {
}
void UIProxyConfigService::SetCurrentNetwork(
const std::string& current_network) {
Network* network = NULL;
if (!current_network.empty()) {
network = CrosLibrary::Get()->GetNetworkLibrary()->FindNetworkByPath(
current_network);
LOG_IF(ERROR, !network)
<< "Can't find requested network " << current_network;
}
current_ui_network_ = current_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;
// Notify observers.
std::vector<base::Closure>::iterator iter = callbacks_.begin();
while (iter != callbacks_.end()) {
if (iter->is_null()) {
iter = callbacks_.erase(iter);
} else {
iter->Run();
++iter;
}
}
}
void UIProxyConfigService::MakeActiveNetworkCurrent() {
const Network* network =
CrosLibrary::Get()->GetNetworkLibrary()->active_network();
SetCurrentNetwork(network ? network->service_path() : std::string());
}
void UIProxyConfigService::GetCurrentNetworkName(std::string* network_name) {
if (!network_name)
return;
network_name->clear();
Network* network = CrosLibrary::Get()->GetNetworkLibrary()->FindNetworkByPath(
current_ui_network_);
if (!network) {
LOG(ERROR) << "Can't find requested network " << current_ui_network_;
return;
}
if (network->name().empty() && network->type() == chromeos::TYPE_ETHERNET) {
*network_name =
l10n_util::GetStringUTF8(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET);
} else {
*network_name = network->name();
}
}
void UIProxyConfigService::GetProxyConfig(UIProxyConfig* config) {
*config = current_ui_config_;
}
void UIProxyConfigService::SetProxyConfig(const UIProxyConfig& config) {
current_ui_config_ = config;
if (current_ui_network_.empty())
return;
// Update config to shill.
std::string value;
if (!current_ui_config_.SerializeForNetwork(&value))
return;
VLOG(1) << "Set proxy (mode=" << current_ui_config_.mode
<< ") for " << current_ui_network_;
current_ui_config_.state = ProxyPrefs::CONFIG_SYSTEM;
// Set ProxyConfig of the current network.
Network* network = CrosLibrary::Get()->GetNetworkLibrary()->FindNetworkByPath(
current_ui_network_);
if (!network) {
NOTREACHED() << "Can't find requested network " << current_ui_network_;
return;
}
network->SetProxyConfig(value);
VLOG(1) << "Set proxy for "
<< (network->name().empty() ? current_ui_network_ : network->name())
<< ", value=" << value;
}
void UIProxyConfigService::AddNotificationCallback(base::Closure callback) {
std::vector<base::Closure>::iterator iter = std::find_if(
callbacks_.begin(), callbacks_.end(), ClosureEquals(callback));
if (iter == callbacks_.end())
callbacks_.push_back(callback);
}
void UIProxyConfigService::RemoveNotificationCallback(base::Closure callback) {
std::vector<base::Closure>::iterator iter = std::find_if(
callbacks_.begin(), callbacks_.end(), ClosureEquals(callback));
if (iter != callbacks_.end())
callbacks_.erase(iter);
}
void UIProxyConfigService::DetermineEffectiveConfig(const Network& network) {
// Get prefs proxy config if available.
net::ProxyConfig pref_config;
ProxyPrefs::ConfigState pref_state = ProxyConfigServiceImpl::ReadPrefConfig(
pref_service_, &pref_config);
// Get network proxy config if available.
net::ProxyConfig network_config;
net::ProxyConfigService::ConfigAvailability network_availability =
net::ProxyConfigService::CONFIG_UNSET;
if (ParseProxyConfig(network.proxy_config(), &network_config)) {
// Network is private or shared with user using shared proxies.
VLOG(1) << this << ": using network proxy: " << network.proxy_config();
network_availability = net::ProxyConfigService::CONFIG_VALID;
}
// Determine effective proxy config, either from prefs or network.
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);
// Store effective proxy into |current_ui_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(network)) {
// TODO(xiyuan): Figure out the right way to set config state for managed
// network.
current_ui_config_.state = ProxyPrefs::CONFIG_POLICY;
current_ui_config_.user_modifiable = false;
} else {
current_ui_config_.user_modifiable =
!ProxyConfigServiceImpl::IgnoreProxy(pref_service_,
network.profile_path(),
network.ui_data().onc_source());
}
}
} // namespace chromeos
// Copyright 2013 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.
#ifndef CHROME_BROWSER_CHROMEOS_UI_PROXY_CONFIG_SERVICE_H_
#define CHROME_BROWSER_CHROMEOS_UI_PROXY_CONFIG_SERVICE_H_
#include <string>
#include <vector>
#include "base/basictypes.h"
#include "base/callback.h"
#include "chrome/browser/chromeos/ui_proxy_config.h"
class PrefService;
namespace chromeos {
class Network;
class ProxyConfigServiceImpl;
// This class is only accessed from the UI via Profile::GetProxyConfigTracker to
// allow the user to read and modify the proxy configuration via
// GetProxyConfig and SetProxyConfig.
//
// Before reading/setting a proxy config, a network has to be selected using
// either SetCurrentNetwork (any remembered network) or
// MakeActiveNetworkCurrent.
class UIProxyConfigService {
public:
explicit UIProxyConfigService(PrefService* pref_service);
~UIProxyConfigService();
// Add/Remove callback functions for notification when network to be viewed is
// changed by the UI.
// Currently, these are only called by CoreChromeOSOptionsHandler.
void AddNotificationCallback(base::Closure callback);
void RemoveNotificationCallback(base::Closure callback);
// Called by UI to set the network with service path |current_network| to be
// displayed or edited. Subsequent Set*/Get* methods will use this
// network, until this method is called again.
void SetCurrentNetwork(const std::string& current_network);
// Called from UI to make the current active network the one to be displayed
// or edited. See SetCurrentNetwork.
void MakeActiveNetworkCurrent();
// Called from UI to get name of the current network.
void GetCurrentNetworkName(std::string* network_name);
// Called from UI to retrieve the stored proxy configuration, which is either
// the last proxy config of the current network or the one last set by
// SetProxyConfig.
void GetProxyConfig(UIProxyConfig* config);
// Called from UI to update proxy configuration for different modes. Stores
// and persists |config| to shill for the current network.
void SetProxyConfig(const UIProxyConfig& config);
private:
// Determines effective proxy config based on prefs from config tracker,
// |network| and if user is using shared proxies. The effective config is
// stored in |current_ui_config_| but not activated on network stack, and
// hence, not picked up by observers.
void DetermineEffectiveConfig(const Network& network);
// Service path of network whose proxy configuration is being displayed or
// edited via UI.
std::string current_ui_network_;
// Proxy configuration of |current_ui_network_|.
UIProxyConfig current_ui_config_;
// Callbacks for notification when network to be viewed has been changed from
// the UI.
std::vector<base::Closure> callbacks_;
PrefService* pref_service_;
DISALLOW_COPY_AND_ASSIGN(UIProxyConfigService);
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_UI_PROXY_CONFIG_SERVICE_H_
......@@ -129,7 +129,7 @@ PrefProxyConfigTrackerImpl::PrefProxyConfigTrackerImpl(
: pref_service_(pref_service),
chrome_proxy_config_service_(NULL),
update_pending_(true) {
config_state_ = ReadPrefConfig(&pref_config_);
config_state_ = ReadPrefConfig(pref_service_, &pref_config_);
proxy_prefs_.Init(pref_service);
proxy_prefs_.Add(prefs::kProxy,
base::Bind(&PrefProxyConfigTrackerImpl::OnProxyPrefChanged,
......@@ -212,6 +212,40 @@ void PrefProxyConfigTrackerImpl::RegisterUserPrefs(
user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
}
// static
ProxyPrefs::ConfigState PrefProxyConfigTrackerImpl::ReadPrefConfig(
const PrefService* pref_service,
net::ProxyConfig* config) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// Clear the configuration and source.
*config = net::ProxyConfig();
ProxyPrefs::ConfigState config_state = ProxyPrefs::CONFIG_UNSET;
const PrefService::Preference* pref =
pref_service->FindPreference(prefs::kProxy);
DCHECK(pref);
const DictionaryValue* dict = pref_service->GetDictionary(prefs::kProxy);
DCHECK(dict);
ProxyConfigDictionary proxy_dict(dict);
if (PrefConfigToNetConfig(proxy_dict, config)) {
if (!pref->IsUserModifiable() || pref->HasUserSetting()) {
if (pref->IsManaged())
config_state = ProxyPrefs::CONFIG_POLICY;
else if (pref->IsExtensionControlled())
config_state = ProxyPrefs::CONFIG_EXTENSION;
else
config_state = ProxyPrefs::CONFIG_OTHER_PRECEDE;
} else {
config_state = ProxyPrefs::CONFIG_FALLBACK;
}
}
return config_state;
}
ProxyPrefs::ConfigState PrefProxyConfigTrackerImpl::GetProxyConfig(
net::ProxyConfig* config) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
......@@ -301,7 +335,8 @@ bool PrefProxyConfigTrackerImpl::PrefConfigToNetConfig(
void PrefProxyConfigTrackerImpl::OnProxyPrefChanged() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
net::ProxyConfig new_config;
ProxyPrefs::ConfigState config_state = ReadPrefConfig(&new_config);
ProxyPrefs::ConfigState config_state = ReadPrefConfig(pref_service_,
&new_config);
if (config_state_ != config_state ||
(config_state_ != ProxyPrefs::CONFIG_UNSET &&
!pref_config_.Equals(new_config))) {
......@@ -313,35 +348,3 @@ void PrefProxyConfigTrackerImpl::OnProxyPrefChanged() {
if (update_pending_)
OnProxyConfigChanged(config_state, new_config);
}
ProxyPrefs::ConfigState PrefProxyConfigTrackerImpl::ReadPrefConfig(
net::ProxyConfig* config) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// Clear the configuration and source.
*config = net::ProxyConfig();
ProxyPrefs::ConfigState config_state = ProxyPrefs::CONFIG_UNSET;
const PrefService::Preference* pref =
pref_service_->FindPreference(prefs::kProxy);
DCHECK(pref);
const DictionaryValue* dict = pref_service_->GetDictionary(prefs::kProxy);
DCHECK(dict);
ProxyConfigDictionary proxy_dict(dict);
if (PrefConfigToNetConfig(proxy_dict, config)) {
if (!pref->IsUserModifiable() || pref->HasUserSetting()) {
if (pref->IsManaged())
config_state = ProxyPrefs::CONFIG_POLICY;
else if (pref->IsExtensionControlled())
config_state = ProxyPrefs::CONFIG_EXTENSION;
else
config_state = ProxyPrefs::CONFIG_OTHER_PRECEDE;
} else {
config_state = ProxyPrefs::CONFIG_FALLBACK;
}
}
return config_state;
}
......@@ -125,6 +125,12 @@ class PrefProxyConfigTrackerImpl {
static void RegisterPrefs(PrefRegistrySimple* registry);
static void RegisterUserPrefs(user_prefs::PrefRegistrySyncable* registry);
// Creates a proxy configuration from proxy-related preferences of
// |pref_service|. Configuration is stored in |config|, return value indicates
// whether the configuration is valid.
static ProxyPrefs::ConfigState ReadPrefConfig(const PrefService* pref_service,
net::ProxyConfig* config);
protected:
// Get the proxy configuration currently defined by preferences.
// Status is indicated in the return value.
......@@ -143,11 +149,6 @@ class PrefProxyConfigTrackerImpl {
bool update_pending() const { return update_pending_; }
private:
// Creates a proxy configuration from proxy-related preferences. Configuration
// is stored in |config|, return value indicates whether the configuration is
// valid.
ProxyPrefs::ConfigState ReadPrefConfig(net::ProxyConfig* config);
// Tracks configuration state. |pref_config_| is valid only if |config_state_|
// is not CONFIG_UNSET.
ProxyPrefs::ConfigState config_state_;
......
......@@ -7,23 +7,23 @@
#include "base/basictypes.h"
#include "base/logging.h"
namespace ProxyPrefs {
namespace {
// These names are exposed to the proxy extension API. They must be in sync
// with the constants of ProxyPrefs.
const char* kProxyModeNames[] = { ProxyPrefs::kDirectProxyModeName,
ProxyPrefs::kAutoDetectProxyModeName,
ProxyPrefs::kPacScriptProxyModeName,
ProxyPrefs::kFixedServersProxyModeName,
ProxyPrefs::kSystemProxyModeName };
const char* kProxyModeNames[] = { kDirectProxyModeName,
kAutoDetectProxyModeName,
kPacScriptProxyModeName,
kFixedServersProxyModeName,
kSystemProxyModeName };
COMPILE_ASSERT(arraysize(kProxyModeNames) == ProxyPrefs::kModeCount,
COMPILE_ASSERT(arraysize(kProxyModeNames) == kModeCount,
kProxyModeNames_must_have_size_of_NUM_MODES);
} // namespace
namespace ProxyPrefs {
const char kDirectProxyModeName[] = "direct";
const char kAutoDetectProxyModeName[] = "auto_detect";
const char kPacScriptProxyModeName[] = "pac_script";
......@@ -51,4 +51,23 @@ const char* ProxyModeToString(ProxyMode mode) {
return kProxyModeNames[mode];
}
std::string ConfigStateToDebugString(ConfigState state) {
switch (state) {
case CONFIG_POLICY:
return "config_policy";
case CONFIG_EXTENSION:
return "config_extension";
case CONFIG_OTHER_PRECEDE:
return "config_other_precede";
case CONFIG_SYSTEM:
return "config_system";
case CONFIG_FALLBACK:
return "config_fallback";
case CONFIG_UNSET:
return "config_unset";
}
NOTREACHED();
return "";
}
} // namespace ProxyPrefs
......@@ -63,6 +63,7 @@ bool IntToProxyMode(int in_value, ProxyMode* out_value);
bool StringToProxyMode(const std::string& in_value, ProxyMode* out_value);
// Ownership of the return value is NOT passed to the caller.
const char* ProxyModeToString(ProxyMode mode);
std::string ConfigStateToDebugString(ConfigState state);
} // namespace ProxyPrefs
......
......@@ -40,7 +40,6 @@
#include "testing/gtest/include/gtest/gtest.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/login/mock_user_manager.h"
#include "chrome/browser/chromeos/login/user_manager.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
......@@ -101,12 +100,7 @@ class ProfileManagerTest : public testing::Test {
extension_event_router_forwarder_(new extensions::EventRouterForwarder),
ui_thread_(BrowserThread::UI, &message_loop_),
db_thread_(BrowserThread::DB, &message_loop_),
file_thread_(BrowserThread::FILE, &message_loop_),
io_thread_(local_state_.Get(),
g_browser_process->policy_service(),
NULL,
extension_event_router_forwarder_.get()) {
TestingBrowserProcess::GetGlobal()->SetIOThread(&io_thread_);
file_thread_(BrowserThread::FILE, &message_loop_) {
}
virtual void SetUp() {
......@@ -127,10 +121,6 @@ class ProfileManagerTest : public testing::Test {
}
#if defined(OS_CHROMEOS)
// Do not change order of stub_cros_enabler_, which needs to be constructed
// before io_thread_ which requires CrosLibrary to be initialized to construct
// its data member pref_proxy_config_tracker_ on ChromeOS.
chromeos::ScopedStubCrosEnabler stub_cros_enabler_;
chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
chromeos::ScopedTestCrosSettings test_cros_settings_;
#endif
......@@ -145,8 +135,6 @@ class ProfileManagerTest : public testing::Test {
content::TestBrowserThread ui_thread_;
content::TestBrowserThread db_thread_;
content::TestBrowserThread file_thread_;
// IOThread is necessary for the creation of some services below.
IOThread io_thread_;
#if defined(OS_CHROMEOS)
chromeos::ScopedTestUserManager test_user_manager_;
......
......@@ -11,6 +11,7 @@
#include "chrome/browser/chromeos/proxy_config_service_impl.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/chromeos/system/statistics_provider.h"
#include "chrome/browser/chromeos/ui_proxy_config_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler.h"
#include "chrome/browser/ui/webui/options/chromeos/proxy_handler.h"
......@@ -126,10 +127,11 @@ void ProxySettingsUI::InitializeHandlers() {
core_handler_->InitializePage();
proxy_handler_->InitializePage();
Profile* profile = Profile::FromWebUI(web_ui());
PrefProxyConfigTracker* proxy_tracker = profile->GetProxyConfigTracker();
proxy_tracker->UIMakeActiveNetworkCurrent();
UIProxyConfigService& proxy_config_service =
profile->GetProxyConfigTracker()->GetUIService();
proxy_config_service.MakeActiveNetworkCurrent();
std::string network_name;
proxy_tracker->UIGetCurrentNetworkName(&network_name);
proxy_config_service.GetCurrentNetworkName(&network_name);
}
} // namespace chromeos
......@@ -16,6 +16,7 @@
#include "chrome/browser/chromeos/proxy_config_service_impl.h"
#include "chrome/browser/chromeos/proxy_cros_settings_parser.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/chromeos/ui_proxy_config_service.h"
#include "chrome/browser/policy/browser_policy_connector.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/chromeos/ui_account_tweaks.h"
......@@ -94,7 +95,7 @@ CoreChromeOSOptionsHandler::CoreChromeOSOptionsHandler()
CoreChromeOSOptionsHandler::~CoreChromeOSOptionsHandler() {
PrefProxyConfigTracker* proxy_tracker =
Profile::FromWebUI(web_ui())->GetProxyConfigTracker();
proxy_tracker->RemoveNotificationCallback(
proxy_tracker->GetUIService().RemoveNotificationCallback(
base::Bind(&CoreChromeOSOptionsHandler::NotifyProxyPrefsChanged,
pointer_factory_.GetWeakPtr()));
}
......@@ -111,7 +112,7 @@ void CoreChromeOSOptionsHandler::InitializeHandler() {
// Observe the chromeos::ProxyConfigServiceImpl for changes from the UI.
PrefProxyConfigTracker* proxy_tracker =
Profile::FromWebUI(web_ui())->GetProxyConfigTracker();
proxy_tracker->AddNotificationCallback(
proxy_tracker->GetUIService().AddNotificationCallback(
base::Bind(&CoreChromeOSOptionsHandler::NotifyProxyPrefsChanged,
pointer_factory_.GetWeakPtr()));
}
......
......@@ -38,6 +38,7 @@
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/chromeos/sim_dialog_delegate.h"
#include "chrome/browser/chromeos/status/network_menu_icon.h"
#include "chrome/browser/chromeos/ui_proxy_config_service.h"
#include "chrome/browser/net/pref_proxy_config_tracker.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
......@@ -1240,8 +1241,8 @@ void InternetOptionsHandler::PopulateIPConfigsCallback(
if (!network)
return;
Profile::FromWebUI(web_ui())->GetProxyConfigTracker()->UISetCurrentNetwork(
service_path);
Profile::FromWebUI(web_ui())->
GetProxyConfigTracker()->GetUIService().SetCurrentNetwork(service_path);
const chromeos::NetworkUIData& ui_data = network->ui_data();
const chromeos::NetworkPropertyUIData property_ui_data(ui_data.onc_source());
......
......@@ -758,6 +758,10 @@
'browser/chromeos/ui/idle_logout_dialog_view.h',
'browser/chromeos/ui/screen_capture_notification_ui_chromeos.cc',
'browser/chromeos/ui/screen_capture_notification_ui_chromeos.h',
'browser/chromeos/ui_proxy_config.cc',
'browser/chromeos/ui_proxy_config.h',
'browser/chromeos/ui_proxy_config_service.cc',
'browser/chromeos/ui_proxy_config_service.h',
'browser/chromeos/upgrade_detector_chromeos.cc',
'browser/chromeos/upgrade_detector_chromeos.h',
'browser/chromeos/version_loader.cc',
......
......@@ -11,6 +11,7 @@
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversion_utils.h"
#include "chromeos/network/network_event_log.h"
#include "chromeos/network/network_ui_data.h"
#include "chromeos/network/onc/onc_utils.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
......@@ -56,6 +57,7 @@ NetworkState::NetworkState(const std::string& path)
auto_connect_(false),
favorite_(false),
priority_(0),
onc_source_(onc::ONC_SOURCE_NONE),
signal_strength_(0),
connectable_(false),
passphrase_required_(false),
......@@ -117,7 +119,7 @@ bool NetworkState::PropertyChanged(const std::string& key,
scoped_ptr<base::DictionaryValue> proxy_config_dict(
onc::ReadDictionaryFromJson(proxy_config_str));
if (proxy_config_dict) {
// Warning: The DictionaryValue return from
// Warning: The DictionaryValue returned from
// ReadDictionaryFromJson/JSONParser is an optimized derived class that
// doesn't allow releasing ownership of nested values. A Swap in the wrong
// order leads to memory access errors.
......@@ -126,6 +128,24 @@ bool NetworkState::PropertyChanged(const std::string& key,
LOG(WARNING) << "Failed to parse dictionary value for: " << key;
}
return true;
} else if (key == flimflam::kUIDataProperty) {
std::string ui_data_str;
if (!value.GetAsString(&ui_data_str)) {
LOG(WARNING) << "Failed to parse string value for:" << key;
return false;
}
onc_source_ = onc::ONC_SOURCE_NONE;
if (ui_data_str.empty())
return true;
scoped_ptr<base::DictionaryValue> ui_data_dict(
onc::ReadDictionaryFromJson(ui_data_str));
if (ui_data_dict)
onc_source_ = NetworkUIData(*ui_data_dict).onc_source();
else
LOG(WARNING) << "Failed to parse dictionary value for: " << key;
return true;
} else if (key == flimflam::kNetworkTechnologyProperty) {
return GetStringValue(key, value, &technology_);
} else if (key == flimflam::kDeviceProperty) {
......@@ -192,8 +212,8 @@ void NetworkState::GetProperties(base::DictionaryValue* dictionary) const {
favorite_);
dictionary->SetIntegerWithoutPathExpansion(flimflam::kPriorityProperty,
priority_);
// Proxy config is intentionally omitted: This property is
// placed in NetworkState to transition proxy configuration from
// Proxy config and ONC source are intentionally omitted: These properties are
// placed in NetworkState to transition ProxyConfigServiceImpl from
// NetworkLibrary to the new network stack. The networking extension API
// shouldn't depend on this member. Once ManagedNetworkConfigurationHandler
// is used instead of NetworkLibrary, we can remove them again.
......
......@@ -10,6 +10,7 @@
#include "base/values.h"
#include "chromeos/network/managed_state.h"
#include "chromeos/network/onc/onc_constants.h"
namespace chromeos {
......@@ -48,6 +49,7 @@ class CHROMEOS_EXPORT NetworkState : public ManagedState {
bool favorite() const { return favorite_; }
int priority() const { return priority_; }
const base::DictionaryValue& proxy_config() const { return proxy_config_; }
onc::ONCSource onc_source() const { return onc_source_; }
// Wireless property accessors
int signal_strength() const { return signal_strength_; }
bool connectable() const { return connectable_; }
......@@ -102,9 +104,10 @@ class CHROMEOS_EXPORT NetworkState : public ManagedState {
bool auto_connect_;
bool favorite_;
int priority_;
// TODO(pneubeck): Remove this property once NetworkConfigurationHandler
// provides proxy configuration. crbug/241775
// TODO(pneubeck): Remove ProxyConfig and ONCSource once
// NetworkConfigurationHandler provides proxy configuration. crbug/241775
base::DictionaryValue proxy_config_;
onc::ONCSource onc_source_;
// IPConfig properties.
// Note: These do not correspond to actual Shill.Service properties
// but are derived from the service's corresponding IPConfig object.
......
......@@ -218,7 +218,7 @@ void ProxyConfig::ClearAutomaticSettings() {
pac_url_ = GURL();
}
base::Value* ProxyConfig::ToValue() const {
base::DictionaryValue* ProxyConfig::ToValue() const {
base::DictionaryValue* dict = new base::DictionaryValue();
// Output the automatic settings.
......
......@@ -170,7 +170,7 @@ class NET_EXPORT ProxyConfig {
// Creates a Value dump of this configuration. The caller is responsible for
// deleting the returned value.
base::Value* ToValue() const;
base::DictionaryValue* ToValue() const;
ProxyRules& proxy_rules() {
return proxy_rules_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment